From acf5fae64d7e791e54410dfbcb7f2a4c1a160295 Mon Sep 17 00:00:00 2001 From: ashgpta <66237411+ashgpta@users.noreply.github.com> Date: Fri, 16 Oct 2020 01:09:50 +0530 Subject: [PATCH 1/2] Create Jump Search Hactoberfest 2020 --- .../searching/Jump Search | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/algorithms_data_structures/searching/Jump Search diff --git a/src/algorithms_data_structures/searching/Jump Search b/src/algorithms_data_structures/searching/Jump Search new file mode 100644 index 0000000..7f4e7f1 --- /dev/null +++ b/src/algorithms_data_structures/searching/Jump Search @@ -0,0 +1,56 @@ +// 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; +} + +// Contributed by Ayush From c65d5fd3a35b0fe669504ce659ea3e674e184fc5 Mon Sep 17 00:00:00 2001 From: ashgpta <66237411+ashgpta@users.noreply.github.com> Date: Fri, 16 Oct 2020 01:14:17 +0530 Subject: [PATCH 2/2] Create Full Pyramid of Numbers --- src/patterns/Full Pyramid of Numbers | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/patterns/Full Pyramid of Numbers diff --git a/src/patterns/Full Pyramid of Numbers b/src/patterns/Full Pyramid of Numbers new file mode 100644 index 0000000..30f8962 --- /dev/null +++ b/src/patterns/Full Pyramid of Numbers @@ -0,0 +1,25 @@ +#include +int main() { + int i, space, rows, k = 0, count = 0, count1 = 0; + printf("Enter the number of rows: "); + scanf("%d", &rows); + for (i = 1; i <= rows; ++i) { + for (space = 1; space <= rows - i; ++space) { + printf(" "); + ++count; + } + while (k != 2 * i - 1) { + if (count <= rows - 1) { + printf("%d ", i + k); + ++count; + } else { + ++count1; + printf("%d ", (i + k - 2 * count1)); + } + ++k; + } + count1 = count = k = 0; + printf("\n"); + } + return 0; +}