Presentation is loading. Please wait.

Presentation is loading. Please wait.

SNU IDB Lab. Ch 15. Binary Search Trees © copyright 2006 SNU IDB Lab.

Similar presentations


Presentation on theme: "SNU IDB Lab. Ch 15. Binary Search Trees © copyright 2006 SNU IDB Lab."— Presentation transcript:

1 SNU IDB Lab. Ch 15. Binary Search Trees © copyright 2006 SNU IDB Lab.

2 SNU IDB Lab. Data Structures 2 Bird’s-Eye View (0) Chapter 15: Binary Search Tree BST and Indexed BST Chapter 16: Balanced Search Tree AVL tree: BST + Balance B-tree: generalized AVL tree Chapter 17: Graph

3 SNU IDB Lab. Data Structures 3 Bird’s-Eye View Binary search trees Similar to skip-list Search(), insert(), delete(): 0(log n) search efficiently for keys close to a specified key k: 0(n) Find the largest key k 0(n + D) in hashing, 0(log n) in skip-list Indexed binary search trees BST with a variable leftsize Allow dictionary operations by key value and by rank Ex. Get the element the with 10 th smallest key

4 SNU IDB Lab. Data Structures 4 Table of Contents Binary Search Trees Definition Binary Search Tree Operations and Implementation Binary Search Tree With Duplicates Indexed Binary Search Trees Binary Search Tree Application Histogramming Best-Fit Bin Packing Crossing Distribution

5 SNU IDB Lab. Data Structures 5 Binary Search Tree (1) A binary search tree is a binary tree that may be empty. A nonempty binary search tree satisfies the following properties. 1. Every element has a key(or value), and no two elements have the same keys; therefore, all keys are distinct. 2. The keys (if any) in the left subtree of the root are smaller than the key in the root. 3. The keys (if any) in the right subtree of the root are larger than the key in the root. 4. The left and right subtrees of the root are also binary search trees.

6 SNU IDB Lab. Data Structures 6 Binary Search Tree (2) 20 1218 15 25 22 30 40 5 2 60 70 80 65 Not Binary Search Trees (fail to Property 4) Binary Search Trees

7 SNU IDB Lab. Data Structures 7 Break time Chap 12: Binary Tree and Complete Binary Tree Chap 13: Heap Heap is a complete binary tree with some properties RemoveTop of Heap gives you “sorting” Chap 14: Tournament Tree Tournament tree is a complete binary tree with some properties Remove & Replay of Tournament tree gives you “sorting” Chap 15: Binary Search Tree BST is a binary tree with some properties (not necessarily CBT) Inorder traversal of BST gives you “sorting” Can be skewed and unbalanced  so, chap 16 (Balanaced Tree)

8 SNU IDB Lab. Data Structures 8 Indexed Binary Search Tree An indexed binary search tree is derived from an ordinary binary search tree by adding the field leftSize to each tree node leftSize: size of the left subtree Allow dictionary operations by key value and by rank Ex. Get the element the with 10 th smallest key 20 1218 15 25 22 30 40 5 2 3 1 0 0 0 0 2 1 0 0

9 SNU IDB Lab. Data Structures 9 The ADT BSTree & IndexedBSTree AbstractDataType BSTree { operations get(k) : return the element with key k put(k,x) : put element x with key k into the search tree remove(k) : remove the element with key k and return it ascend() : output all elements in ascending order of key } AbstractDataType IndexedBSTree { operations get(k) : return the element with key k get(index) : return the indexth element put(k,x) : put element x with key k into the search tree remove(k) : remove the element with key k and return it remove(index) : remove the indexth element and return it ascend() : output all elements in ascending order of key }

10 SNU IDB Lab. Data Structures 10 One more review on Interfaces The interface Dictionary { get(k), put(k,x), remove(k) } The interface BinaryTree { isEmpty(), root(), makeTree(root, left, right), removeLsubtree(), removeRsubtree(), preOrder(), inOrder(), postOrder(), levelOrder() } Public interface BSTree extends Dictionary { public void ascend(); } Public interface IndexedBSTree extends BSTree { public Object get(int index); public Object remove(int index); }

