O ptimal B inary S earch T ree. Optimal( 理想 ) Binary ( 二元 ) Search ( 搜尋 ) Tree ( 樹 ) OBST + + + =

Slides:



Advertisements
Similar presentations
Introductory to database handling Endre Sebestyén.
Advertisements

CMSC420: Skip Lists Kinga Dobolyi Based off notes by Dave Mount.
Chapter 12 Binary Search Trees
Interval Heaps Complete binary tree. Each node (except possibly last one) has 2 elements. Last node has 1 or 2 elements. Let a and b be the elements in.
Optimal Binary Search Tree
Analysis of Algorithms CS 477/677 Binary Search Trees Instructor: George Bebis (Appendix B5.2, Chapter 12)
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
InOrder Traversal Algorithm // InOrder traversal algorithm inOrder(TreeNode n) { if (n != null) { inOrder(n.getLeft()); visit(n) inOrder(n.getRight());
1 Advanced Data Structures. 2 Topics Data structures (old) stack, list, array, BST (new) Trees, heaps, union-find, hash tables, spatial, string Algorithm.
Review for Test 2 i206 Fall 2010 John Chuang. 2 Topics  Operating System and Memory Hierarchy  Algorithm analysis and Big-O Notation  Data structures.
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
1 B-Trees Disk Storage What is a multiway tree? What is a B-tree? Why B-trees? Comparing B-trees and AVL-trees Searching a B-tree Insertion in a B-tree.
Optimal binary search trees
1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in.
Marc Smith and Jim Ten Eyck
Data Structures and Algorithms Semester Project – Fall 2010 Faizan Kazi Comparison of Binary Search Tree and custom Hash Tree data structures.
Indexing. Goals: Store large files Support multiple search keys Support efficient insert, delete, and range queries.
D ESIGN & A NALYSIS OF A LGORITHM 07 – M AP Informatics Department Parahyangan Catholic University.
S EARCHING AND T REES COMP1927 Computing 15s1 Sedgewick Chapters 5, 12.
© 2011 Pearson Addison-Wesley. All rights reserved 11 B-1 Chapter 11 (continued) Trees.
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
Chapter 13 B Advanced Implementations of Tables – Balanced BSTs.
D ESIGN & A NALYSIS OF A LGORITHM 05 – N - ARY T REE & B INARY T REE Informatics Department Parahyangan Catholic University.
1 Binary Trees Informal defn: each node has 0, 1, or 2 children Informal defn: each node has 0, 1, or 2 children Formal defn: a binary tree is a structure.
We learnt what are forests, trees, bintrees, binary search trees. And some operation on the tree i.e. insertion, deletion, traversing What we learnt.
“Enthusiasm releases the drive to carry you over obstacles and adds significance to all you do.” – Norman Vincent Peale Thought for the Day.
Binary SearchTrees [CLRS] – Chap 12. What is a binary tree ? A binary tree is a linked data structure in which each node is an object that contains following.
MA/CSSE 473 Day 21 AVL Tree Maximum height 2-3 Trees Student questions?
CS2223 Recitation 6 Finding the optimal Binary Search Tree for Keys with Given Probabilities Song Wang April 20.
CS 361 – Chapter 3 Sorted dictionary ADT Implementation –Sorted array –Binary search tree.
1 Tree Indexing (1) Linear index is poor for insertion/deletion. Tree index can efficiently support all desired operations: –Insert/delete –Multiple search.
Chapter 13 A Advanced Implementations of Tables. © 2004 Pearson Addison-Wesley. All rights reserved 13 A-2 Balanced Search Trees The efficiency of the.
AVL Trees. AVL Node Structure The AVL node structure follows the same structure as the binary search tree, with the addition of a term to store the.
Chapter 11 B Trees. © 2004 Pearson Addison-Wesley. All rights reserved 11 B-2 The ADT Binary Search Tree A deficiency of the ADT binary tree which is.
Hashing is a method to store data in an array so that sorting, searching, inserting and deleting data is fast. For this every record needs unique key.
H EAPS. T WO KINDS OF HEAPS : MAX AND MIN Max: Every child is smaller than its parent Meaning the max is the root of the tree 10 / \ 9 7 / \ 6 8 / \ 2.
Symbol Tables Computing 2 COMP s1. S YMBOL T ABLES Searching: like sorting, searching is a fundamental element of many computational tasks data.
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
Lecture 10COMPSCI.220.FS.T Binary Search Tree BST converts a static binary search into a dynamic binary search allowing to efficiently insert and.
STARS Efficiency Rating System Student Transportation.
TOPIC 5 ASSIGNMENT SORTING, HASH TABLES & LINKED LISTS Yerusha Nuh & Ivan Yu.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: TEL 3049.
Data Structures Red-Black Trees Design and Analysis of Algorithms I.
Nov 2, 2001CSE 373, Autumn Hash Table example marking deleted items + choice of table size.
UOP ECET 370 W EEK 7 L AB 7 B INARY T REES
Red-Black Tree Neil Tang 02/04/2010
Trees Chapter 11 (continued)
Trees Chapter 11 (continued)
PROJECT -1 (4 points) Week before midterm, C++.
Binary search tree. Removing a node
Binary Search Tree Neil Tang 01/28/2010
Lesson 5-15 AP Computer Science Principles
Binary Search Tree Chapter 10.
ECET 370 HELPS Education Your Life-- ecet370helps.com.
ECET 370 HELPS Lessons in Excellence- -ecet370helps.com.
ECET 370 HELPS Education for Service- - ecet370helps.com.
Heap Sort Ameya Damle.
Searching and BST Exercises
Priority Queues (Chapter 6.6):
CS223 Advanced Data Structures and Algorithms
Binary Trees: Motivation
Given value and sorted array, find index.
Binary Search Tree Neil Tang 01/31/2008
CS223 Advanced Data Structures and Algorithms
Priority Queues (Chapter 6):
Binary Search Counting
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Topic 10 Trees.
Optimal Binary Search Tree. 1.Preface  OBST is one special kind of advanced tree.  It focus on how to reduce the cost of the search of the BST.  It.
Presentation transcript:

