# lec4 - Lecture 4 Binary search tree average cost analysis...

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

Page 1 of 40 CSE 100, UCSD: LEC 4 Lecture 4 Binary search tree average cost analysis The importance of being balanced AVL trees and AVL rotations Insert in AVL trees Reading: Weiss Ch 4, sections 1-4

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

View Full Document
Page 2 of 40 CSE 100, UCSD: LEC 4 Best, worst, and average case time costs in data structures Often we would like to analyze time costs for data structure operations Typical operations we would care about would be: successful find, unsuccessful find, insert new data, update existing data, delete data. .. We are looking for time cost functions that are functions of the size of the problem For data structure operations, the size of the problem is: N, the number of data items stored in the structure We can consider the time cost of performing one of those operations. .. ... and we will want to think about the best , worst , or average case for that operation Whether analyzing best, worst, or average case, there are two aspects to the question: What is the internal state of the data structure? What data element is the operation being performed on? You have to think about both of these. ..
Page 3 of 40 CSE 100, UCSD: LEC 4 Data structure state and data element choice For each of the following, give an example of an internal state of the data structure, and a choice of data element, that gives the correct answer What is the worst-case number of nodes visited in an unsuccessful find operation in a binary tree with N nodes? What is the best-case number of nodes visited in an unsuccessful find operation in a binary tree with N nodes? What is the worst-case number of nodes visited in a successful find operation in a completely filled binary tree with N = 2 H+1 - 1 nodes?

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

View Full Document
Page 4 of 40 CSE 100, UCSD: LEC 4 Analyzing Find and Insert in binary search trees Define the “depth” of a node x i in the tree as the number of nodes on the path from the root to x i inclusive (thus the depth of x i is equal to the zero-based level of x i , plus 1) In the worst case, the number of comparisons in the Find and Insert operations is equal to the depth of deepest leaf of the tree (and the total number of steps required for any of these operations is proportional to the number of comparisons) In a binary search tree with N nodes, this can be as large as:________ This worst-case performance is not very good, and it very easily can occur: for example, when items are inserted in the BST in sorted, or reverse sorted, order! and various partially sorted insertion orders are as bad, or almost as bad So, overall worst-case time cost of BST operations is not very good at all. But what about average-case?. ..
Page 5 of 40 CSE 100, UCSD: LEC 4 Analysis of average-case successful find in a BST We will do an average case analysis of the “successful find” operation: how many steps are required, on average, for the find algorithm to find a key that’s in the tree?

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.

## lec4 - Lecture 4 Binary search tree average cost analysis...

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

View Full Document
Ask a homework question - tutors are online