Professional Documents
Culture Documents
DAA-Assignment 04 (2.5 Points) : Fatima Jinnah Women University Computer Science
DAA-Assignment 04 (2.5 Points) : Fatima Jinnah Women University Computer Science
Computer Science
You are advised to refer to the recommended textbook “Introduction to Algorithms (CLRS) 3rd
edition by Thomas H. Corman, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein”. Have a
reading through Chapter 06, 11, 12 and answer the following questions as a follow up exercise:
Consider the array A = {29, 18, 10, 15, 20, 9, 5, 13, 2, 4, 15}.
1. Does A satisfy the max-heap property? If not, fix it by swapping two elements.
2. Using array A (possibly corrected), illustrate the execution of the heap-extract-max algorithm, which
extracts the max element and then rearranges the array to satisfy the max-heap property. For each
iteration or recursion of the algorithm, write the content of the array A.
Question # 02:
1. What are the minimum and maximum numbers of elements in a heap of height h?
2. Show that an n-element heap has height ⌊lg n⌋.
3. Show that in any subtree of a max-heap, the root of the subtree contains the largest value
occurring anywhere in that subtree.
4. Is an array that is in sorted order a min-heap?
Generate Hash Keys for a table of size 8. Resolve collision, if any, using
a) Chaining
b) Linear Probing
Draw the hash table, to show before and after scenario with the given data.
Design and Analysis of Algorithm Assignment 04 Submission Date: 12/06/20
For the set of {1, 4, 5, 10, 16, 17, 21} of keys, draw binary search trees of height 2,3,4,5,6.
What is the difference between the binary-search-tree property and the min-heap property?
Can the min-heap property be used to print out the keys of an n-node tree in sorted order in
O(n)O(n) time? Show how? or explain why not.
Note:
You may submit your assignment as a word document, or hand-written on white pages, take images/scan
and convert to pdf format.