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
-
Stack
-
Multi set
-
Array
-
Structure
-
Queue
E
Correct answer
Explanation
This data structure is an ordered list in which insertion always occurs at one end and deletion always occurs at the other end.
-
Abstract level
-
Storage structure
-
Implementation level
-
Structure
-
RAID level 0
C
Correct answer
Explanation
In this specification of data structure, the user needs to create the sequence of instructions that will cause the operations to perform as specified.
-
Dequeue
-
Multi set
-
List
-
Array
-
Structure
A
Correct answer
Explanation
In this data structure, the elements cannot be inserted into the middle of list or deleted from the middle of the list.
-
Sorting phase
-
Linear search
-
Merging phase
-
Hash key
-
None of these
C
Correct answer
Explanation
In this phase, merging of the sorted runs is carried out over in one or more phases.
-
It must use a sorted array.
-
The requirement of sorted array is expensive when a lot of insertion and deletions are needed.
-
There must be a mechanism to access middle element directly.
-
The binary search algorithm is not efficient when the data elements are more than 1000.
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.
-
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.
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.
-
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.