Question

Question 4 (10 marks) When analysing the complexity of algorithms, there are three main approaches: worst case, best case and

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ans:'-

a) consider following table the list size is 3

S.NO CASE COMPARISONS REQUIRED
1 ABC,DEF 3
2 ABD,CEF 4
3 ACD,BEF 4
4 BCD,AEF 4
5 ABE,CDF 5
6 ACE,BDF 5
7 ADE,BCF 5
8 BCE,ADF 5
9 BDE,ACF 5
10 CDE,ABF 5

SO EXPECTED VALUE IS = 1*3+4*3+6*5/10 = 4.5

NOW go for n = 4

i`m showing you a way by which you can calculate easily

if n = 4 then comparisons will be 4,5,6 and 7

when comparison will be 4

then all the elements of the first list will be smaller than all the elements of the second list

so only one combination is possible i.e, ABCD,EFGH

when comparison will be 5

then we have following fixed formula

- - - E, -F G H

it means first 3 characters of first list and only the first character of the second list can be changed

so from 4 we can choose any 3

so 4C3 = 4

when comparison will be 6

then we have following fixed formula

- - -F, - -G H

it means the first 3 place of the first list and the first 2 elements of the second list can be changed

so from remaining 5 characters we have to find combination of 3

so 5C3 = 10 ways are there

- - - G, - - - H

so we have 3 positions can be fixed with the remaining 6 characters

6C3 = 20

so expected value = 1*4 + 4* 5 + 10*6 + 20*7 /35 = 6.4

b) now for n =5

we can directly write

for comparison 5 = 1

for comparison 6 = 5C1 = 5

for comparison 7 = 6C2 = 15

for comparison 8 = 7C3 = 35

for comparison 9 = 8C4 = 70

expected value = 1*5 + 5*6 + 15*7 + 35*8 + 70*9 /126 = 8.33

c)now we can simply write that as formula

NOW

FOR n items in a list

E(comparison) =

\sum_{i=0}^{n-1}^{n-1+ i}\left C_{i}^{X(n+i)} \right )/\sum_{i=0}^{n-1}^{n-1+i}C_{i}

use this formula when n = 3

+246 CS Scanned with CamScanner

Add a comment
Know the answer?
Add Answer to:
Question 4 (10 marks) When analysing the complexity of algorithms, there are three main approaches: worst case, best ca...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that...

    What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that share a set of tasks, even though the tasks are executed in different ways. Polymorphism allows a programmer to use a subclass object in place of a superclass object. Polymorphism allows a subclass to override a superclass method by providing a completely new implementation. Polymorphism allows a subclass to extend a superclass method by performing the superclass task plus some additional work. Assume that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT