MIDTERM TEST 2
Câu 1: (IDHSQAS02) N elements of a Queue are to be reversed using another queue. The number
of enqueuer() and dequeuer() operations required to do is?
A. N
B. The task cannot be accomplished
C. 2*N
D. 4*N
Câu 2: (IDMSOA12) The Merge method in Merge sort algorithm is used to combine two sorted
array A = {3,27,38,43} and B = {9,10,82}. What is the result array C?
A. C = {9,10,82,3,27,38,43}
B. C = {3,9,10,27,38,43,82}
C. C = {3,27,38,43,9,10,82}
D. C = {3,82,9,43,10,38,27}
Câu 3: (IDHAOA01) What is the time complexity of the following code with respect to the input
size N?
A. O(logN)
B. O(N)
C. O(1)
D. O(N^2)
Câu 4: (IDESOA14) Suppose that we are using Radix sort on N elements, each element has P digits
in base b (each digit is in the range [0 .. B-1]), and couting sort algorithm is used to sort the digits.
What is the time complexity of the Radix sort algorithm?
A. O(P(N+B))
B. O(N.P.B)
C. O(P+N+B)
D. O(B+N)
Câu 5: (IDEAOA14) Suppose that the estimated time complexity of algorithm A and B is TA(N) and
TB(N) respectively. How can we compare the time complexity of A and B?
A. We compare the value of TA and TB corresponding to some special value of n
B. We compare the grow rate of the leading terms of TA(N) and TB(N)
C. We compare the value of TA and TB corresponding to every value of n
D. We compare the value of TA and TB corresponding to a very large, pre-defined value of n
Câu 6: (IDMAOA07) Estimate the time complexity in Big-Oh notation, with respect to the input size
N for the code below:
a = 0; c = d + e;
for (int i = 0; i < 1000; i++) {
x = y + z; b++;
n = n * i;
return n;
A. O(N)
B. O(1)
C. O(1000N)
D. O(N^1000)
Câu 7: (IDESQAS09) Which of the following is not an application of the stack data structure?
A. Message buffering
B. Managing function calls
C. Arithmetic expression evaluation
D. Backtracking
Câu 8: (IDEAO07) Which statement is wrong?
A. The estimated time complexity of an algorithm T(N) varies with the input data of the
different size
B. The time complexity of an algorithm T(N) is estimated by counting the number of primitive
operations
C. The estimated time complexity of an algorithm T(N) does not vary with the input data of
the same size N
D. Pseudocode can be used to describe an algorithm for estimating its time complexity T(N)
Câu 9 (IDMSQ07): One difference between a queue and a stack is:
A. Queues use two ends of the structure; stacks use only one
B. Stacks use two ends of the structure, queues use only one
C. Queues require linked lists, but stack do not
D. Stacks require linked lists, but queues do not
Câu 10 (IDHSOA05): Consider a modified version of Merge sort where the input array is partitioned
at the position one-third of the length N of the array. What is the recurrence of this algorithm?
A. T(N)=2T(N/3)+O(N)
B. T(N)=2T(2N/3)+O(N)
C. T(N)=T(N/2)+T(3N.2)+O(N)
D. T(N)=T(N/3)+T(2N/3)+O(N)
Câu 11 (IDMSOA08): Which array represents a Min-Heap?
A. A={2,5,9,8,10,13,12,22,50}
B. A={2,5,9,22,10,13,12,8,50}
C. A={50,22,13,12,10,8,9,5,2}
D. A={9,5,2,8,10,13,12,22,50}
Câu 12 (IDMSQAS06): In the following list of number: 8 17 25 35 41 52 60 75 86. How many
comparisons would binary search take to find 52?
A. 6
B. 4
C. 2
D. 3
Câu 13 (IDMLI07): Consider method F in Java and a singly linked linked list L below. Suppose that H
is the head node of the list L. What is the result if we call F(H)?
if (node != null)
{
F(node.getNext());
System.out.println (node.getData());
}
}
L={'A'-->'B'-->'C'-->'D'-->'E'-->'F'}
H is the head of L, H='A'
A. ‘A’-->‘B’-->‘C’-->‘D’-->‘E’-->‘F’
B. ‘F’-->‘E’-->‘D’-->‘C’-->‘B’-->‘A’
C. ‘A’-->‘C’-->‘E’
D. ‘B’-->‘D’-->‘F’
Câu 14 (IDELI16): A mathemactical-model with a collection of operations defined on that model is
called?
A. Abstract Data Type
B. Primitive data type
C. Algorithm
D. Data Structure
Câu 15 (IDESQ01): Which statement below is wrong concerning to stack data structure?
A. push() and pop() are two operations defined in Stack’s ADT
B. A stack contains a sequence of zero or more items of the same type
C. List-based stack has no limit on total number of items of the stack
D. It is a First In First Out (FIFO) list
Bonus round
IDMAOA03 – What is the time complexity of the following algorithm with respect to the input size N
Select one:
O(M)
O(N+M)
O(N)
O(N*M)
IDHSOA06
– Which of the following sorting algorithms has the lowest worst case time complexity?
Select one:
Quick sort O(N^2)
Bubble sort O(N^2)
Merge sort O (NlogN)
Insertion sort O(N^2)
IDEAOA04
– Which statement is correct concerning to the complexity of algorithm?
Select one:
The complexity of an algorithm is determined by the total lines of code of the program that implements the
algorithm using a given programming language.
The complexity of an algorithm is a measure of the amount of time and cost needed to implement this
algorithm.
The complexity of an algorithm is a measure of the amount of time and space required by the
algorithm for an input of a given size n.
The complexity of an algorithm is determined by the maximum value of the input size n that does not affect
the correctness of the algorithm.
IDEAOA05
– When evaluating algorithm’s complexity, which approach makes possible an evaluation that is independent
of the hardware and software environments?
Select one:
Using input data sets of varying size.
Theoretical approach.
Measuring the running time and memory space using the same hardware and software environment.
Experimental approach. -> evaluate efficience of algo, measure running time
IDHAOA09 – What is O(T(N)), if
Choose one answer.
O(NlogN)
O(logN)
O(N^2)
O(2^N)
IDESQAS07 – A close hashing hash table has an array size of 512. What is the maximum number of entries
that can be placed in the table?
Choose one answer.
256.
1024.
There is no maximum.
511.
512.
IDESQAS13 – Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash
function: h(k)=k mod 10. Which of the following statements are true?
Choose one answer.
1471 and 6171 has to different value.
Each element hashes to a different value.
All elements hash to the same value.
4199 and 9679 hash to the same value.
IDESOA12 – In Radix sort algorithm …?
Choose one answer.
A stable sorting algorithm is used to sort the digits.
Sort key can be a string or an object.
The time complexity is O(NlogN).
Digits are sort from left most to right most.
IDMSOA09
– Which array represents a Max-Heap?
Select one:
A={78,56,45,32,23,8,15}
A={8,15,23,32,56,45,78}
A={78,23,15,56,32,8,45}
A={8,78,56,32,15,23,45}
IDELI14
– Which is the common form of a node X in a Doubly Linked List?
Select one:
X(data, next)
X(data)
X(data, prev, next)
X(data, prev)
IDELI15
– Which is common form of a node X in a Singly Linked List?
Select one:
X(data, next)
X(data)
X(data, prev, next)
X(data, prev)
IDESOA04 – The time complexity of an algorithm T(N) is estimated by couting the number of primitive
operations.…?
Choose one answer.
The order of both key and non-key values are maintained.
The relative order of elements with equal keys are maintained.
The order of key values are maintained.
The relative order of elements with equal keys are not maintained.
IDMSQ08 – In an array-based stack, which operation has time complexity O(N) in the worst-case?
Choose one answer.
No operation that has time complexity O(N).
isEmpty().
push().
pop().
IDMLI03 – In an Array-based list, what does this code do to the list?
Choose one answer.
Traversing the list.
Remove an item from the list.
Duplicate items in the list.
Remove all item from the list except one.
IDEAOA01 - Which statement below is correct?
Choose one answer.
An algorithm takes the input to a problem and transforms it to the output which solves
the problem. There is only one algorithm for a specific problem.
An algorithm is a program written in machine code.
An algorithm is a step-by-step procedure for solving a problem in a finite amount of
time.
An algorithm is a representation of a program in pseudocode.
IDMSQ04 – A queue Q has 05 character items, Q={“5”, “4”, “3”, “2”, “1”} where “1” is the front and “5” is
the rear of Q. Which operations must be perform to change Q into a new state: Q={“3”, “2”, “1”, “4”, “5”}?
Choose one answer.
enqueue(“5”)-->enqueue(“4”)-->dequeue()-->dequeue()
enqueue(“4”)-->enqueue(“5”)-->dequeue()-->dequeue()
dequeue()-->enqueue(“5”)-->dequeue()-->enqueue(“4”)
dequeue()-->dequeue()-->enqueue(“5”)-->enqueue(“4”)
IDESOA10 – In Merge sort algorithm …?
Choose one answer.
The worst case is O(N^2).
The input array is divided into two parts based on the pivot values.
The input array is divided into two parts at the middle of the array.
The merge algorithm combines two sorted array by attaching the second array
to the end of the first one.
Complete the code for the dequeue() method in array-based circular queue?
Choose one answer.
rear=rear+1
front=(front+1)%maxSize
front=front+1
rear=(rear+1)%maxSize
IDESOA09 – Which statement is wrong concerning to the Heap data structure?
Choose one answer.
It is used in Heap sort algorithm.
In a min-heap the parent node value is always greater than or equal to its children’s values.
An array can be used to store heap’s nodes.
It is a tree where all nodes have zero, one or two children.
Remove all item from the list except one.
1
Marks: 1
IDEAOA01 - Which statement below is correct?
Choose one answer.
An algorithm takes the input to a problem and transforms it to the output which solves
the problem. There is only one algorithm for a specific problem.
An algorithm is a program written in machine code.
An algorithm is a step-by-step procedure for solving a problem in a finite amount of
time.
An algorithm is a representation of a program in pseudocode.
Question2
Marks: 1
IDMSQ04 – A queue Q has 05 character items, Q={“5”, “4”, “3”, “2”, “1”} where “1” is the front and “5” is the rear of Q.
Which operations must be perform to change Q into a new state: Q={“3”, “2”, “1”, “4”, “5”}?
Choose one answer.
enqueue(“5”)-->enqueue(“4”)-->dequeue()-->dequeue()
enqueue(“4”)-->enqueue(“5”)-->dequeue()-->dequeue()
dequeue()-->enqueue(“5”)-->dequeue()-->enqueue(“4”)
dequeue()-->dequeue()-->enqueue(“5”)-->enqueue(“4”)
Question3
Marks: 1
IDMAOA13 – Consider three algorithms which have the time complexity in Big-Oh notation below. Please arrange these
algorithms in the ascending order of time efficiency (the slowest algorithm is the first one in the order).
Choose one answer.
Algorithm 3, Algorithm 1, Algorithm 2
Algorithm 1, Algorithm 3, Algorithm 2
Algorithm 1, Algorithm 2, Algorithm 3
Algorithm 3, Algorithm 2, Algorithm 1
Algorithm 2, Algorithm 3, Algorithm 1
Algorithm 2, Algorithm 1, Algorithm 3
Question4
Marks: 1
IDEL16 – A mathematical-model with a collection of operations defined on that model is called?
Choose one answer.
Data structure.
Primitive data type.
Abstract Data Type.
Algorithm.
Question5
Marks: 1
IDESOA10 – In Merge sort algorithm …?
Choose one answer.
The worst case is O(N^2).
The input array is divided into two parts based on the pivot values.
The input array is divided into two parts at the middle of the array.
The merge algorithm combines two sorted array by attaching the second array
to the end of the first one.
Question6
Marks: 1
IDESQ10 – Complete the code for the dequeue() method in array-based circular queue?
Choose one answer.
rear=rear+1
front=(front+1)%maxSize
front=front+1
rear=(rear+1)%maxSize
Question7
Marks: 1
IDMLI09 - Consider method F in Java and a singly linked list L below. Suppose that H is the head node of the list L. What
is the result if we call F(H)?
Choose one answer.
‘F’-->‘D’-->‘B’
‘A’-->‘C’-->‘E’
‘E’-->‘C’-->‘A’
‘B’-->‘D’-->‘F’
Question8
Marks: 2
Please complete the code of the linear search method below?
public intLinearSearch(int[] a, int key)
{
int index=0;
boolean found=false;
intpos=-1;
while ((index<n)&&(!found)
{
a[index]!=key
if ( )
{
found=true;
pos=index;
}
index++;
}
pos
return ;
}
Question9
Marks: 1
IDESOA09 – Which statement is wrong concerning to the Heap data structure?
Choose one answer.
It is used in Heap sort algorithm.
In a min-heap the parent node value is always greater than or equal to its
children’s values.
An array can be used to store heap’s nodes.
It is a tree where all nodes have zero, one or two children.
Question10
Marks: 1
IDHAOA08 – The method f3(N) calls two methods f1(N) and f2(N) as follows. What is the time complexity of method
f3(N)?
Choose one answer.
O(N^4)
O(N^2)
O(N)
O(N^3)
Question11
Marks: 1
IDESQAS11 – Complete the code below to search for key in an array using linear seach algorithm?
Choose one answer.
-1.
i.
a[i].
true.
Question13
Marks: 1
IDHSQ04 – In the method F below, q1 and q2 are two queues containing integer items. What should method F print on the
screen?
Choose one answer.
1 2 3 4 5 6 7 8 9 10
9 7 5 3 1 10 8 6 4 2
9 10 7 8 5 6 3 4 1 2
1 3 5 7 9 2 4 6 8 10
10 9 8 7 6 5 4 3 2 1
Question15
Marks: 1
IDMSOA01 – Selection sort algorithm is used to sort the array A={23,78,45,8,32,56} in the ascending order. What are the
items of A after 03 sort pass?
Choose one answer.
A={8,32,23,45,56,78}
A={78,45,56,8,32,23}
A={78,45,56,23,32,8}
A={23,32,8,45,56,78}
Question16
Marks: 1
IDESQAS10 – Consider a hash table of size seven, with starting index zero, and a hash function h(k)=(3k+4) mod 7. What
is the address of the key k=10?
Choose one answer.
0.
3.
6.
7.
Question17
Marks: 1
IDHSOA03 – Given an array A that is almost sorted (only one or two elements are misplaced). Which sorting algorithm
gives the best time efficiency when applied on A.
Choose one answer.
Selection sort
Insertion sort
Bubble sort
Quick sort