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
-
Reverse a word
-
Backtracking
-
Undo task in text
-
Conversion of decimal to binary
-
None of the above
E
Correct answer
Explanation
Yes, all of the above are the applications of the stack data structure.
-
A queue is defined as an ordered list.
-
A queue can be implemented by the array.
-
The element is deleted from the from end of the queue.
-
A queue is a FIFO (First In First Out Data Structure).
-
None of the above
E
Correct answer
Explanation
Yes, all of the above are the true statements.
-
Array
-
Queue
-
Stack
-
Tree
-
Graph
C
Correct answer
Explanation
A stack is a last in first out type of data structure. Here, the insertion and deletion of elements can be done only from one end.
-
Traversing
-
Searching
-
Merging
-
Sorting
-
Inserting
D
Correct answer
Explanation
Arranging the records in some logical order is referred to as sorting.
-
ia[0];
-
*ia;
-
&ia[0];
-
Ia[1];
C
Correct answer
Explanation
It gives the address of the first element of the array.
-
Vector
-
List
-
Both list and vector
-
Random access is not supported in STL.
A
Correct answer
Explanation
Vector consists of contiguous memory location and is the appropriate choice.
-
Tree
-
Graph
-
Linked list
-
All of the above
-
None of the above
C
Correct answer
Explanation
It is a linear data structure. A linear data structures elements are arranged in a list.
-
O(|E|log|V|)
-
O(VlogE)
-
O(EV)
-
O(log V)
A
Correct answer
Explanation
Kruskal's algorithm uses edge sorting and union-find. Sorting |E| edges takes O(|E| log |E|) ≈ O(|E| log |V|) since |E| ≤ |V|². Union-find operations are nearly O(1) with path compression and union by rank. The dominant cost is sorting, giving O(|E| log |V|). Adjacency list representation is standard.
-
O(|V|2)
-
O(VlogE)
-
O(EV)
-
O(log V)
A
Correct answer
Explanation
Prim's algorithm on an adjacency matrix requires scanning all vertices to find the minimum weight edge, taking O(|V|) per vertex. With |V| iterations, total is O(|V|²). With Fibonacci heap + adjacency list, it becomes O(|E| + |V| log |V|), but O(|V|²) is the standard answer for basic implementation.
-
O(|E|log|V|)
-
O(VlogE)
-
O(EV)
-
O(log V)
A
Correct answer
Explanation
Prim's algorithm using a binary heap performs O(|E|) extract-min and O(|V|) decrease-key operations, each costing O(log|V|). The dominant term is |E|log|V| because the number of edges is typically greater than vertices. Option B incorrectly writes V as base and E as exponent, while C and D are not the correct complexity for heap-based Prim's.
-
INSERT
-
DELETE
-
ALTER
-
LOOKUP
-
ADD
A
Correct answer
Explanation
It inserts data into the list, so that the length increases.
-
only similar data type
-
any data type
-
only two data types
-
only 5 data types
B
Correct answer
Explanation
Structures in C++ can contain members of different data types (int, float, char, etc.) unlike arrays which require similar types. This makes structs versatile for grouping related data.
-
analysis traversal operation
-
traversal operation
-
search operation
-
linear search operation
B
Correct answer
Explanation
Traversal is the process of systematically visiting each element in a data structure exactly once. This fundamental operation is essential for accessing, processing, or analyzing every element in an array, linked list, tree, or other data structure. It forms the basis for many algorithms including searching, sorting, and counting operations.
-
Linear search
-
Binary search
-
Both (1) & (2)
-
None of these
C
Correct answer
Explanation
Both linear search and binary search are fundamental approaches to search operations. Linear search works on unsorted data by checking each element sequentially, while binary search requires sorted data and repeatedly divides the search interval in half, making it much faster for large datasets.
-
Binary search
-
Logical search
-
Search field
-
Linear search
D
Correct answer
Explanation
Linear search traverses sequentially through a list to locate a specific item. It examines each element one by one from the beginning until the target is found or the list ends. This simple approach works on any list but is less efficient than binary search for large, sorted datasets.