Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

CSC204 Data Structure Practice Questions

Database structure practice past questions

Uploaded by

nicoleeddie221
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

CSC204 Data Structure Practice Questions

Database structure practice past questions

Uploaded by

nicoleeddie221
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

CSC204 Data Structure practice questions

What is an array?

A. A collection of nodes

B. A collection of elements stored in contiguous memory locations

C. A linked data structure

D. A binary search tree

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

What is the time complexity of searching for an element in an unsorted array?

A. O(1)

B. O(log n)

C. O(n)

D. O(n^2)

ANSWER: C

Which data structure is suitable for implementing a sparse matrix?

A. Array

B. Linked list
C. Queue

D. Stack

ANSWER: B

In a two-dimensional array, what is the term for the number of rows?

A. Length

B. Width

C. Rows

D. Columns

ANSWER: C

What is a linked list?

A. A collection of elements stored in contiguous memory locations

B. A collection of nodes

C. A tree data structure

D. An array data structure

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

In a doubly linked list, each node has how many pointers?

A. 0

B. 1

C. 2

D. 3

ANSWER: C

Which data structure follows the Last-In-First-Out (LIFO) order?

A. Queue

B. Stack

C. Linked list
D. Binary tree

ANSWER: B

Which operation is used to remove an element from the top of a stack?

A. Push

B. Pop

C. Peek

D. Enqueue

ANSWER: B

Which data structure follows the First-In-First-Out (FIFO) order?

A. Stack

B. Queue

C. Linked list

D. Tree

ANSWER: B

Which operation is used to add an element to the rear of a queue?

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

What is a binary tree?

A. A tree with a single branch

B. A tree with a maximum of two children per node

C. A tree with no nodes

D. A tree with a variable number of children per node

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

D. In the root node

ANSWER: A

What is the primary purpose of an AVL tree?

A. Storing data in a linked list

B. Achieving a self-balancing binary search tree

C. Building a directed graph

D. Traversing a tree in postorder


ANSWER: B

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?

A. Finding the shortest path in a graph

B. Discovering all the connected components in a graph

C. Finding a tree that spans all the vertices with minimum total edge weight

D. Traversing the graph in breadth-first order

ANSWER: C

What is a graph?

A. A tree with no cycles

B. A collection of nodes connected by edges

C. A linear data structure

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

Which data structure is commonly used to represent a graph's connections?

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

In graph theory, what is a Hamiltonian cycle?

A. A cycle that visits every vertex exactly once

B. A cycle that includes all edges in the graph

C. A directed cycle

D. A path with the maximum number of vertices

ANSWER: A
What is hashing?

A. A method for sorting data

B. A technique for converting data into a fixed-size array index

C. A way to represent graphs

D. A data structure for storing elements in contiguous memory locations

ANSWER: B

Which of the following is a commonly used hash function?

A. Random number generator

B. Modulus operation (%)

C. Traversal algorithm

D. Queue operation

ANSWER: B

What is a collision in hashing?

A. A node in a linked list

B. A situation where two different keys map to the same index

C. A data structure for storing key-value pairs

D. A property of AVL trees

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

What is a hash map?

A. A tree structure

B. A data structure for organizing data into a sorted list

C. A data structure that uses hashing for key-value storage and retrieval

D. A data structure for implementing a queue

ANSWER: C

What is the primary use of a heap data structure?

A. Sorting elements

B. Implementing a queue

C. Maintaining the maximum (or minimum) element efficiently

D. Representing a graph

ANSWER: C

In a priority queue, what is the element with the highest priority?

A. The first element added

B. The last element added

C. The element with the smallest value

D. The element with the largest value

ANSWER: C
What is a trie data structure primarily used for?

A. Storing key-value pairs

B. Searching for elements in an array

C. Efficiently representing and searching for strings

D. Storing data in a contiguous memory block

ANSWER: C

Red-Black Trees are a type of:

A. Binary tree

B. B-Tree

C. Heap

D. AVL tree

ANSWER: A

B-Trees are commonly used for:

A. Implementing a stack

B. Representing hierarchical data

C. Sorting elements

D. Searching for a single element in an array

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

C. It remains the same

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

What is linear search?

A. A search algorithm with logarithmic time complexity

B. A search algorithm with constant time complexity

C. A search algorithm that checks each element one by one

D. A sorting algorithm

ANSWER: C

Binary search is most efficient on which type of data structure?


A. Sorted arrays

B. Linked lists

C. Hash tables

D. Stacks

ANSWER: A

What does Big O notation describe?

A. The lower bound of algorithm performance

B. The upper bound of algorithm performance

C. The average performance of an algorithm

D. The best-case performance of an algorithm

ANSWER: B

In time complexity analysis, what does O(n) represent?

A. Constant time complexity

B. Linear time complexity

C. Quadratic time complexity

D. Logarithmic time complexity

ANSWER: B

Which scenario does the best-case time complexity address?

A. The average performance of an algorithm

B. The upper bound of algorithm performance

C. The lower bound of algorithm performance

D. The minimum time required for an algorithm to execute


