[MODULE] AVL Tree
Posted: Wed Dec 18, 2019 1:15 pm
Hello at all,
i make a module for manage a AVL tree, its advantage against a linked list is the fast for find a item into it.
For example :
if your have some 6.000.000.000 of records, with a list and its sequential search mode, in the wrong case that will take 6000.000.000 of comparaisons for find a record. With a equilibrate tree and its dicotomique method, in the wrong case will take 33 comparaisons for find the record.
Anyway, that make a cost when you add a record. That take more time with it comparate at a list.
I tried to make a generic module, for this reason we need take some precaution.
You must to create a structure and allocate it dynamically.
You must to create a typical function for compare keys. You give it when you create your tree
you can download my github project with a test with more of 450.000 record.about 25 seconds for load with debugger and 1.21 seconds without deboger the cvs file, but less a millisecond for found a record.
Well for maximize the test performs, disable the debugger
github zip dowload
Prototypes code
Implementation code
Edit : for compare with a list, i added a new file Lk_compare.pb
Result :
For load 0.86 s
For search in the wrong case 65 ms
i make a module for manage a AVL tree, its advantage against a linked list is the fast for find a item into it.
For example :
if your have some 6.000.000.000 of records, with a list and its sequential search mode, in the wrong case that will take 6000.000.000 of comparaisons for find a record. With a equilibrate tree and its dicotomique method, in the wrong case will take 33 comparaisons for find the record.
Anyway, that make a cost when you add a record. That take more time with it comparate at a list.
I tried to make a generic module, for this reason we need take some precaution.
You must to create a structure and allocate it dynamically.
Code: Select all
Structure people
id.l
name.s
EndStructure
Define *p.people
*p = AllocateStructure(people)
Code: Select all
Procedure compare(*a.people,*b.people)
If *a\id > *b\id :ProcedureReturn 1 :EndIf
If *a\id < *b\id :ProcedureReturn -1 :EndIf
ProcedureReturn 0
EndProcedure
Global myTree.AVL_TREE::tree = AVL_TREE::new_tree(@compare())
Well for maximize the test performs, disable the debugger

github zip dowload
Prototypes code
Implementation code
Edit : for compare with a list, i added a new file Lk_compare.pb
Result :
For load 0.86 s
For search in the wrong case 65 ms