From 3510ea7580ffc80e578b9a2ce5660db354918d07 Mon Sep 17 00:00:00 2001 From: hardik chitkara <56203317+hardikchitkara@users.noreply.github.com> Date: Sun, 11 Oct 2020 23:15:20 +0530 Subject: [PATCH 1/4] Update vikhyatsingh123_linear_search.cpp --- Linear Search/vikhyatsingh123_linear_search.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Linear Search/vikhyatsingh123_linear_search.cpp b/Linear Search/vikhyatsingh123_linear_search.cpp index 96aabd22..9a76ba71 100644 --- a/Linear Search/vikhyatsingh123_linear_search.cpp +++ b/Linear Search/vikhyatsingh123_linear_search.cpp @@ -7,9 +7,12 @@ int search(int array[], int n, int x) { // Going through array sequencially for (int i = 0; i < n; i++) + { if (array[i] == x) - return i; + {return i;} + } return -1; + } int main() { @@ -19,5 +22,5 @@ int main() { int result = search(array, n, x); - (result == -1) ? cout << "Element not found" : cout << "Element found at index: " << result; + (result == -1) ?cout << "Element not found" : cout << "Element found at index: " << result; } From 93cd08eadae7aa9ef9654875dc2884fbcc4b2126 Mon Sep 17 00:00:00 2001 From: hardikchitkara Date: Thu, 22 Oct 2020 20:55:18 +0530 Subject: [PATCH 2/4] jumpsortversion1 --- cpp/hardikchitkara_jumpsearch.cpp | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 cpp/hardikchitkara_jumpsearch.cpp diff --git a/cpp/hardikchitkara_jumpsearch.cpp b/cpp/hardikchitkara_jumpsearch.cpp new file mode 100644 index 00000000..0625caca --- /dev/null +++ b/cpp/hardikchitkara_jumpsearch.cpp @@ -0,0 +1,52 @@ +#include +using namespace std; + +int jumpSearch(int arr[], int x, int n) +{ + // Finding block size to be jumped + int step = sqrt(n); + + // Finding the block where element is + // present (if it is present) + int prev = 0; + while (arr[min(step, n)-1] < x) + { + prev = step; + step += sqrt(n); + if (prev >= n) + return -1; + } + + // Doing a linear search for x in block + // beginning with prev. + while (arr[prev] < x) + { + prev++; + + // If we reached next block or end of + // array, element is not present. + if (prev == min(step, n)) + return -1; + } + // If element is found + if (arr[prev] == x) + return prev; + + return -1; +} + +// Driver program to test function +int main() +{ + int arr[] = { 0, 1, 1, 2, 3, 5, 8, 13, 21, + 34, 55, 89, 144, 233, 377, 610 }; + int x = 55; + int n = sizeof(arr) / sizeof(arr[0]); + + // Find the index of 'x' using Jump Search + int index = jumpSearch(arr, x, n); + + // Print the index where 'x' is located + cout << "\nNumber " << x << " is at index " << index; + return 0; +} \ No newline at end of file From fa7f8988140377e5693a960b97c95c443ab0174f Mon Sep 17 00:00:00 2001 From: hardik chitkara <56203317+hardikchitkara@users.noreply.github.com> Date: Thu, 22 Oct 2020 20:57:35 +0530 Subject: [PATCH 3/4] Delete hardikchitkara_jumpsearch.cpp --- cpp/hardikchitkara_jumpsearch.cpp | 52 ------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 cpp/hardikchitkara_jumpsearch.cpp diff --git a/cpp/hardikchitkara_jumpsearch.cpp b/cpp/hardikchitkara_jumpsearch.cpp deleted file mode 100644 index 0625caca..00000000 --- a/cpp/hardikchitkara_jumpsearch.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include -using namespace std; - -int jumpSearch(int arr[], int x, int n) -{ - // Finding block size to be jumped - int step = sqrt(n); - - // Finding the block where element is - // present (if it is present) - int prev = 0; - while (arr[min(step, n)-1] < x) - { - prev = step; - step += sqrt(n); - if (prev >= n) - return -1; - } - - // Doing a linear search for x in block - // beginning with prev. - while (arr[prev] < x) - { - prev++; - - // If we reached next block or end of - // array, element is not present. - if (prev == min(step, n)) - return -1; - } - // If element is found - if (arr[prev] == x) - return prev; - - return -1; -} - -// Driver program to test function -int main() -{ - int arr[] = { 0, 1, 1, 2, 3, 5, 8, 13, 21, - 34, 55, 89, 144, 233, 377, 610 }; - int x = 55; - int n = sizeof(arr) / sizeof(arr[0]); - - // Find the index of 'x' using Jump Search - int index = jumpSearch(arr, x, n); - - // Print the index where 'x' is located - cout << "\nNumber " << x << " is at index " << index; - return 0; -} \ No newline at end of file From ea086675800f1e2b7f2cc08fe4f8aedb0668590c Mon Sep 17 00:00:00 2001 From: hardik chitkara <56203317+hardikchitkara@users.noreply.github.com> Date: Thu, 25 Feb 2021 18:15:55 +0530 Subject: [PATCH 4/4] Added Contributors --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ce8e9e48..70d04d43 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -25,3 +25,4 @@ If you have contributed to this repository, kindly add your username here - [qwertymaden](https://github.com/qwertymaden) - [mjnorton](https://github.com/mjnorton) - [gauravkhatri2698](https://github.com/gauravkhatri2698) +- [Hardik Chitkara](https://github.com/hardikchitkara)