Computer Knowledge

Data Structures and Algorithms

1,256 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. 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)

Multiple choice
  1. n/2

  2. n-1

  3. 2n-1

  4. 2n

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

2 × (4) − 1 = 7 reductions $\Rightarrow$2n − 1 reductions are required. [Note: Unit production is given as A $\rightarrow$ a, it was typo] Above reductions are not in reverse of RMD but when they are reduced in bottom-up parsing, we will get same number of reductions.

Multiple choice
  1. $\Theta(1)$
  2. $\Theta(\sqrt{\log} n)$
  3. $\Theta(\frac{\log n}{\log \log n})$
  4. $\Theta(\log n)$
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

After constructing a max-heap in the heap sort, the time to extract maximum element and then heapifying the heap takes $\Theta$(log n) time by which we could say that $\Theta$ (log n) time is required to correctly place an element in sorted array. If $\Theta$ (logn) time is taken to sort using heap sort, then number of elements that can be sorted is constant which is $\Theta$ (1).

Multiple choice
  1. ExitX (R, S) {
       P (R) ;
       V (S) ;
    }
    EntryY (R, S) {
       P (S);
       V (R);
    }
    
  2. ExitX(R, S) { 
      V (R); 
      V (S);
    }
    EntryY (R, S) {
      P (R);
      P (S);
    }
    
  3. ExitX (R, S) {
      P (S);
      V (R);
    }
    EntryY (R, S) {
      V (S);
       P (R);
    }
    
  4. ExitX (R, S) {
      V (R);
      P (S);
    }
    EntryY (R, S) {
      V (S);
      P (R);
    }
    
Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Process X produces a[i] and signals completion. Process Y consumes a[i] and must wait for X to produce it. ExitX signals completion by V(R) and V(S) (signal both semaphores). EntryY waits for X's signal by P(R) then P(S) (wait on both semaphores). This ensures Y only accesses a[i] after X has written it. Option B implements this correctly - V(R), V(S) in ExitX and P(R), P(S) in EntryY ensures proper synchronization.

Multiple choice
  1. 2.4 ns

  2. 2.3 ns

  3. 1.8 ns

  4. 1.7 ns

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

Multiple choice
  1. 2.4 ns

  2. 2.3 ns

  3. 1.8 ns

  4. 1.7 ns

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

Multiple choice
  1. 0

  2. $\dfrac{1}{16}$
  3. $\dfrac{1}{8}$
  4. 16

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