KH of data structure [First four chapters] --> Multiple-choice questions (1)

Including introduction linear table stack queue string array generalized table


1. Introduction multiple choice questions

(1) In the data structure, the data structure can be logically divided into (C).
A. Dynamic structure and static structure B. Compact structure and non-compact structure
C. Linear structure and nonlinear structure D. Internal structure and external structure


(2) The data has nothing to do with the form, content, relative position, and number of the data element itself (C).
A. Storage structure B. Storage implementation
C. Logical structure D. Operational realization


(3) It is usually required that all data elements in the same logical structure have the same characteristics, which means (B).
A. The data has the same characteristics
B. Not only the number of data items contained in the data elements must be the same, but also the types of the corresponding data items must be consistent
. Each data element is the same
D. The number of data items contained in the data element must be equal


(4) Which of the following statements is correct is (D).
A. The data element is the smallest unit of data
B. Data item is the basic unit of data
C. Data structure is a collection of data items with structure
D. Some apparently very different data can have the same logical structure

Explanation: Data element is the basic unit of data, data item is the smallest unit of data, and data structure is a collection of data elements with structure.


Explanation: Data element is the basic unit of data, data item is the smallest unit of data, and data structure is a collection of data elements with structure.
(5) The time complexity of the algorithm depends on (D).
A. The scale of the problem B. The initial state of the data to be processed
C. Computer configuration D. A and B

Explanation: The time complexity of the algorithm is not only related to the scale of the problem, but also related to other factors of the problem. For example, for some sorting algorithms, the execution time is related to the initial state of the records to be sorted. For this reason, sometimes the algorithm has the best, worst and average time complexity evaluation.


(6) Among the following data structures, (A) is a non-linear data structure
. Tree B. String C. Queue D. Stack


2. Linear table multiple choice questions

1. Multiple-choice question
(1) The storage address of the first element in the sequence 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

Explanation: The data in the sequence table is stored continuously, so the address of the fifth element is: 100+2*4=108.


(2) In the sequence table of n nodes, the time complexity of the algorithm is O(1) and the operation is (A).
A. Visit the i-th node (1≤i≤n) and find the immediate predecessor of the i-th node (2≤i≤n)
B. Insert a new node after the i-th node (1≤i≤n)
C. Delete the i-th node (1≤i≤n)
D. Sort n nodes from small to large

Explanation: The time complexity of inserting a node in the sequence table is O(n 2 ), and the time complexity of sorting is O(n 2 ) or O(nlog 2 n). The sequence table is a random access structure. Both the access to the i-th node and the direct predecessor of the i-th node can be directly located by the subscript of the array, and the time complexity is O(1).


(3) Insert a new element into a sequence table with 127 elements and keep the original sequence unchanged. The average number of elements to be moved is (B).
A. 8 B. 63.5 C. 63 D. 7

Explanation: The average number of elements to be moved is: n/2.


(4) The storage space occupied by the storage structure of the link storage (A).
A. Divided into two parts, one part stores the value of the node, and the other part stores the pointer indicating the relationship between the nodes
. Only part of it, storing the node value
C. Only a part of it stores pointers that indicate the relationship between nodes
D. Divided into two parts, one part stores the node value, and the other part stores the number of units occupied by the node


(5) If the linear table adopts the chain storage structure, the address of the available storage unit in the memory (D) is required.
A. Must be continuous B. Part of the address must be continuous
C. It must be discontinuous D. Continuous or discontinuous


(6) The linear table L is suitable for the realization of the chain structure in the case of (B).
A. The node value in L needs to be modified frequently B. Need to continue to delete and insert L
C. L contains a large number of nodes Complex node structure in L

Explanation: The biggest advantage of linked lists is that you don't need to move data when inserting and deleting, just modify the pointer directly.


(7) The storage density of singly linked lists (C).
A. Greater than 1 B. Equal to 1 C. Less than 1 D. Can not be sure

Explanation: Storage density refers to the ratio of the storage space occupied by a node's data itself to the storage space occupied by the entire node. Assume that the space occupied by a node of a singly linked list is D, and the space occupied by the pointer domain is N , The storage density is: D/(D+N), which must be less than 1.


(8) Merge two ordered lists with n elements each into an ordered list, and the minimum number of comparisons is (A).
A. n B. 2n-1 C. 2n D. n-1

