Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
2.4k views
in Computer by (69.2k points)

Show under what order of input, the insertion sort will have worst-case and bestcase situations for sorting the set {142, 543, 123, 65, 453, 879, 572, 434}. 

1 Answer

+2 votes
by (69.8k points)
selected by
 
Best answer

The given list is 142 543 123 65 453 879 572

 As we know that insertion sort is based on the idea of inserting records into an existing sorted file. To insert a record, we must find the proper place for the record to be inserted and this requires searching the list. 

An insertion sort will have the worst-case when the list is reversely sorted i.e. in a decreasing order. So for the above given list the insertion sort exhibits its worse case when the list is in following order

879 572 543 453 434 142 123 65

Again since it is the property of the insertion sort that it searches for the correct position in the list for an element, so this technique exhibits its best case computing when the list is already sorted in ascending order as given below.

65 123 142 434 453 543 572 879 

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...