0% found this document useful (0 votes)
27 views6 pages

数据结构例题

The document contains a series of programming and algorithm-related questions, including multiple choice, fill-in-the-blank, and application of algorithms. Topics covered include time complexity, data structures, graph theory, and tree traversal. It also includes practical coding tasks related to binary trees and linked lists.

Uploaded by

2609600312
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

数据结构例题

The document contains a series of programming and algorithm-related questions, including multiple choice, fill-in-the-blank, and application of algorithms. Topics covered include time complexity, data structures, graph theory, and tree traversal. It also includes practical coding tasks related to binary trees and linked lists.

Uploaded by

2609600312
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

I Single Choice(10 points)

1. ( )For the following program fragment the running time(Big-Oh) is .


i = 0;
s = 0;
while(s <( 5*n*n + 2))
{ i++;
s = s + i;
}
a. O(n) b. O(n2) c. O(n1/2) d. O(n3)

2. ( )Which is non-linear data structure_____.


a. queue b.stack c. tree d. sequence list

3.( )The worst-time for removing an element from a sequence list (Big-Oh) is .
a. O(1) b. O(n) c. O(n2) d. O(n3)

4.( )In a circular queue we can distinguish(区分) empty queues from full queues by .
a. using a gap in the array
b. incrementing queue positions by 2 instead of 1
c.keeping a count of the number of elements
d. a and c
5. ( )A recursive function can cause an infinite sequence of function calls if .
a. the problem size is halved at each step
b. the termination condition is missing
c. no useful incremental computation is done in each step
d. the problem size is positive

6.( )The full binary tree with height 4 has nodes.


a. 15 b. 16 c.31 d.32
7. ( )Searching in an unsorted list can be made faster by using .
a. binary search
b. a sentinel(哨兵) at the end of the list
c. linked list to store the elements
d. a and c
8. ( ) Suppose there are 3 edges in an undirected graph G, If we represent graph G with a
adjacency matrix, How many “1”s are there in the matrix?
a. 3 b. 6 c. 1 d. 9
9. ( ) Construct a Huffman tree by four leaf whose weights are 9, 2, 5, 7 respectively. The
weighted path length is___________.
a. 29 b. 37 c. 46 d.44
10. Consider the following weighted graph.
Consider Dijkstra’s algorithm on this graph to find the shortest paths with s as a starting vertex.
Which are the first four vertices extracted from the priority queue by the algorithm (listed in the
order they are extracted) ?
a. s, y, t, x b. s, y, x, z c. s, t, y, x d. s, y, x, t

Fig. 1
11. Here is an array of ten integers:
5389170264
Suppose we partition this array using quicksort's partition function and using 5 for the pivot.
Which shows the array after partition finishes:
a. 5 3 4 2 1 0 7 9 6 8
b. 0 3 4 2 1 5 7 9 6 8
c. 3 1 0 2 4 5 8 9 6 7
d. 3 1 0 2 4 5 8 9 7 6
e. None of the above

II Fill in Blank (10 points)


1. For the following program fragment the running time(Big-Oh) is .
for ( int i = 0; i < n; i++ )
for ( int j = 0; j < =i; j++)
s; //s 为某种基本操作
2. We store a 4×4 symmetric matrix A into an array B with row major order, Store the lower
triangle only. the index of element a[2][3] in B is .
3. We can use 3 vector type to store value and of non-zero elements in a sparse matrix.
4. A______________ is a list where removal and addition occur at the same end . Frequently
known a LIFO (Last-In-First-Out) structure.
5. T( n ) = 2T( n/2 )+ cn, T(n) = T( n-1)+cn, T( n ) = O(___________)
6. There is a binary tree whose elements are characters. Preorder list of the binary tree is
“ABECDFGHIJ” and inorder list of the binary tree is “EBCDAFHIGJ”. Postorder traversal
sequence of the binary tree is .
7.There are leaf nodes in a full binary tree with n nodes.
8.When the input has been sorted ,the running time of insertion sort(Big-Oh) is .
9.We sort the sequence(43,02,80,48,26,57,15,73,21,24,66)with shell sort for increment
3, the result is ______ _.
10 、 In a circular queue, “front” and “rear” are the front pointer and rear pointer respectively.
Queue size is “maxsize”. When insert an element in the queue, rear = _________
11. A ____________________________________________ is an example of a search tree which
is multiway (allows more than two children).
12. A tree in which every node is no smaller than its children is termed
______________________.

