Re: Questions on Using Python to Teach Data Structures and Algorithms




sturlamolden wrote:

Remember that O(1) is not neccesarily faster than O(N)! Unless your
linked list is very big, you will get something called a 'cache miss'
inside your CPU. Thus it is usually more efficient to work with dynamic
arrays.

This was a bit ackwardly formulated. What I was trying to say is that
linked lists produces cache misses rather often, whereas small dynamic
arrays do not. This is because linked lists are not contigous in
memory, in contrast to dynamic arrays. Thus, adding an element to a
dynamic array is in most cases faster, even tough you have to make a
copy the whole array. The same is true when you try do delete some
elements from a list. Small dynamic arrays are faster than linked
lists, because they can be kept in cache. Creating a new array in cache
is faster than tracing after pointers. It is only when dynamic arrays
are to large to fit in cache that linked lists perform better. But in
this case, something like Java's ArrayList is the preferred data
structure.

That is the reason only fools and DSA students use linked lists. They
are a nice teoretical cobnstruct, but not friendly to real-world
computer hardware. Perhaps they were the better option some time in the
past, when CPUs had much less cache and could only accomodate very
short arrays.

.



Relevant Pages

  • Re: Strange behavior while rendering display lists or vertex arrays
    ... GPU's local memory using same order as the cache entries in ... Don't bother with indexed triangle strips, they are waste of time, ... As long as i can i will use them, because they also reduce memory usage (well for Vertex Arrays only the index arrays gets smaller and so bus traffic is reduced, but that also reduces memory needed for Display lists in VRAM). ...
    (comp.graphics.api.opengl)
  • Re: Dominance Tree Sorts
    ... Performance problems with heapsort are often blamed on cache effects. ... This kind of information loss does not occur either quicksort or mergesort. ... Using a simplified analysis of the mergesort cost function we get ... catch is that the references in the linked lists are scattered. ...
    (comp.programming)
  • Re: Dominance Tree Sorts
    ... Performance problems with heapsort are often blamed on cache effects. ... This kind of information loss does not occur either quicksort or mergesort. ... Using a simplified analysis of the mergesort cost function we get ... catch is that the references in the linked lists are scattered. ...
    (comp.theory)
  • Re: should every thing be zero indexed?
    ... >> My guess is that in the casual heap, ... > I now believe these results are due solely to cache behavior when run ... > on large arrays. ... N hsortx1 hsortm husort husort2 ...
    (comp.programming)
  • Re: Strategy for caches & GC
    ... that receives incoming calls and stores/retrieves random information. ... scavenge on approximately 14gb of cache. ... I end up writing manual allocators for byte arrays. ...
    (microsoft.public.dotnet.framework.clr)