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. It must use a sorted array.

  2. The requirement of sorted array is expensive when a lot of insertion and deletions are needed.

  3. There must be a mechanism to access middle element directly.

  4. The binary search algorithm is not efficient when the data elements are more than 1000.

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

Binary search IS efficient (O(log n)) even for large datasets - its power grows with size. The real limitations are: A) it requires a sorted array, B) maintaining sorted order is costly with frequent insertions/deletions (requires resorting or complex data structures), and C) it needs direct middle element access (random access, not suitable for linked lists). Option D is NOT a limitation.

Multiple choice
  1. We should not use recursion because iteration is always more efficient.

  2. We write less code if we use iteration instead of recursion.

  3. Recursion is always the most efficient technique to solve problems.

  4. In recursion, we divide a problem into subtasks where one subtask can be a smaller version of the original problem.

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

Recursion solves problems by breaking them into smaller instances of the same problem. The function calls itself with reduced input until reaching a base case. This divide-and-conquer approach is the essence of recursive thinking. Options A and B are incorrect - recursion has valid uses and is not about writing less code. Option C is wrong - recursion is not always most efficient due to overhead.

Multiple choice
  1. Stacks

  2. Queues

  3. Linked list

  4. Bubble sort

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

Queues are specifically designed as FIFO (First-In-First-Out) data structures where elements are removed from the front and inserted at the rear. Stacks use LIFO order (last-in-first-out). Linked lists allow insertion/deletion at any position, and bubble sort is a sorting algorithm, not a data structure.

Multiple choice
  1. LOC(Array[5]=Base(Array)+w(5-lower bound), where w is the number of words per memory cell for the array

  2. LOC (Array[5]=Base(Array[5])+(5-lower bound), where w is the number of words per memory cell for the array

  3. LOC(Array[5]=Base(Array[4])+(5-Upper bound), where w is the number of words per memory cell for the array

  4. LOC (Array[5]=Base(Array)+w(5-Upper bound), where w is the number of words per memory cell for the array

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

The formula for calculating memory address uses: Base Address + (Index - Lower_Bound) × Word_Size. Option A correctly shows this pattern (despite minor notation issues). Options B and C incorrectly index into the array rather than using the base address. Option D uses Upper bound instead of Lower bound in the offset calculation, which is incorrect.

Multiple choice
  1. Wasted memory

  2. Time complexity

  3. Memory access overhead

  4. None of these

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

Time complexity in memory management measures the computational cost of operations like allocating memory blocks, locating free space, or deallocating used blocks. Efficient allocation algorithms (like buddy systems) reduce this complexity, improving overall system performance.

Multiple choice
  1. True

  2. False

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

Arrays in C/C++ are stored in contiguous memory locations. This means elements are placed in adjacent memory cells, which enables pointer arithmetic and efficient array traversal. This contiguous allocation is a fundamental property of arrays.

Multiple choice
  1. o(n)2

  2. o(n2)

  3. o(2n)

  4. None of these

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

Bubble sort's worst-case time complexity is O(n²) because it makes n-1 passes, each comparing up to n-1 pairs of adjacent elements. The total comparisons approach (n-1) + (n-2) + ... + 1 = n(n-1)/2, which is O(n²). Option B correctly represents this quadratic complexity.

Multiple choice
  1. Space utilization

  2. Time efficiency

  3. Both (1) and (2)

  4. None of these

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

Data structure evaluation considers both space utilization (memory efficiency) and time efficiency (operation speed). The best data structure balances these competing factors - using minimal memory while enabling fast operations. This tradeoff is fundamental to algorithm design and optimization.

Multiple choice
  1. List

  2. Stack

  3. Tree

  4. None of these

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

Lists, stacks, and trees can all grow or shrink during runtime, making them dynamic data structures. Arrays are the primary example of static (non-dynamic) data structures with fixed sizes. Since lists, stacks, and trees are all dynamic, the correct answer is D - none of these are non-dynamic.