Lecture 11 Binary Search Tree Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.

21
Data Structure Lecture 11 Binary Search Tree Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1

Transcript of Lecture 11 Binary Search Tree Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.

  • Slide 1

Lecture 11 Binary Search Tree Sandy Ardianto & Erick Pranata Sekolah Tinggi Teknik Surabaya 1 Slide 2 Structure Terminology Tree Variation Action Insert Traverse Search Delete Exercises 2 Sekolah Tinggi Teknik Surabaya Slide 3 3 Slide 4 4 5 5 3 3 8 8 2 2 4 4 9 9 Slide 5 5 Slide 6 6 Subtree 5 5 3 3 8 8 2 2 4 4 9 9 root leaf Slide 7 Sekolah Tinggi Teknik Surabaya 7 Slide 8 Binary Search Tree Ternary Search Tree Red Black Tree AVL Tree (Adelson-Velskii dan Landis) etc 8 Sekolah Tinggi Teknik Surabaya Slide 9 9 Slide 10 Insert Traverse Show all elements Search Find its element Delete 10 Sekolah Tinggi Teknik Surabaya Slide 11 11 Slide 12 If root is null New node is root Else Find empty position Locate New Node to there In a binary tree, a small number will go on the left, while a large number will be entered in the right 12 Sekolah Tinggi Teknik Surabaya Slide 13 13 Slide 14 Breadth First Search Search Widens Using Queue Depth First Search Search Depth Do recursively There are 3 types: +Pre-order traversal +In-order traversal +Post-order traversal 14 Sekolah Tinggi Teknik Surabaya Slide 15 15 Slide 16 Done by utilizing the Traverse action. 16 Sekolah Tinggi Teknik Surabaya Slide 17 17 Slide 18 Find the node to be deleted, reffered to as del_node If del_node dont have children, remove immediately But if del_node had one child, point the pointer parent to a child of del_node But if del_node had two children: Option 1: find the rightmost child of the left subtree, referred to as the replacer; Option 2: find the leftmost child of the right subtree, referred to as the replacer; Replace del_node with replacer 18 Sekolah Tinggi Teknik Surabaya Slide 19 19 Slide 20 Implement Binary Search Tree in C#.NET 20 Sekolah Tinggi Teknik Surabaya Slide 21 Andrew Troelsen, Pro C# and The.Net 4.5 Framework (Sixth Edition), Apress, 2012 http://en.wikipedia.org/wiki/Binary_tre e http://en.wikipedia.org/wiki/Binary_tre e 21 Sekolah Tinggi Teknik Surabaya