This program creates level lists using C language. It measures the time taken to look for a value in a level list using two different methods.
- Dichotomic search
- Linear search
We recommend not to exceed 15 levels (= 32768 nodes) for the level list.
We tested for 16 levels (= 65535 nodes): the complete run took over 40 minutes for 10000, 100000 and 1000000 searches.
- Example for 3 levels (zoom out for alignment):
[list head_1 @-]-->[ 1|@-]-->[ 2|@-]-->[ 3|@-]-->[ 4|@-]-->[ 5|@-]-->[ 6|@-]-->[ 7|@-]--> NULL
[list head_2 @-]------------>[ 2|@-]------------>[ 4|@-]------------>[ 6|@-]------------> NULL
[list head_3 @-]-------------------------------->[ 4|@-]--------------------------------> NULL
- Example for 4 levels (zoom out for alignment):
[list head_1 @-]-->[ 1|@-]-->[ 2|@-]-->[ 3|@-]-->[ 4|@-]-->[ 5|@-]-->[ 6|@-]-->[ 7|@-]-->[ 8|@-]-->[ 9|@-]-->[ 10|@-]--> [ 11|@-]-->[ 12|@-]-->[ 13|@-]-->[ 14|@-]-->[ 15|@-]--> NULL
[list head_2 @-]------------>[ 2|@-]------------>[ 4|@-]------------>[ 6|@-]------------>[ 8|@-]------------>[ 10|@-]--- --------->[ 12|@-]------------>[ 14|@-]------------> NULL
[list head_3 @-]-------------------------------->[ 4|@-]-------------------------------->[ 8|@-]------------------------ -------->[ 12|@-]----------------------------------------------------> NULL
[list head_4 @-]------------------------------------------------------------------------>[ 8|@-]------------------------ ------------------------------------------------> NULL
- Compile the program and run it.
- Follow the steps on the screen:
- Enter the number of levels you want to create (number of cells will be automatically computed).
- Choose to display the arrays (values and levels of the cells) or not.
- Choose a format for the list to be printed in.
- Choose a value to look for.
- Enter 3 integers (separated by a space) to define the number of searches to perform.
Enter the max number of levels of the list (1-15 max. recommended):
3Display arrays (value / level) ? (1/0):
0Head inserted.
Insertion finished.Formats :
- Do not display the list
- Aligned
- Not aligned
1
[list head_1 @-]-->[ 1|@-]-->[ 2|@-]-->[ 3|@-]-->[ 4|@-]-->[ 5|@-]-->[ 6|@-]-->[ 7|@-]--> NULL
[list head_2 @-]------------>[ 2|@-]------------>[ 4|@-]------------>[ 6|@-]------------> NULL
[list head_3 @-]-------------------------------->[ 4|@-]--------------------------------> NULLEnter a value to look for:
4Enter 3 integers (separated by a space) to define the number of searches to perform:
10000 500000 2000000Dichotomic search : The value 6 is found.
Time taken to search 1000000 times: [0]ms 0,007sSimple search : The value 6 is found in first line.
Time taken to search 1000000 times: [0]ms 0,009sDichotomic search : The value 6 is found.
Time taken to search 10000000 times: [0]ms 0,054sSimple search : The value 6 is found in first line.
Time taken to search 10000000 times: [0]ms 0,101sDichotomic search : The value 6 is found.
Time taken to search 100000000 times: [0]ms 0,574sSimple search : The value 6 is found in first line.
Time taken to search 100000000 times: [0]ms 1,025s
Please note that for level list containing more than 15 levels (= 32768 nodes), you shouldn't exceed 10000000 searches, otherwise the program will take too much time to run (around 20 minutes).