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. 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. Depth first search algorithm

  2. Depth limited search algorithm

  3. Algorithm

  4. Uniform cost search algorithm

  5. Metropolis algorithm

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

This algorithm of artificial intelligence avoids the pitfalls of depth first search by imposing a cutoff on the maximum depth of a path.

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. node address field

  2. data field

  3. next address field

  4. none of these

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

Every linked list node must contain a 'next' address field (pointer) that points to the subsequent node or null if it's the last node. Without this field, nodes couldn't be linked together to form a list. Nodes typically also have a data field, but the next pointer is the essential requirement.

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.

Multiple choice
  1. Stacks

  2. Queues

  3. Dequeues

  4. None of these

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

Stacks are used for postfix expression evaluation because operators are applied to the most recent operands, matching the LIFO (Last In First Out) principle. When encountering an operator, pop required operands from the stack, apply the operation, and push the result back.