Sei sulla pagina 1di 5

Analysis of Algorithms

Section: W1 / W3

Assignment # 1

Submitted by:
Analysis of Algorithms Assignment 1 Due Date: Nov. 08, 2019

BubbleSort (A)
n=A.lenght //time=0.5μsec
for j=n downto 2 //time=3μsec
for i=1 to j-1 //time=3μsec
if A[i]>A[i+1] //time=2μsec
A[i]⟷A[i+1] //time=4μsec

SelctionSort (A)
n=A.length //time=0.5μsec
for i=1 to n-1 //time=3μsec
MinLoc=i //time=0.5μsec
for j=i+1 to n //time=3μsec
if A[j]<A[MinLoc] //time=2μsec
MinLoc=j //time=0.5μsec
A[i]⟷A[MinLoc] //time=4μsec

InsertionSort (A)
n=A.length //time=0.5μsec
for j=2 to n //time=3μsec
temp=A[j] //time=0.5μsec
i=j-1 //time=0.5μsec
while i>1 and A[i]>temp //time=5μsec
A[i+1]=A[i] //time=0.5μsec
i=i-1 //time=0.5μsec
A[i+1]=temp //time=0.5μsec

Page |2
Analysis of Algorithms Assignment 1 Due Date: Nov. 08, 2019

0.25 Marks

How much time (in micro seconds) would be taken by the given code of BubbleSort to sort the following
array:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
5 15 23 37 41 60 132 169 300 416 500 559 671 835 910

Answer:_______________

0.25 Marks

How much time (in micro seconds) would be taken by the given code of BubbleSort to sort the following
array:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
580 350 187 137 121 110 82 69 30 26 25 21 17 15 10

Answer:_______________

0.25 Marks

How much time (in micro seconds) would be taken by the given code of BubbleSort to sort the following
array:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
58 35 87 37 21 10 32 69 30 16 50 29 71 35 10

Answer:_______________

0.25 Marks

How much time (in micro seconds) would be taken by the given code of BubbleSort to sort the following
array:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
83 94 24 55 36 89 55 92 28 94 25 22 16 74 28

Answer:_______________

Page |3
Analysis of Algorithms Assignment 1 Due Date: Nov. 08, 2019

0.25 Marks

How much time (in micro seconds) would be taken by the given code of SelectionSort to sort the
following array:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
5 15 23 37 41 60 132 169 300 416 500 559 671 835 910

Answer:_______________

0.25 Marks

How much time (in micro seconds) would be taken by the given code of SelectionSort to sort the
following array:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
580 350 187 137 121 110 82 69 30 26 25 21 17 15 10

Answer:_______________

0.25 Marks

How much time (in micro seconds) would be taken by the given code of SelectionSort to sort the
following array:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
58 35 87 37 21 10 32 69 30 16 50 29 71 35 10

Answer:_______________

0.25 Marks

How much time (in micro seconds) would be taken by the given code of SelectionSort to sort the
following array:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
83 94 24 55 36 89 55 92 28 94 25 22 16 74 28

Answer:_______________

Page |4
Analysis of Algorithms Assignment 1 Due Date: Nov. 08, 2019

0.25 Marks

How much time (in micro seconds) would be taken by the given code of InsertionSort to sort the
following array:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
5 15 23 37 41 60 132 169 300 416 500 559 671 835 910

Answer:_______________

0.25 Marks

How much time (in micro seconds) would be taken by the given code of InsertionSort to sort the
following array:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
580 350 187 137 121 110 82 69 30 26 25 21 17 15 10

Answer:_______________

0.25 Marks

How much time (in micro seconds) would be taken by the given code of InsertionSort to sort the
following array:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
58 35 87 37 21 10 32 69 30 16 50 29 71 35 10

Answer:_______________

0.25 Marks

How much time (in micro seconds) would be taken by the given code of InsertionSort to sort the
following array:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
83 94 24 55 36 89 55 92 28 94 25 22 16 74 28

Answer:_______________

Page |5

Potrebbero piacerti anche