Question

Consider the list of characters: ['P', 'Y', 'T', 'H', 'O', 'N']. Show how this list is...

Consider the list of characters: ['P', 'Y', 'T', 'H', 'O', 'N']. Show how this list is sorted using merge sort, use induction to prove the run time of this algorithm.

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

[P Y T H O N]

split in two

[P Y T] [O N]

split

[P Y] [T] [O N]

split

[P] [Y] [T] [O N]

merge [P] and [Y]

[P Y] [T] [O N]

merge [P Y] [T]

[P T Y] [O N]

split [O N]

[P T Y] [O] [N]

merge [O] [N]

[P T Y] [N O]

merge

[N O P T Y]

running time of this program is n(logn)

T(n) = 2T(n/2) + O(n)

T(n) = O(nlogn)

T(2) = 2T(1) + O(1) = 2

= which is same 2log2

so base case satisfied, let it be true till n-1 (i..e, true for n/2)

T(n) = 2T(n/2) + O(n)

= 2knlogn + cn

= n(2klogn + c)

= O(nlogn)

Hence proved

Let see

Add a comment
Know the answer?
Add Answer to:
Consider the list of characters: ['P', 'Y', 'T', 'H', 'O', 'N']. Show how this list is...
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
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
ADVERTISEMENT