From c0f018bd798a50b443cf990f4f2f2546f3319a76 Mon Sep 17 00:00:00 2001 From: nirmay0503 <19ucs061@lnmiit.ac.in> Date: Wed, 23 Oct 2019 00:06:21 +0530 Subject: [PATCH 1/2] I added algorithm for jump search !! --- Search/jump_search.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Search/jump_search.cpp diff --git a/Search/jump_search.cpp b/Search/jump_search.cpp new file mode 100644 index 000000000..0ee7e4e00 --- /dev/null +++ b/Search/jump_search.cpp @@ -0,0 +1,54 @@ +// C++ program to implement Jump Search + +#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; +} From 61664e9639bfa05ca7c1646224ed3b663876eadf Mon Sep 17 00:00:00 2001 From: nirmay0503 <19ucs061@lnmiit.ac.in> Date: Wed, 23 Oct 2019 20:14:43 +0530 Subject: [PATCH 2/2] I added algorithm to find factorial of a number --- Math/factorial.cpp | 18 ++++++++++++++++++ Math/factorial.exe | Bin 0 -> 1564138 bytes Math/factorial.o | Bin 0 -> 1687 bytes 3 files changed, 18 insertions(+) create mode 100644 Math/factorial.cpp create mode 100644 Math/factorial.exe create mode 100644 Math/factorial.o diff --git a/Math/factorial.cpp b/Math/factorial.cpp new file mode 100644 index 000000000..49748fb42 --- /dev/null +++ b/Math/factorial.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; + +int main() +{ + int n; + cout<<"Enter number = "; + cin>>n; + int num=1; + for(int i=1;i