III Application of Algorithms (35 points)

1.Graph G shown in Fig 2 is a directed graph, please describe G with adjacency matrix and write
the orders of breadth first traversal and depth first traversal.

B C

A E

Fig.2

2.The sequence of input keys is shown below:


19,1,23,14,55,20,84,27,68,11,10,17
A fixed table size of 19 and a hash function H(key)=key%13,with linear probing(线性探测), fill the
table below and compute the average length of successful search.

3. Show the results of inserting 53,17,78,09,45,65,87 each , one at a time, in a initially empty max
heap(大根堆)

4. write the sequence of preorder,postorder traversals and add inorder threads in the tree.
A

B C

D E F
Fig. 3
5. Build a Huffman tree and determine Huffman code when the probability distribution( 概率分布)
over the 8 alphabets ( c1, c2, c3, c4, c5, c6, c7, c8 ) is (0.05, 0.25, 0.03, 0.06, 0.10, 0.11, 0.36, 0.04

6. Graph G shown in Fig 4 is a directed graph, please describe G with adjacency list and write
topological ordering.

Fig. 4

IV Fill in blank of algorithms. (15)


1. Here is single source shortest path algorithm Dijkstra. Fill in blank of the algorithm.
class Graph { //图的类定义
private:
float Edge[NumVertices][NumVertices];
float dist[NumVertices]; //最短路径长度数组
int path[NumVertices]; //最短路径数组
int S[NumVertices]; //最短路径顶点集
public:
void ShortestPath ( int, int );
int choose ( int );
};
void Graph :: ShortestPath ( int n, int v ){
//在具有 n 个顶点的带权有向图中, 各边上权值由 Edge[i][j]给出。建立一个数组: dist[j], 0 £ j < n, //保存从顶点 v 到顶点 j 的最短
路径长度, 同时用数组 path[j], 0 £ j < n, 存放求到的最短路径。
for ( int i = 0; i < n; i++) {
dist[i] = Edge[v][i]; //dist 数组初始化
S[i] = 0;
if ( i != v && dist[i] < MAXNUM) path[i] = v;
else path[i] = -1; //path 数组初始化
}
S[v] = 1; dist[v] = 0; //顶点 v 加入顶点集合
//选择当前不在集合 S 中具有最短路径的顶点 u
for ( i = 0; i < ; i++ ) {
float min = MAXNUM; int u = v;
for ( int j = 0; j < n; j++ )
if ( !S[j] && )
{ u = j; min = dist[j]; }
S[u] = 1; //将顶点 u 加入集合 S
for ( int w = 0; w < n; w++ ) //修改
if ( !S[w] && Edge[u][w] < MAXNUM && ){
dist[w] = ;
path[w] = u;
} }
}
3 . Consider the following function to balance symbols stored in string exp that includes
parentheses(圆括号) and numbers.Please Fill in blank.
#include <stack>
Using namespace std;
int matching(string &exp) {
//exp is a pointer to a string to check
int state = 1,i=0;
char e;
stack<char> s;
while ( i<exp.length() && state )
switch (exp[i]) {
case '(':
;
i++;
break;
case ')':
if ( ){
s.pop(); i++; }
else
state = 0; //an error occurs
break;
default:
i++; break;
} //end of while

if ( ) return 1;
else return 0;

V Programming (30)

1. Write efficient functions (and give their Big-Oh running times)that take a pointer to a binary
tree root T and compute:
– The number of leaves of T
typedef struct BiTNode
{ TElemType data;
struct BiTNode *lchild,*rchild;
} BiTNode , *BiTree;

2.Write a method called maximumDegree of an undirectedh graph that returns


the maximum degree of any vertex in the graph. The graph is stored with adjacency
matrix. Write the definition of the graph. implement the function. Analyze space
complexity and time complexity of your function.

3. Write a function with linked list that inserts a number into a sorted linked list.
Firstly, you should write a function creates a list that like this:
L={3,5,8,12,32,48}
and then insert 25 into this list.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy