The Gateway to Computer Science Excellence
0 votes
148 views
Consider the following array with 7 elements for insertion sort?

25, 15, 30, 9, 99, 20, 26 In how many passes, the given sequence will be sorted? (a) 4 pass (b) 5 pass (c) 6 pass (d) More than 6 pass

Answer is 6 passes. Can anyone explain it step by step.
in Algorithms by (181 points)
edited by | 148 views

1 Answer

0 votes
Best answer
Pass 0 = Array = 25, 15, 30, 9, 99, 20, 26

In pass 1, only 2 elements - 25, 15 ---> make them sorted

Pass 1 - 15, 25, 30, 9, 99, 20, 26

IN pass 2, only 3 elements - 15, 25, 30

Pass 2 - 15, 25, 30, 9, 99, 20, 26
Pass 3 - 9, 15, 25, 30, 99, 20, 26
Pass 4 - 9, 15, 25, 30, 99, 20, 26
Pass 5 - 9, 15, 20, 25, 30, 99, 26
Pass 6 - 9, 15, 20, 25, 26, 30, 99
by (117 points)
selected by
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,650 questions
56,242 answers
194,288 comments
95,938 users