Explanation: When all the elements in the first ordered list are less than (or greater than) the elements in the second list, only the first element in the second list needs to be compared with the elements in the first list in turn, Compare n times in total.


(9) In a sequence table of length n, when inserting a new element before the i-th element (1≤i≤n+1), it must move backward (B) elements.
A. ni B. n-i+1 C. ni-1 D. I


(10) Linear table L=(a1, a2,……an), which of the following statements is correct is (D).
A. Each element has a direct predecessor and a direct successor
. There is at least one element in the linear table
C. The arrangement of the elements in the table must be from small to large or from large to small
D. Except for the first and last elements, every other element has one and only one immediate predecessor and immediate successor.


(11) The time complexity of creating an ordered singly linked list with n nodes is (C).
A. O(1) B. O(n) C. O(n 2 ) D. O(nlog 2 n)

Explanation: The time complexity of creating a singly linked list is O(n), and to build an ordered singly linked list, each time a new node is generated, it needs to be compared with the existing nodes to determine the appropriate insertion position, so The time complexity is O(n 2 ).


(12) The following statement is wrong (D).
A. The two operations of seeking table length and positioning are not less efficient when using sequential storage structure than when using chain storage structure
. Sequentially stored linear tables can be accessed randomly
C. Because sequential storage requires continuous storage areas, it is not flexible enough in storage management
. == The chain storage structure of linear tables is better than sequential storage structure ==

Explanation: The chain storage structure and the sequential storage structure have their own advantages and disadvantages, and they have different applications.


(13) In a singly linked list, to insert the node pointed to by s after the node pointed by p, the sentence should be (D).
A. s->next=p+1; p->next=s;
B. (*p).next=s; (*s).next=(*p).next;
C. s->next=p->next; p->next=s->next;
D. s->next=p->next; p->next=s;


(14) In the doubly linked list storage structure, the pointer (A) must be modified when deleting the node pointed to by p.
A. p->next->prior=p->prior; p->prior->next=p->next;
B. p->next=p->next->next; p->next->prior=p;
C. p->prior->next=p; p->prior=p->prior->prior;
D. p->prior=p->next->next; p->next=p->prior->prior;


(15) In a doubly circular linked list, insert a new node pointed to by q after the node pointed to by the p pointer, and the operation to modify the pointer is (C).
A. p->next=q; q->prior=p; p->next->prior=q; q->next=q;
B. p->next=q; p->next->prior=q; q->prior=p; q->next=p->next;
C. q->prior=p; q->next=p->next; p->next->prior=q; p->next=q;
D. q->prior=p; q->next=p->next; p->next=q; p->next->prior=q;


Three. Stack and queue multiple choice questions

1. Multiple-choice question
(1) If the elements 1, 2, 3, 4, and 5 are pushed into the stack in turn, the unstacking sequence cannot appear in the case of (C).
A. 5,4,3,2,1
B. 2,1,5,4,3
C. 4,3,1,2,5
D. 2, 3, 5, 4, 1

Explanation: The stack is a last-in-first-out linear table. It is not difficult to find that element 1 is popped out of the stack before element 2 in the C option, which violates the last-in-first-out principle of the stack, so the situation shown in the C option is impossible.


(2) If it is known that the incoming sequence of a stack is 1, 2, 3,..., n, its output sequence is p1, p2, p3,..., pn, if p1=n, then pi is (C).
A. i B. ni C. n-i+1 D. uncertain

Explanation: The stack is a last-in-first-out linear list. The incoming sequence of a stack is 1, 2, 3,..., n, and the first element of the output sequence is n, indicating that 1, 2, 3,..., n once All the properties are pushed into the stack and then output, so p1=n, p2=n-1,..., pi=n-i+1.


(3) Array Q[n] is used to represent a circular queue, f is the previous position of the head element of the current queue, r is the position of the end element of the queue, assuming that the number of elements in the queue is less than n, calculate the number of elements in the queue The formula is (D).
A. rf B. (n+fr)%n C. n+rf D. (N+rf)%n

Explanation: For acyclic queues, the difference between the tail pointer and the head pointer is the length of the queue. For circular queues, the difference may be a negative number, so you need to add the difference to MAXSIZE (in this title, n), and then to MAXSIZE ( This question is n) Find the remainder, that is, (n+rf)%n.


