Grading: 50%
Student name:
Student ID:
Students are allowed to use one A4 page with two sides for reference.
Books and other documents are not allowed to use.
This examination consists of 6 pages
void insert_left(Node* L) {
left = L; }
void insert_right(Node* R) {
left = R; }
void node_print() {
cout << element << " "; }
void set_value(char C) {
element = C;}
};
E
G
Page%1/6%
%
int main()
{
Node* A = new Node('A');
Node* B = new Node('B');
2. Write a function that print out preorder traversal of the binary tree
void preorder_traversal(BinaryTree BT)
{
10
Page%2/6%
%
Describe step by step the balance process; note the steps that use single rotation or double rotation
Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Problem 4: Insert into an initially empty binary search tree, items with the following key (in this order):
50, 45, 18, 55, 20, 60, 46, and 58. Draw the tree after each insertion.
Insert 50
Insert 45
Insert 18
Insert 55
Insert 60
Insert 46
Insert 58
50
Insert 20
Page%3/6%
%
Problem 5: Give the C++ code for Quick-sort using List STL
void quick_sort(list <int> *L)
{ list <int> *L1 = new list <int>;
list <int> *L2 = new list <int>;
int pivot_num;
int N = L->size();
if (N>1)
{
pivot_num = pivot(L);
partition(L, L1, L2, pivot_num);
quick_sort(L1);
quick_sort(L2);
merge(L,L1,L2,pivot_num);
}
}
merge(list <int> *L, list <int> *L1, list <int> *L2, int
pivot_num)
{
Page%4/6%
%
Problem 6: Fill in the following table for the operation of Priority Queue ADT
No.
1
2
3
4
5
6
7
8
9
10
Operation
insertItem(10, C)
insertItem(8, A)
insertItem(9, B)
minElement()
minKey()
insertItem(7, D)
size()
removeMin()
removeMin()
removeMin()
Output
-
Priority Queue
{(10,C)}
Problem 7: Describe the sorting process using Radix-sort algorithm for the following sequence of 4-bit
unsigned number.
1110
0111
1100
0101
1101
1000
0110
Page%5/6%
%
Problem 9: Give the graph G below. Assume that the graph is implemented by a linked list with alphabet
order and numeric order. Find traversal of G using Depth first search (DFS) and Breadth first search (BFS)
starting at S0.
Draw DFS traversal
Graph G
S0
S1
S2
S4
S3
S5
S6
Problem 10: Apply Dijkstras algorithm to find Minimum Spanning Tree for the following graph.
Describe step by step the shortest path finding process.
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Step 8:
27
23
13
25
24
15
E
0 A
10
13
23
29
C
D