I am learning Prolog and trying to solve some of the exercises from the book "The Art of Prolog". Someone, please help me to solve Q 3.3.1.(vi), below is the problem -
Q. Write a logic program for kth_largest (Xs, K) that implements the linear algorithm for finding the kth largest element K of a list Xs. The algorithm has the following steps:
- Break the list into groups of five elements.
- Efficiently find the median of each of the groups, which can be done with a fixed number of comparisons.
- Recursively find the median of the medians.
- Partition the original list with respect to the median of medians.
- Recursively find the kth largest element in the appropriate smaller list.
Any help will be appreciated. Thanks in advance.