Mid Term Study Guide

advertisement
CmSc250 Fundamentals of Computing
Mid-Term Study Guide
Questions and problems on the Mid-Term test will be related to the following topics:
1.
2.
3.
4.
Big Oh notation
Binary Search Trees, AVL trees
Hashing - basic concepts
Hashing - collision resolution
Here are some sample test questions.
1. Compare NlogN and N2 : NlogN = O(N2) or N2 = O(NlogN) ?
2. Is it true that NlogN = o(N2) ?
3. Compare
NlogN and N: NlogN = O(N) or N = O(NlogN) ?
4. Is it true that
NlogN = o(N) ?
5. Fill in appropriately:
N2 + NlogN = O(….. )
N + NlogN = O(….. )
N2 + logN = O(….. )
6. Find a function f(N) such that N2 = o(f(N))
7. Find a function g(N) such that N2 = ω(g(N))
8. Arrange the following functions in order of increasing rate of growth. Identify any
functions with the same rate of growth.
n2, 2n, nlogn, n!, n6 + n2, n4, n6 - n3, 4n, n, nn, 22n.
9. Give an analysis of the running time for the following loops, using the Big-Oh
notation:
a.
Problem 1
sum = 0;
for( i = 0; i < n; i++)
sum++;
1
b.
Problem 2
sum = 0;
for( i = 0; i < n; i++)
for( j = 0; j < n; j++)
sum++;
c.
Problem 3
sum = 0;
for( i = 0; i < n; i++)
for( j = 0; j < n * n; j++)
sum++;
10. Explain the relation between the depth M of a perfect binary tree and the number
of nodes N.
11. What is the minimal depth of a binary tree with 17 nodes? What would be the
maximal depth?
12. What is the maximal number of nodes in a tree with 5 levels? What would be the
minimal number of nodes?
13. Draw a binary tree with 10 nodes and minimal number of levels.
14. Choose a name of a state with more than 7 letters. Construct a binary tree with
minimal number of levels and assign the letters to the nodes so that the name can
be read in a pre-order, in-order, and post-order traversal.
15. What is a Binary Search Tree, how are the keys located?
16. How are the elements in a Binary Search Tree retrieved in sorted order?
17. What is the complexity of search and insert operations in a BST?
18. What is the complexity of creating a BST?
19. Discuss the advantages and disadvantages of Binary Search Trees.
20. Given a sequence of letters to serve as keys, draw the corresponding binary search
tree.
21. What is an AVL tree? What drawback of Binary Search Trees is overcome by the
AVL trees?
22. Given a sequence of letters to serve as keys, draw the corresponding AVL tree.
23. What does a hash function do?
24. The size of the hash table is usually chosen to be a prime number. Why?
2
25. Assume that each letter is a key of a record, and the hash function is computed for
each key:
S I M P L E T A S K
Hash : 7 3 5 7 5 3 7 1 7 4
What would be the disposition of the keys using separate chaining in a table of size 7?
26. Discuss the complexity of search in separate chaining.
27. Discuss the choice of the table size in separate chaining.
28. Assume that each letter is a key of a record, and the hash function is computed for
each key:
S I M P L E T A S K
Hash : 7 3 5 7 5 3 7 1 7 4
What would be the disposition of the keys using linear probing in a table of size 15?
29. What should be the value of the load factor with open addressing so that we have
good performance?
30. When is separate chaining preferred over open addressing?
See also the problems in the homework assignments and the “exam-like questions” posted in the
Lecture notes.
3
Download