From e1879d3432feb39f637550d0ad9e9d9abd1fe469 Mon Sep 17 00:00:00 2001 From: Naveen Hegde Date: Mon, 25 Dec 2017 23:38:23 +0530 Subject: [PATCH] Added SlowSort added the main function as requested. added only the necessary header as requested. Description of Slow Sort can be found here https://en.wikipedia.org/wiki/Slowsort --- Sorting/Slow Sort.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Sorting/Slow Sort.cpp diff --git a/Sorting/Slow Sort.cpp b/Sorting/Slow Sort.cpp new file mode 100644 index 000000000..686dcbccb --- /dev/null +++ b/Sorting/Slow Sort.cpp @@ -0,0 +1,57 @@ +//Returns the sorted vector after performing SlowSort +//It is a sorting algorithm that is of humorous nature and not useful. +//It's based on the principle of multiply and surrender, a tongue-in-cheek joke of divide and conquer. +//It was published in 1986 by Andrei Broder and Jorge Stolfi in their paper Pessimal Algorithms and Simplexity Analysis. +//This algorithm multiplies a single problem into multiple subproblems +//It is interesting because it is provably the least efficient sorting algorithm that can be built asymptotically, +//and with the restriction that such an algorithm, while being slow, must still all the time be working towards a result. + +#include +using namespace std; + +void SlowSort(int a[], int i, int j) +{ + if(i>=j) + return; + int m=i+(j-i)/2; //midpoint, implemented this way to avoid overflow + int temp; + SlowSort(a, i, m); + SlowSort(a, m + 1, j); + if(a[j]>size; + + int arr[size]; + + cout<<"\nEnter the unsorted elements : "; + + for (int i = 0; i < size; ++i) + { + cout<<"\n"; + cin>>arr[i]; + } + + SlowSort(arr, 0, size); + + cout<<"Sorted array\n"; + + for (int i = 0; i < size; ++i) + { + cout << arr[i] << " "; + } + return 0; +}