Tutorial #07

advertisement
Kingdom of Saudi Arabia
‫اململكة العربية السعودية‬
Ministry of Higher Education
‫وزارة التعليم العايل‬
Salman Bin Abdulaziz University
‫جامعة سلمان بن عبدالعزيز‬
College of Computer Engineering and sciences
‫كلية هندسة وعلوم احلاسب‬
‫قسم علوم احلاسب‬
Computer Science Department
CS2320: Data Structures & Algorithms
Tutorial #07: Trees & BST & Heaps
Part I: Choose the most appropriate answer:
1. One of nonlinear data structures is:
(a) Tree.
(b) Stack.
(c) Array.
(d) Linked list.
2. Height of a tree is:
(a) The number of nodes in the shortest path length from the root to one of the leaves.
(b) The number of nodes in the tree.
(c) The number of nodes in the longest path length from the root to one of the leaves.
(d) None of the above.
3. In a binary tree a node has at most
(a) Two children.
(b) Any number of children.
(c) One child only.
(d) None of the above.
4. The ____________ is the only node in a tree that doesn’t have a parent.
a) Parent.
b) Root.
c) Leaf.
d) Child.
5. Removing an item from a max heap occurs on:
(a) The rightmost leaf of the last level.
(b) The rightmost leaf of the last level.
(c) The root.
(d) The maximum item of the last level.
6. A(n) ____________ has one, and only one path from a root node to any other node.
(a) Priority queue.
(b) Tree.
(c) Level.
(d) Depth.
1
7. One way to solve the problem of “unbalanced Binary Search Tree” is to use:
(a) Graph.
(b) 2-3 Trees.
(c) Linked List.
(d) None of the above.
8. Binary heaps use Complete tree structure to:
(a) Make sure that the tree is well balanced.
(b) Make sure that number of leaves is maximum.
(c) Make sure that the number of levels is maximum.
(d) None of the above.
9. When dealing with Data stored in Hard Disk, then the best way for searching in such data is using:
(a) Graph.
(b) Linked List.
(c) Stack.
(d) B-Trees.
10. In a tree a node without any children is called a
(a) Parent
(b) Leaf
(c) Root
(d) Child
11. Time efficiency for percolate-up or percolate-down is:
(a) O(1).
(b) O(N).
(c) O(log N).
(d) O(N2).
12. Time efficiency for heapsort is:
(a) O(1).
(b) O(N).
(c) O(N log N).
(d) O(N2).
13. The worst case time complexity for searching a binary tree is:
(a) O(1).
(b) O(log N).
(c) O(N).
(d) O(N2).
14. The average case time complexity for searching a binary tree is:
(a) O(1).
(b) O(log N).
(c) O(N).
(d) O(N2).
2
PART II: Essay Questions:
1. Consider the following Binary tree and then answer the coming questions:
a.
b.
c.
d.
e.
f.
g.
h.
What is the root of the tree?
What is the depth of the tree?
Show the array representation of the tree in memory?
Show the preorder traversal of the tree?
Show the inorder traversal of the tree?
How many nodes this tree will contain if it becomes a full binary tree?
What is the father of node (-)?
Show the full binary tree version of this binary tree?
Answer:
3
2. Consider the following Binary Search Tree (BST):
42
32
62
27
17
37
29
35
52
39
48
68
59
Answer the following questions for the BST shown above.
(a) What is the height of this tree?
(b) Name the children of 42.
(c) Write down the pre-order traversal of this tree.
(d) Write down the in-order traversal of this tree.
(e) Write down the post-order traversal of this tree.
(f) How many steps are required to find the node with data value 48?
(g) In the given tree insert a new node with data value 41 and show the resulting tree.
4
(h) In the given tree delete the node with data value 42 and draw the resulting tree.
3. Build a max heap from the following list of numbers:
10
8
20
17
15
4
6
9
3
Answer:
5
6
Download