CS1132_Fall_2011_Lecture7_BB

CS1132_Fall_2011_Lecture7_BB - Lecture 7 Complexity of...

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

View Full Document Right Arrow Icon
Lecture 7 Complexity of Searching with BST Binary heaps Midterm1 review CS 103 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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:
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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:
Background image of page 5

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

View Full DocumentRight Arrow Icon
The sum needed to compute the average can be rewritten as CS 103 6
Background image of page 6
add by columns. CS 103
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/14/2011 for the course CSCI 1132 taught by Professor Haya during the Fall '11 term at GWU.

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 Right Arrow Icon
Ask a homework question - tutors are online