wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Worksheet Extraction

Total questions: 73

Worksheet time: 37mins

Name
Class
Date
1.

Queue is also called as

a)

Last In First Out

b)

First In Last Out

c)

Last In Last Out

d)

First In First Out

2.

When sorting an already ordered sequence, what is the time complexity of the bubble sort algorithm

a)

O(n)O(n)

b)

O(n2)O(n^2)

c)

O(nlogn)O(n \log n)

d)

All is incorrect

3.

If we sort the sequence of numbers 47, 891, 3, 11, 27, 69, 26, 8 using the Radix sort algorithm, then after step 1 (sorting by units), what is the resulting sequence

a)

3, 8, 11, 26, 27, 47, 69, 891

b)

891, 11, 3, 26, 27, 47, 8, 69

c)

891, 11, 3, 26, 47, 27, 8, 69

d)

3, 8, 11, 26, 47, 27, 69, 891

4.

The average-case time complexity of the Quick Sort algorithm is

a)

O(n)O(n)

b)

O(n2)O(n^2)

c)

O(nlogn)O(n \log n)

d)

O(n3)O(n^3)

5.

For a binary search algorithm to work, the array must be

a)

Unsorted

b)

Sorted

c)

In a heap

d)

Popped out of stack

6.

To find an element in a matrix of size m×nm \times n , what is the time complexity of the algorithm

a)

O(n2)O(n^2)

b)

O(m2)O(m^2)

c)

O(mn)O(mn)

d)

All is incorrect

7.

The minimum number of comparisons required when searching in an ascending ordered sequence of 256 elements (using the binary search algorithm) is:

a)

1

b)

10

c)

256

d)

8

8.

The postfix form of the expression A/X + B*C^F is:

a)

A X + B C * F + ^

b)

A X / B C F ^ * +

c)

A X + B C * F ^ +

d)

A X B + / C * F ^ +

9.

The operation of processing each element in the list is known as ......

a)

sorting

b)

merging

c)

inserting

d)

traversal

10.

Each node in a single linked list must contain at least .....

a)

Three fields

b)

Two fields

c)

Four fields

d)

Five fields

11.

A doubly linked list has _____pointers with each node.

a)

0

b)

1

c)

2

d)

3

12.

The correct order to permute a second and third note in list l has more than 3 elements [ (1) p=head; (2) head.next=q; (3) q= p.next; (4) p.next= q.next; (5) q.next=p; ]

a)

(1), (5), (3), (4), (2)

b)

(2), (3), (4), (5), (1)

c)

(1), (3), (5), (4), (2)

d)

(1), (3), (4), (5), (2)

13.

The postfix form of the expression (M+N)(CDE)F/G (M+N)*(C*D- E)*F / G is

a)