O ptimal B inary S earch T ree

Optimal( 理想 ) Binary ( 二元 ) Search ( 搜尋 ) Tree ( 樹 ) OBST =

Preface of OBST It is one special kind of advanced tree. It focus on how to reduce the cost of the search of the BST. It may not have the lowest height. It needs 3 tables to record.

Purpose In order to promote the efficiency of the search, we can let the cost of the search minimum or mean the average of compare minimum

It has n keys in sorted order (representation k 1,k 2,…,k n ) ( k 1 <k 2 <…<k n ) some searches may be for values not in k i, so we also have n+1 “dummy keys” d 0,d 1,…,d n representating not in k i. d 0 = all values < k 1. d n = all values > k n.

APPLE Bird CatDog Egg Fish Grape dummy keys (d0,d1,…,dn) Keys (k1,k2,..kn)

For each key ki, a pi which means the probability searching for ki. For each key di, a qi which means the probability searching for di.

elements k n = key p n = probability of searching k n d n = dummy key q n = probability of searching d n

Success probability = (i=1~n) ∑ p i Failure probability = (i=0~n) ∑ q i (i=1~n) ∑ p i + (i=0~n) ∑ q i = 1 Success cost = (i=1~n) ∑ p i * (depth(k i )+1) Failure cost= (i=0~n) ∑ q i * (depth(d i )+1) Useful statement

E[search cost in ]= Success+ Failure =(i=1~n) ∑ p i * (depth(ki)+1) +(i=0~n) ∑ q i * (depth(di)+1) = (i=1~n) ∑ p i +(i=0~n) ∑ q i +(i=1~n) ∑ p i * depth(ki) +(i=0~n) ∑ q i * depth(di) = 1+(i=1~n) ∑ p i * depth(ki) +(i=0~n) ∑ q i * depth(di)

Example#1 i pi qi K1K1 K1K1 K2K2 K2K2 K3 K4 K5 K4 K5 d0 d1 d2d3d4d5 d1 d2d3 d4 d5

K2K2 d0d0 i pi qi K 1 =2*0.15=0.3 K 2 =1*0.1=0.1 K 3 =3*0.05=0.15 K 4 =2*0.1=0.2 K 5 =3*0.2=0.6 d 0 =3*0.05=0.15 d 1 =3*0.1=0.3 d 2 =4*0.05=0.2 d 3 =4*0.05=0.2 d 4 =4*0.05=0.2 d 5 =4*0.1=0.4 K4K4 K1K1 K3K3 K5K5 d1d1 d2d2 d5d5 d4d4 d3d3 Cost=Probability * (Depth+1) all cost=2.8

i pi qi K 1 =2*0.15=0.3 K 2 =1*0.1=0.1 K 3 =4*0.05=0.2 K 4 =3*0.1=0.3 K 5 =2*0.2=0.4 d 0 =3*0.05=0.15 d 1 =3*0.1=0.3 d 2 =5*0.05=0.25 d 3 =5*0.05=0.25 d 4 =4*0.05=0.2 d 5 =3*0.1=0.3 Cost=Probability * (Depth+1) K1K1 K2K2 K5K5 K4K4 K3K3 d0d0 d1d1 d5d5 d4d4 d2d2 d3d3 all cost=2.75

Picture#1=2.8 Picture#2=2.75 SO Picture#1 cost more than Picture#2 Picture#2 is better. The depth of Picture#1 is 3 The depth of Picture#2 is 4