CSC204 Data Structure Practice Questions
CSC204 Data Structure Practice Questions
What is an array?
A. A collection of nodes
ANSWER: B
Which data structure allows for random access to elements with constant time complexity?
A. Linked list
B. Queue
C. Array
D. Stack
ANSWER: C
A. O(1)
B. O(log n)
C. O(n)
D. O(n^2)
ANSWER: C
A. Array
B. Linked list
C. Queue
D. Stack
ANSWER: B
A. Length
B. Width
C. Rows
D. Columns
ANSWER: C
B. A collection of nodes
ANSWER: B
In a singly linked list, how many pointers does each node have?
A. 0
B. 1
C. 2
D. 3
ANSWER: B
Which operation involves removing a node from a linked list?
A. Traversal
B. Deletion
C. Insertion
D. Creation
ANSWER: B
What is the time complexity for inserting a node at the beginning of a singly linked list?
A. O(1)
B. O(log n)
C. O(n)
D. O(n^2)
ANSWER: A
A. 0
B. 1
C. 2
D. 3
ANSWER: C
A. Queue
B. Stack
C. Linked list
D. Binary tree
ANSWER: B
A. Push
B. Pop
C. Peek
D. Enqueue
ANSWER: B
A. Stack
B. Queue
C. Linked list
D. Tree
ANSWER: B
A. Dequeue
B. Push
C. Enqueue
D. Pop
ANSWER: C
Stacks and queues can be implemented using which underlying data structure?
A. Array
B. Linked list
C. Tree
D. Hash table
ANSWER: A
ANSWER: B
In a binary search tree (BST), where should smaller elements be placed with respect to the root?
A. Left subtree
B. Right subtree
C. It doesn't matter
ANSWER: A
Which tree traversal visits the left subtree, then the root, and finally the right subtree?
A. Preorder
B. Inorder
C. Postorder
D. Level order
ANSWER: B
What is the primary goal of minimum spanning tree algorithms like Prim's and Kruskal's?
C. Finding a tree that spans all the vertices with minimum total edge weight
ANSWER: C
What is a graph?
D. An array of elements
ANSWER: B
In a directed graph, what is the term for a sequence of vertices where there is a directed edge from one
vertex to the next?
A. Cycle
B. Path
C. Tree
D. Graph
ANSWER: B
A. Linked list
B. Array
C. Stack
D. Queue
ANSWER: A
What is the time complexity of depth-first search (DFS) in a graph with V vertices and E edges?
A. O(V)
B. O(E)
C. O(V + E)
D. O(V * E)
ANSWER: C
C. A directed cycle
ANSWER: A
What is hashing?
ANSWER: B
C. Traversal algorithm
D. Queue operation
ANSWER: B
ANSWER: B
Which collision resolution technique involves creating a linked list at each index in the hash table to
handle collisions?
A. Chaining
B. Linear probing
C. Quadratic probing
D. Double hashing
ANSWER: A
A. A tree structure
C. A data structure that uses hashing for key-value storage and retrieval
ANSWER: C
A. Sorting elements
B. Implementing a queue
D. Representing a graph
ANSWER: C
ANSWER: C
What is a trie data structure primarily used for?
ANSWER: C
A. Binary tree
B. B-Tree
C. Heap
D. AVL tree
ANSWER: A
A. Implementing a stack
C. Sorting elements
ANSWER: B
What is the time complexity of the Quick Sort algorithm in the worst case?
A. O(1)
B. O(log n)
C. O(n)
D. O(n^2)
ANSWER: D
In binary search, how does the search space reduce with each comparison?
A. By a fixed amount
B. By a variable amount
D. It increases
ANSWER: B
Which sorting algorithm is known for its best-case time complexity of O(n)?
A. Insertion Sort
B. Bubble Sort
C. Merge Sort
D. Heap Sort
ANSWER: A
D. A sorting algorithm
ANSWER: C
B. Linked lists
C. Hash tables
D. Stacks
ANSWER: A
ANSWER: B
ANSWER: B
ANSWER: D
What is the time complexity of an algorithm that has both O(n) and O(log n) operations in sequence?
A. O(n)
B. O(log n)
C. O(n log n)
D. O(n^2)
ANSWER: C
ANSWER: B
A. Sorting data
B. Implementing a queue
C. Implementing a cache
ANSWER: C
D. To represent a graph
ANSWER: B
What is a primary consideration when choosing a data structure for a specific problem?
ANSWER: D
Which data structure would be most appropriate for implementing a dictionary with word definitions?
A. Array
B. Linked list
C. Hash map
D. Queue
ANSWER: C
What is the primary advantage of using arrays for data storage?
D. Simplicity of implementation
ANSWER: B
What is the time complexity for inserting an element at the end of an array with N elements?
A. O(1)
B. O(log N)
C. O(N)
D. O(N^2)
ANSWER: A
A. Width
B. Rows
C. Length
D. Depth
ANSWER: A
A. O(1)
B. O(N)
C. O(log N)
D. O(N^2)
ANSWER: B
Which data structure provides dynamic sizing, making it easier to add or remove elements?
A. Array
B. Linked list
C. Stack
D. Queue
ANSWER: B
In a singly linked list, how many pointers does each node have?
A. 0
B. 1
C. 2
D. 3
ANSWER: B
What is the time complexity for deleting a node from a singly linked list when given a reference to the
node to be deleted?
A. O(1)
B. O(log N)
C. O(N)
D. O(N^2)
ANSWER: A
Which operation is used to add a node to the end of a singly linked list?
A. Insertion
B. Deletion
C. Traversal
D. Append
ANSWER: D
In a doubly linked list, how many pointers does each node have?
A. 0
B. 1
C. 2
D. 3
ANSWER: C
What is the primary advantage of using a doubly linked list over a singly linked list?
B. Simpler implementation
D. Constant-time deletion
ANSWER: C
In a stack, what operation removes the top element without returning it?
A. Push
B. Pop
C. Peek
D. Enqueue
ANSWER: B
A. Dequeue
B. Push
C. Enqueue
D. Pop
ANSWER: C
Which data structure is suitable for implementing a breadth-first search (BFS) algorithm?
A. Stack
B. Queue
C. Linked list
D. Binary tree
ANSWER: B
ANSWER: D
What is the maximum number of children a node can have in a general tree?
A. 0
B. 1
C. 2
D. More than 2
ANSWER: D
ANSWER: A
Which tree traversal visits the root, followed by the left and right subtrees?
A. Preorder
B. Inorder
C. Postorder
D. Level order
ANSWER: A
B. To implement a stack
C. To create a graph
ANSWER: C
ANSWER: C
ANSWER: B
Which data structure is commonly used to implement depth-first search (DFS) and breadth-first search
(BFS) algorithms?
A. Stack
B. Queue
C. Linked list
D. Tree
ANSWER: A
What is the time complexity of breadth-first search (BFS) in a graph with V vertices and E edges?
A. O(V)
B. O(E)
C. O(V + E)
D. O(V * E)
ANSWER: C
ANSWER: B
Quiz 4 Solutions
Question: 1
(A) Array
(B) Stack
(C) Linked list
Ans: C
Linked list
Question: 2
Which of the following data structure works on the principle of First Come First Serve?
(B) Heap
(C) Stack
(D) Queue
Ans: D
Queue
Question: 3
A ____ is a linear collection of self-referential structures, called nodes, connected by pointer links.
(A) Queue
(C) Tree
(D) Stack
Ans: B
Linked list
Question: 4
Ans: C
Question: 5
Ans: A
Input file
b. Previous function calls are still open when the function calls itself and the activation records of
these previous calls still occupy space on the call stack.
ANS: b. Previous function calls are still open when the function calls itself and the activation records of
these previous calls still occupy space on the call stack.
Q3: Linear search is highly inefficient compared to binary search when dealing with: a. Small, unsorted
arrays.
b. 13
c. 10
d. 8
ANS: a. 15
Q5: Using square brackets ([]) to retrieve vector elements __________ perform bounds checking; using
member function at to retrieve vector elements __________ perform bounds checking. a. Does not,
does not.
d. Does, does.
Q6: Which file open mode would be used to write data only to the end of an existing file?
a. ios::app
b. ios::in
c. ios::out
a. Array.
b. Object.
c. Class.
a. ios::app
b. ios::ate
c. ios::trunc
Q9: The total number of elements that can be stored in a string without increasing its current amount of
allocated memory is called its:
a. Size.
b. Length.
c. Capacity.
Q10: An algorithm that requires __________ operations to complete its task on n data elements is said
to have a linear runtime.
a. n3 + 9
b. 3 n2 + 3 n + 2
c. 2n+1
d. 6
ANS c. 2 n + 1
Q11: At most, how many comparisons are required to search a sorted vector of 1023 elements using the
binary search algorithm?
a. 10
b. 15
c. 20
d. 30 ANS a. 10
Q12: Which of the following represents the efficiency of the insertion sort?
a. O(1)
b. O(log n)
c. O(n)
d. O(n2)
ANS: d. O(n2)
a. Linked list.
b. Stack.
c. Array.
Q15: Which data structure represents a waiting line and limits insertions to be made at the back of the
data structure and limits removals to be made from the front?
a. Stack.
b. Queue.
c. Binary tree.
delete newPtr;
c. The pointer newPtr only exists if there was an error freeing the memory.
d. The pointer newPtr still exists. ANS d. The pointer newPtr still exists.
Q17: What kind of linked list begins with a pointer to the first node, and each node contains a pointer to
the next node, and the pointer in the last node points back to the first node?
c. Singly-linked list.
d. Doubly-linked list.
Q18: How many pointers are contained as data members in the nodes of a circular, doubly linked list of
integers with five nodes?
a. 5
b. 8
c. 10
d. 15 ANS c. 10
d. The last node (at the bottom) of a stack has a null (0) link. ANS b. Stacks are first-in, first-out
(FIFO) data structures.
Q20: Select the incorrect statement. Binary search trees (regardless of the order in which the values are
inserted into the tree):
ANS: c. Always have the same shape for a particular set of data.
Q21: Which of the following is not a sequence container provided by the STL?
a. vector
b. array
c. list
d. deque
ANS: b. array
The next 3 questions are about the speaker and talk from May 10th which you were asked to attend.
a. Peter Dinda
b. Ian Foster
c. Alok Choudhary
a. Distributed
b. Federation
c. Computing
d. Cloud
ANS: b. Federation
Q25: (2 points) What relationship does the speaker have with the instructor?
a. He is his professor.
d. He is a relative.
(B) 3
(C) 4
Ans: B
Ans: A
Complete graph
(C) Sink
Ans: C
Sink
Ans: B
Contains no cycles
(A) In a structure
(B) In an array
Ans: C
(A) List
(B) Queue
(C) Stack
Ans: C
Stack
7. To perform level-order traversal on a binary tree, which of the following data structure will be
required?
(B) Queue
(D) Stack
Ans: B
Queue
8. Which of the following data structure is required to convert arithmetic expression in infix to its
equivalent postfix notation?
(A) Queue
Ans: D
None of above
9. A binary tree in which all its levels except the last, have maximum numbers of nodes, and all the
nodes in the last level have only one child it will be its left child. Name the tree.
Ans: B
10. Which of following data structure is more appropriate for implementing quick sort iteratively?
(A) Deque
(B) Queue
(C) Stack
Ans: C
Stack
(A) n(n+1)/2
(B) n(n-1)/2
(C) n2/2
12. If two trees have same structure and but different node content, then they are called ___
Ans: D
Similar trees
13. If two trees have same structure and node content, then they are called ____ (A) Synonyms trees
Ans: C
Equivalent trees
A. Discovering
B. Finding
C. Searching
A. O(n)
B. O(logn)
C. O(n2)
D. O(n logn)
Ans. D
O(n logn)
A. merge sort
B. tree sort
C. shell sort
Ans. D
17. ………. sorting is good to use when alphabetizing a large list of names.
A. Merge
B. Heap
C. Radix
D. Bubble Ans. C
Radix
A. O(n logn)
B. O(2n)
C. O(n2)
D. O(n) Ans. A
O(n logn)
19. ……… form of access is used to add and remove nodes from a queue.
D. None of these
Ans. B
A. Front
B. Back
C. Middle
D. Both A and B
Ans. B
Back
A. Array
B. Lists
C. Stacks
D. Trees
Ans. C
Stacks
A. finding factorial
B. tower of Hanoi
C. infix to postfix
A. sorting
B. merging
C. inserting
A. Underflow
B. Overflow
C. Houseful
D. Saturated Ans. A
Underflow
Ans. D
A. FIRST
B. AVAIL
C. TOP
D. REAR
Ans. B
AVAIL
27. Which of the following data structure can’t store the non-homogeneous data elements? A) Arrays
B) Records
C) Pointers
D) Stacks
Ans. A
Arrays
A) Stacks
B) List
C) Strings
D) Trees
Ans. D
Trees
29. To represent hierarchical relationship between elements, which data structure is suitable?
A) Dequeue
B) Priority
C) Tree
D) Graph
Ans. C
Tree
30. Identify the data structure which allows deletions at both ends of the list but insertion at only one
end. A) Input restricted dequeue
C) Priority queues
D) Stack
Ans. A