Preparing for Autumn Recruitment | Strong Training for Written Examination 20

Table of contents

1. Multiple choice questions

2. Programming questions

3. Solutions to multiple choice questions

4. Programming problem solving


1. Multiple choice questions

1. For linear tables stored sequentially, the time complexity of accessing nodes and adding nodes is ().

A. O(n) O(n)

B. O(n) O(1)

C. O(1) O(n)

D. O(1) O(1)

2. In the following linked list, the other nodes that cannot be accessed from the current node are ()

A. Doubly linked list'

B. Single circular linked list

C. Single linked list

D. Two-way circular linked list

3. The operation of inserting s after the node p of the two-way circular linked list is ()

A. p->next=s;s->prior=p;p->next->prior=s;s->next=p->next

B. p->next->prior=s;p->next=s;s->prior=p;s->next=p->next

C. s->prior=p;s->next=p->next;p->next=s;p->next->prior=s

D. s->prior=p;s->next=p->next;p->next->prior=s;p->next=s

4. The stack is a special linear table that intelligently inserts and deletes at one end. It stores data according to the last-in-first-out principle. The data that enters first is pushed to the bottom of the stack, and the last data is on the top of the stack. If the 6th element is A , B, C, D, E, and F are popped out of the stack in order of B, D, C, F, E, and A. Then the minimum capacity of the S stack is ().

A. 3

B. 4

C. 5

D. 6

5. There is a circular queue whose head pointer is front and tail pointer is rear; the length of the circular queue is N. The effective length in the queue is () (assuming no data is stored at the head of the queue)

A. (rear - front + N) % N + 1

B. (rear - front + N) % N

C. (rear - front) % (N + 1)

D. (rear - front + N) % (N - 1)

6. Among the following conclusions, the correct ones are () ① The degree of a binary tree with only one node is 0; ② The degree of a binary tree is 2; ③ The left and right subtrees of a binary tree can be exchanged arbitrarily; ④ The result of a complete binary tree with a depth of K A full binary tree whose number of points is less than or equal to the same depth

A. ①②③

B. ②③④

C. ②④

D. ①④

7. If the keywords 1, 2, 3, 4, 5, 6, and 7 are inserted into the initially empty balanced binary tree T, then the number of branch nodes with a balance factor of 0 in T is ( )

A. 0

B. 1

C. 2

D. 3

8. The initial sequence is 1 8 6 2 5 4 7 3. A group of numbers is sorted by heap. When the heap (small root heap) is completed, the in-order traversal sequence of the binary tree corresponding to the heap is ()

A. 8 3 2 5 1 6 4 7

B. 3 2 8 5 1 4 6 7

C. 3 8 2 5 1 6 7 4

D. 8 2 3 5 1 4 7 6

9. The method often used to solve conflict problems in hashing is ()

A. Numeric analysis method, remainder method, square method

B. Numerical analysis method, remainder method, linear detection method

C. Numeric analysis method, linear detection method, multiple hashing method

D. Linear detection method, multi-hash method, chain address method

10. Among the following options, the one that cannot be the second sorting result of quick sort is ()

A. 2,3,5,4,6,7,9

B. 2,7,5,6,4,3,9

C. 3,2,5,4,7,6,9

D. 4,2,3,5,7,6,9

2. Programming questions

1. String reversal   question link

2. Public substring calculation   question link 

3. Solutions to multiple choice questions

1. For linear tables stored sequentially, the time complexity of accessing nodes and adding nodes is ().

A. O(n) O(n)

B. O(n) O(1)

C. O(1) O(n)

D. O(1) O(1)

Correct answer: C

answer:

         Sequentially stored linear tables support random access, so the access time is O(1). When inserting data, data may be moved. Our time complexity at this time is O(N);

2. In the following linked list, the other nodes that cannot be accessed from the current node are ()

A. Doubly linked list'

B. Single circular linked list

C. Single linked list

D. Two-way circular linked list

Correct answer: C

answer:

         A singly linked list cannot access the elements in front of the node;

3. The operation of inserting s after the node p of the two-way circular linked list is ()

A. p->next=s;s->prior=p;p->next->prior=s;s->next=p->next

B. p->next->prior=s;p->next=s;s->prior=p;s->next=p->next

C. s->prior=p;s->next=p->next;p->next=s;p->next->prior=s

D. s->prior=p;s->next=p->next;p->next->prior=s;p->next=s

Correct answer: D

answer:

         As shown in the figure below, the order of the first and second steps can be exchanged, but the third and fourth steps cannot;

 

4. The stack is a special linear table that intelligently inserts and deletes at one end. It stores data according to the last-in-first-out principle. The data that enters first is pushed to the bottom of the stack, and the last data is on the top of the stack. If the 6th element is A , B, C, D, E, and F are popped out of the stack in order of B, D, C, F, E, and A. Then the minimum capacity of the S stack is ().

