find the average-case time complexity for bogosort where we are ordering the list a1, a2, . . . , an. We begin by finding the average number of shuffles needed to order the list.   Problem: What is the probability that a list a1, a2, . . . , an is ordered?

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
Question

This assignment is an exercise in finding the average-case complexity of an algorithm.
Rather than looking at how long an algorithm can run in the worst case as in worst-
case analysis, we are looking at how long an algorithm runs on average. This is done
by computing the average number of comparisons and operations executed until the
algorithm ends.
Bogosort is a sorting algorithm that orders a list in increasing order by taking the
list, checking to see if the list is ordered increasingly, if the list is not ordered increasingly
then the list is randomly shuffled, and then repeating this process until the list is ordered
increasingly.
Expressed in pseudocode:
Algorithm 1 Bogosort
Require: list: a1, a2, . . . , an of real numbers
Ensure: list is sorted in increasing order
1: procedure bogo(list)
2: while not sorted(list) do ▷ Checks to see if list is sorted
3: shuffle(list) ▷ Shuffle the current list if not sorted
4: end while
5: end procedure

We will now find the average-case time complexity for bogosort where we are ordering
the list a1, a2, . . . , an. We begin by finding the average number of shuffles needed to
order the list.
 
Problem: What is the probability that a list a1, a2, . . . , an is ordered?
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Breadth First Search Algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning