Author: Jonah ThomasJonah Thomas Date: Sep 3, 2008 16:09
mhx@iae.nl (Marcel Hendrix) wrote:
> Let's see. Both schemes (a = keep sorted, b = search) can cache the
> current minimum, so searching candidates is equally fast.
Yes, and if you can find any way to speed up that part it can
potentially make a big difference. It happens about a million times and
the rest happens much fewer.
> If scheme a keeps a sorted array, it will need 4 compares and about
> 128 memory moves to insert a new element.
Are you figuring a maximum of 8 compares and so 4 compares on average?
But half the time it takes 8 compares, 1/4 the time it takes 7, 1/8 the
time it takes 6, etc.
> If it uses a linked list,
> there would be no moves, but 128 compares and maybe 3 writes (are
> there algorithms to do a binary search in a linked list?).
You can build a binary tree with linked lists but then it isn't just a
linked list -- you have to rebuild the tree.
3 writes? Because you have the list ordered. That looks like a good
trade, 2 extra writes to avoid on average 128 compares.
> I guess the linked list will be faster than an array.
|