From e3d406912a29f632ac665c19abb7013785eb41d1 Mon Sep 17 00:00:00 2001 From: RoLoDeXx <35224521+RoLoDeXx@users.noreply.github.com> Date: Wed, 3 Oct 2018 12:03:24 +0530 Subject: [PATCH] Create bucket_sort.h --- bucket_sort.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 bucket_sort.h diff --git a/bucket_sort.h b/bucket_sort.h new file mode 100644 index 0000000..325bf58 --- /dev/null +++ b/bucket_sort.h @@ -0,0 +1,40 @@ +//BUCKET SORT + // Best case performance Ω(n+k) +// Average case performace θ(n+k) +// Worst Average case performace O(n^2) +// Wost case space complexity O(n) + //https://en.wikipedia.org/wiki/Bucket_sort + // The following header files are a must in order to execute the following code +#include +#include +#include +using namespace std; + +// Function to sort arr[] of size n using bucket sort +template +void bucketSort(T arr[], int n) +{ + // 1) Create n empty buckets + vector b[n]; + + // 2) Put array elements in different buckets + for (int i=0; i