ADA1
ADA1
void solve() {
string s = "scaler";
int n = s.size();
for(int i = 0; i < n; i++) {
s = s + s[i];
}
cout << s << endl;
}
a. O(n)
b. O(n^2)
c. O(1)
d. O(log n)
16. What is the time complexity of the binary search algorithm?
a. O(n)
b. O(1)
c. O(log2n)
d. O(n^2)
17. What will be the best sorting algorithm, given that the array elements are small(<=1e6)?
a. Bubble sort
b. Merge sort
c. Counting sort
d. Heap sort
18. What is the time complexity of the Sieve of Eratosthenes to check if a number is prime?
a. O(nlog(logn)) Precomputation, O(1) for check
b. O(n) Precomputation, O(1) for check
c. O(n*logn) Precomputation, O(logn) for check
d. O(n) Precomputation, O(logn) for check
19. The worst-case time complexity of Quicksort is
a. O(n)
b. O(1)
c. O(log2n)
d. O(n^2)
20. What is the technique called in which it does not require extra memory for carrying out the
sorting procedure?
a. Stable
b. Unstable
c. In-place
d. In-partition
21. Identify the slowest sorting technique among the following
a. Merge sort
b. Quick sort
c. Bubble sort
d. Selection sort
22. Select the correct recurrence relation of Tower of Hanoi
a. T(N)=2T(N-1)+1
b. T(N)=2T(N/2)+1
c. T(N)=2T(N-1)+N
d. T(N)=2T(N-2)+2
23. Identify the sorting technique which compare adjacent elements in a list and switches
whenever necessary
a. Merge sort
b. Quick sort
c. Bubble sort
d. Selection sort
24. Which of the following algorithms are used to find the shortest path from a source node to all
other nodes in a weighted graph?
a. BFS
b. Dijkstra’s Algorithm
c. Prims Algorithm
d. Kruskal’s Algorithm
25. Which of the following are applications of Topological Sort of a graph?
a. Sentence Ordering
b. Course Scheduling
c. OS Deadlock Detection
d. All of the above
26. What is the time complexity in decreasing the node value in a binomial heap?
a. O(1)
b. O(N)
c. O(logN)
d. O(NlogN)
27. What should be considered when designing an algorithm?
a. If this software is used correctly
b. If the hardware is used correctly
c. If there is more than one way to solve the problem
d. All of the above are correct
28. Which of the following is known to be not an NP-Hard Problem?
a. Vertex cover problem
b. o/1 Knapsack problem
c. Maximal independent set problem
d. Travelling salesman problem
29. What is the difference between
class Codechef {
public static void main(String[] args) {
System.out.println(12);
System.out.println(11);
}
}
and
class Codechef {
public static void main(String[] args) {
System.out.println(12);
System.out.println(11);
}
}
Select one of the following options.
a. The first code will have outputs on the same line, and the second code will output
inseparate lines.
b. The two codes are equivalent.
c. The second code is wrong, and will not compile.
Ans: b
30. Depth First Search is equivalent to which of the traversal in the Binary
Trees?
a. Pre-order Traversal
b. Post-order Traversal
c. Level-order Traversal
d. In-order Traversal
Ans: a
Ans: c
Ans: c
33. Suppose T(n) = 2T(n/2) + n, T(0) = T(1) = 1 Which one of the following is false.
a. T(n) = O(n^2)
b. T(n) = \theta(nLogn)
c. T(n) = \Omega(n^2)
d. T(n) = O(nLogn)
Ans: c
34. In a complete k-ary tree, every internal node has exactly k children. The number of leaves in
such a tree with n internal nodes is:
a. nk
b. (n – 1) k+ 1
c. n( k – 1) + 1
d. n( k – 1)
Ans: c
Ans: a
36. What is the time complexity of Floyd–Warshall algorithm to calculate all pair shortest path in
a graph with n vertices?
a. O(n2log(n))
b. Theta(n2log(n))
c. Theta(n4)
d. Theta(n3)
Ans: d
Ans: b
38. ______ solution requires reasoning built on knowledge and experience
a. Algorithmic Solution
b. Heuristic Solution
c. Random Solution
d. None of these
Ans: b
39. Artificial Intelligence makes use of following prominently
a. Database
b. Data Warehouse
c. Knowledge base
d. None of these
Answer: c
Ans: d
Ans: a
Ans: b1
Ans:a
Ans:b
45. Evaluate for the equation e = 5*a\d*(b+1) where a = 5, b = 4,c = 3, d = 12
a. 10
b. 24
c. 0
d. 10
Ans: c
46. There are four algorithms A1, A2, A3, A4 to solve the given problem with the order log(n),
nlog(n), log(log(n))n/log(n),Which is the best algorithm.
a. A1
b. A2
c. A3
d. A4
Ans: c
Ans: d
48. The three factors contributing to the sort efficiency considerations are the efficiency in
coding, machine run time and the space requirement for running the procedure.
a. True
b. False
Ans: a
49. How many passes are required to sort a file of size n by bubble sort method?
a. N2
b. N
c. N-1
d. N/2
Ans: c
50. How many number of comparisons are required in insertion sort to sort a file if the file is
sorted in reverse order?
a. N2
b. N
c. N-1
d. N/2
Ans: a