11 SNU IDB Lab. Data Structures 11 The Class BinarySearchTree (1) The subclass: java.lang.Object  dataStructures.LinkedBinaryTree Implements BinaryTree interface sEmpty(), root(), makeTree(root, left, right), removeLsubtree(), removeRsubtree(), preOrder(), inOrder(), postOrder(), levelOrder() The interface: BSTree (also from Dictionary) get(key), put(key,index), remove(key), ascend(); public class BinarySearchTree extends LinkedBinaryTree implements BSTree extends BinaryTree interface implements Dictionary interface

12 SNU IDB Lab. Data Structures 12 The Class BinarySearchTree (2) Each Element of BST static class Data { Object element; Comparable key;... } The method BinarySearchTree.ascend() public void ascend() { inOrderOutput(); // LinkedBinaryTree.inOrderOutput() } Complexity of inOrderOutput() = O( n ) for an n-element tree

13 SNU IDB Lab. Data Structures 13 Searching an Element in BST Wish to Search for thekey from root to leaf If (root == null) search is unsuccessful; else if (thekey < key in root) only left subtree is to be searched; else if (thekey > key in root) only right subtree is to be searched; else (thekey == key in root) search terminates successfully; Subtrees may be searched similarly in a recursive manner TimeComplexity = O(height)

14 SNU IDB Lab. Data Structures 14 Inserting an Element in BST First perform a search for theKey successful  replace the old element with new one unsuccessful  new element is inserted as a child of the last node examined during the search To Put an element with key 80 30 40 5 2 35 80 To Put an element with key 35

15 SNU IDB Lab. Data Structures 15 Deleting an element in BST Case 1: If node p is in a leaf  discard the leaf Case 2: If node p is in a degree 1 node If p has no parent  the root of its single subtree becomes the new search tree root If p has parent  change the pointer from parent so that it points to p’s only child Case 3: If node p has two nonempty subtrees Replace this element with the largest element in its left subtree or the smallest element in its right subtree TimeComplexity = O(height)

16 SNU IDB Lab. Data Structures 16 Deleting an Element: Ex 1 Remove the element with key 40 Option1: the smallest element in the right subtree takes the position of the deleted element 30 60 5 2 3580 32 3133 85 30 40 5 2 3580 32 3133 8560

17 SNU IDB Lab. Data Structures 17 Deleting an Element: Ex 2 Remove the element with key 40 Option2: the largest element in the left subtree takes the position of the deleted element 30 40 5 2 3580 32 3133 85 30 5 2 3580 32 3133 8560 30 60 5 2 35 80 3285 30 35 5 2 32 80 31338560

18 SNU IDB Lab. Data Structures 18 Deleting an Element: Ex 3 Remove the element with key 30 Option1: the largest element in the left subtree becomes the root 30 60 5 2 35 80 3285 30 35 5 2 32 80 31338560 30 60 35 80 3285 5 35 2 32 80 31338560

19 SNU IDB Lab. Data Structures 19 Deleting an Element: Ex 4 Remove the element with key 30 Option2: the smallest element in the right subtree becomes the root 30 60 5 2 35 80 3285 30 35 5 2 32 80 31338560 30 60 5 2 35 80 85 31 35 5 2 32 80 338560

20 SNU IDB Lab. Data Structures 20 Height of a Binary Search Tree Worst case Height of a binary search tree with n element can become as large as n key[1,2,3…n] in this order 0(n) Average case O(logn)

21 SNU IDB Lab. Data Structures 21 Binary Search Tree with Duplicates Permitted to contain two or more elements that have the same key Same key elements goes to the left subtree So, n elements with same key  left-skewed BST whose height n We can build the new class DBinarySearchTree easily while (p != null) { pp = p; if (elementKey.compareTo(((Data) pp.element).key) <= 0) p = p.leftChild; else p = p.rightChild; }

22 SNU IDB Lab. Data Structures 22 Table of Contents Binary Search Trees Definition Binary Search Tree Operations and Implementation Binary Search Tree With Duplicates Indexed Binary Search Trees Binary Search Tree Application Histogramming Best-Fit Bin Packing Crossing Distribution

23 SNU IDB Lab. Data Structures 23 Indexed Binary Search Tree BST with a variable leftsize Allow dictionary operations by key value and by rank Ex. Get the element the with 10 th smallest key 20 1218 15 25 22 30 40 5 2 3 1 0 0 00 2 1 0 0

24 SNU IDB Lab. Data Structures 24 Search in Indexed BST Looking for the element whose rank is 3 LeftSize field of the root(20) is 3 So the element we desire is in the left subtree of 20 LeftSize field of the root(15) is 1 So the element we desire is in the right subtree of 15 So the element whose rank is 3 is 18 20 1218 15 25 22 3 1 0 0 0 0

25 SNU IDB Lab. Data Structures 25 Table of Contents Binary Search Trees Definition Binary Search Tree Operations and Implementation Binary Search Tree With Duplicates Indexed Binary Search Trees Binary Search Tree Application Histogramming Best-Fit Bin Packing Crossing Distribution

26 SNU IDB Lab. Data Structures 26 Histogramming (1) A collection of n keys and must output a list of the distinct keys and the number of times each occurs in the collection.

27 SNU IDB Lab. Data Structures 27 Histogramming (2) keys [2, 4, 2, 2, 3, 4, 2, 6, 4, 2] N 개 Input int[] h = new int[r+1] 123456 01130 5 0 0

28 SNU IDB Lab. Data Structures 28 Simple Histogramming code using Integer Array public class SimpleHistogramming { public static void main(String[] args) { int n = keyboad.readInteger(); //number of elements int r = keyboad.readInteger(); //between 0 or r int[] h = new int[r + 1]; // declaring histogram table for(int i=1; i <= n; i++) { System.out.println(“Enter element “ + i); h[keyboad.readInteger()]++; } System.out.println(“Output histogram”); for(int i=0; i <= r; i++) if(h[i] != 0) System.out.println(i + “ “ + h[i]); }

29 SNU IDB Lab. Data Structures 29 Histogramming with a BST (1) public class BSTWithVisit extends BST { public void put (Object theKey, Object theElement, Method theVisit) { if (no element with key equal to theKey) put theElement into the search tree Else method theVisit(e) is invoked; } } public class Histogramming { // top-level member class public static class ElementType { …. } // static data member static method add1; // static initializer static { …} // increment the count of e by 1 public static void add1(object e) { ((ElementType) e).count++; } }

30 SNU IDB Lab. Data Structures 30 Histogramming with a BST (2) public static void main(String [] args) { BSTWithVisit theTree = new BSTWithVisit(); for (int i = 1; i <= n; i++) { ElementType e = new ElementType (keyboard.readInteger()); theTree.put(new MyInteger(e.key), e, theAdd1); } // output distinct elements and their counts theTree.ascend(); }

31 SNU IDB Lab. Data Structures 31 Histogramming with BST (1) Input [2, 4, 2, 2, 3, 4, 2, 6, 4, 2] Blue number :key, Red Number :count 2121 2121 4141 2222 4141 2323 4141 2323 4141 3131 1) 2)3)4) 5)

