Question
The merge-sort algorithm for sorting a list is based on dividing the list, then sorting the smaller lists (using a recursive call to merge-sort) and
The merge-sort algorithm for sorting a list is based on dividing the list, then sorting the smaller lists (using a recursive call to merge-sort) and finally merging these sorted smaller lists. Accordingly, to sort a list L:
- divide L into two lists L1 and L2, of approximately equal length;
- sort L1 and L2 giving S1 and S2; and
- merge S1 and S2 giving L3 (sorted). Write a Prolog implementation of merge-sort.
Test results:
?- merge_sort([83,5,5,4,16,6], M). M = [4, 5, 5, 6, 16, 83]
?- merge_sort([3,2,5,4,1,6], M). M = [1,2,3,4,5,6]
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 StartedRecommended Textbook for
Data Structures and Algorithms in Java
Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
6th edition
1118771334, 1118771338, 978-1118771334
Students also viewed these Algorithms questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App