Final review questions for data institutions

Final review questions for data institutions

1. True or False

1. The linear table stored sequentially can be accessed randomly. (√)


2. In the sequential storage structure of the linear table, when inserting and deleting elements, the number of moved elements is related to the position of the element. (√)


3. The basic characteristic of linear structure is that each node has at most one direct predecessor and one direct successor (√).


4. The linear storage structure of the linear table is better than the storage structure of the linked list. (X)


5. The so-called circular queue refers to the storage structure of the queue is a circular linked list (X).


6. After converting a tree into a binary tree, the root node of this binary tree has no right subtree (√ ).
Insert picture description here
Analysis: When the tree is transformed into a binary tree, the left subtree of the node is the original child node, and the right subtree is the original sibling node. That is, the left child of the root node is connected to its sibling node to the right (nodes at the same level are not connected to each other) and its subtree is deleted, except for the left child, the original line connected to the root node is erased. In this way, the root node has no right child, because the left subtree of a node A of the binary tree transformed from the tree is the child of A when it was originally the tree, and its right subtree is his brother


7. If a node of a complete binary tree has no left child, it must be a leaf node. (√)

Analysis: The numbering of the complete binary tree is from top to bottom, from left to right, so if a node has no left child, there must be no right child. It is the leaf node.


8. In the preorder traversal sequence of the binary tree, any node is in front of its subtree node. (√)


9. The preorder and postorder traversal sequence of the binary tree can uniquely determine the binary tree. (X)

解析:1.这里需要注意的是,两个序列中必须有一个中序序列才可以。 前序和后续组合无法确定唯一二叉树.
      2.给出一个中序序列,再给一个前序或后续序列,则可以确定一个个唯一的二叉树。

10. In an undirected graph, the number of edges is the sum of the degrees of the nodes. (X)

Analysis: is the sum of degrees divided by 2;


11. The adjacency matrix of the graph must be a symmetric matrix. (X)


12. Sequential search does not require the key codes to be in order. (√)


Two, multiple choice questions

  1. Computer algorithm refers to (C), it must have input, output and (F) 5 characteristics.
    A. Calculation method
    B. Sorting method
    C.Finite sequence of operations to solve the problem
    D. Scheduling method
    E. Feasibility, portability and scalability
    F.Feasibility, certainty and finitude
    G. Certainty, finiteness and stability
    H. Legibility, stability and security

  1. The purpose of algorithm analysis is (C), and the two main aspects of algorithm analysis are (E).
    A. Give the rationality of the data structure
    B. Study the relationship between input and output in the algorithm
    C.Analyze the efficiency of the algorithm for improvement
    D. The ease of understanding and documentation of the analysis algorithm
    E.Space complexity and time complexityF. Correctness and conciseness
    G. Readability and documentation H. Data complexity and program complexity

  1. The main difference between the algorithm and the program is that the algorithm must satisfy (D).
    A, advanced B, correctness C, high efficiency D,Poorness

  1. If the unordered linear table of length n adopts a sequential storage structure, the average number of moves to insert an element into it is (C).
    A, n B, (n-1) / 2 C,n / 2 D、( n + 1 ) / 2

  1. The single circular linked list with a head node takes first as the head pointer, and next is the pointer field of the linked list. The condition for the linked list to be empty is (B).
    A, first -> next = = first B, first -> next = = NULL
    C, first = = NULL D, first != NULL

  1. In a singly linked list, if you want to insert a node pointed to by the pointer q after the node pointed to by the pointer p, and set the next field to store the pointer, the executed statement series is (B).
    A, p -> next = q -> next; q = p;
    B, q -> next = p -> next; p -> next = q;
    C, p-> next = q -> next; q -> next = p;
    D, p -> next = q; q -> next = p -> next;

  1. Assuming that the head and tail pointers of a circular sequence queue are front and rear respectively, and the storage space size is n, the condition for judging that the queue is empty is (B).
    A, (front + 1)% n = = rear B, front = = rear
    C, (rear + 1)% n = = front D, front = = 0
    Insert picture description here