(4) The chained stack node is: (data, link), top points to the top of the stack. If you want to remove the top node of the stack and save the value of the deleted node to x, you should perform operation (A).
A. x=top->data; top=top->link; B. top=top->link=;x=top->link;
C. x=top;top=top->link; D. x=top->link;

Explanation: x=top->data stores the value of the node in x, and the top=top->link stack top pointer points to the next node on the top of the stack, that is, the top node of the stack is removed.


(5) There is a recursive algorithm as follows
int fact(int n) {//n is greater than or equal to 0
if(n<=0) return 1;
else return n*fact(n-1);}
then calculate fact(n) The number of times the function needs to be called is (A).
A. n+1 B. n-1 C. n D. n+2

Explanation: Special value method. Set n=0, it is easy to know that the fact(n) function is called only once, so select A.


(6) The stack is used in (D).
A. Recursive call B. Function call C. Expression evaluation D. The first three options have

Explanation: Recursive calls, function calls, and expression evaluation all use the last-in, first-out nature of the stack.


(7) In order to solve the problem of speed mismatch between the computer host and the printer, a print data buffer is usually set. The host writes the data to be output into the buffer in turn, and the printer takes out the data from the buffer in turn. The logical structure of the buffer should be (A).
A. Queue B. Stack C. Linear table D. Ordered list

Explanation: To solve the buffer problem, a first-in first-out linear table should be used, and the queue is a first-in first-out linear table.


(8) Assuming that the initial state of stack S and queue Q is empty, elements e1, e2, e3, e4, e5 and e6 enter stack S in turn, and one element enters Q after being unstacked. If the sequence of 6 elements out of the queue is e2, e4, e3, e6, e5 and e1, the capacity of stack S should be at least (B).

A.2 B.3 C.4 D. 6

Explanation: The sequence of element dequeue is e2, e4, e3, e6, e5, and e1. It can be seen that the sequence of element enqueue is e2, e4, e3, e6, e5, and e1. e3, e6, e5, and e1, and elements e1, e2, e3, e4, e5, and e6 enter the stack sequentially. It is easy to know that there are at most 3 elements in stack S at the same time, so the capacity of stack S is at least 3.


(9) If a stack is stored in the vector V[1...n], and the initial stack top pointer top is set to n+1, the correct operation of pushing element x into the stack is (==C ==).
A. top++; V[top]=x; B. V[top]=x; top++;
C. top–; V[top]=x; D. V[top]=x; top–;

Explanation: The initial stack pointer top is n+1, indicating that the element is pushed onto the stack from the high-end address of the array vector, and because the element is stored in the vector space V[1...n], the top pointer first moves down to n when it is pushed onto the stack. , And then store the element x in V[n].


(10) Design an algorithm for judging whether the left and right parentheses appear in pairs in the expression, using (D) the best data structure.
A. The sequential storage structure of the linear table B. Queue
C. Chain storage structure of linear table D. Stack

Explanation: Use the last-in, first-out principle of the stack.


(11) Queues stored in link mode are being deleted (D).
A. Modify only the head pointer B. Modify only the tail pointer
C. Both the head and tail pointers must be modified D. The head and tail pointers may both be modified

Explanation: In general, only the head pointer is modified,but, When the last element in the queue is deleted, the tail pointer is also lost, so it is necessary to re-assign the tail pointer.


(12) The circular queue is stored in an arrayA[0…m], The operation when joining the queue is (D).
A. rear=rear+1 B. rear=(rear+1)%(m-1)
C. rear=(rear+1)%m D. rear=(rear+1)%(m+1)

Explanation: The array A[0…m] containsm+1Element, so it should be divided by m+1 when calculating the modulus.


(13) For a circular queue with a maximum capacity of n, the tail pointer is rear and the head of the team is front, the condition for the team to be empty is (B).
A. (rear+1)%n = =front B. rear= =front
C. rear+1= =front D. (rear-l)%n= =front

Explanation: For a circular queue with a maximum capacity of n, the queue full condition is (rear+1)%n= =front, and the queue empty condition is rear= =front.


(14) The common point of stack and queue is (C).
A. All are first-in first-out B. All are first-in-last-out
C. Only insert and delete elements at the endpoints are allowed D. Nothing in common

Explanation: The stack only allows inserting and deleting elements at the top of the stack, and the queue only allows inserting elements at the end of the line and deleting elements at the head of the line.


(15) A recursive algorithm must include (B).
A. Recursion part B. Termination condition and recursion part
C. Iteration part D. Termination condition and iteration part


