110 likes | 221 Views
Average Number of Probes Successful Search. A. E. S. C. H. R. Digital Search Example. A 00001 S 1 0011 E 0 0101 R 10 010 C 00 011 H 01 000. Radix Trie Example. A 0000 1 S 10011 E 001 01 R 10010 C 0001 1 H 01 000. H. E. A. C. S. R. i=0; p=root;
E N D
A E S C H R Digital Search Example A 00001 S 10011 E 00101 R 10010 C 00011 H 01000
Radix Trie Example A 00001 S 10011 E 00101 R 10010 C 00011 H 01000 H E A C S R
i=0; p=root; While not inserted if (end of word K reached) set end-of-word marker in p to true else if (p.ptrs[K[i]] == null) create leaf containing K and put its address in p.ptrs[K[i]] else if (refernce p.ptrs[k[i]] refers to a leaf) K_L = key in leaf p.ptrs[K[i]]; do create a non-leaf and put its address in p.ptrs[K[i]] p = the new non-leaf; while (K[i] == K_L[i++]; create a leaf containing K and put its address in p.ptrs[K[--i]] if (end-of-word K reached) set end-of-word marker in p to true else create leaf containing K_L and put address in p.ptrs[K_L[i]] else p = p.ptrs[K[i++]]
Empty Trie Insert “ARA” # A E I P R ARA
# A E I P R ARA # A E I P R P # A E I P R P # A E I P R K_L K ARA AREA Insert “AREA”
# A E I P R Insert “A” P P # A E I P R A # A E I P R ARA AREA
# A E I P R # A E I P R # A E I P R # A E I P R # A E I P R # A E I P R PIER EIRE IPA IRE EERIE A # A E I P R # A E I P R ARA # A E I P R ERA ERIE ERE PEER ARE PEAR PER AREA
A L Radix Tree O ADAM G G E I A N D R LOGGIA LOGGING LOGGED LOGGERHEAD
A L N E A 0 0 0 Patricia Tree 0 4 ADAM I 0 D R 0 0 LOGGIA LOGGING LOGGERHEAD LOGGED
Radix Sort using Counts The Queues can be avoided by using counts. M=2^m, sorting on rightmost w bits: void RadixSort(int a[], int b[], int N) { int i, j, pass, count[M]; for (pass=0; pass < w/m; pass++) { for (j=0; j < M; j++) count[j] = 0; for (i=1; i <= N; i++) count[a[i].bits(pass*m, m)]++; for (j=1; j < M; j++) count[j] = count[j-1] + count[j]; for (i=N; i >= 1; i--) b[count[a[i].bits(pass*m, m)]--] = a[i]; for (i=1; i <= N; i++) a[i] = b[i]; } }