KH of the data structure [5, 6] --> Multiple-choice questions (2)

KH of the data structure [5, 6] --> Multiple-choice questions (2)


Five. Tree and binary tree multiple choice questions

(1) After converting a tree into a binary tree, the shape of the binary tree is (A).
A. The only B. There are many kinds of
C. There are many types, but none of the root nodes have left children. There are many, but none of the root nodes have right children

Explanation: Because a binary tree has a left child and a right child, after a tree is converted to a binary tree, the shape of the binary tree is unique.


(2) How many different binary trees can be constructed from 3 nodes? (D)
A. 2 B. 3 C. 4 D. 5

Explanation: The five situations are as follows:
Insert picture description here


(3) There are 1001 nodes on a complete binary tree, among which the number of leaf nodes is (D).
A. 250 B. 500 C. 254 D. 501

Explanation: Set the number of nodes with degree 0 (leaf nodes) as A, the number of nodes with degree 1 as B, and the number of nodes with degree 2 as C. A=C+1, A+B +C=1001, we can get 2C+B=1000. From the nature of the complete binary tree, we can get B=0 or 1, and because C is an integer, so B=0, C=500, A=501, that is, there are 501 leaves Node.


(4) The height h of a binary tree with 1025 nodes is (C).
A. 11 B. 10 C. Between 11 and 1025 D. Between 10 and 1024


Explanation: If there is only one node in each layer, the tree height h is 1025; and the minimum tree height is log 2 1025 + 1=11, that is, h is between 11 and 1025.


(5) Full m-ary tree with depth hThe k layer has(A) Nodes. (1=<k=<h)
A. m k-1 B. m k- 1 C. m h-1 D. m^h-1

Explanation: The full m-ary tree with depth h has m h -1 nodes, and the k- th layer has m k-1 nodes.


(6) Using a binary linked list to store the tree, the right pointer of the root node is (C).
A. Point to the leftmost child B. Point to the rightmost child C. D. Empty non empty

Explanation: When using a binary linked list to store the tree, the right pointer points to a sibling node. Because the root node has no sibling nodes, the right pointer of the root node points to null.


(7) The nodes of the binary tree are numbered consecutively starting from 1, and the number of each node is required to be 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. , You can use (C) to traverse the number.
A. First order B. Middle order C. Later order D. From the root to traverse hierarchically

Explanation: According to the meaning of the question, it can be known that the binary tree is traversed in the order of the left child first, then the right child, and the parent node last, that is, the binary tree is traversed in the subsequent order.


(8) If the binary tree adopts a binary linked list storage structure, to exchange the positions of the left and right subtrees of all its branch nodes, the (C) traversal method is most suitable.
A. Preface B. In order C. Subsequent D. By level

Explanation: Both subsequent traversal and hierarchical traversal can achieve the exchange of left and right subtrees, but the implementation cost of hierarchical traversal is larger than that of subsequent traversal, and the post-order traversal method is the most suitable.


(9) Among the following storage forms, (D) is not a tree storage form?
A. Parental representation B. Child linked list notation C. D. Child brother notation Sequential storage notation

Explanation: There are three storage structures for trees: parent representation, child representation, and child brother representation. Among them, child brother representation is a commonly used representation, and any tree can be converted to a binary tree for storage through child brother representation.


(10) The preorder traversal sequence and the postorder traversal sequence of a non-empty binary tree are exactly the opposite, then the binary tree must satisfy (C).
A. All nodes have no left children B. All nodes have no right children
C. There is only one leaf node D. Is any binary tree

Explanation: Because the result of first-order traversal is "middle left and right", the result of subsequent traversal is "left-right center". When there is no left subtree, it is "center right" and "right center"; when there is no right subtree, it is " "Center Left" and "Left Center". Then all nodes have no left children or all nodes have no right children, so A and B cannot be selected, and all nodes have no left children and all nodes have no right children, there is only A leaf node, so choose C.


(11) Suppose there are 199 nodes in the Huffman tree, then there are (B) leaf nodes in the Huffman tree.
A. 99 B. 100
C. 101 D. 102

Explanation: In the Huffman tree, there are no nodes with degree 1, only nodes with degree 0 (leaf nodes) and degree 2. Suppose the number of leaf nodes is n0, and the number of nodes with degree 2 is n2. From the nature of the binary tree n0=n2+1, then the number of points n= n0+n2=2*n0-1 is obtained, and n0= 100.

Degree 0 node number = Degree 2 node number + 1


(12) If X is a node with a left child in the binary middle-order clue tree, and X is not the root, then the predecessor of X is (C).
A. X's parents B. The leftmost node in the right subtree of X
C. The rightmost node in the left subtree of X D.The rightmost leaf node in the left subtree of X


(13) The purpose of introducing binary clue tree is (A).
A. Speed ​​up the search for the predecessor or successor of the node B. In order to be able to insert and delete conveniently in the binary tree
C. In order to find the parents easily D. Make the traversal result of the binary tree unique


