Font size
WorksheetsThuật toán và độ phức tạp – Bài tập trắc nghiệm
Total questions: 87
Worksheet time: 44mins
What is the complexity of calculating the longest palindromic subsequence using dynamic programming?
O(n)
O(n2)
O(n3)
All are incorrect
In order to perform a binary search on array A, what condition must array A satisfy?
The array must be sorted in ascending order
The array does not need to be sorted
The array must be sorted in descending order
A or C are both correct
What is the value of the variable k after executing the following code: int k=0, n=20; for(int i=1; i<=n; i++) { int j=i; while(j<=n) { k++; j=j*2; } } What is the value of k?
400
30
40
All are incorrect
What is the time complexity of the binary search algorithm?
O(n)
O(nlogn)
O(logn)
All are incorrect
In order to perform binary search on array A, what condition must array A satisfy?
The array must be sorted in ascending order
The array does not need to be sorted
The array must be sorted in descending order
Either A or C is correct
What is the complexity of the following code: int i=1; while(i<=n) { k++; i=i*2; } What is the complexity?
O(n)
O(nlogn)
O(logn)
O(1)
What is the best time complexity for the problem of finding the maximum sum of a contiguous subarray?
O(n2)
O(n3)
O(logn)
O(n)
Which of the following points does not belong to the exhaustive search method?
No strategy in searching for solutions
Trying all candidates for the solution
Dividing a large problem into smaller subproblems
Usually not used to solve problems with large data sizes
How does the backtracking method solve problems?
Depth-first search for solutions
Breadth-first search for solutions
Trying all possible acceptable options at the same time
All are incorrect
In the 8 queens problem, after placing a queen in the first row, what is the minimum number of possible placements for a queen in the second row?
6
5
7
All are incorrect
In the 8 queens problem, after placing a queen in the first row and placing a queen in the second row, what is the minimum number of possibilities to place a queen in the third row?
4
5
2
3
According to the divide-and-conquer method, how many multiplications are needed to calculate x25 ?
25
5
6
7
According to the Indian multiplication algorithm, when multiplying 13 by 17, what is the value of the variable S after the second iteration?
0
13
39
81
In the helicopter patrol problem, suppose there are fuel tanks with values {3, 5, 1, 4} and the distance k=2, how many ways are there to arrange the fuel tanks for the patrol?
2
3
4
5
What is the similarity between the divide and conquer method and dynamic programming?
Used to solve optimization problems
Divides a large problem into smaller subproblems
Uses recursion to solve the problem
All of the above
In the problem of a mouse moving in a maze to reach the destination, a cell is called safe when it satisfies how many conditions?
3
4
5
2
In the sudoku problem, how many conditions need to be checked when filling a number into a cell?
2
3
4
5
Which of the following algorithms can produce incorrect results?
Greedy method
Divide and conquer method
Exhaustive search method
Probabilistic algorithm
According to the greedy method, how many times do we need to read the file when merging 5 files with sizes {13, 10, 4, 8, 3} into one file?
83
123
122
38
How many groups can probability algorithms be divided into?
1
2
3
4
In the recursive definition of the ant problem, if we call C(5, 4), how many intermediate calls (calculations) of C(3,3) are needed?
1
2
3
4
What is the complexity of calculating the longest palindromic subsequence using dynamic programming?
O(n)
O(n2)
O(n3)
All are incorrect
What condition must array A satisfy in order to perform binary search on it?
A. The array is sorted in ascending order
B. The array does not need to be sorted
C. The array is sorted in descending order
D. Both A and C are correct
What is the value of the variable k after executing the following code: int k=0, n=20; for(int i=1; i<=n; i++) { int j=i; while(j<=n) { k++; j=j*2; } }
400
30
40
All are incorrect
What is the time complexity of the following code: int i=1; while(i<=n) { k++; i=i*2; }
O(n)
O(nlogn)
O(logn)
O(1)
The best time complexity for the problem of finding the maximum sum of a contiguous subarray is
O(n2)
O(n3)
O(logn)
O(n)
Which of the following points does not belong to the exhaustive search method?
No strategy in searching for solutions
Trying all candidates for the solution
Dividing a large problem into smaller subproblems
Usually not used to solve problems with large data sizes
How does the backtracking method solve problems?
Search for solutions in depth
Search for solutions in breadth
Try all possible acceptable options at the same time
All are incorrect
In the 8 queens problem, after placing a queen in the first row, what is the minimum number of possibilities to place a queen in the second row?
6
5
7
9
In the 8 queens problem, after placing a queen in the first row and placing a queen in the second row, what is the minimum number of possible placements for a queen in the third row?
4
5
2
3
According to the Indian multiplication algorithm, when multiplying 13 by 17, what is the value of variable S after the second iteration?
0
13
39
81
In the helicopter patrol problem, suppose there are fuel tanks with values {3, 5, 1, 4} and the distance k=2, how many ways are there to arrange the fuel tanks for the patrol?
2
3
4
5
The similarity between the divide and conquer method and the dynamic programming method is
Used to solve optimization problems
Divides a large problem into smaller subproblems
Uses recursion to solve the problem
All of the above are correct
In the problem of a mouse moving in a maze to reach the destination, a cell is called safe when it satisfies how many conditions
3
4
5
2
Which of the following algorithms can produce incorrect results?
Greedy method
Divide and conquer method
Exhaustive search method
Probabilistic algorithm
According to the greedy method, how many times do we need to read the file when merging 5 files with sizes {13, 10, 4, 8, 3} into one file?
83
123
122
38
How many groups can probability algorithms be divided into?
1
2
3
4
Which algorithm design method describes solving a problem by listing all candidate solutions and checking each candidate to select the solution?
Randomized Algorithm
Dynamic Programming
Exhaustive Search
Greedy Algorithms
Which algorithm design method describes solving the problem of finding the contiguous subsequence with the largest sum by listing all possible subsequences and calculating the sum of each subsequence to select the one with the largest sum?
Greedy Algorithms
Exhaustive Search
Randomized Algorithm
Divide and Conquer
The algorithm design method that describes how a robot can take 2 types of steps with lengths of 1 m and 2 m by listing all possible ways to walk and checking in each way if there is a way that does not take more than 2 steps of 1 m
Dynamic Programming
Randomized Algorithm
Greedy Algorithms
Exhaustive Search
Which algorithm design method describes the solution to the problem of a robot that can take 2 types of steps with lengths of 1 m and 2 m by using state variables to analyze how to cover the distance?
Greedy Algorithms
Exhaustive Search
Randomized Algorithm
Dynamic Programming
Which algorithm design method describes solving the problem of a patrol aircraft by organizing a program that uses arrays to store information about fuel tanks and results?
Exhaustive Search
Dynamic Programming
Divide and Conquer
Backtracking
Which algorithm design method describes solving the Sudoku puzzle by assigning the numbers from 1 to 9 to the empty cells so that each row, column, and 3x3 region contains each number from 1 to 9 exactly once
Exhaustive Search
Backtracking
Dynamic Programming
Divide and Conquer
Which algorithm design method describes the process of solving the problem of counting how many ways to choose numbers to sum up to k from n different integers?
Randomized Algorithm
Dynamic Programming
Greedy Algorithms
Exhaustive Search
Which algorithm design method describes the enumeration of permutations of characters in the string S?
Dynamic Programming
Backtracking
Greedy Algorithms
Exhaustive Search
Which algorithm design method describes the solution to the problem of breaking down the number n into the sum of 3 numbers and counting how many ways it can be done?
Exhaustive Search
Greedy Algorithms
Randomized Algorithm
Dynamic Programming
Which algorithm design method describes the enumeration of binary sequences of length n such that no two adjacent bits are 1?
Dynamic Programming
Backtracking
Greedy Algorithms
Exhaustive Search
In the Merge Sort algorithm, what is the time complexity of the "merge" step?
O(1)
O(logN)
O(N)
O(N2)
What is another name for a Queue?
Last In First Out (LIFO)
First In Last Out (FILO)
Last In Last Out (LILO)
First In First Out (FIFO)
What is the time complexity of the Bubble Sort algorithm when sorting an already sorted array?
O(n)
O(n2)
O(nlogn)
All are incorrect
Use Radix Sort to sort the array: 47, 891, 3, 11, 27, 69, 26, 8; after step 1 (sorting by the unit place), the resulting array is:
3, 8, 11, 26, 27, 47, 69, 891
891, 11, 3, 26, 27, 47, 8, 69
891, 11, 3, 26, 47, 27, 8, 69
3, 8, 11, 26, 47, 27, 69, 891
The complexity of the Quick Sort algorithm is
O(n)
O(n2)
O(nlogn)
O(n3)
For the binary search algorithm to work, the array (list) must be
Unordered
Ordered (Sorted)
Heap format
Removed from the stack
Find an element in a matrix of size m×n with what complexity?
O(n2)
O(m2)
O(m×n)
All are incorrect
What is the minimum number of comparisons needed when searching in a sorted array of 256 elements (using binary search)?
1
10
256
8
The postfix form of the expression A/X+B∗CF is:
A X + B C * F + ^
A X / B C F ^ * +
A X + B C * F ^ +
A X B + / C * F ^ +
What is the process of handling each element in a list called?
sorting
merging
inserting
traversal
How many fields must each node in a singly linked list contain at a minimum?
Three fields
Two fields
Four fields
Five fields
How many pointers does a doubly linked list have at each node?
0
1
2
3
The correct order to swap the second and third nodes in a list l with more than 3 elements using the steps: (1) p=head; (2) head.next=q; (3) q=p.next; (4) p.next=q.next; (5) q.next=p; is:
(1), (5), (3), (4), (2)
(2), (3), (4), (5), (1)
(1), (3), (5), (4), (2)
(1), (3), (4), (5), (2)
The postfix form of the expression (M + N)*(C*D − E)*F / G is:
MN+ CD*E− FG /**
MN+ CD* E− F **G /
MN + CD* E − *F *G /
MN + CDE * − * F *G /
What does the following function do for a linked list with the head node as head? void fun1(Node head) { if(head == null) return; System.out.print(head.data + " "); fun1(head.next); }
Prints all nodes of the linked list
Prints all nodes in reverse order
Prints alternate nodes of the linked list
Prints alternate nodes in reverse order
What is the output of the function when start points to the head of the list: 1->2->3->4->5->6? void fun(Node start) { if(start == NULL) return; System.out.print (start.data + " "); if(start.next.next != null ) fun(start.next.next); System.out.print (start.data + " "); }
1 4 6 6 4 1
1 3 5 1 3 5
1 3 5
1 3 5 5 3 1
Which algorithmic model involves systematically listing all candidates for a solution and checking whether each candidate satisfies the problem statement or not?
Divide and Conquer
Dynamic Programming
Greedy
Brute Force
The appropriate algorithm to solve the Knight Tour problem is:
Divide and Conquer
Dynamic Programming
Backtracking
Brute Force
The appropriate algorithm to solve the problem of merging n files into 1 file is:
Divide and Conquer
Greedy
Backtracking
Brute Force
What technique is the Merge Sort algorithm an example of?
Divide and Conquer
Dynamic Programming
Backtracking
Brute Force
In the Travelling Salesman problem, if using the Brute Force technique and the number of cities is 30, how many trials are needed to find the result?
30!
29!
302
292
In the function to remove a node from a linked list, what is the correct order of the 3 commands: p->next = t (1); q = p (2); delete q (3);?
(1), (2), (3)
(3), (1), (2)
(2), (3), (1)
(2), (1), (3)
What is the command used in the function to calculate the sum of all nodes in a linked list?
p = NULL;
k = k + p->data;
p->next->next != NULL;
k = k + 1;
What is the command used in the function to calculate the height of a binary tree?
return 1 + max(height(T->left), height(T->right));
return max(height(T->left), height(T->right));
return 1 + height(T->left) + height(T->right);
All of the above are correct
In the Fibonacci sequence, what is F(6)?
5
8
13
1
Where is the maximum value located in a Binary Search Tree?
the leftmost branch
the rightmost branch
the root
There is no correct answer
What operation reduces the size of the stack?
popS()
pushS()
Both A and B are correct
All are incorrect
What operation increases the size of the queue?
addQ()
removeQ()
Both A and B are correct
All are incorrect
Let LCS(Xi, Yj) be the length of the longest common subsequence. What is the formula for calculating LCS(Xi, Yj) if X[i] ≠ Y[j]?
LCS(Xi,Yj)=LCS(Xi−1,Yj−1)
LCS(Xi,Yj)=LCS(Xi−1,Yj−1)+1
LCS(Xi,Yj)=max(LCS(Xi,Yj−1),LCS(Xi−1,Yj))
LCS(Xi,Yj)=max(LCS(Xi−1,Yj−1),LCS(Xi−2,Yj−2))
Prints the numbers from 0 to n-1
Prints the numbers from n-1 to 0
Prints the first n Fibonacci numbers
Prints the first n Fibonacci numbers in reverse order
The Karatsuba algorithm for multiplying two numbers with n digits requires a number of operations that scales according to which complexity?
O(n2)
O(n3)
O(nlog3)
O(nlogn)
Choose the C pseudocode of the function that takes a queue Q and uses a stack S to process it: void fun(Queue *Q) { Stack S; while (!isEmpty(Q)) { deQueue an element from Q and push that element into S; } while (!isEmpty(&S)) { Pop an element from S and enQueue (add) that element into Q; } } What does the above function generally do?
Remove the last element of Q
Keep Q unchanged as before calling
Make Q empty
Reverse the order of Q
To find two numbers with the largest product in an array of n integers using the brute force technique, how many pairs need to be checked?
n×n
n(n−1)
2n(n−1)
2n×n
To retrieve information from an AVL tree in descending order, what order should be traversed?
left, root, right
root, left, right
right, root, left
No correct answer
How much time is needed to insert a node x into a doubly linked list with n nodes?
O(n)
O(logn)
O(1)
O(nlogn)
Choose the C pseudocode of the function that takes a number n and uses stack S to process: void fun(int n) { Stack S; while (n > 0) { push(&S, n % 2); n = n/2; } while (!isEmpty(&S)) printf("%d ", pop(&S)); } What does the above function generally print?
Prints the binary representation of n in reverse order
Prints the value of log n
Prints the value of log n in reverse order
Prints the binary representation of n
Assuming p points to the head of the linked list: 3->2->5->7->6->9->NULL. What is the result of the statement cout << p->next->next->next->data?
6
2
7
All are incorrect
Matrix A of size 4×5 and matrix B of size 5×7 . How many multiplications are needed to compute A×B ?
20
35
150
All are incorrect
Which of the following algorithms can produce incorrect results?
Greedy method
Divide and conquer method
Exhaustive search method
Probabilistic algorithm
What is the similarity between the divide and conquer method and the dynamic programming method?
Used to solve optimization problems
Divides a large problem into smaller subproblems
Uses techniques to solve the problem
All of the above are correct
