Computer Knowledge

Data Structures and Algorithms

1,518 Questions

Data Structures and Algorithms form the core of computer science, focusing on arrays, linked lists, trees, and sorting mechanisms. These concepts are essential for solving complex computational problems efficiently. Test takers preparing for technical and administrative IT exams will find these questions highly relevant.

Array OperationsLinked List ApplicationsSorting AlgorithmsTree Data StructuresMultilevel IndexingAlgorithm Time Complexity

Data Structures and Algorithms Questions

Multiple choice
  1. 46, 42, 34, 52, 23, 33

  2. 34, 42, 23, 52, 33, 46

  3. 46, 34, 42, 23, 52, 33

  4. 42, 46, 33, 23, 34, 52

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Multiple choice
  1. The algorithm uses dynamic programming paradigm.

  2. The algorithm has a linear complexity and uses branch and bound paradigm.

  3. The algorithm has a non-linear polynomial complexity and uses branch and bound paradigm.

  4. The algorithm uses divide and conquer paradigm.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This algorithm uses dynamic programming because it solves the problem by breaking it into smaller subproblems (L_i depends on L_{i+1]) and stores the results. It builds the solution bottom-up from the base case L[n-1] = 1. The complexity is O(n) linear time. It does not use branch and bound (which prunes search trees) or divide and conquer (which recursively splits problems).

Multiple choice
  1. 0

  2. 1

  3. n!

  4. $\frac{1} {n+1} .^{2n}C_n$
Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The number of distinct BSTs with n distinct keys is the nth Catalan number: C(n) = (1/(n+1)) * (2nCn) = (2n)!/((n+1)!n!). This is a fundamental result in combinatorics - the structure of a BST is determined solely by the relative ordering of elements. With n distinct elements and n nodes, there are exactly C(n) ways to build a BST.

Multiple choice
  1. 2

  2. 9

  3. 5

  4. 3

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Load R1,a ; R1 $\leftarrow$M[a] Load R2,b ; R2 $\leftarrow$M[b] Sub R1,R ; R1 $\leftarrow$R1 – R2 Load R2 ,c ; R2 $\leftarrow$M[c] Load R3 ,d ; R3 $\leftarrow$Md] Add R2 , R3 ; R2 $\leftarrow$R2 R3 Load R3 ,e ; R3 $\leftarrow$M[e] Sub R3, R2 : R3$\leftarrow$R3 – R2 Add R1 ,R3 ; R1 $\leftarrow$R1 R3 Minimum 3 Registers are required.

Multiple choice
  1. full: (REAR+l) mod n == FRONT empty: REAR ==FRONT

  2. full:(REAR+l)mod n == FRONT empty: (FRONT+l)mod n==REAR

  3. full: REAR == FRONT empty: (REAR+l) mod n == FRONT

  4. full:(FRONT+ l)mod n == REAR empty: REAR == FRONT

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Multiple choice
  1. O(nlogn)

  2. O(n2 logn)

  3. O(n2 +logn)

  4. O(n2)

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The height of the recursion tree using merge sort is logn and n2 comparisons are done at each level, where at most n pairs of strings are compared at each level and n comparisons are required to compare any two strings, So the worst case running time is O(n2 logn)

Multiple choice
  1. B1: (1 + height (n$\rightarrow$right)) B2: (1 - max (h1, h2))
  2. B1: (height (n$\rightarrow$right)) B2: (1 - max (h1, h2))
  3. B1: height (n$\rightarrow$right) B2: max (h1, h2)
  4. B1: (1 + height (n$\rightarrow$right)) B2: max (h1, h2)
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Multiple choice
  1. (j mod v) *k to (j mod v) * k + (k - 1)

  2. (j mod v) to (j mod v) + (k - 1)

  3. (j mod k) to (j mod k) + (v - 1)

  4. (j mod k) * v to (j mod k) * v + (v - 1)

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Set number in the cache = (main memory block number) MOD number of sets in the cache As the lines in the set are placed in sequence, we can have the lines from 0 to K – 1 in the set. Number of sets = v Main memory block number = j First line = (j mod v); last line = (j mod v) + (k – 1)