0% found this document useful (0 votes)
55 views

DSA Quiz

Uploaded by

rickyomegonol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

DSA Quiz

Uploaded by

rickyomegonol
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CIS1532 - Data Structures and Algorithms

Quiz
Time: 30 mins

1. Which one of the following is the non-primitive data structure?


a. Array
b. Real
c. Boolean
d. Integer

2. Which one of the following is not a data structure?


a. Ring
b. Graph
c. Linked List
d. Tree

3. Which of the following is an advantage of using an array data structure?


a. It allows for efficient insertion and deletion of elements
b. It can store elements of different data types in the same array
c. It provides fast searching and sorting algorithms
d. It provides constant time complexity for all operations

4. Which sorting algorithm is commonly used for sorting small data sets?
a. Quick sort
b. Bubble sort
c. Merge sort
d. Insertion sort

5. Which sorting algorithm has the best space complexity?


a. Quick sort
b. Insertion sort
c. Merge sort
d. Bubble sort

1
6. Which of the following statements are false regarding recursion?
a. A recursive algorithm should always call itself directly to solve a smaller version of
its task.
b. A recursive algorithm needs to have a terminating condition.
c. Any recursive algorithm can be rewritten to use loops instead of recursion.
d. Divide and conquer algorithms such as merge sort do not use recursion.

7. Consider the following stack where the rightmost element is at the top of the
stack.

4 9 5 2 5 7 9 1
How will the stack look like after performing the following sequence operation in order?

• pop
• push(3)
• pop
• pop
• push(2)
• pop
• push(8)
• push(6)
a. 4, 9, 5, 2, 5, 7, 8, 6
b. 4, 9, 5, 2, 8, 6, 5, 7
c. 4, 9, 5, 2, 5, 7, 9, 1, 8, 6
d. 8, 6, 4, 9, 5, 2, 5, 7

8. Drag and drop the appropriate time costs to the given lines of merge sort.
Assume that the time cost for the function itself is T( n ).

MERGE-SORT(array, left_index, right_index) T( n )

IF left_index < right_index c1

middle_index ← ⌊(left_index + right_index)/2⌋ c2

MERGE-SORT(array, left_index, middle_index) T(n/2)

MERGE-SORT (array, middle_index + 1, right_index) T(n/2)

MERGE(array, left_index, middle_index, right_index) F( n )

c2 T(n/2) T(n/2) T(n/3) T(n/4)

2
9. Select the appropriate worst-case running time for the following algorithms.

Bubble sort O(n^2)

Merge sort O(n log n)

Insertion sort O (n^2)

O(n^2) O(n log n) O(n^2) O(log n) O(n) O(1)

10. A queue follows __________.


a. FIFO (First in First Out) principle
b. LIFO (Last In First Out) principle
c. Unordered array
d. Linear Tree

Consider the following code fragment and answer the questions 11-13.

11. How many times is statement 4 executed?


a. O( N )
b. O ( N^2 )
c. O( N^3 )
d. O( N^4 )

3
12. How many times is statement 10 executed?
a. O( N )
b. O( N^2 )
c. O( N^3 )
d. O( N^4 )

13. What is the running time of the code fragment?


a. O( N )
b. O( N^2 )
c. O( N^4 )
d. O( N^3 )

14. When the user tries to delete the element from the empty stack then the
condition is said to be a ____.
a. Overflow
b. Underflow
c. Garbage collection
d. None of the above

15. Which one of the following is correct for the maximum value that the 'rear' can
take to avoid the overflow condition if a linear queue is implemented using an
array with a size MAX_SIZE?
a. rear = front
b. rear = front + 1
c. rear = MAX_SIZE - 1
d. rear = MAX_SIZE

You might also like