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
-
We should not use recursion because iteration is always more efficient.
-
We write less code if we use iteration instead of recursion.
-
Recursion is always the most efficient technique to solve problems.
-
In recursion, we divide a problem into subtasks where one subtask can be a smaller version of the original problem.
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.
-
Stacks
-
Queues
-
Linked list
-
Bubble sort
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.
-
LOC(Array[5]=Base(Array)+w(5-lower bound), where w is the number of words per memory cell for the array
-
LOC (Array[5]=Base(Array[5])+(5-lower bound), where w is the number of words per memory cell for the array
-
LOC(Array[5]=Base(Array[4])+(5-Upper bound), where w is the number of words per memory cell for the array
-
LOC (Array[5]=Base(Array)+w(5-Upper bound), where w is the number of words per memory cell for the array
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.
-
Wasted memory
-
Time complexity
-
Memory access overhead
-
None of these
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.
-
Metropolis algorithm
-
Uniform cost search algorithm
-
Alpha-beta algorithm
-
Algorithm
-
Merge sort algorithm
C
Correct answer
Explanation
This algorithm is more efficient because it prunes away the branches of the search tree.
-
Time complexity
-
Process affinity
-
Optimality
-
Automated debugging
-
Caching
C
Correct answer
Explanation
This technique is used to provide the strategy to find the highest quality solution when there several different solutions.
-
Depth first search algorithm
-
Depth limited search algorithm
-
Algorithm
-
Uniform cost search algorithm
-
Metropolis algorithm
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.
A
Correct answer
Explanation
In C and C++, uninitialized local array elements contain garbage values - whatever bits were previously in those memory locations. Only static and global arrays are automatically initialized to zero. This is why explicit initialization is important.
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.
-
node address field
-
data field
-
next address field
-
none of these
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.
-
o(n)2
-
o(n2)
-
o(2n)
-
None of these
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.
-
Space utilization
-
Time efficiency
-
Both (1) and (2)
-
None of these
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.
-
List
-
Stack
-
Tree
-
None of these
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.
-
Stacks
-
Queues
-
Dequeues
-
None of these
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.
-
Stack
-
Queue
-
Array
-
None of these
A
Correct answer
Explanation
The stack insertion operation (push) adds a new node to the top of the stack. The description matches this exactly: create a node, store the element, and insert at the top (the only insertion point in a stack).