32 SNU IDB Lab. Data Structures 32 Histogramming with BST (2) 6)7) 8) 2323 4242 3131 2424 4242 3131 2424 4242 3131 6161 9) 2424 4343 3131 6161 10) 2525 4343 3131 6161 Input [2, 4, 2, 2, 3, 4, 2, 6, 4, 2] Blue number :key, Red Number :count

33 SNU IDB Lab. Data Structures 33 Table of Contents Binary Search Trees Indexed Binary Search Trees Binary Search Tree Application Histogramming Best-Fit Bin Packing Crossing Distribution

34 SNU IDB Lab. Data Structures 34 Best-Fit Bin Packing Object I is packed into the bin with the least unusedCapacity that is at least objectSize[I] To pack n objects into bins of capacity c in the following manner If (find the best bin for i from search tree) delete it from the BST reduce its unused capacity by objectSize[i] reinsert it into the BST Else // (not find a bin with enough capacity) start a new bin & insert the new bin into a BST Implementation By using a binary search tree with duplicates O(nlogn) By using a balanced search tree such as AVL worst case Θ(nlogn)

35 SNU IDB Lab. Data Structures 35 Best-Fit Bin Packing Example (1) The object O is packed into 9 bins (a, b, … g, h, i) The unused capacity of the bins forms a binary search tree for 9 bins If ObjectSize[O] is 4, we want a bin whose unused size is slightly over 4

36 SNU IDB Lab. Data Structures 36 Best-Fit Bin Packing Example (2) When a new object O that is to be packed requires 4 Units At bin h : unused size = 6, so object O fit into bin h; the candidate  bin h & move to the left subtree At bin b : unused size = 3, so not adequate; move to the right subtree At bin i : unused size = 5, so object O fit into bin i; the candidate  bin i Subtree is empty: the bin search terminates with the candidate bin i