ANSWER: C

What is amortized analysis used for?

A. Analyzing average-case performance

B. Analyzing the upper bound of algorithm performance

C. Analyzing the lower bound of algorithm performance

D. Analyzing the average performance over a sequence of operations

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

In which application is a stack often used?

A. Implementing a web browser

B. Managing function calls in a program

C. Storing database records

D. Implementing a priority queue

ANSWER: B

What is one practical application of hash tables?

A. Sorting data
B. Implementing a queue

C. Implementing a cache

D. Representing a binary tree

ANSWER: C

When might you use a trie data structure?

A. To implement a linked list

B. In a spell checker or autocomplete system

C. To store elements in a contiguous memory block

D. To represent a graph

ANSWER: B

What is a primary consideration when choosing a data structure for a specific problem?

A. Its alphabetical order

B. Its ability to perform any operation

C. Its space complexity

D. Its suitability for the problem's requirements

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?

A. Constant-time insertions and deletions

B. Efficient memory usage

C. Flexible data structure

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

In a two-dimensional array, which term refers to the number of columns?

A. Width

B. Rows

C. Length

D. Depth

ANSWER: A

What is the space complexity of an array of size N?

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?

A. Lower memory usage

B. Simpler implementation

C. Ability to traverse in both directions

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

In a queue, what operation adds an element to the rear?

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

In a priority queue, which element is removed first?

A. The last element added

B. The first element added

C. The element with the largest value

D. The element with the smallest value

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

In a binary tree, what is a leaf node?

A. A node with no children

B. A node with exactly one child

C. A node with two children

D. The root node

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

What is the primary purpose of a Red-Black Tree?

A. To maintain a balanced binary search tree

B. To implement a stack

C. To create a graph

D. To store data in a linked list


ANSWER: A

What is the main application of a B-Tree?

A. Representing unsorted data

B. Implementing a priority queue

C. Storing hierarchical data, like file systems and databases

D. Implementing a linked list

ANSWER: C

What is a weighted graph?

A. A graph that can hold more data

B. A graph with nodes of different sizes

C. A graph where each edge has a numerical value associated with it

D. A graph with directed edges

ANSWER: C

In a directed graph, what is an outdegree of a node?

A. The number of incoming edges

B. The number of outgoing edges

C. The sum of incoming and outgoing edges

D. The total number of nodes

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

What is a strongly connected component in a directed graph?

A. A component that has no connections

B. A component where all nodes can be reached from each other

C. A component with only one node

D. A component with the highest outdegree

ANSWER: B

Quiz 4 Solutions

Data Structure Multiple Choice Questions & Answers Pdf

Question: 1

A data structure in which linear sequence is maintained by pointers is known as

(A) Array

(B) Stack
(C) Linked list

(D) Pointer-based data structure

Ans: C

Linked list

Question: 2

Which of the following data structure works on the principle of First Come First Serve?

(A) Priority queue

(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

(B) Linked list

(C) Tree

(D) Stack

Ans: B

Linked list

Question: 4

A queue where all elements have equal priority is a

(A) ILFO data structure

(B) LILO data structure

(C) FIFO data structure


(D) LIFO data structure

Ans: C

FIFO data structure

Question: 5

A file that is only read by a program is known as ____

(A) Input file

(B) Temporary file

(C) Work file

(D) Input/output file

Ans: A

Input file

Q2: Recursion is memory-intensive because:

a. Recursive functions tend to declare many local variables.

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.

c. Many copies of the function code are created.

d. It requires large data values.

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. Small, sorted arrays.

c. Large, unsorted arrays.

d. Large, sorted arrays.

ANS: d. Large, sorted arrays.


Q4: A double subscripted array declared as int a[ 3 ][ 5 ]; has how many elements? a. 15

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.

b. Does not, does.

c. Does, does not.

d. Does, does.

ANS: b. Does not, 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

d. ios::trunc ANS a. ios::app

Q7: A random access file is organized most like a(n):

a. Array.

b. Object.

c. Class.

d. Pointer. ANS: a. Array.


Q8: To write fixed-length records, use file open mode:

a. ios::app

b. ios::ate

c. ios::trunc

d. ios::binary ANS: d. ios::binary

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.

d. Maximum size. ANS: 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)

Q13: Which of the following is not a dynamic data structure?

a. Linked list.

b. Stack.

c. Array.

d. Binary tree. ANS c. Array.

Q14: In general, linked lists allow:

a. Insertions and removals anywhere.

b. Insertions and removals only at one end.

c. Insertions at the back and removals from the front.

d. None of the above.

ANS a. Insertions and removals anywhere.

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.

d. Linked list. ANS b. Queue.

Q16: Given that the line

delete newPtr;

just executed, what can you conclude?

a. The memory referenced by newPtr is released only if it is needed by the system.

b. The pointer newPtr is of type void *.

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?

a. Circular, singly-linked list.

b. Circular, doubly-linked list.

c. Singly-linked list.

d. Doubly-linked list.

ANS a. Circular, singly-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

Q19: Which of the following statements about stacks is incorrect?