8If a complete binary tree with n nodes is stored in a one-dimensional array with subscript numbers 0, 1, …, n-1 in the order of hierarchical traversal, set the subscript of a node as k (k >= 0 ), if its left child exists, the subscript of its left child node is (C ).
A, 2k-1 B, 2k C, 2k + 1 D, 2k + 2


  1. The binary tree obtained by the equivalent conversion of a tree is called the binary tree corresponding to the tree. The following conclusion is correct (A).
    A. The first root traversal sequence of the tree is the same as the previous traversal sequence of the corresponding binary tree.
    B. The first root traversal sequence of the tree is the same as the middle-order traversal sequence of the corresponding binary tree.
    C. The rear root traversal sequence of the tree and the previous traversal sequence of the corresponding binary tree The same
    D, the post-root traversal sequence of the tree is the same as the post-order traversal sequence of the corresponding binary tree

  1. As shown on the right, an undirected graph composed of 7 vertices, starting from vertex 1, the vertex sequence that is impossible to obtain by depth-first traversal is (D).
    A, 1245367 B, 1467253
    C, 1342765 D, 1534267
    Insert picture description here

  1. The time complexity of the algorithm to connect a singly linked list of length m to a singly linked list of length n is (B).
    A. O(m+n) BO(n) CO(m) D.(m*n)

  1. In a directed graph with 10 vertices, the difference between the sum of in-degrees of all vertices and the sum of out-degrees of all vertices is (C).
    A. 10 B.20 C. 0 D.5

  1. The storage address of the first element of a linear table is 100, and the length of each element is 2, then the address of the fifth element is (B).
    A. 110 B. 108 C. 100 D. 120

  1. In a complete binary tree with n (n>l) nodes, the left child node (C) of node i (2i>n)
    A. It is 2i B. Is 2i+1
    C. There is no D. Is 2i-l
    Insert picture description here

  1. The binary tree is numbered consecutively starting from 1, requiring that the number of each node is greater than the number of its left and right children. Among the left and right children of the same node, the number of its left child is less than the number of its right child, then (C) The order of the traversal realization number.
    A. First order B. Middle order C. Post order D. Hierarchical traversal from the root

  1. Binary search requires node (A).
    A. Ordered, sequential storage B. Ordered, linked storage
    C. Unordered, sequential storage D. Unordered, linked storage

  1. There are 100 elements, and the maximum number of comparisons is (D) when searching by the binary search method.
    A. 25 B. 50 C. 10 D. 7

  1. There is a stack, the order of the elements into the stack is abcde, and the middle of the stack can be popped. It is impossible to get (C) pop sequence:
    A. abcde B. edcba C. decab D. dceba

  1. Suppose T is a Huffman tree with 5 leaf nodes, and the height of the tree T can be up to (D).
    A. 2 B. 3 C. 4 D. 5

Analysis:
Insert picture description here


  1. As shown in the figure, if the graph is traversed according to the breadth-first search method starting from vertex a, a possible vertex sequence is (B).
    A. abcedf B. abcefd C. abedfc D. acfdeb
    Insert picture description here

Three. Short answer questions

1. It is known that the post sequence of the node of a binary tree is BDCGFEA, and the middle sequence is BCDAEGF.
(1) Draw the binary tree, (2) find the preorder traversal sequence.

Analysis (1)
Insert picture description here
(2) ACBDEFG


2. Suppose the probability of occurrence of 8 characters from A to H is: w={0.10, 0.16, 0.01, 0.02, 0.29, 0.10, 0.07, 0.25}, design the optimal binary code and calculate the weighted path length WPL.

Insert picture description here
A:101
B:001
C:00000
D:00001
E:01
F:101
G:0001
H:11

WPL = 3 × (0.1+0.16+0.1) + 5 × (0.01 + 0.02) + 2 × (0.29 + 0.25) + 4 × 0.07= 2.59


