From 41368fb99c780dff8f8f272a4016c7346ad74dd2 Mon Sep 17 00:00:00 2001 From: vaibhav mishra <89639461+VaibhavM01@users.noreply.github.com> Date: Mon, 25 Oct 2021 10:55:25 +0530 Subject: [PATCH 1/5] added jumpSearch.js Implemented Jumpsearch in javaScript --- Jump Search/jumpSearch.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Jump Search/jumpSearch.js diff --git a/Jump Search/jumpSearch.js b/Jump Search/jumpSearch.js new file mode 100644 index 0000000..af2b978 --- /dev/null +++ b/Jump Search/jumpSearch.js @@ -0,0 +1,26 @@ +function jumpSearch(arr, target) { + + let len = arr.length + let step = Math.floor(Math.sqrt(len)); + let blockStart = 0, currentStep = step; + + while (arr[Math.min(currentStep, len) - 1] < target) { + blockStart = currentStep; + currentStep += step; + + if (blockStart >= len) + return -1; + } + + while (arr[blockStart] < target) + { + blockStart++; + if (blockStart == Math.min(currentStep, len)) + return -1; + } + + if (arr[blockStart] == target) + return blockStart + else + return -1; +} From da3c67b8256bed4d5b90ab8c26a9ff1dd939113c Mon Sep 17 00:00:00 2001 From: Izuku29 <89025886+Izuku29@users.noreply.github.com> Date: Thu, 28 Oct 2021 22:57:40 +0530 Subject: [PATCH 2/5] fibonacci in c using a recursive function --- Fibonacci series/fibonacci in c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Fibonacci series/fibonacci in c diff --git a/Fibonacci series/fibonacci in c b/Fibonacci series/fibonacci in c new file mode 100644 index 0000000..b59d44f --- /dev/null +++ b/Fibonacci series/fibonacci in c @@ -0,0 +1,14 @@ +#include +int fib(int n) +{ + if(n<=1) + return n; + return fib(n-1)+fib(n-2); +} +int main() +{ + int a; + scanf("%d",&a); + printf("%d",fib(a)); + return 0; +} From e45968b56c0ed146584911baa3a595ed0aaa1a69 Mon Sep 17 00:00:00 2001 From: BugHunters-bug <91728280+BugHunters-bug@users.noreply.github.com> Date: Fri, 29 Oct 2021 12:51:30 +0530 Subject: [PATCH 3/5] rename --- Fibonacci series/{fibonacci in c => fibonacci.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Fibonacci series/{fibonacci in c => fibonacci.c} (100%) diff --git a/Fibonacci series/fibonacci in c b/Fibonacci series/fibonacci.c similarity index 100% rename from Fibonacci series/fibonacci in c rename to Fibonacci series/fibonacci.c From fb2c501bf9ad0d4ee13a0d3ac78cfafccf5bb31b Mon Sep 17 00:00:00 2001 From: chakeson <80765479+chakeson@users.noreply.github.com> Date: Fri, 29 Oct 2021 14:24:11 +0200 Subject: [PATCH 4/5] Added Luhns algorithm --- Luhn algorithm/Luhn.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Luhn algorithm/Luhn.py diff --git a/Luhn algorithm/Luhn.py b/Luhn algorithm/Luhn.py new file mode 100644 index 0000000..c267c9b --- /dev/null +++ b/Luhn algorithm/Luhn.py @@ -0,0 +1,23 @@ +""" + Luhn algorithm or Luhn formula + Checksum algorithm. + Source:https://en.wikipedia.org/wiki/Luhn_algorithm + +""" + +def luhn(input_number): + + input_number = [int(i) for i in str(input_number)] + input_number.reverse() + + sum_answer = 0 + for i, number in enumerate(input_number): + temp = number + if i % 2 == 0: + temp = number * 2 + if temp > 9: + temp -= 9 + + sum_answer = sum_answer + temp + + return sum_answer % 10 == 0 From 130ae49ed6b093ff83a41989575b0537b2032c44 Mon Sep 17 00:00:00 2001 From: cheemra <93471584+cheemra@users.noreply.github.com> Date: Sun, 31 Oct 2021 21:52:37 +0530 Subject: [PATCH 5/5] Create tree_dsa.cpp --- Tree/tree_dsa.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 Tree/tree_dsa.cpp diff --git a/Tree/tree_dsa.cpp b/Tree/tree_dsa.cpp new file mode 100644 index 0000000..5b96ed8 --- /dev/null +++ b/Tree/tree_dsa.cpp @@ -0,0 +1,129 @@ +#include +using namespace std; +#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); +typedef long long ll; +const ll mod=1e9+7; +//<------disjoint set-union------> +vectorparent,size; +void make_set(int v) { + parent[v] = v; + size[v] = 1; +} + +void union_sets(int a, int b) { + a = find_set(a); + b = find_set(b); + if (a != b) { + if (size[a] < size[b]) + swap(a, b); + parent[b] = a; + size[a] += size[b]; + } +} + +int find_set(int v) { + if (v == parent[v]) + return v; + return find_set(parent[v]); +} + +//<-----------fenwick tree---------> +struct FenwickTree { + vector bit; // binary indexed tree + int n; + + FenwickTree(int n) { + this->n = n; + bit.assign(n, 0); + } + + FenwickTree(vector a) : FenwickTree(a.size()) { + for (size_t i = 0; i < a.size(); i++) + add(i, a[i]); + } + + int sum(int r) { + int ret = 0; + for (; r >= 0; r = (r & (r + 1)) - 1) + ret += bit[r]; + return ret; + } + + int sum(int l, int r) { + return sum(r) - sum(l - 1); + } + + void add(int idx, int delta) { + for (; idx < n; idx = idx | (idx + 1)) + bit[idx] += delta; + } +}; + +//<-------------square root decomposition--------------> + +void sqrt_decmpO(){ +//input data +int n; +vector a (n); + +// preprocessing +int len = (int) sqrt (n + .0) + 1; // size of the block and the number of blocks +vector b (len); +for (int i=0; i +int MAXN; +int n; +vectort(4*MAXN); +void build(int a[], int v, int tl, int tr) { + if (tl == tr) { + t[v] = a[tl]; + } else { + int tm = (tl + tr) / 2; + build(a, v*2, tl, tm); + build(a, v*2+1, tm+1, tr); + t[v] = t[v*2] + t[v*2+1]; + } +} +int sum(int v, int tl, int tr, int l, int r) { + if (l > r) + return 0; + if (l == tl && r == tr) { + return t[v]; + } + int tm = (tl + tr) / 2; + return sum(v*2, tl, tm, l, min(r, tm)) + + sum(v*2+1, tm+1, tr, max(l, tm+1), r); +} +void update(int v, int tl, int tr, int pos, int new_val) { + if (tl == tr) { + t[v] = new_val; + } else { + int tm = (tl + tr) / 2; + if (pos <= tm) + update(v*2, tl, tm, pos, new_val); + else + update(v*2+1, tm+1, tr, pos, new_val); + t[v] = t[v*2] + t[v*2+1]; + } +}