subject

You will reimplement the Quicksort given in textbook and lecture slides. The given example, the first (left-most) element of the given list is selected as the pivot. In this question, you will choose the last (right-most) element of the list as the pivot. In order to do so, you can implement a get last(L, E) and remove_last(L, Ls), as described below.[20 points] 2.1 Write a Prolog rule: get last(L, E), which return the last element of list L to E. Test case: ?- get last([a, b, c, x, y], E) It returns E
2.2 Write a Prolog rule: remove last(L, Ls), which return the sub-list without the last element [10] to Ls Test case: ?- remove last([a, b, c, x, y], Ls) It returns Ls [a, b, c, x]
2.3 Rewrite quicksort rule qsort(L, Sorted), which will return the sorted list to Sorted. You must use the get_last and remove last in your qsort rule, so that the qsort rule takes the last (right-most) element of the list L as the pivot. Test case: 1?- qsort([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]

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:00, joedawg50
What is added to the < meta > tag to describe the encoding type?
Answers: 1
image
Computers and Technology, 23.06.2019 11:00, la200564
How should you specify box sizes on a web page if you want the boxes to vary according to the font size of the text they contain? a. in pixels b. in inches c. as percentages d. in em units
Answers: 2
image
Computers and Technology, 23.06.2019 13:00, torresnoemi899
Which of the following statements is false? a. a class can directly inherit from class object. b. if the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly. c. a class's instance variables are normally declared private to enforce good software engineering. d. it's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires.
Answers: 3
image
Computers and Technology, 23.06.2019 17:00, Need1ng
The more powerful, 60 volt cables and the main power shut-off on an hev are both colored orange.
Answers: 1
You know the right answer?
You will reimplement the Quicksort given in textbook and lecture slides. The given example, the firs...

Questions in other subjects:

Konu
Mathematics, 25.05.2021 23:40