37 SNU IDB Lab. Data Structures 37 Best-Fit Bin Packing Example (3) When a new object I that is to be packed requires 7 Units At bin h : unused size = 6, so not adequate; move to the right subtree At bin c : unused size = 12, so object I fit into bin c; the candidate = bin c; move to the left subtree At bin d : unused size = 6, so not adequate; move to the right subtree At bin e : unused size = 8, so object I fit into bin e; the candidate = bin e Subtree is empty : the bin search terminates with the candidate bin e

38 SNU IDB Lab. Data Structures 38 getGreaterThanOrEqual() in The class DBinarySearchTreeWithGE // GE stands for GreaterThanEqualTo public class DBinarySearchTreeWithGE extends DBinarySearchTree { public Object getGreaterThanOrEqual (Object thekey) { BinaryTreeNode currentNode = root; Object bestElement = null; // element with smallest key >= theKey found so far while(currentNode != null) { if (key in currentNode >= theKey) { bestElement = currentNode.element; currentNode = currentNode.leftChild; } else currentNode.rightChild; } return bestElement; }

39 SNU IDB Lab. Data Structures 39 bestFitPack() in DBinaryTreeSearchTreeWithGE public static void bestFitPack(in t [] ObjectSize, int binCapacity){ int n = objectSize.length – 1; int binsUsed = 0; DBinaryTreeSearchTreeWithGE theTree = new DBinaryTreeSearchTreeWithGE; for (int i = 1; i <= n; i++) { BinNode bestBin = (BinNode) theTree.getGreaterThanOrEqual (new Integer(ObjectSize[i])); if (bestBin == null) // start with a new bin bestBin = new BinNode(++binUsed, binCapacity); else // delete the best bin from the BST bestBin = (BinNode)theTree.remove(new Integer(bestBin.unusedCapacity); // reinsert the best bin with new unused capacity into the BST bestBin.unusedCapacity -= objectSize[i]; if (bestBin.unusedCapacity > 0) theTree.put(new Integer(bestBin.unusedCapacity), bestBin); }

40 SNU IDB Lab. Data Structures 40 Table of Contents Binary Search Trees Indexed Binary Search Trees Binary Search Tree Application Histogramming Best-Fit Bin Packing Crossing Distribution

41 SNU IDB Lab. Data Structures 41 Crossing Distribution Routing channel with n pins on both the top and bottom of the channel An wire Wi connects one top pin i and one bottom pin Ci Wire Wi is to the left of wire Wj iff Wi < Wj If this is the case for circuit design, wire crossing can cause a short circuit We want to minimize the number of crossings Let Ki be the number of pairs (Wi, Wj) such that wire Wi and wire Wj cross each other

42 SNU IDB Lab. Data Structures 42 Channel Routing and Crossings: i = top pin num & K i = crossing num (1) 12345678910 0 ikiki Crossingsikiki 172 3 4 5 6 8 1060 263 4 5 6 8 10728 10 334 6 880 4169110 526 7100 Fig 15.7 C=[8,7,4,2,5,1,9,3,10,6]

43 SNU IDB Lab. Data Structures 43 Channel Routing and Crossings: i = top pin num & K i = crossing num (2) 12345678910 0 ikiki Crossingsikiki 172 3 4 5 6 8 1060 263 4 5 6 8 10728 10 334 6 880 4169110 526 7100

44 SNU IDB Lab. Data Structures 44 Channel Routing and Crossings : i = top pin num & K i = crossing num (3) 12345678910 0 ikiki Crossingsikiki 172 3 4 5 6 8 1060 263 4 5 6 8 10728 10 334 6 880 4169110 526 7100

45 SNU IDB Lab. Data Structures 45 Channel Routing and Crossings : i = top pin num & K i = crossing num (4) 12345678910 0 ikiki Crossingsikiki 172 3 4 5 6 8 1060 263 4 5 6 8 10728 10 334 6 880 4169110 526 7100

46 SNU IDB Lab. Data Structures 46 Channel Routing and Crossings : i = top pin num & K i = crossing num (5) 12345678910 0 ikiki Crossingsikiki 172 3 4 5 6 8 1060 263 4 5 6 8 10728 10 334 6 880 4169110 526 7100

47 SNU IDB Lab. Data Structures 47 Distributing the Crossings Given the crossings, a special care must be taken at the crossing points For example, putting an insulator As such, distributing the crossings within the channel is meaningful To balance the routing complexity in the top and lower halves of the channel The top (bottom) half should have k/2 crossings In Fig15.7, the sum of crossings  K = 22 In Fig15.9, we have exactly 11 crossings in each half of the channel Idea: Splitting the crossings

48 SNU IDB Lab. Data Structures 48 Splitting the crossings (1) Fig 15.9 1234567891 0 Fig 15.7 ikiki Crossingsikiki 172 3 4 5 6 8 1060 263 4 5 6 8 10728 10 334 6 880 4169110 526 7100

49 SNU IDB Lab. Data Structures 49 Splitting the crossings (2) Top Pin = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Permutation A = [1, 4, 6, 3, 7, 2, 9, 5, 10, 8] // from top line to center line Center Pin = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Permutation B = [8, 1, 2, 7, 3, 4, 5, 6, 9, 10] // from center line to bottom line C i = B Ai, 1 ≤ i ≤ n // from top line to bottom line Fig 15.9 1234567891 0 Fig 15.7

50 SNU IDB Lab. Data Structures 50 Splitting the crossings (3) ikiki BiBi Crossingsikiki BiBi 1 0 1 60 2 2 2 4 4 672 9 8 10 3 3 6 4 6 880 5 4 1 3 691 10 5 2 7 6 8100 8 ikiki CiCi Crossingsikiki CiCi 17 8 2 3 4 5 6 8 1060 4 20 1 70 5 30 2 80 6 44 7 5 6 7 890 9 50 3 100 Top K = 11 Bottom K = 11

51 SNU IDB Lab. Data Structures 51 Crossing Distribution Algorithm Goal Given C (the original permutation) & K (the total # of crossings), We develop an algorithm to compute the permutations A and B So that the top half of the channel has k/2 crossings Time Complexity The crossing numbers ki and the total # of crossings K can be computed in Θ(n^2) time By examining each wire pair (i, j) The partitioning of C into A and B can then be computed in O(n^2) time By using an ArrayLinearList

52 SNU IDB Lab. Data Structures 52 Crossing Distribution using a Linear List (1) // create data structures ArrayLinearList list = new ArrayLinearList(n); int [] theA = new int [n + 1]; // top-half permutation int [] theB = new int [n + 1]; // bottom-half permutation int [] theX = new int [n + 1]; // center connections int crossingsNeeded = theK / 2; // remaining num of crossings needed in top half int[] theA = new int[n+1] 123……. int[] theB = new int[n+1] 123……. int[] theC = new int[n+1] 123…….

53 SNU IDB Lab. Data Structures 53 Crossing Distribution using a Linear List (2) // scan wires right to left int currentWire = n; while (crossingsNeeded > 0) { // need more crossings in top half if (k[currentWire] < crossingsNeeded) { // use all crossings from currentWire list.add(k[currentWire], new Integer(currentWire)); crossingsNeeded -= k[currentWire]; } else { // use only crossingsNeeded crossings from currentWire list.add(crossingsNeeded, new Integer(currentWire)); crossingsNeeded = 0; } currentWire--; } // determine wire permutation at center for (int i = 1; i <= currentWire; i++) theX[i] = i; // first currentWire wires have same ordering for (int i = currentWire + 1; i <= n; i++) // ordering of remaining wires is from list theX[i] = ((Integer) list.get(i - currentWire - 1)).intValue(); for (int i = 1; i <= n; i++) theA[theX[i]] = i; // compute top-half permutation for (int i = 1; i <= n; i++) theB[i] = theC[theX[i]]; // compute bottom-half permutation

54 SNU IDB Lab. Data Structures 54 Counting the number of Crossings using Indexed BST (1) Examine the wires in the order n, n-1,…,1 Put C i into indexed binary search tree 6 1 (a) 12345678910 0 Examine wire 10 & insert C 10 = 6 into an empty tree - The # outside the node: its leftSize value - The # inside the node: its key (or C value) k 10 = 0 (because there is no left subtree

55 SNU IDB Lab. Data Structures 55 Counting the number of Crossings using Indexed BST (2) 12345678910 0 Examine wire 9 & insert C 9 = 10 into the tree Pass over the root that has leftSize =1 From leftSize, we know that wire 9’s bottom endpoint is to the right of exactly one of the wires seen so far So, k 9 = 1 (k 10 = 0, k 9 = 1 ) 6 1 10 1 (b)

56 SNU IDB Lab. Data Structures 56 Counting the number of Crossings using Indexed BST (3) 12345678910 0 Examine wire 8 & insert C 8 = 3 into the tree Since C 8 is the smallest entry in the tree, no wires are crossed So, k 8 = 0 because there is no left subtree of node 3 (K 10 = 0, K 9 = 1, K 8 = 0) 6 2 10 1 3 1 (c)

57 SNU IDB Lab. Data Structures 57 Counting the number of Crossings using Indexed BST (4) 12345678910 0 Examine wire 7 & insert C 7 = 9 into the tree Determine that C 7 is the 3 rd -smallest entry by keeping a running sum of the lefeSize values of the nodes whose right subtree we enter Since C 7 is the 3 rd -smallest entry in the tree, we conclude that its bottom endpoint is to the right of two others in the tree So, k 7 = 2 (K10 = 0, K9 = 1, K8 = 0, K7 = 2) 6 2 10 2 3 1 9 1 (d)

58 SNU IDB Lab. Data Structures 58 Counting the number of Crossings using Indexed BST (5) 6 3 10 2 3 2 9 1 1 1 6 4 2 3 2 9 1 1 1 5 1 6 5 2 3 3 9 1 1 1 5 1 2 1 (e) (f) (g)

59 SNU IDB Lab. Data Structures 59 Counting the number of Crossings using Indexed BST (6) 6 6 10 2 3 3 9 1 1 1 5 2 2 1 4 1 6 6 3 3 3 9 2 1 1 5 2 2 1 4 1 7 1 (h) (i)

60 SNU IDB Lab. Data Structures 60 Counting the number of Crossings using Indexed BST (7) 12345678910 0 Finally, examine wire 1 & insert C 1 = 8 into the tree The sum of the lefeSize values of the nodes whose right subtree we enter is 6 + 1 = 7 Wire 1 has a bottom endpoint that is to the right of seven of the wires in the tree So, k 1 = 7 ( K10 = 0, K9 = 1, K8 = 0, K7 = 2, K6 = 0, K5 = 2, K4 = 1, K3 = 3, K2 = 6, K1 = 7) 6 6 10 4 3 3 9 3 1 1 5 2 2 1 4 1 8 1 (j) 7 1

61 SNU IDB Lab. Data Structures 61 12345678910 0 We get (h) after 9 crossings (less than 11 crossings). Inorder traversal of (h) yields (1, 2, 3, 4, 5, 6, 9, 10) which are points in the bottom line. We get (6, 4, 8, 3, 5, 10, 7, 9) from bottom line to top line Insert wire s=2 after the second wire in the sequence to get the new wire sequence (6,4,2,8,3,5,10,7,9) The remaining wires 1 through s-1 are added at the front to obtain (1,6,4,2,8,3,5,10,7,9) theA and theB may obtained from theX for (int i = 1; i <= n; i++) theB[i] = theC[theX[i]]; // compute bottom-half permutation Crossing Distribution using Indexed BST (8)

62 SNU IDB Lab. Data Structures 62 Summary (0) Chapter 15: Binary Search Tree BST and Indexed BST Chapter 16: Balanced Search Tree AVL tree: BST + Balance B-tree: generalized AVL tree Chapter 17: Graph

63 SNU IDB Lab. Data Structures 63 Summary (1) Binary search trees Similar to skip-list Search(), insert(), delete(): 0(log n) search efficiently for keys close to a specified key k: 0(n) Find the largest key k 0(n + D) in hashing, 0(log n) in skip-list Indexed binary search trees BST with a variable leftsize Allow dictionary operations by key value and by rank Ex. Get the element the with 10 th smallest key

64 SNU IDB Lab. Data Structures 64 Sahni class: dataStructures.BinarySearchTree(p.572) public class BinarySearchTree extends LinkedBinaryTree { constructors BinarySearchTree(): Constructs an empty binary search tree methods Object get(Object key): Returns the node containing key Object put(Object key, Object value): Inserts value with key as the key Object remove(Object key): Removes the node containing key }


Download ppt "SNU IDB Lab. Ch 15. Binary Search Trees © copyright 2006 SNU IDB Lab."

Similar presentations


Ads by Google