From 69aceb6cfc89dad0696de3889c862369761f7e28 Mon Sep 17 00:00:00 2001 From: Vatsalya Gupta <64428075+vatsalya-gupta@users.noreply.github.com> Date: Fri, 2 Oct 2020 15:20:08 +0530 Subject: [PATCH 1/2] Create jumpSearch.cpp --- jumpSearch.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 jumpSearch.cpp diff --git a/jumpSearch.cpp b/jumpSearch.cpp new file mode 100644 index 0000000..f4ef37e --- /dev/null +++ b/jumpSearch.cpp @@ -0,0 +1,48 @@ +/* +Title - Jump search Algorithm +It will sort array +time complexity - O(N^0.5) +*/ + +#include +#include + +using namespace std; +int jump_Search(int a[], int n, int item) { + int i = 0; + int m = sqrt(n); //initializing block size= √(n) + + while(a[m] <= item && m < n) { + // the control will continue to jump the blocks + i = m; // shift the block + m += sqrt(n); + if(m > n - 1) // if m exceeds the array size + return -1; + } + + for(int x = i; x> n; + int arr[n]; //creating an array of size n + cout << "\n Enter items: "; + + for(int i = 0; i< n; i++) { + cin >> arr[i]; + } + + cout << "\n Enter search key to be found in the array: "; + cin >> item; + loc = jump_Search(arr, n, item); + if(loc>=0) + cout << "\n Item found at location: " << loc; + else + cout << "\n Item is not found in the list."; +} From 8bd8f03f54470df0c5b60b65a562609bb9abb0ec Mon Sep 17 00:00:00 2001 From: Vatsalya Gupta <64428075+vatsalya-gupta@users.noreply.github.com> Date: Fri, 2 Oct 2020 15:21:07 +0530 Subject: [PATCH 2/2] Update jumpSearch.cpp --- jumpSearch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jumpSearch.cpp b/jumpSearch.cpp index f4ef37e..4432cbe 100644 --- a/jumpSearch.cpp +++ b/jumpSearch.cpp @@ -1,6 +1,6 @@ /* Title - Jump search Algorithm -It will sort array +It will search an array time complexity - O(N^0.5) */