Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  What is the worst case time complexity of ins... Start Learning for Free
What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?
  • a)
    N
  • b)
    NlogN
  • c)
    N^2
  • d)
    N(logN)^2
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
What is the worst case time complexity of insertion sort where positio...
Applying binary search to calculate the position of the data to be inserted doesn’t reduce the time complexity of insertion sort. This is because insertion of a data at an appropriate position involves two steps:
1. Calculate the position.
2. Shift the data from the position calculated in step #1 one step right to create a gap where the data will be inserted.

Using binary search reduces the time complexity in step #1 from O(N) to O(logN). But, the time complexity in step #2 still remains O(N). So, overall complexity remains O(N^2).
View all questions of this test
Most Upvoted Answer
What is the worst case time complexity of insertion sort where positio...
Introduction:
Insertion Sort is a simple comparison-based sorting algorithm that builds the final sorted array one item at a time. The position of the data to be inserted can be calculated using binary search, which reduces the time complexity for finding the correct position to logarithmic time. However, the worst case time complexity of insertion sort still remains O(N^2) even with the optimization of binary search.

Explanation:
1. In insertion sort, the array is divided into two parts: sorted and unsorted.
2. Initially, the sorted part contains only the first element, and the unsorted part contains the remaining elements.
3. For each element in the unsorted part, it is compared with the elements in the sorted part to find the correct position for insertion.
4. Binary search can be used to find the correct position in the sorted part, reducing the number of comparisons required.
5. The worst case occurs when the array is in reverse order, i.e., the largest element is at the beginning.
6. In this case, for each element in the unsorted part, it needs to be compared with all the elements in the sorted part before finding the correct position.
7. The number of comparisons required for each element is 1, 2, 3, ..., N-1, which sums up to (N-1)*(N-2)/2.
8. Therefore, the total number of comparisons required in the worst case is (N-1)*(N-2)/2, which is a quadratic function of N.
9. Asymptotically, (N-1)*(N-2)/2 can be simplified to N^2, since the quadratic term dominates when N is large.
10. Hence, the worst case time complexity of insertion sort with binary search for finding the correct position is O(N^2).

Conclusion:
The worst case time complexity of insertion sort, even with the optimization of binary search for finding the correct position, is O(N^2). This occurs when the array is in reverse order, and for each element in the unsorted part, it needs to be compared with all the elements in the sorted part. Insertion sort is efficient for small input sizes or partially sorted arrays, but for large input sizes, other sorting algorithms like merge sort or quick sort with better time complexity should be considered.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Question Description
What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?a)Nb)NlogNc)N^2d)N(logN)^2Correct answer is option 'C'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?a)Nb)NlogNc)N^2d)N(logN)^2Correct answer is option 'C'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?a)Nb)NlogNc)N^2d)N(logN)^2Correct answer is option 'C'. Can you explain this answer?.
Solutions for What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?a)Nb)NlogNc)N^2d)N(logN)^2Correct answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?a)Nb)NlogNc)N^2d)N(logN)^2Correct answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?a)Nb)NlogNc)N^2d)N(logN)^2Correct answer is option 'C'. Can you explain this answer?, a detailed solution for What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?a)Nb)NlogNc)N^2d)N(logN)^2Correct answer is option 'C'. Can you explain this answer? has been provided alongside types of What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?a)Nb)NlogNc)N^2d)N(logN)^2Correct answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?a)Nb)NlogNc)N^2d)N(logN)^2Correct answer is option 'C'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev