See the attached file

CIS350/3501


  1. Please provide necessary steps to gain the partial credit if your final solution is not correct.

  2. Make an effort to write in a readable fashion. We will skip over (and therefore not grade) non-readable portions.

Note, there are 9 problems on 8 pages.



  1. (15 points) Time Complexity

Give a tightest possible bound for the Big-Oh runtime complexity of the following program fragments or functions in terms of the value of the input parameter n:

  1. for (i = 0; i < n; i++)

a[i] = 0;

for (i = 0; i < n; i++)

for (j = 0; j < n; j++)

a[i] += a[j] + i + j;

  1. sum = 0

for (i = 0; i < n*n; i++)

for (j = 0; j < i; j++)

sum++;


  1. for (int i = 0; i < n; i++)

for (int j = 0; j < i*i; j++)

x++;




  1. int simple (int n)

{

if (n < 1000 )

return 1;

else

return n + simple (n – 1);

}





  1. int verysimple (int n)

{

if (n <= 1 )

return 1;

else

return n * verysimple (n/2);

}



  1. (10 points) Binary Search Trees

(a) Show a result of inserting 4, 2, 3, 1, 7, 5, 6, 9, 8 into an initially empty binary search tree.

(b) Show the result of deleting the root.


  1. (6 points) Give the prefix, infix, and postfix expressions corresponding to the following tree:


See the attached file 1


  1. (8 points) AVL Trees

Show a result of inserting 1, 2, 3, 6, 5, 4, 8, 7 into an initially empty AVL tree.















  1. (12 points) Hashing

Draw the result of hashing 58, 13, 18, 3 into a table if the h(x) = x mod 5. The initial hash table size is 5. If you cannot fit everything into the table (when a collision chain is longer than 4), then you have to rehash (reset the table size to 11 and update h(x) = x mod 11), but show both tables. For collisions use: a) separate chaining; b) linear probing; c) quadratic probing; and d) double hashing h2(x)= 3 – (x mod 3).


  1. (6 points) Splay Tree

Show the tree after the search for key 1 in the following splay tree:































  1. (3 points) What is the main difference between a B-tree and a Binary Search Tree? What is the main difference between a B-Tree and a B+ Tree? What are the main applications of B+ tree?

  2. (12 points) Max Binary Heap


  1. Show the results of using the linear-time algorithm to build a max binary-heap using the input: 4, 5, 25, 12, 19, 10, 15, 14, 6.

  2. Show the result of deleteMax to the following max binary heap.

[30, 20, 25, 10, 15, 9, 5, 8, 4, 3]

  1. Show the result of adding 27 to the following max binary heap.

[30, 20, 25, 10, 15, 9, 5, 8, 4, 3]

  1. (8 points)

    1. Write a recursive function that take only a pointer to the root of a binary search tree, BST, and print all the items in BST in the decreasing order.


struct BinaryNode

{

Comparable element;

BinaryNode *left;

BinaryNode *right;
};


int printTreeDecreasingOrder(BinaryNode *node, ostream & out)

{

}


    1. What is the running time of your routine?

8