3. The adjacency list of graph G is as follows, and find its topological sequence.
Insert picture description here
Solution:
Insert picture description here
The topological sequence is as follows (not unique):

1 2 4 5 8 9 10 3 6 11 7 12

l 2 4 5 8 9 10 3 7 6 11 12


4. Knowing that the undirected graph G is as follows, please write down the vertex sequence obtained from vertex 1 and traversed by the depth-first search algorithm.
Insert picture description here
Solution:
1 4 5 2 3 7 6 8 9
1 7 8 9 6 2 3 5 4


5. A directed connected graph with 41 arcs has at least how many vertices and at most how many vertices? A directed disconnected graph with 41 arcs has at least how many vertices? why?

Knowledge points

Insert picture description here
solution:

A directed graph with 6 vertices has at most 6×(6-1)=30 arcs, that is, a directed complete graph.
Obviously, a directed connected graph with 41 arcs has at least 7 vertices. There are at most 41 vertices, which are connected into a ring.

A directed unconnected graph with 41 arcs has at least 8 vertices, of which 7 vertices constitute a strongly connected component, plus an isolated vertex.


6. Draw the forest corresponding to the following known sequence:
the first-order access sequence of the
forest is: ABCDEFGHIJKL; the middle-order access sequence of the forest is: CBEFDGAJIKLH.

How to eat:
(1) Starting from the root node, if the right child exists, delete the connection with the right child node. Check the separated binary tree again, if the right child of the root node exists, delete it continuously. Until all these connections between the root node and the right child are deleted.
(2) Convert each separated binary tree into a tree.
(3) The left child does not move, and the right child becomes the right child of the grandfather root
Insert picture description here


7. The adjacency matrix of graph G is as follows:
Insert picture description here
Try to draw the graph, and use Kruskal algorithm to construct a minimum spanning tree.

solution:
Insert picture description here


8. Determine whether the following sequence is a pile (large root pile or small root pile). If not, adjust it to a pile (large root pile or small root pile).
(43, 5, 47, 1, 19, 11, 59, 15, 48, 41)

序列不是堆。注意要从排无序堆开始,从最后一个非终端结点开始,自下而上调整。

Insert picture description here


9. Use the Dijkstra algorithm to find the shortest path from V1 to V6 in the figure below, and calculate the change of the array D at each step during the execution of the algorithm. (D[i] represents the shortest path length from V1 to each vertex currently found)

Insert picture description here


Four. Algorithmic questions

1. Suppose the data structure of the linear table la stored sequentially is defined as follows. Write an algorithm to delete all data elements with value x in la.

typedef struct{
    
    
	DataType  list [ Maxnum ];
	int  length;
}SeqList;
void  DeleteSeqList ( SeqList  *la , DataType  x ){
    
    
	for ( j = 0 ; j < la -> length ; j++ ){
    
    
		if ( la -> list[ j ] = = x ){
    
    
	for ( k = j ; k < la -> length – 1 ; k++ )
		la -> list [ k ] = la -> list [ k+1 ];
la -> length --;
j --;
}
}
}

2. Write a recursive algorithm to find the value of the node at the kth position in the preorder sequence in the binary tree.

typedef struct Node{
    
    
	char data ;
	struct Node *lchild , * rchild ;
}BinNode , * BinTree ;
void preorder(BinTree root , int *pnum , int k , int *tag ){
    
    
	/* preorder visit bittree and output the NO.k node */
	if ( root ! = NULL ){
    
    
		( *pnum ) ++ ;
		if ( *pnum = = k){
    
    
			printf ( "\nThe NO.%d node by preorder is %c." , k , root->data ) ;
			*tag = 1 ;
		}
		preorder ( root->lchild , pnum , k , tag ) ;
		preorder ( root->rchild , pnum , k , tag ) ;
	}

Personally, I feel that the algorithm is missing one step. Although it can meet the requirements, there are still areas for optimization.

Guess you like

Origin blog.csdn.net/Touale/article/details/112955352