Optimal binary search trees

Slides:



Advertisements
Similar presentations
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.
Advertisements

Splay Tree Algorithm Mingda Zhao CSC 252 Algorithms Smith College Fall, 2000.
Optimal Binary Search Tree
Chapter 7 Dynamic Programming.
© The McGraw-Hill Companies, Inc., Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Comp 122, Fall 2004 Dynamic Programming. dynprog - 2 Lin / Devi Comp 122, Spring 2004 Longest Common Subsequence  Problem: Given 2 sequences, X =  x.
Chapter 15 Dynamic Programming Lee, Hsiu-Hui Ack: This presentation is based on the lecture slides from Hsu, Lih-Hsing, as well as various materials from.
CS Data Structures Chapter 10 Search Structures (Selected Topics)
Chapter 7 Dynamic Programming 7.
CS2420: Lecture 19 Vladimir Kulyukin Computer Science Department Utah State University.
AVL Trees / Slide 1 Delete Single rotation Deletion.
Dynamic Programming Carrie Williams. What is Dynamic Programming? Method of breaking the problem into smaller, simpler sub-problems Method of breaking.
§ 8 Dynamic Programming Fibonacci sequence
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Chapter 5 Trees PROPERTIES OF TREES 3 4.
Dynamic Programming Code
CS2420: Lecture 27 Vladimir Kulyukin Computer Science Department Utah State University.
CS3381 Des & Anal of Alg ( SemA) City Univ of HK / Dept of CS / Helena Wong 4. Dynamic Programming - 1 Dynamic.
7 -1 Chapter 7 Dynamic Programming Fibonacci Sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if.
7 -1 Chapter 7 Dynamic Programming Fibonacci sequence (1) 0,1,1,2,3,5,8,13,21,34,... Leonardo Fibonacci ( ) 用來計算兔子的數量 每對每個月可以生產一對 兔子出生後,
CSC 2300 Data Structures & Algorithms February 13, 2007 Chapter 4. Trees.
Static Dictionaries Collection of items. Each item is a pair.  (key, element)  Pairs have different keys. Operations are:  initialize/create  get (search)
11-1 Matrix-chain Multiplication Suppose we have a sequence or chain A 1, A 2, …, A n of n matrices to be multiplied –That is, we want to compute the product.
E.G.M. PetrakisTrees in Main Memory1 Balanced BST  Balanced BSTs guarantee O(logN) performance at all times  the height or left and right sub-trees are.
Dynamic Programming Introduction to Algorithms Dynamic Programming CSE 680 Prof. Roger Crawfis.
Lecture 5 Dynamic Programming. Dynamic Programming Self-reducibility.
Dynamic Programming Dynamic programming is a technique for solving problems with a recursive structure with the following characteristics: 1.optimal substructure.
Chapter 5 Dynamic Programming 2001 년 5 월 24 일 충북대학교 알고리즘연구실.
7 -1 Chapter 7 Dynamic Programming Fibonacci sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if.
Dynamic Programming Tutorial &Practice on Longest Common Sub-sequence.
CS 5243: Algorithms Dynamic Programming Dynamic Programming is applicable when sub-problems are dependent! In the case of Divide and Conquer they are.
7 -1 Chapter 7 Dynamic Programming Fibonacci sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if.
CS Data Structures Chapter 10 Search Structures.
We learnt what are forests, trees, bintrees, binary search trees. And some operation on the tree i.e. insertion, deletion, traversing What we learnt.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
Static Dictionaries Collection of items. Each item is a pair.  (key, element)  Pairs have different keys. Operations are:  initialize/create  get (search)
Rudiments of Trees a Joshua presentation DATA STRUCTURES.
Foundation of Computing Systems
15.Dynamic Programming. Computer Theory Lab. Chapter 15P.2 Dynamic programming Dynamic programming is typically applied to optimization problems. In such.
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
Dynamic Programming 又稱 動態規劃 經常被用來解決最佳化問題. Dynamic Programming2 Rod cutting problem Given a rod of length N inches and a table of prices p[i] for i=1..N,
Chapter 15 Dynamic Programming Lee, Hsiu-Hui Ack: This presentation is based on the lecture slides from Hsu, Lih-Hsing, as well as various materials from.
MA/CSSE 473 Day 30 Optimal BSTs. MA/CSSE 473 Day 30 Student Questions Optimal Linked Lists Expected Lookup time in a Binary Tree Optimal Binary Tree (intro)
2.1 Matrix Operations 2. Matrix Algebra. j -th column i -th row Diagonal entries Diagonal matrix : a square matrix whose nondiagonal entries are zero.
11/20/2016IT 2791 Is this an AVL tree?
Advanced Algorithms Analysis and Design
Binary search tree. Removing a node
Advanced Algorithms Analysis and Design
Advanced Algorithms Analysis and Design
Binary Search Tree Chapter 10.
Tree.
Section 8.1 Trees.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Static Dictionaries Collection of items. Each item is a pair.
Lecture 5 Dynamic Programming
Dynamic Programming Several problems Principle of dynamic programming
Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms
Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms
Dynamic Programming Comp 122, Fall 2004.
Dynamic Programming General Idea
Trees Addenda.
CIS595: Lecture 5 Acknowledgement:
Static Dictionaries Collection of items. Each item is a pair.
Dynamic Programming Comp 122, Fall 2004.
Ch. 15: Dynamic Programming Ming-Te Chi
Dynamic Programming General Idea
Advanced Analysis of Algorithms
B-Trees B-trees are characterized in the following way:
Presentation transcript:

Optimal binary search trees e.g. binary search trees for 3, 7, 9, 12;

Optimal binary search trees n identifiers : a1 <a2 <a3 <…< an Pi, 1in : the probability that ai is searched. Qi, 0in : the probability that x is searched where ai < x < ai+1 (a0=-, an+1=).

Internal node : successful search, Pi Identifiers : 4, 5, 8, 10, 11, 12, 14 Internal node : successful search, Pi External node : unsuccessful search, Qi The expected cost of a binary tree: The level of the root : 1

The dynamic programming approach Let C(i, j) denote the cost of an optimal binary search tree containing ai,…,aj . The cost of the optimal binary search tree with ak as its root :

General formula

Computation relationships of subtrees e.g. n=4 Time complexity : O(n3) when j-i=m, there are (n-m) C(i, j)’s to compute. Each C(i, j) with j-i=m can be computed in O(m) time.

Matrix-chain multiplication n matrices A1, A2, …, An with size p0  p1, p1  p2, p2  p3, …, pn-1  pn To determine the multiplication order such that # of scalar multiplications is minimized. To compute Ai  Ai+1, we need pi-1pipi+1 scalar multiplications. e.g. n=4, A1: 3  5, A2: 5  4, A3: 4  2, A4: 2  5 ((A1  A2)  A3)  A4, # of scalar multiplications: 3 * 5 * 4 + 3 * 4 * 2 + 3 * 2 * 5 = 114 (A1  (A2  A3))  A4, # of scalar multiplications: 3 * 5 * 2 + 5 * 4 * 2 + 3 * 2 * 5 = 100 (A1  A2)  (A3  A4), # of scalar multiplications: 3 * 5 * 4 + 3 * 4 * 5 + 4 * 2 * 5 = 160

Let m(i, j) denote the minimum cost for computing Ai  Ai+1  …  Aj Computation sequence : Time complexity : O(n3)