Anda di halaman 1dari 6

Ho Chi Minh City University of Technology

Department of Electrical and Electronics Engineering


FINAL EXAMINATION (K2010)

CS225 Data Structures and Programming Principles

Grading: 50%

(Equivalent course: Computer System Engineering)


Course ID: 407406

Date: 20 Dec, 2012

Duration: 120 minutes

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

Problem 1: Answer the following questions for the binary tree:


1. The height of the tree is
2. The depth of the node B is
3. Descendants of the node B are
4. External nodes of the tree are
5. Pre-order traversal of the tree is
6. Post-order traversal of the tree is
Problem 2: Give the following code for Node class
#include <iostream>
using namespace std;
class Node {
private:
char element;
Node* parent;
Node* left;
Node* right;
public:
Node() {
element = 0; parent = NULL;
left = NULL; right = NULL; }
Node(char value) {
element = value; parent = NULL;
left = NULL; right = NULL; }

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;}
};

1. Write C++ code to implement the following binary tree BT


A
B
D
F

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)
{

Problem 3: Balance the binary search tree below


15

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);
}
}

int pivot(list <int> *L)


{
list <int>::iterator L_Iter;
int N = L->size();
int t = rand() % N;
L_Iter = L->begin();
for (int i=0; i< t; i++) L_Iter++;
return *L_Iter;
}

Write C++ code for the functions partition and merge


void partition(list <int> *L, list <int> *L1, list <int>
*L2, int 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

Problem 8: Answer the following questions about Graph ADT


1. If the number of vertices is 10, the maximum number of edges in the graph is
2. If the number of edges is 12, the sum of degree of all vertices in the graph is
3. If the number of vertices is n, and the number of edges is m, the running time of DFS is
4. If the number of vertices is n, and the number of edges is m, the running time of BFS is
5. If the number of vertices is n, and the number of edges is m, the running time of Dijkstras
algorithm is

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

Draw BFS traversal

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

--------------------------------------------------- The end -----------------------------------------------------Electronics Department


Lecturer

Dr. Hoang Trang

Dr. Truong Quang Vinh


Page%6/6%

Anda mungkin juga menyukai