(14) Let F be a forest, and B is a binary tree transformed from F. If there are n non-terminal nodes in F, the nodes whose right pointer field is empty in B are (C) Pieces.
A. n−1 B. n C. n + 1 D. n + 2


(15) n (n≥2) characters with different weights constitute a Huffman tree. In the description of the tree, the error is (A).
A. The tree must be a complete binary tree
B. There must be no node with degree 1 in the tree
. The two nodes with the smallest weights in the tree must be sibling nodes
. The weight of any non-leaf node in the tree must not be less than the weight of any node in the next layer

Explanation: The construction process of the Huffman tree is to select the tree with the smallest weight as the left and right subtrees to construct a new binary tree, so there must be no node with degree 1 and two nodes with the smallest weight in the tree. It must be a sibling node, and the weight of any non-leaf node must not be less than the weight of any node in the next layer.


Six. Graph multiple choice questions

1. Multiple choice question
(1) In a graph, the sum of the degrees of all vertices is equal to (C) times the number of edges in the graph.
A. 1/2 B. 1 C. 2 D. 4


(2) In a directed graph, the sum of in-degrees of all vertices is equal to (B) times the sum of out-degrees of all vertices.
A. 1/2 B. 1 C. 2 D. 4

Explanation: The sum of in-degrees of all vertices in a directed graph is equal to the sum of out-degrees of all vertices.


(3) A directed graph with n vertices has at most (B) edges.
A. n B. n(n-1) C. n(n+1) D. n 2

Explanation: The edges of a directed graph are divided into directions, that is, 2 vertices are selected from n vertices and arranged in order, and the result is n(n-1).


(4) When a connected graph with n vertices is represented by an adjacent matrix, the matrix has at least (B) non-zero elements.
A. n B. 2(n-1) C. n/2 D. n^2 ^

The so-called connected graph must be an undirected graph, and the directed graph is called a strongly connected graph

Connect n vertices, at least n-1 edges are enough, or it is a spanning tree

Since each edge of the undirected graph associates two vertices at the same time, each edge in the adjacency matrix is ​​stored twice (that is, a symmetric matrix), so there are at least 2 (n-1) non-zero elements


(5) G is a non-connected undirected graph with 28 edges in total, so the graph has at least (C) vertices.
A. 7 B. 8 C. 9 D. 10

Explanation: An undirected graph with 8 vertices has at most 8*7/2=28 edges. Adding another point constitutes a non-connected undirected graph, so there are at least 9 vertices.


(6) If starting from any vertex of the undirected graph, a depth-first search can access all the vertices in the graph, then the graph must be a (B) graph.
A. Non-connected B. Connect C. Strongly connected D. Directed

Explanation:That is, from any vertex of the undirected graph, there is a path to each vertex, so the undirected graph is a connected graph


(7) The following (A) algorithm is suitable for constructing a minimum spanning tree of a dense graph G.
A. Prim algorithm B. Kruskal algorithm C. Floyd algorithm D. Dijkstra algorithm

Explanation: Prim algorithm is suitable for constructing a minimum spanning tree of dense graph G, and Kruskal algorithm is suitable for constructing a minimum spanning tree of sparse graph G.


(8) When using the adjacency list to represent the graph for breadth-first traversal, (B) is usually used to implement the algorithm.
A. Stack B. Queue C. Tree D. Figure

Explanation:Breadth-first traversal usually uses queues to implement algorithms, and depth-first traversal usually uses stacks to implement algorithms


(9) When using the adjacency list to represent the graph for depth-first traversal, (A) is usually used to implement the algorithm.
A. Stack B. Queue C. Tree D. Figure

Explanation: Breadth-first traversal usually uses queues to implement algorithms, and depth-first traversal usually uses stacks to implement algorithms.


(10) Depth-first traversal is similar to the binary tree (A).
A. First traverse B. In-order traversal C. D. Post-order traversal Level traversal


(11) Breadth first traversal is similar to binary tree (D).
A. First traverse B. In-order traversal C. D. Post-order traversal Level traversal


(12) The height of the BFS spanning tree in the figure is higher than that of the DFS spanning tree (C).
A. Little B. Equal C. Small or equal D. Greater or equal

Explanation: For some special graphs, such as a graph with only one vertex, the height of the BFS spanning tree is equal to that of the DFS spanning tree. The general graph, according to the algorithm ideas of the BFS spanning tree and DFS tree of the graph,The height of the BFS spanning tree is smaller than that of the DFS spanning tree


(13) The adjacency matrix of the known graph is shown in Figure 6.30, and the result of depth-first traversal from vertex v0 is (C).


Just have eyes! ! !


(14) The adjacency list of the known graph is shown in Figure 6.31, the result of breadth-first traversal from vertex v0 is (D), and the result of depth-first traversal is (D).

Insert picture description here
6.31 FIG adjacent table
A. 0 1 3 2 B. 0 2 3 1 C. 0 3 2 1 D. 0 1 2 3


(15) The following method (B) can determine whether a directed graph has a loop.
A. Depth-first traversal B. Topological sorting C. Find the shortest path D. Find the critical path


Guess you like

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