{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS1132_Fall_2011_Lecture7_BB

# CS1132_Fall_2011_Lecture7_BB - Lecture 7 Complexity of...

This preview shows pages 1–8. Sign up to view the full content.

Lecture 7 Complexity of Searching with BST Binary heaps Midterm1 review CS 103 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Complexity of Searching with BST Theorem: A full BST of height h has 2 h+1 - 1 nodes S n = A 1 *(1-2 n )/(1-2) S h = A 1 *(1-2 h+1 )/(1-2)=2 h+1 -1 h=0; A 1 = 1 h=1; A 2 = 2 h=2; A 3 = 4 h=3; A 4 = 8 h=4; A = 16
Complexity of Searching with BST If we look at a full binary tree as a geometric sequence we get the same result as well: 1 + 2 + 4 +…… 2 h = 2 h+1 - 1 Thus 2 h+1 - 1 = N and h = log(N + 1) -1 h = O(log N) Where h (= height) CS 103 3 Proof:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Therefore, for a BST with N nodes the following holds : best time analysis ………… O(1) worst time analysis ………… O (log O (log N N ) ) if the tree is “balanced” if the tree is “balanced” ………… O ( O ( N N ) ) if the tree is “unbalanced” if the tree is “unbalanced” average case analysis ………… ??? Complexity of Searching with BST
CS 103 5 BTS Average Case Analysis With i steps 2 i-1 leaves can be found A is the average number of steps taken by a binary search to find a number in the list:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
The sum needed to compute the average can be rewritten as CS 103 6
To see that this is the same as the original, add by columns.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 20

CS1132_Fall_2011_Lecture7_BB - Lecture 7 Complexity of...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online