4. Strings, arrays and generalized tables

(1) String is a special linear table, and its particularity is reflected in (B).
A. Can be stored sequentially B. The data element is a character
C. Can chain storage D. The data element can be multiple characters if


(2) String In the following description of string, (B) is incorrect?
A. A string is a finite sequence of characters
B. An empty string is a string composed of spaces
C. Pattern matching is an important operation of string
D. Strings can be stored sequentially or chained

Explanation: A space is often an element in the character set of a string. A string consisting of one or more spaces becomes a space string, and a string of zero characters becomes an empty string, and its length is zero.


Knock on blackboard

(3) The next array of the string "ababaaababaa" is (C).
A. 012345678999 B. 012121111212 C. 011234223456 D. 0123012322345

To calculate the next function value of a string, please refer to "KMP Pattern Matching Algorithm".

calculation process:

Subscript j 1 2 3 4 5 6 7 8 9 10 11 12
String a b a b a a a b a b a a
next [j] 0 1 1 2 3 4 2 2 3 4 5 6
  1. When j=1, the fixed value is next[1]=0;
  2. When j=2, the string from 1 to j-1 is "a", which belongs to other situations, and the fixed value is next[2]=1;
  3. When j=3, the string from 1 to j-1 is "ab", the prefix character "a" and the suffix character "b" are not equal, which
    belongs to other situations, so next[3]=1;
  4. When j=4, the string from 1 to j-1 is "aba", the prefix character "a" is equal to the suffix character "a",
    that is, 1 character is equal, so next[4]=1+ 1=2;
  5. When j=5, the string from 1 to j-1 is "abab", the prefix character "ab" is equal to the suffix character "ab",
    that is, there are two characters equal, so next[5]=2+ 1=3;
  6. When j=6, the string from 1 to j-1 is "ababa", the prefix character "aba" is equal to the suffix character "aba",
    that is, there are 3 characters equal, so next[6]=3+ 1=4;
  7. When j=7, the string from 1 to j-1 is "ababaa", the prefix character "a" is equal to the suffix character "a",
    that is, 1 character is equal, so next[7]=1+ 1=2;
  8. When j=8, the string from 1 to j-1 is "ababaaa", the prefix character "a" is equal to the suffix character "a",
    that is, 1 character is equal, so next[8]=1+ 1=2;
  9. When j=9, the string from 1 to j-1 is "ababaaab", the prefix character "ab" is equal to the suffix character "ab",
    that is, there are two characters equal, so next[9]=2+ 1=3;
  10. When j=10, the string from 1 to j-1 is "ababaaaba", the prefix character "aba" is equal to the suffix character "aba",
    that is, there are 3 characters equal, so next[10]=3+ 1=4;
  11. When j=11, the string from 1 to j-1 is "ababaaabab", the prefix character "abab" is equal to the suffix character "abab",
    that is, there are 4 characters equal, so next[11]=4+ 1=5;
  12. When j=12, the string from 1 to j-1 is "ababaaababa", the prefix character "ababa" is equal to the suffix character "ababa",
    that is, there are 5 characters equal, so next[12]=5+ 1=6;

Therefore, the answer is C.011234223456


(4) The nextval of the string "ababaabab" is (A).
A. 010104101 B. 010102101 C. 010100011 D. 010101011

Knowledge points:

nextval[i]的求解需要
s中next[i]所在位置的字符 == s[i]的字符一致,
如果一致
	 则用s[next[i]]的nextval的值作为nextval[i],
如果不一致,
	 则用next[i]做为nextval[i]。
Subscript j 1 2 3 4 5 6 7 8 9
String a b a b a a b a b
next[i] 0 1 1 2 3 4 2 3 4
nextval[i] 0 1 0 1 0 4 1 0 1

(5) The length of the string refers to (B).
A. The number of different letters contained in the string B. The number of characters in the string
C. The number of different characters contained in the string D. The number of non-space characters in the string

Explanation: The number of characters in a string is called the length of the string.


(6) Assuming that the two-dimensional array A=array[1…100,1…100] is stored in row order as the main sequence, and each data element occupies 2 storage units, the base address is 10, then LOC[5,5] =(B).
A. 808 B. 818 C. 1010 D. 1020

Explanation: Based on the line order, then LOC[5,5]=[(5-1)*100+(5-1)]*2+10=818.