a. Stacks can be implemented using linked lists.

b. Stacks are first-in, first-out (FIFO) data structures.

c. New nodes can only be added to the top of the stack.

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):

a. Always have multiple links per node.

b. Can be sorted efficiently.

c. Always have the same shape for a particular set of data.

d. Are nonlinear data structures.

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

Q22: Which of the following is a difference between vectors and arrays?

a. Access to any element using the [] operator.


b. Stored in contiguous blocks of memory.

c. The ability to change size dynamically.

d. Efficient direct access to any element.

ANS: c. The ability to change size dynamically.

The next 3 questions are about the speaker and talk from May 10th which you were asked to attend.

Q23: What was the name of the speaker?

a. Peter Dinda

b. Ian Foster

c. Alok Choudhary

d. Bob Grossman ANS: b. Ian Foster

Q24: (2 points) What is the one word that describes Grid?

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.

b. He doesn't know him personally.

c. He is his PhD advisor.

d. He is a relative.

ANS: c. He is his PhD advisor or a. He is his professor.


Multiple Choice Questions for Data Structures (A) 2

(B) 3

(C) 4

1. Minimum number of fields in each node of a doubly linked list is ____

(D) None of the above

Ans: B

2. A graph in which all vertices have equal degree is known as ____

(A) Complete graph

(B) Regular graph

(C) Multi graph

(D) Simple graph

Ans: A

Complete graph

3. A vertex of in-degree zero in a directed graph is called a/an

(A) Root vertex

(B) Isolated vertex

(C) Sink

(D) Articulation point

Ans: C

Sink

4. A graph is a tree if and only if graph is

(A) Directed graph

(B) Contains no cycles


(C) Planar

(D) Completely connected

Ans: B

Contains no cycles

5. The elements of a linked list are stored

(A) In a structure

(B) In an array

(C) Anywhere the computer has space for them

(D) In contiguous memory locations

Ans: C

Anywhere the computer has space for them

6. A parentheses checker program would be best implemented using

(A) List

(B) Queue

(C) Stack

(D) Any of the above

Ans: C

Stack

7. To perform level-order traversal on a binary tree, which of the following data structure will be
required?

(A) Hash table

(B) Queue

(C) Binary search tree

(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

(B) Linked list

(C) Binary search tree

(D) None of above

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.

(A) Threaded tree

(B) Complete binary tree

(C) M-way search tree

(D) Full binary tree

Ans: B

Complete binary tree

10. Which of following data structure is more appropriate for implementing quick sort iteratively?

(A) Deque

(B) Queue

(C) Stack

(D) Priority queue

Ans: C

Stack

11. The number of edges in a complete graph of n vertices is

(A) n(n+1)/2
(B) n(n-1)/2

(C) n2/2

(D) n Ans: B n(n-1)/2

12. If two trees have same structure and but different node content, then they are called ___

(A) Synonyms trees

(B) Joint trees

(C) Equivalent trees

(D) Similar trees

Ans: D

Similar trees

13. If two trees have same structure and node content, then they are called ____ (A) Synonyms trees

(B) Joint trees

(C) Equivalent trees

(D) Similar trees

Ans: C

Equivalent trees

14. Finding the location of a given item in a collection of items is called ……

A. Discovering

B. Finding

C. Searching

D. Mining Ans. C searching

15. The time complexity of quicksort is ……..

A. O(n)

B. O(logn)

C. O(n2)
D. O(n logn)

Ans. D

O(n logn)

16. Quick sort is also known as ……..

A. merge sort

B. tree sort

C. shell sort

D. partition and exchange sort

Ans. D

partition and exchange sort

17. ………. sorting is good to use when alphabetizing a large list of names.

A. Merge

B. Heap

C. Radix

D. Bubble Ans. C

Radix

18. The total number of comparisons in a bubble sort is ….

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.

A. LIFO, Last In First Out

B. FIFO, First In First Out


C. Both a and b

D. None of these

Ans. B

FIFO, First In First Out

20. New nodes are added to the ……… of the queue.

A. Front

B. Back

C. Middle

D. Both A and B

Ans. B

Back

21. The term push and pop is related to

A. Array

B. Lists

C. Stacks

D. Trees

Ans. C

Stacks

22. Which of the following is an application of stack?

A. finding factorial

B. tower of Hanoi

C. infix to postfix

D. all of the above Ans. D all of the above

23. The operation of processing each element in the list is known as ……

A. sorting
B. merging

C. inserting

D. traversal Ans. D traversal

24. The situation when in a linked list START=NULL is ….

A. Underflow

B. Overflow

C. Houseful

D. Saturated Ans. A

Underflow

25. Which of the following are two-way lists?

A. Grounded header list

B. Circular header list

C. Linked list with header and trailer nodes

D. List traversed in two directions

Ans. D

List traversed in two directions

26. Which is the pointer associated with the availability list?

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

28. Which of the following is non-liner data structure?

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

B) Output restricted queue

C) Priority queues

D) Stack

Ans. A

Input restricted dequeue

You might also like