Insertion Sort MCQ Quiz - Objective Question with Answer for Insertion Sort - Download Free PDF
Last updated on May 13, 2025
Latest Insertion Sort MCQ Objective Questions
Insertion Sort Question 1:
The k-Means algorithm is an ______ algorithm.
Answer (Detailed Solution Below)
Insertion Sort Question 1 Detailed Solution
The correct answer is Unsupervised Learning.
Key Points
1. Supervised Learning:
- In supervised learning, the algorithm is trained on a labeled dataset, where the input data is paired with corresponding output labels.
- The goal is to learn a mapping function from input to output so that the algorithm can make predictions or classifications on new, unseen data.
2. Unsupervised Learning:
- In unsupervised learning, the algorithm is given data without explicit instructions on what to do with it.
- The algorithm tries to find patterns, relationships, or structures within the data on its own.
- Clustering algorithms, like k-Means, fall under unsupervised learning because they group similar data points together without using labeled output information.
3. Semi-supervised Learning:
- Semi-supervised learning is a combination of supervised and unsupervised learning.
- It involves a dataset that contains both labeled and unlabeled examples.
- The algorithm is trained on the labeled data, and then it tries to make predictions on the unlabeled data by leveraging the patterns learned from the labeled data.
4. Reinforcement Learning:
- Reinforcement learning involves an agent interacting with an environment and learning to make decisions by receiving feedback in the form of rewards or punishments.
- The agent learns to take actions that maximize the cumulative reward over time.
- Unlike supervised learning, where the algorithm is provided with explicit labeled examples, in reinforcement learning, the algorithm learns by trial and error.
In the case of the k-Means algorithm, it is unsupervised learning because it doesn't rely on labeled output data. Instead, it aims to partition the input data into clusters based on similarity, without using predefined class labels.
Insertion Sort Question 2:
At the time of sorting an array of size N by normal selection sort, the number of comparisons made in first iteration is :
Answer (Detailed Solution Below)
Insertion Sort Question 2 Detailed Solution
The correct answer is: option 2: N−1
Concept:
In the Selection Sort algorithm, during each iteration, we find the smallest (or largest) element from the unsorted portion of the array and place it at the correct position.
In the first iteration:
- You compare the first element with all the other N−1 elements to find the minimum.
- So, the number of comparisons made in the first iteration is exactly N−1.
General selection sort comparison count:
- Total comparisons = (N−1) + (N−2) + ... + 1 = N(N−1)/2
Explanation of options:
- Option 1 – N: ❌ Too many, only N−1 comparisons are needed.
- Option 2 – N−1: ✅ Correct. This is the actual number of comparisons in the first iteration.
- Option 3 – N×(N−1)/2: ❌ This is the total number of comparisons in the entire sorting process, not just the first iteration.
- Option 4 – NlogN: ❌ This is the time complexity of more efficient algorithms like Merge Sort or Heap Sort, not Selection Sort.
Hence, the correct answer is: option 2: N−1
Insertion Sort Question 3:
The Highest Lower Bound on the number of Comparisons in the worst case for comparison-based sorting order of :
Answer (Detailed Solution Below)
Insertion Sort Question 3 Detailed Solution
The correct answer is n log n.
Key Points
- In comparison-based sorting algorithms, the number of comparisons required to sort a list of n elements in the worst case is at least proportional to n log n.
- This result is derived from the fact that there are n! possible permutations of n elements, and each comparison can at most halve the number of possibilities.
- Therefore, to distinguish between all n! permutations, we need at least log(n!) comparisons.
- Using Stirling's approximation, log(n!) is Θ(n log n), which provides the lower bound for comparison-based sorting algorithms.
- This lower bound applies to all comparison-based sorting algorithms, including well-known ones like Merge Sort, Heap Sort, and Quick Sort (on average).
Additional Information
- Non-comparison-based sorting algorithms, such as Counting Sort, Radix Sort, and Bucket Sort, can achieve better performance under specific conditions, bypassing the n log n lower bound.
- These algorithms rely on additional assumptions about the input data, such as the range of the input values.
- However, for general-purpose sorting where no assumptions can be made about the input data, comparison-based sorting algorithms are the most widely applicable.
- Understanding the lower bound helps in analyzing and comparing the efficiency of different sorting algorithms.
- The n log n lower bound ensures that no comparison-based sorting algorithm can have a worst-case performance better than this bound.
Insertion Sort Question 4:
If the array A contains the items 10, 4, 7, 23, 67, 12 and 5 in that order, what will be the resultant array A after third pass of insertion sort?
Answer (Detailed Solution Below)
Insertion Sort Question 4 Detailed Solution
The correct answer is 4, 7, 10, 23, 67, 12, 5
Concept:
Insertion sort is the sorting mechanism where the sorted array is built having one item at a time. The analogy can be understood from the style we arrange a deck of cards. This sort works on the principle of inserting an element at a particular position, hence the name Insertion Sort.
Insertion Sort works as follows:
- The first step involves the comparison of the element in question with its adjacent element.
- And if at every comparison reveals that the element in question can be inserted at a particular position, then space is created for it by shifting the other elements one position to the right and inserting the element at the suitable position.
- The above procedure is repeated until all the element in the array is at their apt position.
Explanation:
Array: 10, 4, 7, 23, 67, 12, 5
After 1st pass: 4, 10, 7, 23, 67, 12, 5 – 4 and 10 got swapped or 4 got inserted at its apt position
After 2nd pass: 4, 7, 10, 23, 67, 12, 5 – 7 got inserted at its apt position
After 3rd pass: 4, 7, 10, 23, 67, 12, 5 – No change because the value 10 is placed in its apt position alreadyInsertion Sort Question 5:
What is the most efficient way to sum an array of n numbers?
Answer (Detailed Solution Below)
Insertion Sort Question 5 Detailed Solution
The correct answer is Use a single loop.
Key Points
- Using a single loop is the most efficient way to sum an array of n numbers because it has a time complexity of O(n).
- This method involves iterating through the array once and accumulating the sum, making it both simple and efficient.
Additional Information
- Use a nested loop: This method is highly inefficient for summing an array as it has a time complexity of O(n^2). It involves iterating through the array multiple times, which is unnecessary for this task.
- Use recursion: While recursion can be used to sum an array, it is not the most efficient due to the overhead of multiple function calls and potential stack overflow for large arrays. Its time complexity is O(n) but with added space complexity due to the call stack.
- Use divide and conquer approach: This method splits the array into smaller sub-arrays, sums them individually, and then combines the results. Although it has a time complexity of O(n log n), it is more complex and less efficient than a single loop for this specific task.
Top Insertion Sort MCQ Objective Questions
The k-Means algorithm is an ______ algorithm.
Answer (Detailed Solution Below)
Insertion Sort Question 6 Detailed Solution
Download Solution PDFThe correct answer is Unsupervised Learning.
Key Points
1. Supervised Learning:
- In supervised learning, the algorithm is trained on a labeled dataset, where the input data is paired with corresponding output labels.
- The goal is to learn a mapping function from input to output so that the algorithm can make predictions or classifications on new, unseen data.
2. Unsupervised Learning:
- In unsupervised learning, the algorithm is given data without explicit instructions on what to do with it.
- The algorithm tries to find patterns, relationships, or structures within the data on its own.
- Clustering algorithms, like k-Means, fall under unsupervised learning because they group similar data points together without using labeled output information.
3. Semi-supervised Learning:
- Semi-supervised learning is a combination of supervised and unsupervised learning.
- It involves a dataset that contains both labeled and unlabeled examples.
- The algorithm is trained on the labeled data, and then it tries to make predictions on the unlabeled data by leveraging the patterns learned from the labeled data.
4. Reinforcement Learning:
- Reinforcement learning involves an agent interacting with an environment and learning to make decisions by receiving feedback in the form of rewards or punishments.
- The agent learns to take actions that maximize the cumulative reward over time.
- Unlike supervised learning, where the algorithm is provided with explicit labeled examples, in reinforcement learning, the algorithm learns by trial and error.
In the case of the k-Means algorithm, it is unsupervised learning because it doesn't rely on labeled output data. Instead, it aims to partition the input data into clusters based on similarity, without using predefined class labels.
Consider the following array.
23 |
32 |
45 |
69 |
72 |
73 |
89 |
97 |
Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort above array in ascending order?
Answer (Detailed Solution Below)
Insertion Sort Question 7 Detailed Solution
Download Solution PDFInsertion sort:
In Insertion sort, the best-case takes Θ (n) time, the best case of insertion sort is when elements are sorted in ascending order. In that case, the number of comparisons will be n - 1 = 8 - 1 = 7
It is the least number of comparisons (among the array elements) to sort the above array in ascending order:
The number of swaps needed is zero.
Additional Information
In Insertion sort, the worst-case takes Θ (n2) time, the worst case of insertion sort is when elements are sorted in reverse order. In that case the number of comparisons will be like:
\(\mathop \sum \limits_{{\rm{p}} = 1}^{{\rm{N}} - 1} {\rm{p}} = 1 + 2 + 3 + \ldots . + {\rm{N}} - 1 = {\rm{\;}}\frac{{{\rm{N}}\left( {{\rm{N}} - 1} \right)}}{2} - 1\)
This will give Θ (n2) time complexity.
If the array A contains the items 10, 4, 7, 23, 67, 12 and 5 in that order, what will be the resultant array A after third pass of insertion sort?
Answer (Detailed Solution Below)
Insertion Sort Question 8 Detailed Solution
Download Solution PDFConcept:
Insertion sort is the sorting mechanism where the sorted array is built having one item at a time. The analogy can be understood from the style we arrange a deck of cards. This sort works on the principle of inserting an element at a particular position, hence the name Insertion Sort.
Insertion Sort works as follows:
- The first step involves the comparison of the element in question with its adjacent element.
- And if at every comparison reveals that the element in question can be inserted at a particular position, then space is created for it by shifting the other elements one position to the right and inserting the element at the suitable position.
- The above procedure is repeated until all the element in the array is at their apt position.
Explanation:
Array: 10, 4, 7, 23, 67, 12, 5
After 1st pass: 4, 10, 7, 23, 67, 12, 5 – 4 and 10 got swapped or 4 got inserted at its apt position
After 2nd pass: 4, 7, 10, 23, 67, 12, 5 – 7 got inserted at its apt position
After 3rd pass: 4, 7, 10, 23, 67, 12, 5 – No change because the value 10 is placed in its apt position alreadyAverage number of comparison required for a successful search for sequential search on ‘n’ items is
Answer (Detailed Solution Below)
Insertion Sort Question 9 Detailed Solution
Download Solution PDFAs search supposed to be successful.
Probability that number is the first number = 1/n
Probability that the number will be in first two = 1/n + 1/n
Probability that number is in first three numbers = 2/n + 1/n
Probability that number is in n numbers = (n - 1)/n + 1/n = 1
Hence expected number of comparisons = \(1/n+2/n+3/n+…+n/n = (n+1)/2\)
Which of the following is TRUE of the time complexity of the insertion sort algorithm to sort a list of ‘n’ integers?
Answer (Detailed Solution Below)
Insertion Sort Question 10 Detailed Solution
Download Solution PDF- In best case the element in the array is already sorted.
- When a new element which is greater than all the elements of the array is added, then there will be no swap but only a single comparison. In n -1 swaps, only 0 swaps and n-1 comparisons are there.
- Total time complexity in this case will be Ω (n)
- The omega is used to represent the best case. In any case, the best time complexity of insertion sort cannot be less than n, because at least n comparisons are required to identify the list of n elements is sorted or not.
Let Q denote a queue containing sixteen numbers and S be an empty stack. Head(Q) returns the element at the head of the queue Q without removing it from Q. Similarly, Top(S) returns the elements at the top of S without removing it from S. Consider the algorithm given below.
Answer (Detailed Solution Below) 256
Insertion Sort Question 11 Detailed Solution
Download Solution PDFHere, it is given that queue contains 16 numbers. Suppose 16, 15, 14, 13, 12, 11…….1 (in decreasing order)
Now first condition is if S is empty or Top(S) <= Head (Q) then x = dequeuer(Q); Push (S, x)
So, initially stack is empty, 16 will be pushed into the stack.
Top(S) = 16, Head(Q) = 15.
Now if S is empty or Top(S) <= Head (Q) / condition becomes false
16 will be popped out of the stack and enqueued into the queue because else part is executed here.
Now, Queue elements will be like this after 2 iterations and stack is empty.
15 |
14 |
13 |
12 |
……………… |
………….. |
2 |
1 |
16 |
Similarly, for remaining elements, 15, 14, 13, 12, …………2 will be pushed into stack and immediately popped out of stack. So, after 30 iterations stack is empty and queue will be like:
1 |
16 |
15 |
14 |
……………… |
………….. |
4 |
3 |
2 |
Now, 1 will be dequeued and pushed into stack. After this again Head(Q) = 16, top (S) = 1.
After this, 1 will never be popped out from stack because if condition will never become false. So, after 31 iterations queue will be like:
16 |
15 |
14 |
13 |
……………… |
………….. |
4 |
3 |
2 |
Stack contains 1.
By using same logic as above, after other 29 iterations queue will be like: 16, 15, 14, 13 ……..,4,3 and 2 in the stack top.
Iterations will go like: 31 + 29 + 27 + 25 + …………….1 (AP series)
Here a = 1, d = 2, n =16
The maximum possible number of iterations of the while loop in the algorithm is = \(\frac{n}{2}\left[ 2a+\left( n-1 \right)d \right]\)
\(=\frac{16}{2}\left[ 2\times 1+\left( 16-1 \right)2 \right]=256\)
The Highest Lower Bound on the number of Comparisons in the worst case for comparison-based sorting order of :
Answer (Detailed Solution Below)
Insertion Sort Question 12 Detailed Solution
Download Solution PDFThe correct answer is n log n.
Key Points
- In comparison-based sorting algorithms, the number of comparisons required to sort a list of n elements in the worst case is at least proportional to n log n.
- This result is derived from the fact that there are n! possible permutations of n elements, and each comparison can at most halve the number of possibilities.
- Therefore, to distinguish between all n! permutations, we need at least log(n!) comparisons.
- Using Stirling's approximation, log(n!) is Θ(n log n), which provides the lower bound for comparison-based sorting algorithms.
- This lower bound applies to all comparison-based sorting algorithms, including well-known ones like Merge Sort, Heap Sort, and Quick Sort (on average).
Additional Information
- Non-comparison-based sorting algorithms, such as Counting Sort, Radix Sort, and Bucket Sort, can achieve better performance under specific conditions, bypassing the n log n lower bound.
- These algorithms rely on additional assumptions about the input data, such as the range of the input values.
- However, for general-purpose sorting where no assumptions can be made about the input data, comparison-based sorting algorithms are the most widely applicable.
- Understanding the lower bound helps in analyzing and comparing the efficiency of different sorting algorithms.
- The n log n lower bound ensures that no comparison-based sorting algorithm can have a worst-case performance better than this bound.
Insertion Sort Question 13:
The k-Means algorithm is an ______ algorithm.
Answer (Detailed Solution Below)
Insertion Sort Question 13 Detailed Solution
The correct answer is Unsupervised Learning.
Key Points
1. Supervised Learning:
- In supervised learning, the algorithm is trained on a labeled dataset, where the input data is paired with corresponding output labels.
- The goal is to learn a mapping function from input to output so that the algorithm can make predictions or classifications on new, unseen data.
2. Unsupervised Learning:
- In unsupervised learning, the algorithm is given data without explicit instructions on what to do with it.
- The algorithm tries to find patterns, relationships, or structures within the data on its own.
- Clustering algorithms, like k-Means, fall under unsupervised learning because they group similar data points together without using labeled output information.
3. Semi-supervised Learning:
- Semi-supervised learning is a combination of supervised and unsupervised learning.
- It involves a dataset that contains both labeled and unlabeled examples.
- The algorithm is trained on the labeled data, and then it tries to make predictions on the unlabeled data by leveraging the patterns learned from the labeled data.
4. Reinforcement Learning:
- Reinforcement learning involves an agent interacting with an environment and learning to make decisions by receiving feedback in the form of rewards or punishments.
- The agent learns to take actions that maximize the cumulative reward over time.
- Unlike supervised learning, where the algorithm is provided with explicit labeled examples, in reinforcement learning, the algorithm learns by trial and error.
In the case of the k-Means algorithm, it is unsupervised learning because it doesn't rely on labeled output data. Instead, it aims to partition the input data into clusters based on similarity, without using predefined class labels.
Insertion Sort Question 14:
How many pass will run insertion sort to sort the 8 elements?
Answer (Detailed Solution Below)
Insertion Sort Question 14 Detailed Solution
The correct answer is option 3.
Concept:
Insertion sort:
Insertion sort is a basic sorting algorithm that operates in the same manner that you arrange cards in your hands. The array is divided into two halves, one sorted and one not. Values from the unsorted section are selected and placed in the sorted section at the appropriate location.
Explanation:
Consider the array is,
Input: 4 3 2 10 12 1 5 6
Output: 1 2 3 4 5 6 10 12
Explanation:
The implementation of insertion sort that there are again n−1 passes to sort n items. The iteration starts at position 1 and moves through position n−1, as these are the items that need to be inserted back into the sorted sublists.
Hence the total number of elements in an array is n=8.
Total pass will run insertion sort with 8 elements is = 7.
Hence the correct answer is 7.
Insertion Sort Question 15:
Consider the following array.
23 |
32 |
45 |
69 |
72 |
73 |
89 |
97 |
Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort above array in ascending order?
Answer (Detailed Solution Below)
Insertion Sort Question 15 Detailed Solution
Insertion sort:
In Insertion sort, the best-case takes Θ (n) time, the best case of insertion sort is when elements are sorted in ascending order. In that case, the number of comparisons will be n - 1 = 8 - 1 = 7
It is the least number of comparisons (among the array elements) to sort the above array in ascending order:
The number of swaps needed is zero.
Additional Information
In Insertion sort, the worst-case takes Θ (n2) time, the worst case of insertion sort is when elements are sorted in reverse order. In that case the number of comparisons will be like:
\(\mathop \sum \limits_{{\rm{p}} = 1}^{{\rm{N}} - 1} {\rm{p}} = 1 + 2 + 3 + \ldots . + {\rm{N}} - 1 = {\rm{\;}}\frac{{{\rm{N}}\left( {{\rm{N}} - 1} \right)}}{2} - 1\)
This will give Θ (n2) time complexity.