1 / 8

SELECTION TREES

SELECTION TREES. Introduction. Suppose we have k ordered sequences, called runs , that are to be merged into a single ordered sequence.

graceland
Download Presentation

SELECTION TREES

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SELECTION TREES

  2. Introduction • Suppose we have k ordered sequences, called runs, that are to be merged into a single ordered sequence. • Each run consists of some records and is in non-decreasing order of a designated field called key. Let n be the number of records in all k runs together. • The merging task can be accomplished by repeatedly outputting the record with the smaller key. The smallest has to be found from k possibilities, and it could be the leading record in any of the k runs.

  3. Cont… • The most direct way to merge k runs is to make k-1 comparisons to determine the next record to output. • For k >2, we can achieve a reduction in the number of comparisons needed to find the next smallest element by using the selection tree data structure. • Ther are two kind of selection trees:

  4. Winner tree • Winner tree is a complete binary tree in which each node represents the smaller of its two children. Thus the root node represents the smallest node in the tree.

  5. cont… • The construction of the winner tree can be compared to the playing of a tournament in which the winner is the record with the smaller key. Then the each non-leaf node in the tree represents the winner of the tournament and the root node represents the overall winner.

  6. Cont… • Each leaf node represents the first record in the corresponding run. Since the records being merged are generally large, each node will contain only a pointer to the record it represents.

  7. Analysis of merging runs using winner trees • The number of levels in the tree is [log2(k+1)]. So the time to restructure the tree is O(log2k). • The tree has to be restructured each time a record is merged in to the output file. Hence the time required to merge all the n records is O(n log2k). • The time required to set up the selection tree the first time is o(k). Thus total time needed to merge the k runs is O(n log2k)

  8. Loser tree • A selection tree in which each non-leaf node retains a pointer to the loser is called a loser tree.

More Related