Insertion sort MCQs

By: Prof. Dr. Fazal Rehman Shamil | Last updated: September 20, 2024

What is the primary function of Insertion Sort?
A) To search for an element
B) To sort an array
C) To merge two arrays
D) To partition data
Answer: B) To sort an array

What is the worst-case time complexity of Insertion Sort?
A) O(n)
B) O(n log n)
C) O(n^2)
D) O(log n)
Answer: C) O(n^2)

Which statement best describes how Insertion Sort works?
A) It divides the array into sorted and unsorted portions and inserts elements into the sorted portion.
B) It compares adjacent elements and swaps them.
C) It selects the smallest element and places it at the beginning.
D) It merges two sorted lists into one.
Answer: A) It divides the array into sorted and unsorted portions and inserts elements into the sorted portion.

What is the best-case time complexity of Insertion Sort?
A) O(n)
B) O(n log n)
C) O(n^2)
D) O(log n)
Answer: A) O(n)

Which of the following is true about the stability of Insertion Sort?
A) It is a stable sorting algorithm.
B) It is not a stable sorting algorithm.
C) It can only sort numerical data.
D) It requires additional memory for stability.
Answer: A) It is a stable sorting algorithm.

What is the average-case time complexity of Insertion Sort?
A) O(n)
B) O(n log n)
C) O(n^2)
D) O(log n)
Answer: C) O(n^2)

In Insertion Sort, what happens to the elements in the sorted portion of the array?
A) They are ignored until the next pass.
B) They are rearranged randomly.
C) They are compared and shifted as necessary.
D) They are selected one by one to find the minimum.
Answer: C) They are compared and shifted as necessary.

How many comparisons are made in the worst case during Insertion Sort?
A) n
B) n/2
C) n^2
D) n(n-1)/2
Answer: C) n^2

What is the space complexity of Insertion Sort?
A) O(1)
B) O(n)
C) O(n log n)
D) O(n^2)
Answer: A) O(1)

In which of the following scenarios is Insertion Sort particularly useful?
A) Sorting large datasets
B) Sorting small datasets
C) Real-time data processing
D) When memory usage is a concern
Answer: B) Sorting small datasets

What is the effect of using Insertion Sort on an already sorted array?
A) It sorts the array again.
B) It remains unchanged.
C) It becomes unstable.
D) It reverses the array.
Answer: B) It remains unchanged.

How does Insertion Sort achieve its sorting?
A) By merging elements
B) By comparing and shifting
C) By swapping elements
D) By selecting elements randomly
Answer: B) By comparing and shifting

Which algorithm is generally more efficient than Insertion Sort for larger datasets?
A) Bubble Sort
B) Merge Sort
C) Quick Sort
D) All of the above
Answer: D) All of the above

What will be the result of applying Insertion Sort to the array [4, 3, 2, 1]?
A) [1, 2, 3, 4]
B) [4, 3, 2, 1]
C) [2, 1, 3, 4]
D) [3, 4, 1, 2]
Answer: A) [1, 2, 3, 4]

What type of sorting is Insertion Sort classified as?
A) In-place sorting
B) External sorting
C) Comparison-based sorting
D) All of the above
Answer: D) All of the above

Which characteristic of Insertion Sort makes it less suitable for large datasets?
A) It requires too much memory.
B) It makes too many comparisons.
C) It requires multiple passes through the array.
D) It is not adaptive.
Answer: C) It requires multiple passes through the array.

What is the output of Insertion Sort if the input array is [5, 2, 9, 1, 5, 6]?
A) [1, 2, 5, 5, 6, 9]
B) [5, 5, 6, 1, 2, 9]
C) [2, 1, 5, 6, 9, 5]
D) [9, 6, 5, 5, 2, 1]
Answer: A) [1, 2, 5, 5, 6, 9]

How does Insertion Sort handle duplicate elements?
A) It ignores them.
B) It sorts them randomly.
C) It maintains their relative order.
D) It treats them as distinct values.
Answer: C) It maintains their relative order.

What will be the result of applying Insertion Sort to the array [3, 1, 4, 1, 5, 9, 2, 6]?
A) [1, 1, 2, 3, 4, 5, 6, 9]
B) [4, 1, 3, 2, 5, 9, 6, 1]
C) [3, 4, 1, 1, 2, 5, 6, 9]
D) [9, 6, 5, 4, 3, 2, 1, 1]
Answer: A) [1, 1, 2, 3, 4, 5, 6, 9]

What is the final position of the smallest element after one pass of Insertion Sort?
A) It remains in its original position.
B) It is placed at the end of the array.
C) It is placed at the beginning of the sorted portion.
D) It is moved to the middle of the array.
Answer: C) It is placed at the beginning of the sorted portion.

