Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For the list [12, 15, 36, 31, 11, 17, 9, 13, 24, 25]: Illustrate the full execution of Quick-Sort ( a nd quick-sort on page
For the list [12, 15, 36, 31, 11, 17, 9, 13, 24, 25]:
Illustrate the full execution of Quick-Sort ( and quick-sort on page 555. Also refer to the following video: https://www.youtube.com/watch?v= aQiWF4E8flQ)
by python
I def quick.sort (S) 2""Sort the elements of queue S using the quick-sort algorithm.""" 3 n len(S) 4 if n2: return # list is already sorted # divide 7 p S.first() # using first as arbitrary pivot ? LinkedQueue() 9E LinkedQueue() 10 G LinkedQueue) 11 while not S.is.empty() 12 if S.first( ) ? p: 13 14 elif p?S.first(): # divide S into L, E, and G L.enqueue(S.dequeue( G.enqueue(S.dequeue E.enqueue(S.dequeue()) else: # S.first() must equal pvot 16 17 18 # conquer (with recursion) 19 quick.sort(L) 20 quick.sort(G) 21 # concatenate results 22 while not L.is.empty() # sort elements less than p # sort elements greater than p S.enqueue(L.dequeue( 24 while not E.is.empty() 25 S.enqueue(E.dequeue() 26 while not G.is empty(): 27 S.enqueue(G.dequeue()) Code Fragment 12.5: Quick-sort for a sequence S implemented as a queue
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started