3102_hw2 - CSC3102 Advance Data Structures and Algorithm...

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: CSC3102 Advance Data Structures and Algorithm Analysis Homework 2 Due October 7, 2010 (in class) 1. (20 points) Your friend, John (whoever he is!), gives you an array B [1 ..n ] of numbers. He wants to obtain the smallest k numbers in B , in sorted order. One way to solve this is: Sort B and the output the k smallest numbers. This can be done in O ( n log n ) time, using the sorting algorithms we have learnt before. (a) Design an O ( n + k log n )-time algorithm to help John find the desired k numbers, and explain why it runs in O ( n + k log n ) time. Hint: Use heap. 2. (20 points) Consider a following modification in AVL-tree criteria: a BST is a valid AVL tree if height of two siblings differ by at most 2. (In the original AVL tree the height is allowed to differ by at most 1). Show that height of such an AVL tree having n nodes is O (log n ). 3. (20 points) Range Queries. Given an AVL tree show (using pseudocode) how to support the following queries: RangeCount( k 1 ,k 2 ): Count the number of keys in the AVL tree which are between...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online