What happens to the time complexity of Insertion Sort if the input array is mostly sorted?
A) It improves to O(n).
B) It worsens to O(n^2).
C) It remains O(n log n).
D) It stays O(n^2).
Answer: A) It improves to O(n).

Which of the following sorting algorithms is based on a similar concept to Insertion Sort?
A) Quick Sort
B) Selection Sort
C) Merge Sort
D) Heap Sort
Answer: B) Selection Sort

In Insertion Sort, how are elements inserted into the sorted portion?
A) They are appended to the end.
B) They are swapped with larger elements.
C) They are shifted to the right until the correct position is found.
D) They are replaced randomly.
Answer: C) They are shifted to the right until the correct position is found.

Which of the following is a characteristic of Insertion Sort?
A) It is not stable.
B) It is adaptive.
C) It requires a large amount of memory.
D) It cannot sort strings.
Answer: B) It is adaptive.

What is the space requirement for Insertion Sort?
A) O(1)
B) O(n)
C) O(n log n)
D) O(n^2)
Answer: A) O(1)

Which data structure is typically used to implement Insertion Sort?
A) Linked List
B) Array
C) Tree
D) Graph
Answer: B) Array

What is the worst-case scenario for Insertion Sort?
A) The array is already sorted.
B) The array is in random order.
C) The array is in reverse order.
D) The array contains duplicate elements.
Answer: C) The array is in reverse order.

What is a common use case for Insertion Sort?
A) Sorting very large datasets
B) Sorting small datasets or arrays
C) Real-time data sorting
D) All of the above
Answer: B) Sorting small datasets or arrays

In which of the following scenarios would Insertion Sort perform optimally?
A) When the input array is sorted in descending order
B) When the input array is sorted in ascending order
C) When the input array is filled with random values
D) When the input array contains many unique values
Answer: B) When the input array is sorted in ascending order

How does Insertion Sort treat an already sorted array?
A) It becomes unstable.
B) It sorts it again.
C) It performs optimally, making O(n) comparisons.
D) It rearranges the elements randomly.
Answer: C) It performs optimally, making O(n) comparisons.

What is the primary advantage of using Insertion Sort?
A) It requires less memory.
B) It is faster than other sorting algorithms for large arrays.
C) It is easier to implement than other sorting algorithms.
D) It can sort linked lists efficiently.
Answer: A) It requires less memory.

How does Insertion Sort compare to Bubble Sort in terms of efficiency?
A) Insertion Sort is generally faster.
B) Bubble Sort is generally faster.
C) They have the same efficiency.
D) It depends on the implementation.
Answer: A) Insertion Sort is generally faster.

What will be the output of Insertion Sort on the array [8, 5, 3, 7, 6]?
A) [3, 5, 6, 7, 8]
B) [8, 7, 6, 5, 3]
C) [5, 3, 6, 7, 8]
D) [3, 6, 7, 5, 8]
Answer: A) [3, 5, 6, 7, 8]

How many passes does Insertion Sort make through the array?
A) n-1
B) n
C) n log n
D) n^2
Answer: A) n-1

In which of the following cases would Insertion Sort not be efficient?
A) When the array is small
B) When the array is nearly sorted
C) When the array is randomly ordered
D) When the array is in reverse order
Answer: D) When the array is in reverse order

What is the primary limitation of Insertion Sort?
A) It cannot handle negative numbers.
B) It is inefficient for large datasets.
C) It requires additional memory.
D) It cannot sort strings.
Answer: B) It is inefficient for large datasets.

Which of the following is a key operation in Insertion Sort?
A) Swapping
B) Merging
C) Inserting
D) Partitioning
Answer: C) Inserting

What does the term ‘in-place’ mean in relation to Insertion Sort?
A) It does not require extra memory.
B) It sorts elements in the same array.
C) It operates on linked lists only.
D) It cannot handle large datasets.
Answer: B) It sorts elements in the same array.

 

Data Structures MCQs

Basic Concepts

  1. Introduction to Data Structures
  2. Complexity Analysis MCQs

Linear Data Structures MCQs

  1. Arrays MCQs
  2. Linked Lists MCQs
  3. Stacks MCQs
  4. Queues MCQs

Non-Linear Data Structures MCQs

  1. Trees MCQs
  2. Heaps MCQs
  3. Graphs MCQs

Hashing MCQs MCQs

  1. Hash Tables

Sorting and Searching Algorithms MCQs 

  1. Sorting Algorithms MCQs
  2. Searching Algorithms MCQs

Miscellaneous

  1. Memory Management in data structures MCQs
  2. String Manipulation Algorithms MCQs
  1. Data Structures MCQs 1
  2. Data Structures MCQs 2
  3. Data Structures MCQs 3
  4. Data Structures MCQs 4
  5. Data Structures MCQs 5
  6. Stacks Solved MCQs
  7. Queues MCQs
  8. pointer mcqs
  9. Array MCQs