Download presentation
Presentation is loading. Please wait.
Published byMallory Ashurst Modified over 9 years ago
1
1 Pertemuan 12 Binary Search Tree Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1
2
2 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Mahasiswa dapat menghasilkan program modular untuk mengimplementasikan binary search tree
3
3 Outline Materi Pengertian Binary search tree Contoh Binary search tree inserting data dalam binary search tree deleting data dalam binary search tree contoh program implementasi
4
4 Binary Search Tree (BST) is Binary Tree that hasthe following properties : –Every element has a key, and no elements have the same key. –The key in a nonempty left subtree must be smaller than the key in the root of subtree. –The key in a nonempty right subtree must be larger than the key in the root of subtree. –The left and right subtrees are also BST. Benefit : BST has better performance in Insertion, Deletion, Searching. Searching : 1.Start from the rot node. 2.If the key is equal, searching is terminated. Otherwise,compare with the root’s key : a.If the key is less than root’s key then move to Left Subtree b.If the key is larger than root’s key then move to Right Subtree Binary Search Tree (BST) 54 3070 20 3560 Binary Search Tree
5
5 Insert Operation on Binary Search Tree 54 70 60 Insert(54) 54 70 Insert(70)Insert(60)
6
6 Delete Leaf as target node, no replacing for target node. Non Leaf node and target node has single child, the child replaces target node Non Leaf node and target node has many descendants, target node will be replaced by one of elements from : Left subtree that has largest element. Right subtree that has smallest element. Operation on Binary Search Tree 54 3070 20 3560 65 After Delete(65) 54 3070 20 3560 Before Delete(65)
7
7 Operation on Binary Search Tree 54 3070 20 3560 65 After Delete(60) 54 3070 20 3565 Before Delete(60) 54 3070 20 3560 65 After Delete(54) 60 3070 20 3565 Before Delete(54) After Delete(54) 35 3070 20 60 65
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.