The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998 The.Algorithm.Design.Manual.Springer-Verlag.1998

18.04.2013 Views

Binary Search Trees From an algorithm design viewpoint, it is most important to know that these trees exist and that they can be used as black boxes to provide an efficient dictionary implementation. When figuring the costs of dictionary operations for algorithm analysis, assume the worst-case complexities of balanced binary trees to be a fair measure. Next: Priority Queues Up: Fundamental Data Types Previous: Dictionaries Algorithms Mon Jun 2 23:33:50 EDT 1997 file:///E|/BOOK/BOOK/NODE26.HTM (3 of 3) [19/1/2003 1:28:24]

Priority Queues Next: Specialized Data Structures Up: Fundamental Data Types Previous: Binary Search Trees Priority Queues Many algorithms process items according to a particular order. For example, suppose you have to schedule a list of jobs given the deadline by which each job must be performed or else its importance relative to the other jobs. Scheduling jobs requires sorting them by time or importance, and then performing them in this sorted order. Priority queues provide extra flexibility over sorting, which is required because jobs often enter the system at arbitrary intervals. It is much more cost-effective to insert a new job into a priority queue than to re-sort everything. Also, the need to perform certain jobs may vanish before they are executed, meaning that they must be removed from the queue. The basic priority queue supports three primary operations: ● Insert(Q,x): Given an item x with key k, insert it into the priority queue Q. ● Find-Minimum(Q) or Find-Maximum(Q): Return a pointer to the item whose key value is smaller (larger) than any other key in the priority queue Q. ● Delete-Minimum(Q) or Delete-Maximum(Q) - Remove the item from the priority queue Q whose key is minimum (maximum). Figure: The maximum and minimum element in a binary search tree All three of these priority queue operations can be implemented in time by representing the heap with a binary search tree. Implementing the find-minimum operation requires knowing where the minimum element in the tree is. By definition, the smallest key must reside in the left subtree of the root, since all keys in the left subtree have values less than that of the root. Therefore, as shown in Figure , the minimum element must be the leftmost decendent of the root. Similarly, the maximum element must be the rightmost decendent of the root. Find-Maximum(x) Find-Minimum(x) while do x = left[x] return x while return x file:///E|/BOOK/BOOK/NODE27.HTM (1 of 2) [19/1/2003 1:28:25] do x = right[x]

Binary Search Trees<br />

From an algorithm design viewpoint, it is most important to know that these trees exist and that they can<br />

be used as black boxes to provide an efficient dictionary implementation. When figuring the costs of<br />

dictionary operations for algorithm analysis, assume the worst-case complexities of balanced binary trees<br />

to be a fair measure.<br />

Next: Priority Queues Up: Fundamental Data Types Previous: Dictionaries<br />

<strong>Algorithm</strong>s<br />

Mon Jun 2 23:33:50 EDT 1997<br />

file:///E|/BOOK/BOOK/NODE26.HTM (3 of 3) [19/1/2003 1:28:24]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!