Loc(A ij )=10(base address)+[(5-1)*100+(5-1)]*2=818.


(7) There is an array A[i,j], each element of the array is 3 bytes in length, the value of i is 1 to 8, the value of j is 1 to 10, and the array is stored sequentially from the first address BA of the memory. When used as the main storage, the storage first address of element A[5,8] is (B).
A. BA+141 B. BA+180 C. BA+222 D. BA+225

Explanation: Based on column order, LOC[5,8]=[(8-1)*8+(5-1)]*3+BA=BA+180.


(8) There is a 10th-order symmetric matrix A, which adopts compressed storage method, mainly stores in row order, a 1,1 is the first element, and its storage address is 1, and each element occupies an address space, then a The address of 8,5 is (C).
A. 13 B. 32 C. 33 D. 40

Explanation: The index of the array here starts from 1, and only the lower triangle elements are stored . There are 7 rows in front of a 8,5 , 1 element in the first row, 2 elements in the second row, ..., in the seventh row 7 elements, these 7 lines have a total of (1+7)×7/2=28 elements. In the 8th line, there are 4 elements before a8,5, so there are 28+4=32 before a8,5 Elements with address 33.


(9) If the n-th order symmetric matrix A is row-ordered, the elements of the lower triangle (including all elements on the main diagonal) are sequentially stored in a one-dimensional array B[1...(n(n+1)) )/2], the relationship between the position k of a ij (i<j) in B is (B).
A. i*(i-1)/2+j B. j*(j-1)/2+i C. i*(i+1)/2+j D. j*(j+1)/2+i


(10) Each element of the two-dimensional array A is a string consisting of 10 characters, with row subscripts i=0,1,...,8, and column subscripts j=1,2,...,10. If A is stored row first, the starting address of element A[8,5] is the same as the starting address of element (B) when A is stored column first. Let each character occupies one byte.
A. A[8,5] B. A[3,10] C. A[5,8] D. A[0,9]

8×10+5-1=(j-1)×9+i

Explanation: Set the array to be stored sequentially from the memory first address M. If the array is stored row first, the starting address of element A[8,5] is: M+[(8-0)*10+(5-1)]*1 =M+84; if the array is stored first, it is easy to calculate the starting address of element A[3,10] as: M+[(10-1)*9+(3-0)]*1=M+84 . So choose B.


(11) Suppose the two-dimensional array A[1... m, 1... n] (that is, m rows and n columns) is stored in the array B[1... m*n] in rows, then the two-dimensional array elements A[i,j] The subscript in the one-dimensional array B is (A).
A. (i-1) n+j B. (i-1) n+j-1 C. i (j-1) D. j m+i-1

Explanation: Special value method. Taking i=j=1, it is easy to know that the subscript of A[1,1] is 1, and only the value of A can be determined by the four options, so choose A.


(12) The number of elements (B) in the array A[0...4,-1...-3,5...7].
A. 55 B. 45 C. 36 D. 16

Answer: B
Explanation: A total of 5 3 3=45 elements.


(13) The generalized table A=(a,b,(c,d),(e,(f,g))), then the value of Head(Tail(Head(Tail(Tail(A))))) is ( D).
A. (g) B. (d) C. c D. d

解释:Tail(A)=(b,(c,d),(e,(f,g)));Tail(Tail(A))=( (c,d),(e,(f,g))); Head(Tail(Tail(A)))= (c,d);Tail(Head(Tail(Tail(A))))=(d);Head(Tail(Head(Tail(Tail(A)))))=d。


(14) The head of the generalized table ((a,b,c,d)) is (C), and the tail is (B).
A. a B. () C. (a,b,c,d) D. (b,c,d)

Explanation: The header is the first element of a non-empty generalized list, which can be a single atom or a sublist. The header of ((a,b,c,d)) is a sublist (a,b) ,c,d); == The tail of the table is a table composed of other elements except the head of the table ==, the table must be a generalized table, and the tail of ((a,b,c,d)) is an empty table ().


(15) Set the generalized table L=((a,b,c)), then the length and depth of L are respectively (C).
A. 1 and 1 B. 1 and 3 C. 1 and 2 D. 2 and 3

Explanation: The depth of the generalized table refers to the number of levels of brackets in the expanded table, and the length of the generalized table refers to the number of elements contained in the generalized table. According to the definition, the length of L is 1 and the depth is 2.


Guess you like

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