当前位置:文档之家› 数据结构练习题2012-2013

数据结构练习题2012-2013


insertion sort. When 2 is moved to the first position, the number 8
must be at position (start from 1)
.
a. 4
b. 5
c. 6
d. 7
(10) Let T be a tree of N nodes created by union-by-height without path compression, then the depth of the tree is
but stacks cannot d. Stacks and queues are linear structures while lists are not
(5) For an in-order threaded binary tree, if the pre-order and inorder traversal sequences are ABCDEF and CBAEDF respectively,which pair nodes’ right links are both threads?
a. E
b. 2E
c. N2-E
d. N2-2E
(8) If a directed graph is stored by an upper-triangular adjacency
matrix –- that is, all the elements below the main diagonal are zero.
浙江大学 2012–2013 学年秋学期
《数据结构基础》课程期末考试试卷(A)
课程号: 211C0020_,开课学院:_计算机科学与技术_ 考试试卷:√A 卷、B 卷(请在选定项上打√) 考试形式:√闭、开卷(请在选定项上打√),允许带____无___入场 考试日期: 2012 年 11 月 15 日,考试时间: 120 分钟
Then its topological order
.
a. exists and must be unique
b. exists but may not be unique
c. does not exist
d. cannot be determined
(9) Sort a sequence of nine integers {4, 8, 3, 7, 9, 2, 10, 6, 5} by
}
} while (flag_swap > 0);
return h;
}
(2) The function is to perform Find as a Union/Find operation with
path compression. (9 points)
SetType Find ( ElementType X, DisjSet S )
struct node *p, *q; int flag_swap;
if (!h->next) return h;
do{
flag_swap = 0;
p = h;
while (p->next->next){
if (
){
flag_swap++;
q = p->next;

;

;

;
}
else p = p->next;
1. (a)
(b)
2. (a) (b) (c)
3. (a)
(b)
4. i 0 1 2 3 4 5 6 7 8 9 10 11 12
H[i]
5.
(a)
(b)
(c)
Part IV (15)
typedef struct TreeNode *Tree; struct TreeNode {
Tree Child; int key; Tree Sibling; }; int Counter[MAX_LEVEL] ; /* Counter[i] stores the number of leaves on the i-th level.*/ /* The root is on the level 0. */ void Count_Leaves( Tree T )
v1
3
v2 ∧
v3
4
v4 ∧
v5
2
2 5∧ 4
4∧ 1∧
(3) A binary search tree is said to be of “type A” if all the keys along the path from the root to any leaf node are in sorted order (either ascending or descending).
pN. If p2 = 2, then pi (i>2) must be
.
a. i
b. i+2
c. N - i d. cannot be determined
(4) What is the major difference among lists, stacks, and queues?
a. Lists use pointers, and stacks and queues use arrays b. Stacks and queues are lists with insertion/deletion constraints c. Lists and queues can be implemented using circularly linked lists,
(1) Bubble sort is a simple sorting algorithm. Suppose we have a list of integers and want to sort them in ascending order. Bubble sort repeatedly scans the list from the head to the tail, and swaps two adjacent numbers if they are in the wrong order. Please complete the following program to implement bubble sort. (12 points)
诚信考试,沉着应考,杜绝违纪。
考生姓名:
学号:
所属院系:
_
题序




总分
得分
评卷人
1.
2.
6.
7.
1.
_ _ _ _
Answer Sheet
Part I (20)
3.
4.
5.
8.
9.
10.
Part II (21)
_____
_
_____ ____ _
2. _
_
__
___
Part III (44)
.
a. N-1
b. N
c. N(N+1)/2
d. N+1
(7) If an undirected graph with N vertices and E edges is represented
by an adjacency matrix. How many zero elements are there in the matrix?
struct node{ int value; struct node *next; /* some other fields */
}
struct node BubbleSort (struct node *h) {/* h is the head pointer of the list with a dummy head node */
(b) Is Quick Sort stable? Please give a proof if your answer is “YES”, else please provide a counter example. (4 points)
(2) Given the adjacency list representation of a directed graph. Suppose V1 is always the first vertex being visited. Please list
d. N grows faster than N (log N )2
(2) What is the time complexity of the following function computes XN?
long int Pow (long int X, unsigned int N) { if (N == 0) return 1; if (N == 1) return X; if (IsEven(N)) /* IsEven(N) returns 1 if N is even, or 0 otherwise */ return Pow(X, N / 2) * Pow (X, N / 2); else return Pow(X * X, N / 2) * X;
}
that
a. O( N )
b. O( log N )
c. O( N log N )
d. O( N )
(3) Suppose that N integers are pushed into and popped out of a stack.
The input sequence is 1, 2, …, N and the output sequence is p1, p2, …,
相关主题