Data Structures Lecture 11

Total Page:16

File Type:pdf, Size:1020Kb

Data Structures Lecture 11 Fall 2021 Fang Yu Software Security Lab. Data Structures Dept. Management Information Systems, National Chengchi University Lecture 11 Search Trees Binary Search Trees, AVL trees, and Splay Trees 3 Binary Search Trees ¡ A binary search tree is a binary tree storing keys (or key-value ¡ An inorder traversal of a binary entries) at its internal nodes and search trees visits the keys in an satisfying the following increasing order property: ¡ Let u, v, and w be three nodes such that u is in the left subtree of v and w is in the right subtree of v. 6 We have key(u) ≤ key(v) ≤ key(w) 2 9 ¡ External nodes do not store items 1 4 8 4 Search Algorithm TreeSearch(k, v) ¡ To search for a key k, we trace if T.isExternal (v) a downward path starting at the return v root if k < key(v) return TreeSearch(k, T.left(v)) ¡ The next node visited depends else if k key(v) on the comparison of k with the = return v key of the current node else { k > key(v) } ¡ If we reach a leaf, the key is return TreeSearch(k, T.right(v)) not found < 6 ¡ Example: get(4): 2 9 > ¡ Call TreeSearch(4,root) 1 4 = 8 ¡ The algorithms for floorEntry and ceilingEntry are similar 5 Insertion 6 ¡ To perform operation put(k, o), < we search for key k (using 2 9 > TreeSearch) 1 4 8 > ¡ Assume k is not already in the tree, and let w be the leaf w reached by the search 6 ¡ We insert k at node w and expand w into an internal node 2 9 ¡ Example: insert 5 1 4 8 w 5 6 Deletion 6 ¡ To perform operation remove(k), < we search for key k 2 9 > ¡ Assume key k is in the tree, and 1 4 v 8 let v be the node storing k w 5 ¡ If node v has a leaf child w, we remove v and w from the tree with operation removeExternal (w), which removes w and its 6 parent 2 9 ¡ Example: remove 4 1 5 8 7 Deletion (cont.) 1 ¡ We consider the case where the v 3 key k to be removed is stored at a node v whose children are both 2 8 internal 6 9 ¡ we find the internal node w that w follows v in an inorder traversal 5 ¡ we copy key(w) into node v z ¡ we remove node w and its left child z (which must be a leaf) by 1 v means of operation 5 removeExternal(z) 2 8 ¡ Example: remove 3 6 9 8 Performance ¡ Consider n ordered set items implemented by means of a binary search tree of height h ¡ the space used is O(n) ¡ methods get, put and remove take O(h) time ¡ The height h is O(n) in the worst case and O(log n) in the best case We want a balanced binary tree! 9 AVL Tree Definition ¡ AVL trees are balanced 4 ¡ An AVL Tree is a binary 44 search tree such that for 2 3 every internal node v of T, 17 78 the heights of the children of 1 2 1 v can differ by at most 1 32 50 88 1 1 48 62 An example of an AVL tree where the heights are shown next to the nodes: n(2) 3 10 4 n(1) Height of an AVL Tree ¡ Fact: The height of an AVL tree storing n keys is O(log n). ¡ Proof: Let us bound n(h): the minimum number of internal nodes of an AVL tree of height h. ¡ We easily see that n(1) = 1 and n(2) = 2 ¡ For n > 2, an AVL tree of height h contains the root node, one AVL subtree of height n-1 and another of height n-2. ¡ That is, n(h) = 1 + n(h-1) + n(h-2) ¡ Knowing n(h-1) > n(h-2), we get n(h) > 2n(h-2). So n(h) > 2n(h-2), n(h) > 4n(h-4), n(h) > 8n(n-6), … (by induction), n(h) > 2in(h-2i) ¡ Solving the base case we get: n(h) > 2 h/2-1 ¡ Taking logarithms: h < 2log n(h) +2 ¡ Thus the height of an AVL tree is O(log n) AVL Trees 11 Insertion ¡ Insertion is as in a binary search tree ¡ Always done by expanding an external node. ¡ Example: 44 44 c=z 17 78 17 78 a=y 32 50 88 32 50 88 48 62 48 62 b=x 54 w before insertion after insertion After Insertion ¡ All nodes along the path increase their height by 1 ¡ It may violate the AVL property 44 5 44 4 17 78 4 17 78 3 32 50 3 88 32 50 2 88 48 62 2 48 62 1 54 1 Search and repair ¡ Let z be the first violation node from the bottom along the path ¡ Let y be z’child with the higher height (y is 2 greater than its sibling) ¡ Let x be y’s child with the higher height ¡ We rebalance z by calling trinode restructuring method 14 Trinode Restructuring ¡ let (a,b,c) be an inorder listing of x, y, z ¡ perform the rotations needed to make b the topmost node of the three (other two cases a=z a=z are symmetrical) case 2: double rotation (a right rotation about c, c=y then a left rotation about a) b=y T0 T0 c=x b=x T3 T1 b=y b=x T1 T2 T2 T3 a=z c=x a=z c=y case 1: single rotation (a left rotation about a) T0 T1 T2 T3 T0 T1 T2 T3 AVL Trees Restructuring 15 (as Single Rotations) ¡ Single Rotations: a = z single r otation b = y b = y a = z c = x c = x T0 T3 T1 T3 T0 T1 T2 T2 c = z single rotation b = y b = y a = x c = z a = x T3 T3 T0 T2 T2 T1 T0 T AVL Trees 1 Restructuring 16 (as Double Rotations) ¡ double rotations: a = z double rotation b = x c = y a = z c = y b = x T0 T2 T2 T3 T0 T1 T3 T1 c = z double rotation b = x a = y a = y c = z b = x T0 T2 T3 T2 T3 T1 T0 T1 AVL Trees 17 Insertion Example, continued 5 44 2 z 64 17 78 7 2 y 1 3 1 32 1 50 4 88 2 1 x 48 62 1 3 5 54 T3 unbalanced... T T0 2 4 T 1 44 4 2 3 x 17 62 6 2 y z 1 2 2 32 1 50 3 78 7 1 1 5 1 ...balanced 48 54 88 T 2 T0 T 1 T3 AVL Trees 18 Removal ¡ Removal begins as in a binary search tree, which means the node removed will become an empty external node. Its parent, w, may cause an unbalance. ¡ Example: 44 44 17 62 17 62 32 50 78 50 78 48 54 88 48 54 88 before deletion of 32 after deletion AVL Trees 19 Rebalancing after a Removal ¡ Let z be the first unbalanced node encountered while travelling up the tree from w. Also, let y be the child of z with the larger height, and let x be the child of y with the larger height ¡ As this restructuring may upset the balance of another node higher in the tree, we must continue checking for balance until the root of T is reached 62 a=z 44 44 78 w 17 62 b=y 17 50 88 50 78 c=x 48 54 48 54 88 AVL Trees 20 AVL Tree Performance ¡ a single restructure takes O(1) time ¡ using a linked-structure binary tree ¡ get takes O(log n) time ¡ height of tree is O(log n), no restructures needed ¡ put takes O(log n) time ¡ initial find is O(log n) ¡ Restructuring up the tree, maintaining heights is O(log n) ¡ remove takes O(log n) time ¡ initial find is O(log n) ¡ Restructuring up the tree, maintaining heights is O(log n) 21 Splay Tree ¡ a splay tree is a binary search tree where a node is splayed after it is accessed (for a search or update) ¡ deepest internal node accessed is splayed ¡ splay: move the node to the root ¡ splaying costs O(h), where h is height of the tree – which is still O(n) worst-case ¡ O(h) rotations, each of which is O(1) 22 Splay Tree ¡ which nodes are splayed after each operation? method splay node if key found, use that node get(k) if key not found, use parent of ending external node put(k,v) use the new node containing the entry inserted use the parent of the internal node that was actually removed from the tree (the parent of the node that the removed item was remove(k) swapped with) Searching in a Splay Tree: 23 Starts the Same as in a BST (20,Z) (10,A) (35,R) ¡ Search proceeds down the tree (14,J) to found item or an external (7,T) (21,O) (37,P) node. (1,Q) (8,N) (36,L) (40,X) ¡ Example: Search for the item with key 11. (1,C) (5,H) (7,P) (10,U) (2,R) (5,G) (5,I) (6,Y) Splay Trees 24 Example Searching in a BST, continued (20,Z) (10,A) (35,R) ¡ search for key 8, ends at an internal node.
Recommended publications
  • Trees • Binary Trees • Newer Types of Tree Structures • M-Ary Trees
    Data Organization and Processing Hierarchical Indexing (NDBI007) David Hoksza http://siret.ms.mff.cuni.cz/hoksza 1 Outline • Background • prefix tree • graphs • … • search trees • binary trees • Newer types of tree structures • m-ary trees • Typical tree type structures • B-tree • B+-tree • B*-tree 2 Motivation • Similarly as in hashing, the motivation is to find record(s) given a query key using only a few operations • unlike hashing, trees allow to retrieve set of records with keys from given range • Tree structures use “clustering” to efficiently filter out non relevant records from the data set • Tree-based indexes practically implement the index file data organization • for each search key, an indexing structure can be maintained 3 Drawbacks of Index(-Sequential) Organization • Static nature • when inserting a record at the beginning of the file, the whole index needs to be rebuilt • an overflow handling policy can be applied → the performance degrades as the file grows • reorganization can take a lot of time, especially for large tables • not possible for online transactional processing (OLTP) scenarios (as opposed to OLAP – online analytical processing) where many insertions/deletions occur 4 Tree Indexes • Most common dynamic indexing structure for external memory • When inserting/deleting into/from the primary file, the indexing structure(s) residing in the secondary file is modified to accommodate the new key • The modification of a tree is implemented by splitting/merging nodes • Used not only in databases • NTFS directory structure
    [Show full text]
  • Amortized Analysis Worst-Case Analysis
    Beyond Worst Case Analysis Amortized Analysis Worst-case analysis. ■ Analyze running time as function of worst input of a given size. Average case analysis. ■ Analyze average running time over some distribution of inputs. ■ Ex: quicksort. Amortized analysis. ■ Worst-case bound on sequence of operations. ■ Ex: splay trees, union-find. Competitive analysis. ■ Make quantitative statements about online algorithms. ■ Ex: paging, load balancing. Princeton University • COS 423 • Theory of Algorithms • Spring 2001 • Kevin Wayne 2 Amortized Analysis Dynamic Table Amortized analysis. Dynamic tables. ■ Worst-case bound on sequence of operations. ■ Store items in a table (e.g., for open-address hash table, heap). – no probability involved ■ Items are inserted and deleted. ■ Ex: union-find. – too many items inserted ⇒ copy all items to larger table – sequence of m union and find operations starting with n – too many items deleted ⇒ copy all items to smaller table singleton sets takes O((m+n) α(n)) time. – single union or find operation might be expensive, but only α(n) Amortized analysis. on average ■ Any sequence of n insert / delete operations take O(n) time. ■ Space used is proportional to space required. ■ Note: actual cost of a single insert / delete can be proportional to n if it triggers a table expansion or contraction. Bottleneck operation. ■ We count insertions (or re-insertions) and deletions. ■ Overhead of memory management is dominated by (or proportional to) cost of transferring items. 3 4 Dynamic Table: Insert Dynamic Table: Insert Dynamic Table Insert Accounting method. Initialize table size m = 1. ■ Charge each insert operation $3 (amortized cost). – use $1 to perform immediate insert INSERT(x) – store $2 in with new item IF (number of elements in table = m) ■ When table doubles: Generate new table of size 2m.
    [Show full text]
  • Lecture 26 Fall 2019 Instructors: B&S Administrative Details
    CSCI 136 Data Structures & Advanced Programming Lecture 26 Fall 2019 Instructors: B&S Administrative Details • Lab 9: Super Lexicon is online • Partners are permitted this week! • Please fill out the form by tonight at midnight • Lab 6 back 2 2 Today • Lab 9 • Efficient Binary search trees (Ch 14) • AVL Trees • Height is O(log n), so all operations are O(log n) • Red-Black Trees • Different height-balancing idea: height is O(log n) • All operations are O(log n) 3 2 Implementing the Lexicon as a trie There are several different data structures you could use to implement a lexicon— a sorted array, a linked list, a binary search tree, a hashtable, and many others. Each of these offers tradeoffs between the speed of word and prefix lookup, amount of memory required to store the data structure, the ease of writing and debugging the code, performance of add/remove, and so on. The implementation we will use is a special kind of tree called a trie (pronounced "try"), designed for just this purpose. A trie is a letter-tree that efficiently stores strings. A node in a trie represents a letter. A path through the trie traces out a sequence ofLab letters that9 represent : Lexicon a prefix or word in the lexicon. Instead of just two children as in a binary tree, each trie node has potentially 26 child pointers (one for each letter of the alphabet). Whereas searching a binary search tree eliminates half the words with a left or right turn, a search in a trie follows the child pointer for the next letter, which narrows the search• Goal: to just words Build starting a datawith that structure letter.
    [Show full text]
  • Balanced Trees Part One
    Balanced Trees Part One Balanced Trees ● Balanced search trees are among the most useful and versatile data structures. ● Many programming languages ship with a balanced tree library. ● C++: std::map / std::set ● Java: TreeMap / TreeSet ● Many advanced data structures are layered on top of balanced trees. ● We’ll see several later in the quarter! Where We're Going ● B-Trees (Today) ● A simple type of balanced tree developed for block storage. ● Red/Black Trees (Today/Thursday) ● The canonical balanced binary search tree. ● Augmented Search Trees (Thursday) ● Adding extra information to balanced trees to supercharge the data structure. Outline for Today ● BST Review ● Refresher on basic BST concepts and runtimes. ● Overview of Red/Black Trees ● What we're building toward. ● B-Trees and 2-3-4 Trees ● Simple balanced trees, in depth. ● Intuiting Red/Black Trees ● A much better feel for red/black trees. A Quick BST Review Binary Search Trees ● A binary search tree is a binary tree with 9 the following properties: 5 13 ● Each node in the BST stores a key, and 1 6 10 14 optionally, some auxiliary information. 3 7 11 15 ● The key of every node in a BST is strictly greater than all keys 2 4 8 12 to its left and strictly smaller than all keys to its right. Binary Search Trees ● The height of a binary search tree is the 9 length of the longest path from the root to a 5 13 leaf, measured in the number of edges. 1 6 10 14 ● A tree with one node has height 0.
    [Show full text]
  • Assignment 3: Kdtree ______Due June 4, 11:59 PM
    CS106L Handout #04 Spring 2014 May 15, 2014 Assignment 3: KDTree _________________________________________________________________________________________________________ Due June 4, 11:59 PM Over the past seven weeks, we've explored a wide array of STL container classes. You've seen the linear vector and deque, along with the associative map and set. One property common to all these containers is that they are exact. An element is either in a set or it isn't. A value either ap- pears at a particular position in a vector or it does not. For most applications, this is exactly what we want. However, in some cases we may be interested not in the question “is X in this container,” but rather “what value in the container is X most similar to?” Queries of this sort often arise in data mining, machine learning, and computational geometry. In this assignment, you will implement a special data structure called a kd-tree (short for “k-dimensional tree”) that efficiently supports this operation. At a high level, a kd-tree is a generalization of a binary search tree that stores points in k-dimen- sional space. That is, you could use a kd-tree to store a collection of points in the Cartesian plane, in three-dimensional space, etc. You could also use a kd-tree to store biometric data, for example, by representing the data as an ordered tuple, perhaps (height, weight, blood pressure, cholesterol). However, a kd-tree cannot be used to store collections of other data types, such as strings. Also note that while it's possible to build a kd-tree to hold data of any dimension, all of the data stored in a kd-tree must have the same dimension.
    [Show full text]
  • Search Trees
    Lecture III Page 1 “Trees are the earth’s endless effort to speak to the listening heaven.” – Rabindranath Tagore, Fireflies, 1928 Alice was walking beside the White Knight in Looking Glass Land. ”You are sad.” the Knight said in an anxious tone: ”let me sing you a song to comfort you.” ”Is it very long?” Alice asked, for she had heard a good deal of poetry that day. ”It’s long.” said the Knight, ”but it’s very, very beautiful. Everybody that hears me sing it - either it brings tears to their eyes, or else -” ”Or else what?” said Alice, for the Knight had made a sudden pause. ”Or else it doesn’t, you know. The name of the song is called ’Haddocks’ Eyes.’” ”Oh, that’s the name of the song, is it?” Alice said, trying to feel interested. ”No, you don’t understand,” the Knight said, looking a little vexed. ”That’s what the name is called. The name really is ’The Aged, Aged Man.’” ”Then I ought to have said ’That’s what the song is called’?” Alice corrected herself. ”No you oughtn’t: that’s another thing. The song is called ’Ways and Means’ but that’s only what it’s called, you know!” ”Well, what is the song then?” said Alice, who was by this time completely bewildered. ”I was coming to that,” the Knight said. ”The song really is ’A-sitting On a Gate’: and the tune’s my own invention.” So saying, he stopped his horse and let the reins fall on its neck: then slowly beating time with one hand, and with a faint smile lighting up his gentle, foolish face, he began..
    [Show full text]
  • Splay Trees Last Changed: January 28, 2017
    15-451/651: Design & Analysis of Algorithms January 26, 2017 Lecture #4: Splay Trees last changed: January 28, 2017 In today's lecture, we will discuss: • binary search trees in general • definition of splay trees • analysis of splay trees The analysis of splay trees uses the potential function approach we discussed in the previous lecture. It seems to be required. 1 Binary Search Trees These lecture notes assume that you have seen binary search trees (BSTs) before. They do not contain much expository or backtround material on the basics of BSTs. Binary search trees is a class of data structures where: 1. Each node stores a piece of data 2. Each node has two pointers to two other binary search trees 3. The overall structure of the pointers is a tree (there's a root, it's acyclic, and every node is reachable from the root.) Binary search trees are a way to store and update a set of items, where there is an ordering on the items. I know this is rather vague. But there is not a precise way to define the gamut of applications of search trees. In general, there are two classes of applications. Those where each item has a key value from a totally ordered universe, and those where the tree is used as an efficient way to represent an ordered list of items. Some applications of binary search trees: • Storing a set of names, and being able to lookup based on a prefix of the name. (Used in internet routers.) • Storing a path in a graph, and being able to reverse any subsection of the path in O(log n) time.
    [Show full text]
  • Comparison of Dictionary Data Structures
    A Comparison of Dictionary Implementations Mark P Neyer April 10, 2009 1 Introduction A common problem in computer science is the representation of a mapping between two sets. A mapping f : A ! B is a function taking as input a member a 2 A, and returning b, an element of B. A mapping is also sometimes referred to as a dictionary, because dictionaries map words to their definitions. Knuth [?] explores the map / dictionary problem in Volume 3, Chapter 6 of his book The Art of Computer Programming. He calls it the problem of 'searching,' and presents several solutions. This paper explores implementations of several different solutions to the map / dictionary problem: hash tables, Red-Black Trees, AVL Trees, and Skip Lists. This paper is inspired by the author's experience in industry, where a dictionary structure was often needed, but the natural C# hash table-implemented dictionary was taking up too much space in memory. The goal of this paper is to determine what data structure gives the best performance, in terms of both memory and processing time. AVL and Red-Black Trees were chosen because Pfaff [?] has shown that they are the ideal balanced trees to use. Pfaff did not compare hash tables, however. Also considered for this project were Splay Trees [?]. 2 Background 2.1 The Dictionary Problem A dictionary is a mapping between two sets of items, K, and V . It must support the following operations: 1. Insert an item v for a given key k. If key k already exists in the dictionary, its item is updated to be v.
    [Show full text]
  • Search Trees for Strings a Balanced Binary Search Tree Is a Powerful Data Structure That Stores a Set of Objects and Supports Many Operations Including
    Search Trees for Strings A balanced binary search tree is a powerful data structure that stores a set of objects and supports many operations including: Insert and Delete. Lookup: Find if a given object is in the set, and if it is, possibly return some data associated with the object. Range query: Find all objects in a given range. The time complexity of the operations for a set of size n is O(log n) (plus the size of the result) assuming constant time comparisons. There are also alternative data structures, particularly if we do not need to support all operations: • A hash table supports operations in constant time but does not support range queries. • An ordered array is simpler, faster and more space efficient in practice, but does not support insertions and deletions. A data structure is called dynamic if it supports insertions and deletions and static if not. 107 When the objects are strings, operations slow down: • Comparison are slower. For example, the average case time complexity is O(log n logσ n) for operations in a binary search tree storing a random set of strings. • Computing a hash function is slower too. For a string set R, there are also new types of queries: Lcp query: What is the length of the longest prefix of the query string S that is also a prefix of some string in R. Prefix query: Find all strings in R that have S as a prefix. The prefix query is a special type of range query. 108 Trie A trie is a rooted tree with the following properties: • Edges are labelled with symbols from an alphabet Σ.
    [Show full text]
  • Trees, Binary Search Trees, Heaps & Applications Dr. Chris Bourke
    Trees Trees, Binary Search Trees, Heaps & Applications Dr. Chris Bourke Department of Computer Science & Engineering University of Nebraska|Lincoln Lincoln, NE 68588, USA [email protected] http://cse.unl.edu/~cbourke 2015/01/31 21:05:31 Abstract These are lecture notes used in CSCE 156 (Computer Science II), CSCE 235 (Dis- crete Structures) and CSCE 310 (Data Structures & Algorithms) at the University of Nebraska|Lincoln. This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License 1 Contents I Trees4 1 Introduction4 2 Definitions & Terminology5 3 Tree Traversal7 3.1 Preorder Traversal................................7 3.2 Inorder Traversal.................................7 3.3 Postorder Traversal................................7 3.4 Breadth-First Search Traversal..........................8 3.5 Implementations & Data Structures.......................8 3.5.1 Preorder Implementations........................8 3.5.2 Inorder Implementation.........................9 3.5.3 Postorder Implementation........................ 10 3.5.4 BFS Implementation........................... 12 3.5.5 Tree Walk Implementations....................... 12 3.6 Operations..................................... 12 4 Binary Search Trees 14 4.1 Basic Operations................................. 15 5 Balanced Binary Search Trees 17 5.1 2-3 Trees...................................... 17 5.2 AVL Trees..................................... 17 5.3 Red-Black Trees.................................. 19 6 Optimal Binary Search Trees 19 7 Heaps 19
    [Show full text]
  • AVL Tree, Bayer Tree, Heap Summary of the Previous Lecture
    DATA STRUCTURES AND ALGORITHMS Hierarchical data structures: AVL tree, Bayer tree, Heap Summary of the previous lecture • TREE is hierarchical (non linear) data structure • Binary trees • Definitions • Full tree, complete tree • Enumeration ( preorder, inorder, postorder ) • Binary search tree (BST) AVL tree The AVL tree (named for its inventors Adelson-Velskii and Landis published in their paper "An algorithm for the organization of information“ in 1962) should be viewed as a BST with the following additional property: - For every node, the heights of its left and right subtrees differ by at most 1. Difference of the subtrees height is named balanced factor. A node with balance factor 1, 0, or -1 is considered balanced. As long as the tree maintains this property, if the tree contains n nodes, then it has a depth of at most log2n. As a result, search for any node will cost log2n, and if the updates can be done in time proportional to the depth of the node inserted or deleted, then updates will also cost log2n, even in the worst case. AVL tree AVL tree Not AVL tree Realization of AVL tree element struct AVLnode { int data; AVLnode* left; AVLnode* right; int factor; // balance factor } Adding a new node Insert operation violates the AVL tree balance property. Prior to the insert operation, all nodes of the tree are balanced (i.e., the depths of the left and right subtrees for every node differ by at most one). After inserting the node with value 5, the nodes with values 7 and 24 are no longer balanced.
    [Show full text]
  • Leftist Heap: Is a Binary Tree with the Normal Heap Ordering Property, but the Tree Is Not Balanced. in Fact It Attempts to Be Very Unbalanced!
    Leftist heap: is a binary tree with the normal heap ordering property, but the tree is not balanced. In fact it attempts to be very unbalanced! Definition: the null path length npl(x) of node x is the length of the shortest path from x to a node without two children. The null path lengh of any node is 1 more than the minimum of the null path lengths of its children. (let npl(nil)=-1). Only the tree on the left is leftist. Null path lengths are shown in the nodes. Definition: the leftist heap property is that for every node x in the heap, the null path length of the left child is at least as large as that of the right child. This property biases the tree to get deep towards the left. It may generate very unbalanced trees, which facilitates merging! It also also means that the right path down a leftist heap is as short as any path in the heap. In fact, the right path in a leftist tree of N nodes contains at most lg(N+1) nodes. We perform all the work on this right path, which is guaranteed to be short. Merging on a leftist heap. (Notice that an insert can be considered as a merge of a one-node heap with a larger heap.) 1. (Magically and recursively) merge the heap with the larger root (6) with the right subheap (rooted at 8) of the heap with the smaller root, creating a leftist heap. Make this new heap the right child of the root (3) of h1.
    [Show full text]