[Include] [INC] some useful data structures
#7

Linear list is kind of structure which is supposed to hold some values connected with each other for easy and fast enumeration (remember foreach from Y_Less, it is internally based on linear list) and it take very small (constant) time for element inserting/removal (as there is no need to find free array slot every time because it has a list of free slots), but O(n) in average when searching, so basically LL is bad for lookups.

The binary tree is another kind of a linked list and more complicated. It is also good for inserting/deletion but VASTLY faster on element retrieval - it takes O(log n) in the worst case if a tree is hardly balanced and O(n) if not. For example, imagine you have an array of 1000 elements and you need to find that one located somewhere at 500th slot; if you search for it linearly, one by one, you must pass though 499 elements before you succeed; but if you use binary tree, you will find it at most in 9 steps! So what is better?

Also take a look at these links, Y_Less said a few words on this subject in his Code Optimisations topic:
http://forum.sa-mp.com/index.php?top...0.0#post_lists
http://forum.sa-mp.com/index.php?top...0.0#post_trees

and these too:
http://en.wikipedia.org/wiki/Linked_list
http://en.wikipedia.org/wiki/Binary_tree
Reply


Messages In This Thread
[INC] some useful data structures - by Zeex - 30.04.2010, 09:35
Re: [INC] stack - by RyDeR` - 30.04.2010, 10:16
Re: [INC] stack - by Onyx09 - 30.04.2010, 10:49
Re: [INC] basic data structures - by Zeex - 03.05.2010, 13:41
Re: [INC] some useful data structures - by Zeex - 10.05.2010, 16:37
Re: [INC] some useful data structures - by ¤Adas¤ - 10.05.2010, 16:52
Re: [INC] some useful data structures - by Zeex - 10.05.2010, 18:02
Re: [INC] some useful data structures - by ¤Adas¤ - 10.05.2010, 18:17

Forum Jump:


Users browsing this thread: 2 Guest(s)