Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. BubbleSort a1,... ,an, array of integers) For i from 1 to n - 1 1. 2 3 For j from 1 to n-i j

image text in transcribed

1. BubbleSort a1,... ,an, array of integers) For i from 1 to n - 1 1. 2 3 For j from 1 to n-i j aj+1 then Interchange aj and aj+1 RevisedBubbleSort( a1,... , an, array of integers) 1. For i from 1 to n -1 done-true 3.For j from 1 ton-i If aj > aj+1 then Interchange a, and aj+1 done false If done true then 6 7 Break Please answer the following questions. No justification needed (a) How many comparisons does BubbleSort make on an array of size n that is already sorted fronm smallest to largest? (b) How many comparisons does BubbleSort make on an array of size n that is sorted from largest to smallest? (c) What are the big-Theta classes for the runtimes of the best case and worst cases of BubbleSort? (d) Explain the difference between BubbleSort and RevisedBubbleSort (e) How many comparisons does RevisedBubbleSort make on an array of size n that is already sorted (f) How many comparisons does RevisedBubbleSort make on an array of size n that is sorted from (g) What are the big-Theta classes for the runtimes of the best case and worst cases of RevisedBub- (h) List all possible arrays containing the numbers 1, 2, 3, 4, and 5 for which RevisedBubbleSort will (i) What is the loop invariant of BubbleSort? from smallest to largest? largest to smallest? bleSort? terminate with a value of i = 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions