subject
Engineering, 07.05.2021 15:40 xdimplesjoon

You will reimplement the Quicksort given in textbook and lecture slides. In the given example, the first (left-most) element of the given list is selected as the pivot. In this question, you must choose the second element of the list as the pivot. Hint: You can represent the input list into pairs: [First | [Pivot Tail]]. You must write comments to indicate the size-n problem, stopping condition and its return value, size m-problems, and construction of the size-n problem from size-m problems. [20 points) Test case: | ?- qsort2([8, 3, 4, 12, 25, 4, 6, 1, 9, 22, 6), Sorted). It returns: Sorted = (1,3,4,4,6,6,8,9,12,22,25) Quick Sort Code in Prolog asort([],[)) :-! % empty list is already sorted qsort([Pivot/Tail], Sorted):- % Take first number as pivot split(Pivot, Tail, L1, L2), qsort(L1, Sorted1), % sort first part qsort(L2,Sorted2), % sort second part append(Sorted 1, [Pivot|Sorted2], Sorted). split(_,0,0,0). split(Pivot,[X|T],[X|Le], Gt):- X= Pivot, split(Pivot, T, Le, Gt). % stopping condition % take first from Tail % and put it into Le % take first from Tail % and put it into Gtchs 9/2002

ansver
Answers: 3

Another question on Engineering

question
Engineering, 03.07.2019 15:10
Heat is added to a piston-cylinder device filled with 2 kg of air to raise its temperature 400 c from an initial temperature of t1 27 cand pressure of pi 1 mpa. the process is isobaric process. find a)-the final pressure p2 b)-the heat transfer to the air.
Answers: 1
question
Engineering, 03.07.2019 15:10
Two flowing streams of argon gas are adiabatically mixed to form a single flow/stream. one stream is 1.5 kg/s at 400 kpa and 200 c while the second stream is 2kg/s at 500 kpa and 100 ? . it is stated that the exit state of the mixed single flow of argon gas is 150 c and 300 kpa. assuming there is no work output or input during the mixing process, does this process violate either the first or the second law or both? explain and state all your assumptions.
Answers: 1
question
Engineering, 04.07.2019 18:10
What difference(s) did you notice using a pneumatic circuit over hydraulic circuit.explain why the pneumatic piston stumbles when it hits an obstacle.
Answers: 2
question
Engineering, 04.07.2019 18:10
If a particle moves along a path such that r : (3 sin t) m and ? : 2t rad, where t is in seconds. what is the particle's acceleration in m/s in 4 seconds? a)- 16.43 b)- 16.29 c)- 15.21 d)- 13.79
Answers: 1
You know the right answer?
You will reimplement the Quicksort given in textbook and lecture slides. In the given example, the f...
Questions
question
Mathematics, 22.09.2019 23:20
question
World Languages, 22.09.2019 23:20
question
Computers and Technology, 22.09.2019 23:20
Questions on the website: 13722359