Python Forum
Bubble sort quiz: why the result is not the same?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bubble sort quiz: why the result is not the same?
#5
I don't know what the problem is, but the code definitely does not return the theoretical results for Pass 2. When creating code like this, you should try to estimate what the output should look like. Since you have theoretical answers, the expected values should be (for 1,000,000 iterations):
Pass1: 1 /930 = 107.5 (and my results were 1092 - which I consider an acceptable answer)
Pass2: 1/ 14880 = 1/16th of 1 /930 = 67.2 (and my results were 2079 = not acceptable)

Using random numbers makes a solution more difficult, because the answer is different each time. I suggest you either use a fixed list for testing, or use a random number seed for testing purposes only. For example:
random.seed(12345)
For more information about Python random numbers see: https://python-forum.io/Thread-Proposed-...and-Python

I suggest you proceed as follows with concentration on the Pass2 algorithm:
a. Use a preset list as suggested above.
b. Reduce the number of items in the array to 5 or 10.
c. Verify that Pass2 performs an accurate sort, by testing Pass2 by itself (print the list after each iteration).
d. When c. is successful, test with a 40 item list, then test with a random list.

If you need additional help, post the 'original question' in this thread.

Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply


Messages In This Thread
RE: Bubble sort quiz: why the result is not the same? - by ljmetzger - Apr-24-2018, 07:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  QUIZ GUI Form_When admin panel is open, main quiz form is getting freeze Uday 4 807 Aug-25-2023, 08:24 PM
Last Post: deanhystad
Photo a.sort() == b.sort() all the time 3lnyn0 1 1,368 Apr-19-2022, 06:50 PM
Last Post: Gribouillis
  Python Networkx: Visualize an edge weight with a bubble/circle uvw 0 2,045 Sep-01-2021, 06:26 AM
Last Post: uvw
  Bubble sort on randomized integers bellevie 4 5,413 May-16-2017, 05:28 PM
Last Post: bellevie

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020