Title | Lab Prolog - Ernesto Gomez |
---|---|
Author | Linxuan Liu |
Course | Programming Languages |
Institution | California State University San Bernardino |
Pages | 4 |
File Size | 466.6 KB |
File Type | |
Total Downloads | 86 |
Total Views | 141 |
Ernesto Gomez...
Linxuan Liu 006151141 CSE 320 Algorithm: Quicksort Language: Prolog
1. Source Code qsort([],[]). qsort([H|T],Sorted) :partition(H,T,Less,Greater), qsort(Less,SortedLess), qsort(Greater,SortedGreater), append(SortedLess,[H|SortedGreater],Sorted). partition(_,[],[],[]). partition(P,[H|T],[H|Less],Greater) :H =< P, partition(P,T,Less,Greater). partition(P,[H|T],Less,[H|Greater]) :H > P, partition(P,T,Less,Greater).
2. Output with 5 different data:
3. Timing of multiple runs:
4. Comments: Prolog is a language which stands for programming logic. I never used prolog as an implement language before, so I need to start learning from very beginning and learn prolog through tutorials. After I implement the quicksort algorithm, I found it use 14 lines to finish the algorithm but hard to understand. Since the logic is the most basic
thing in prolog, there are still many stuffs to learn. Debugging is quite difficult for me because the first learning experience. However, after I find how to get the time for execution, the execution it gives me are all 0s. I think maybe it use integer to present the time it used so like 0.002s will give 0s as well. Therefore, I think it’s quite hard to find the time in prolog than other language and I will try to learn more about prolog in the future....