MN+ CD*E - FG /**

b)

MN + CD* E - F **G /

c)

MN + CD* E - *F *G /

d)

MN + CDE * - * F *G /

14.

What does the following function do for a given Linked List with first node as head? void fun1(Node head) { if(head == null) return; System.out.print(head.data + " " ); fun1(head.next); }

a)

Prints all nodes of linked lists

b)

Prints all nodes of linked list in reverse order

c)

Prints alternate nodes of linked list

d)

Prints alternate nodes in reverse order

15.

What is the output of following function for start pointing to first node of following linked 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 + " "); }

a)

1 4 6 6 4 1

b)

1 3 5 1 3 5

c)

1 3 5

d)

1 3 5 5 3 1

16.

What algorithmic paradigm that consists of systematically enumerating all possible candidates for the solution and checking whether each candidate satisfies the problem's statement?

a)

Divide and Conquer

b)

Dynamic Programming

c)

Greedy

d)

Brute Force

17.

The appropriate algorithm to solve the Knight Tour problem is:

a)

Divide and Conquer

b)

Dynamic Programming

c)

Backtracking

d)

Brute Force

18.

The appropriate algorithm to solve the Merge n files into one file (trộn n file thành 1 file) problem is:

a)

Divide and Conquer

b)

Dynamic Programming

c)

Greedy

d)

Backtracking

19.

The Merge Sort algorithm is an example for:

a)

Divide and Conquer technique.

b)

Dynamic Programming technique.

c)

Backtracking technique.

d)

Brute Force technique.

20.

For the Travelling salesman problem, if the Brute Force technique is used and the number of the city is 30, the number of tests to find the result is:

a)

30!

b)

29!

c)

30230^2

d)

29229^2

21.

In the function remove a node from the linked list, the right order for 3 statements: p= p->next =t (1); q=p (2); delete q (3); is:

a)

(1), (2), (3)

b)

(3), (1), (2)

c)

(2), (3), (1)

d)

(2), (1), (3)

22.

The statement used in the function calculating the sum of all nodes in a linked list is:

a)

p=NULL;

b)

k= k+ p->data;

c)

p->next->next!=NULL;

d)

k= k+1;

23.

The statement used in the function calculating the height of a binary tree is:

a)

return 1 + max(cao(T->left), cao(T->right));

b)

return max(cao(T->left), cao(T->right));

c)

return 1 + cao(T->left) + cao(T->right);

d)

All is correct.

24.

In the Fibonacci problem, F(6)F(6) equals what?

a)

5

b)

8

c)

13

d)

1

25.

Which one of the following is an application of Stack Data Structure?

a)

Managing function calls

b)

The stock span problem

c)

Arithmetic expression evaluation

d)

All of the above

26.

The largest value in the Binary Search Tree is in position:

a)

left most.

b)

right most.

c)

root.

d)

None is correct.

27.

The operation that reduces the size of the stack is:

a)

popS();

b)

pushS();

c)

A and B is correct.

d)

All is incorrect.

28.

The operation that increases the size of the queue is:

a)

addQ();

b)

removeQ();

c)

A and B is correct.

d)

All is incorrect.

29.

Let LCS(Xi,Yj) represent the length of longest common subsequence. The formula to calculate LCS(Xi,Yj) if X[i] <> Y[j] is:

a)

LCS(Xi,Yj) = LCS(Xi-1,Yj-1)

b)

LCS(Xi,Yj) = LCS(Xi-1,Yj-1) +1

c)

LCS(Xi,Yj) = max(LCS(Xi,Yj-1), LCS(Xi-1,Yj))

d)

LCS(Xi,Yj) = max(LCS(Xi-1,Yj-1), LCS(Xi-2,Yj-2))

30.

Consider the following pseudo code. What is the output of the segment code? void fun(int n) {queue q; q.push(0); q.push(1); for (int i = 0; i <= n; i++) int a = q.front(); q.pop(); int b = q.front(); q.pop(); q.push(b); q.push(a + b); cout<

a)

Prints numbers from 0 to n-1

b)

Prints numbers from n-1 to 0

c)

Prints first n Fibonacci numbers

d)

Prints first n Fibonacci numbers in reverse order

31.

The largest value in the binary tree is in position:

a)

Left most

b)

Right most.

c)

root.

d)

None is correct.

32.

The Karatsuba algorithm (procedure) for multiplication of two n-digit numbers requires a number of elementary operations proportional to:

a)

O(n2)O(n^2)

b)

O(n3)O(n^3)

c)

O(n(log3)O(n^{(log3)}

d)

O(nlogn)O(n^{logn})

33.

Following is C like pseudo code of a function that takes a Queue as an argument, and uses a stack S to do processing. void fun(Queue *Q) { Stack S; while (!isEmpty(Q)) { // deQueue (lấy) an item from Q and push the dequeued item to S push(&S, deQueue(Q)); } while (!isEmpty(&S)) { // Pop an item from S and enqueue (thêm) the popped item to Q enQueue(Q, pop(&S)); } } What does the above function do in general?

a)

Removes the last from Q

b)

Keeps the Q same as it was before the call

c)

Makes Q empty

d)

Reverses the Q

34.

To find the two numbers with the largest product (có tích lớn nhất) in an array of n integers, using Brute Force technique, the number of pairs to test is:

a)

n*n

b)

n*(n-1)

c)

n*(n-1)/2

d)

n*n/2

35.

In order to get the information stored in a AVL Tree in the descending order, one should traverse it in which of the following order?

a)

left, root, right.

b)

root, left, right.

c)

right, root, left.

d)

None is correct.

36.

The time required to insert a node x into a doubly linked list having n nodes is:

a)

O (n)

b)

O (log n)

c)

O (1)

d)

O (n log n)

37.

Following is C like pseudo code of a function that takes a number as an argument, and uses a stack S to do processing. 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 do in general?

a)

Prints binary representation of n in reverse order

b)

Prints the value of Logn

c)

Prints the value of Logn in reverse order

d)

Prints binary representation of n

38.

Assume p point to the head of the linked list ==>3->2->5->7->6->9->NULL. What is the output of the code cout<next->next->next->data;

a)

6

b)

2

c)

7

d)

All is incorrect

39.

Assume p point to the head of the linked list ==>3->2->5->7->6->9->NULL. What is the output of the segment code : Node *q=head->next; p->next= q->next; q->next=p; cout<next->data;

a)

5

b)

2

c)

3

d)

6

40.

The size of matrix A is 4*5 and the size of matrix B is 5*7. The number of multiplication when calculating A*B is:

a)

20

b)

35

c)

150

d)

All is incorrect

41.

The size of matrix A is 3*7, matrix B is 7*5 and matrix C is 5*2. The minimum of number of multiplication when calculating A*B*C is:

a)

42

b)

210

c)

135

d)

112

42.

The statement used in the function calculating the sum of all nodes in a binary tree is:

a)

return T->data + max(sum(T->left), sum(T->right));

b)

return T->data + sum(T->left)+ sum(T->right);

c)

return sum(T->left)+ sum(T->right);

d)

All is correct

43.

In the Hanoi Tower problem, if n=5, the number of moves required to solve is:

a)

10

b)

32

c)

31

d)

All is incorrect

44.

When inserting the value 8,3,6 into the AVL tree, we will use rotation:

a)

qL

b)

qR

c)

qLR

d)

qRL

45.

In the Hanoi Tower problem, if n=10, the number of moves required to solve is:

a)

1024

b)

10

c)

1023

d)

512

46.

When inserting the values 10, 20, 15 into an AVL tree, which rotation is used?

a)

qL

b)

qR

c)

qLR

d)

qRL

47.

The Merge Sort algorithm is an example of which algorithmic technique?

a)

Dynamic Programming

b)

Backtracking

c)

Brute Force

d)

Divide and Conquer

48.

Which algorithmic paradigm systematically enumerates all possible candidates for a solution and checks whether each candidate satisfies the problem statement?

a)

Divide and Conquer

b)

Dynamic Programming

c)

Greedy

d)

Brute Force

49.

Which algorithm is appropriate for finding a path in a maze?

a)

Dynamic Programming

b)

Divide and Conquer

c)

Brute Force

d)

Backtracking

50.

Which algorithm is appropriate to solve the problem of merging n files into a single file?

a)

Divide and Conquer

b)

Greedy

c)

Backtracking

d)

Brute Force

51.

For the Travelling Salesman Problem, if the Brute Force technique is used and the number of cities is 20, what is the number of tests required to find the result?

a)

20!20!

b)

20220^2

c)

19!19!

d)

19219^2

52.

Matrix A has size 2×52\times 5 and matrix B has size 5×75\times 7 . What is the number of scalar multiplications when calculating A×BA\times B ?

a)

10

b)

35

c)

70

d)

All are incorrect

53.

Which return statement is used in a function that counts the number of nodes in a binary tree?

a)

return T->data + count(T->left) + count(T->right);

b)

return 1 + count(T->left) + count(T->right);

c)

return count(T->left) + count(T->right);

d)

All are correct.

54.

For the Travelling Salesman Problem, if the Brute Force technique is used and the number of cities is 5, what is the number of tests required to find the result?

a)

5

b)

10

c)

20

d)

24

55.

The time complexity of binary search is:

a)

O(n)O(n)

b)

O(nlogn)O(n\log n)

c)

O(logn)O(\log n)

d)

All are incorrect

56.

To perform binary search on an array A, which condition must A satisfy?

a)

A is sorted in ascending order

b)

A does not need to be sorted

c)

A is sorted in descending order

d)

A or C are both correct

57.

Given the 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 after the code executes?

a)

400

b)

30

c)

40

d)

All are incorrect

58.

Backtracking solves problems by which approach?

a)

Searching for solutions depth-first

b)

Searching for solutions breadth-first

c)

Trying multiple possibilities that can be accepted simultaneously

d)

All are incorrect

59.

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?

a)

6

b)

5

c)

7

d)

All are incorrect

60.

In the 8-queens problem, after placing a queen in the first row and one queen in the second row, what is the minimum number of possibilities to place a queen in the third row?

a)

4

b)

5

c)

2

d)

3

61.

Using divide-and-conquer, how many multiplications are needed to compute x25x^{25} ?

a)

25

b)

5

c)

6

d)

7

62.

According to the Russian peasant multiplication algorithm, when multiplying 13 by 17, what is the value of S after the second iteration?

a)

0

b)

13

c)

39

d)

81

63.

In the helicopter patrol problem, suppose fuel can values are {3, 5, 1, 4} and the range k=2k=2 . How many arrangements of the fuel cans satisfy the range constraint?

a)

2

b)

3

c)

4

d)

5

64.

In the recursive definition of the binomial coefficient, when computing C(5,4)C(5,4) , how many times is C(3,3)C(3,3) computed as an intermediate call?

a)

1

b)

2

c)

3

d)

4

65.

What is a similarity between the divide-and-conquer method and dynamic programming?

a)

Used to solve optimization problems

b)

Splitting a large problem into smaller subproblems

c)

Using heuristics to solve problems

d)

All of the above

66.

In the rat-in-a-maze problem, a cell is considered safe when it satisfies how many conditions?

a)

3

b)

4

c)

5

d)

2

67.

In Sudoku, when placing a number into a cell, how many conditions must be checked?

a)

2

b)

3

c)

4

d)

5

68.

Which algorithmic approach can produce an incorrect result?

a)

Greedy method

b)

Divide and conquer

c)

Exhaustive search

d)

Probabilistic algorithm

69.

Using the greedy method for optimal file merging, how many total reads occur when merging five files of sizes {13, 10, 4, 8, 3} into a single file?

a)

83

b)

123

c)

122

d)

38

70.

Into how many groups can probabilistic algorithms be classified?

a)

1

b)

2

c)

3

d)

4

71.

What is the time complexity of computing the longest palindromic subsequence using dynamic programming?

a)

O(n)O(n)

b)

O(n2)O(n^2)

c)

O(n3)O(n^3)

d)

None of the above

72.

Which statement is not a characteristic of the brute-force method?

a)

Having no strategy in searching for the solution

b)

Trying all candidate solutions

c)

Splitting a large problem into smaller subproblems

d)

Usually not used for problems with large data sizes

73.

Under divide-and-conquer exponentiation, how many multiplications are needed to compute x25x^{25} ?

a)

25

b)

5

c)

6

d)

7