Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Chapter: 44
Q681:
What is the time complexity of bubble sort?
A. O(N)
B. O(N log N)
C. O(N^2)
D. O(log N)
Correct Answer:
C
Chapter: 44
Q682:
In bubble sort, what happens to the largest element in each pass?
A. It is moved to the start of the array
B. It is moved to the end of the array
C. It is moved to the middle of the array
D. It is not moved
Correct Answer:
B
Chapter: 44
Q683:
What is the key difference between selection sort and insertion sort?
A. Selection sort only finds the smallest element while insertion sort places each element in the correct position
B. Selection sort places elements in their correct position while insertion sort finds the smallest element
C. Selection sort is faster than insertion sort
D. Insertion sort is more memory efficient than selection sort
Correct Answer:
A
Chapter: 44
Q684:
What is the purpose of the swapped variable in bubble sort?
A. To keep track of the number of swaps
B. To determine if the array is already sorted
C. To track the bound of the array being sorted
D. To count the number of comparisons made
Correct Answer:
B
Chapter: 44
Q685:
Which of the following sorting algorithms is known to be an in-place sort?
A. Selection Sort
B. Insertion Sort
C. Bubble Sort
D. All of the above
Correct Answer:
D
Chapter: 44
Q686:
What will the array look like after the first pass of bubble sort for the array [5, 12, 7, 19]?
A. [5, 7, 12, 19]
B. [12, 5, 7, 19]
C. [5, 7, 19, 12]
D. [5, 12, 7, 19]
Correct Answer:
B
Chapter: 44
Q687:
How many comparisons are required in the worst-case scenario for insertion sort with N elements?
A. N
B. N log N
C. N^2
D. log N
Correct Answer:
C
Chapter: 44
Q688:
What does the outer loop of the bubble sort algorithm do?
A. Repeats the swapping process until no swaps are needed
B. Swaps neighboring elements
C. Finds the smallest element in the array
D. Inserts elements into their correct positions
Correct Answer:
A
Chapter: 44
Q689:
How does the insertionSort function insert an element into the sorted portion of the array?
A. By comparing it with all elements in the array
B. By shifting elements to make space
C. By swapping it with adjacent elements
D. By sorting the entire array again
Correct Answer:
B
Chapter: 45
Q690:
What is the time complexity of merge sort?
A. O(n)
B. O(n^2)
C. O(n log n)
D. O(log n)
Correct Answer:
C
Chapter: 45
Q691:
What is the key concept behind divide and conquer algorithms?
A. Sorting elements in place
B. Partitioning the problem into subproblems
C. Iterating over all elements
D. None of the above
Correct Answer:
B
Chapter: 45
Q692:
What happens when you reach a single element in a divide and conquer algorithm?
A. The algorithm continues dividing
B. The algorithm merges the elements immediately
C. The algorithm sorts the element and stops
D. The algorithm performs a linear search
Correct Answer:
C
Chapter: 45
Q693:
How is the merge step performed in merge sort?
A. Using a recursive call
B. By iterating through the arrays and comparing elements
C. By swapping adjacent elements
D. Using a binary search algorithm
Correct Answer:
B
Chapter: 45
Q694:
In the merge sort algorithm, what does the temporary array `tmpArrayPtr` store?
A. The original array
B. The merged array
C. Intermediate sorted results
D. The unsorted array
Correct Answer:
C
Chapter: 45
Q695:
What is the main advantage of using merge sort over insertion sort?
A. Merge sort is in-place
B. Merge sort has better average time complexity
C. Merge sort uses less memory
D. Merge sort is simpler to implement
Correct Answer:
B
Chapter: 45
Q696:
What is the role of the pivot in the quicksort algorithm?
A. To merge sorted halves
B. To partition the array into two sub-arrays
C. To find the median of the array
D. To sort the array in place
Correct Answer:
B
Chapter: 45
Q697:
What happens when quicksort partitions the array around the pivot?
A. The array is sorted
B. The array is divided into smaller sub-arrays
C. The pivot is removed from the array
D. The array is merged with another array
Correct Answer:
B
Chapter: 45
Q698:
Which of the following sorting algorithms is not a divide and conquer algorithm?
A. Mergesort
B. Quicksort
C. Heap sort
D. Insertion sort
Correct Answer:
D
Chapter: 45
Q699:
What is the purpose of the `mergeArrays` function in merge sort?
A. To divide the array into halves
B. To merge two sorted arrays into a single sorted array
C. To sort the array in place
D. To find the median of the array
Correct Answer:
B
Chapter: 45
Q700:
What is the space complexity of merge sort?
A. O(1)
B. O(n)
C. O(n log n)
D. O(n^2)
Correct Answer:
B