lec13 - Lecture 13 Radix search Digital search trees...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Page 1 of 39 CSE 100, UCSD: LEC 13 Lecture 13 Radix search Digital search trees Multiway tries Ternary tries
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Page 2 of 39 CSE 100, UCSD: LEC 13 Whole-key search Consider the usual find operation in a linked list Nodes in the list hold keys The key you are looking for is compared to the key in each node in sequence, until found or until reaching the end of the list Consider the usual find operation in a binary search tree Nodes in the tree hold keys The key you are looking for is compared to the key in the root node; depending on the result of the comparison, the search continues recursively in the left or right subtree, until found or reaching a null reference In each case, when a comparison is done, the entire search key is compared to the key in the current node. (This comparison is usually assumed to take O(1) time. ..) For example, if keys are Strings, all the characters in the search key String may be compared to all the characters in the current node key String ... or if keys are double precision floating point variables, all 64 bits in both keys are used for the comparisons Another approach is possible: each comparison only uses a small piece of the keys This leads to the idea of radix search
Background image of page 2
Page 3 of 39 CSE 100, UCSD: LEC 13 Radix search A key can be considered as a sequence of smaller segments Call each segment a digit Each digit can take on values from some set The size of this set of possible digit values is the base or radix Examples: An int can be considered as a sequence of 32 1-bit digits The radix is 2: each digit can have one of two values An int can be considered as a sequence of 8 4-bit digits The radix is 16: each digit can have one of 16 values A Java String can be considered as a sequence of 16-bit chars The radix is 65536: each digit can have one of 65536 values The idea of radix search is: search is guided by comparisons that involve only one digit of the keys at a time This will have some advantages, but requires somewhat different data structures and algorithms: digital search trees, multiway tries, ternary tries
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Page 4 of 39 CSE 100, UCSD: LEC 13 Digital search trees Digital search trees (DST’s) are binary trees In a DST, both internal nodes and leaf nodes hold keys But, unlike a regular binary search tree, branching when searching a DST is determined by comparing just one bit of the keys at a time (i.e., radix search with radix 2) however: whole-key comparisons are also done The basic search algorithm to find key in a DST: 1. Set currentNode = root, i = 0. 2. If currentNode is null, return "not found." 3. Compare key to currentNode.key. If equal, return "found". 4. Look at the value of the ith bit in key. If 0, set currentNode = currentNode.left; else set currentNode = currentNode.right 5. Set i = i+1 and Go to 2.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/15/2010 for the course CSE CSE100 taught by Professor Kube during the Fall '09 term at UCSD.

Page1 / 39

lec13 - Lecture 13 Radix search Digital search trees...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online