A. 3

B. 4

C. 5

D. 6

Correct answer: A

answer:

         When popping out of the stack to B, it is not difficult to imagine that at most two elements AB are stored in the stack at this time. When popping out to D, it means that there are three elements ACD in the stack before popping out, then C is popping out, and when popping out to F, the previous elements must be After entering EF, there is AEF in the stack, and then E and A are output; the whole process will have up to three elements, so A is selected;

5. There is a circular queue whose head pointer is front and tail pointer is rear; the length of the circular queue is N. The effective length in the queue is () (assuming no data is stored at the head of the queue)

A. (rear - front + N) % N + 1

B. (rear - front + N) % N

C. (rear - front) % (N + 1)

D. (rear - front + N) % (N - 1)

Correct answer: B

answer:

         fixed formula;

6. Among the following conclusions, the correct ones are () ① The degree of a binary tree with only one node is 0; ② The degree of a binary tree is 2; ③ The left and right subtrees of a binary tree can be exchanged arbitrarily; ④ The result of a complete binary tree with a depth of K A full binary tree whose number of points is less than or equal to the same depth

A. ①②③

B. ②③④

C. ②④

D. ①④

Correct answer: D

answer:

         The so-called degree of a tree can only be the number of subtrees with the most subtrees in the tree. For a binary tree with only one node, this node has no subtrees, so the degree is 0, which is correct; the degree of a binary tree is not necessarily 2, there are It may be 1 or 0. For example, ① is 0. The degree of a binary tree with only two nodes is 1; a binary tree is an ordered tree and cannot exchange the positions of the two left and right subtrees; ④ is correct;

7. If the keywords 1, 2, 3, 4, 5, 6, and 7 are inserted into the initially empty balanced binary tree T, then the number of branch nodes with a balance factor of 0 in T is ( )

A. 0

B. 1

C. 2

D. 3

Correct answer: D

answer:

         If the keywords are inserted into the balanced binary tree in sequence, as shown below; the question asks about the branch node with a balance factor of 0 , so it is 3;

8. The initial sequence is 1 8 6 2 5 4 7 3. A group of numbers is sorted by heap. When the heap (small root heap) is completed, the in-order traversal sequence of the binary tree corresponding to the heap is ()

A. 8 3 2 5 1 6 4 7

B. 3 2 8 5 1 4 6 7

C. 3 8 2 5 1 6 7 4

D. 8 2 3 5 1 4 7 6

Correct answer: A

answer:

        We simulate the above sequence and build a heap as shown in the figure below, so choose A;

9. The method often used to solve conflict problems in hashing is ()

A. Numeric analysis method, remainder method, square method

B. Numerical analysis method, remainder method, linear detection method

C. Numeric analysis method, linear detection method, multiple hashing method

D. Linear detection method, multi-hash method, chain address method

Correct answer: D

answer:

         Numerical analysis, division by remainder, square-centering, etc. are all hash mapping functions and are not methods to resolve conflicts; only option D is a method to resolve conflicts;

10. Among the following options, the one that cannot be the second sorting result of quick sort is ()

A. 2,3,5,4,6,7,9

B. 2,7,5,6,4,3,9

C. 3,2,5,4,7,6,9

D. 4,2,3,5,7,6,9

Correct answer: C

answer:

         We all know that each pass of quick sort can determine the position of a number. In option C, we can only determine that 9 is in its own position, so it cannot be the result of the second pass of sorting;

4. Programming problem solving

1. String reversal

Idea: We can use the reverse function in the library to achieve it in one step, but it is not recommended. We can also use two subscripts, one pointing to the starting position and one pointing to the position of the last character, to exchange them in sequence;

#include <iostream>
#include <string>
using namespace std;

int main() 
{
    string str;
    cin >> str;
    int begin =0;
    int end = str.size() -1;
    while(begin < end)
    {
        swap(str[begin], str[end]);
        begin++;
        end--;
    }
    cout << str << endl;
    return 0;
}

2. Common substring calculation

Idea: Dynamic programming, isn’t this question a simplified version of the question we asked yesterday? You can move to the link below;

Question analysis

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() 
{
    string str1, str2;
    cin >> str1 >> str2;
    int len1 = str1.size();
    int len2 = str2.size();
    int max = 0;
    vector<vector<int>> dp(len1 + 1, vector<int>(len2 + 1, 0));
    for(int i = 1; i <= len1; i++)
    {
        for(int j = 1; j <= len2; j++)
        {
            if(str1[i - 1] == str2[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            if(max < dp[i][j])
                max = dp[i][j];
        }
    }
    cout << max << endl;
    return 0;
}

Guess you like

Origin blog.csdn.net/Nice_W/article/details/132042971