From ba30f55d0da5f373421d46ffc3743d42feb1afba Mon Sep 17 00:00:00 2001 From: TarunISCO <201552063@iiitvadodara.ac.in> Date: Wed, 24 May 2017 23:45:22 +0530 Subject: [PATCH 1/9] Added Breadth First Search [C++] --- breadth_first_search/BreadhFirstSearch.cpp | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 breadth_first_search/BreadhFirstSearch.cpp diff --git a/breadth_first_search/BreadhFirstSearch.cpp b/breadth_first_search/BreadhFirstSearch.cpp new file mode 100644 index 00000000..4588d26a --- /dev/null +++ b/breadth_first_search/BreadhFirstSearch.cpp @@ -0,0 +1,54 @@ +#include +#include +using namespace std; + +class Graph { + int v; + list *adjlist; + public : + + Graph(int V) { + v = V; + adjlist = new list[V]; + } + + void addEdge (int source, int dest) { + adjlist[source].push_back(dest); + } + + void breadthFirstSearch (int source) { + bool *visited = new bool[v]; + list queue; + + visited[source] = true; + queue.push_back(source); + + list::iterator itr; + while (!queue.empty()) { + source = queue.front(); + queue.pop_front(); + cout<"; + + for(itr = adjlist[source].begin(); itr != adjlist[source].end(); itr++) { + if(!visited[*itr]) { + visited[*itr] = true; + queue.push_back(*itr); + } + } + } + } +} ; + +int main () { + Graph G(4); + G.addEdge(0, 1); + G.addEdge(0, 2); + G.addEdge(1, 2); + G.addEdge(2, 0); + G.addEdge(2, 3); + G.addEdge(3, 3); + + cout<<"BFS starting from vertex 2 is "< Date: Thu, 25 May 2017 12:27:23 +0530 Subject: [PATCH 2/9] modified --- breadth_first_search/BreadhFirstSearch.cpp | 52 +++++++++++++--------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/breadth_first_search/BreadhFirstSearch.cpp b/breadth_first_search/BreadhFirstSearch.cpp index 4588d26a..ef1675a1 100644 --- a/breadth_first_search/BreadhFirstSearch.cpp +++ b/breadth_first_search/BreadhFirstSearch.cpp @@ -1,5 +1,10 @@ +// Program to print Breadth First Traversal of a Graph +// Time Complexity : O( no_of_vertices + no_of_edges) +// Space Complexity : O( no_of_vertices + no_of_edges) + #include #include + using namespace std; class Graph { @@ -7,48 +12,51 @@ class Graph { list *adjlist; public : - Graph(int V) { - v = V; - adjlist = new list[V]; + // Constructor Function + Graph(int v) { + this->v = v; + adjlist = new list[v]; } + // Function to add edge from source node to dest node void addEdge (int source, int dest) { adjlist[source].push_back(dest); } + // Function to print Breadth First Traversal of graph starting from source node void breadthFirstSearch (int source) { bool *visited = new bool[v]; - list queue; + list node_queue; visited[source] = true; - queue.push_back(source); + node_queue.push_back(source); list::iterator itr; - while (!queue.empty()) { - source = queue.front(); - queue.pop_front(); - cout<"; + while (!node_queue.empty()) { + source = node_queue.front(); + node_queue.pop_front(); + cout << source << "->"; - for(itr = adjlist[source].begin(); itr != adjlist[source].end(); itr++) { + for(itr = adjlist[source].begin(); itr != adjlist[source].end(); ++itr) { if(!visited[*itr]) { visited[*itr] = true; - queue.push_back(*itr); + node_queue.push_back(*itr); } } } } -} ; +}; int main () { - Graph G(4); - G.addEdge(0, 1); - G.addEdge(0, 2); - G.addEdge(1, 2); - G.addEdge(2, 0); - G.addEdge(2, 3); - G.addEdge(3, 3); - - cout<<"BFS starting from vertex 2 is "< Date: Mon, 12 Jun 2017 14:49:55 +0530 Subject: [PATCH 3/9] indentation improved --- .coafile | 25 ++ .codeclimate.yml | 20 ++ .editorconfig | 30 ++ .travis.yml | 6 + CONTRIBUTING.md | 3 +- PULL_REQUEST_TEMPLATE.md | 2 +- README.md | 65 +++-- avl_tree/AvlTree.java | 272 ++++++++++++++++++ bin_sort/BinSort.java | 75 +++++ binary_search/binary_search.c | 56 +++- binary_search/binary_search.go | 31 ++ breadth_first_search/BreadhFirstSearch | Bin 0 -> 22928 bytes breadth_first_search/BreadhFirstSearch.cpp | 1 + dijkstra/dijkstra.c | 65 +++++ insertion_sort/insertion_sort.py | 10 +- merge_sort/merge_sort.py | 1 + modular_exponential/modular_exponential.c | 23 ++ modular_exponential/modular_exponential.py | 1 + n_queen_problem/NQueenProblem.java | 64 +++++ quicksort/quick_sort.py | 1 + rod_cutting_problem/rod_cutting.c | 32 +++ rod_cutting_problem/rod_cutting.py | 36 +++ shell_sort/ShellSort.cpp | 43 +++ shell_sort/shell_sort.go | 28 ++ shell_sort/shell_sort.py | 41 +++ .../SieveOfEratosthenes.java | 35 +++ stack/stack.go | 39 +++ stack/stack.js | 37 +++ stack/stack.py | 1 + 29 files changed, 1000 insertions(+), 43 deletions(-) create mode 100644 .codeclimate.yml create mode 100644 .editorconfig create mode 100644 avl_tree/AvlTree.java create mode 100644 bin_sort/BinSort.java create mode 100644 binary_search/binary_search.go create mode 100755 breadth_first_search/BreadhFirstSearch create mode 100644 dijkstra/dijkstra.c create mode 100644 modular_exponential/modular_exponential.c create mode 100644 n_queen_problem/NQueenProblem.java create mode 100644 rod_cutting_problem/rod_cutting.c create mode 100644 rod_cutting_problem/rod_cutting.py create mode 100644 shell_sort/ShellSort.cpp create mode 100644 shell_sort/shell_sort.go create mode 100644 shell_sort/shell_sort.py create mode 100644 sieve_of_eratosthenes/SieveOfEratosthenes.java create mode 100644 stack/stack.go create mode 100644 stack/stack.js diff --git a/.coafile b/.coafile index 8e784dfa..532c520e 100644 --- a/.coafile +++ b/.coafile @@ -18,3 +18,28 @@ bears = GoLintBear [Gofmt] files = **/*.go bears = GofmtBear + +# python lint +[pep8] +files = **/*.py +bears = PEP8Bear + +# Haskell +[haskell] +files = **/*.hs +bears = HaskellLintBear + +# hlint +[hlint] +files = **/*.hs +bears = GhcModBear + +# JavaScript +[happiness] +files = **/*.js +bears = HappinessLintBear + +# yaml +[yml] +files = **/*.yml +bears = YAMLLintBear diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 00000000..1a427b59 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,20 @@ +--- +engines: + duplication: + enabled: true + checks: + Similar code: + enabled: false # matches in different files + config: + languages: + - javascript + - python + fixme: + enabled: true + radon: + enabled: true +ratings: + paths: + - "**.js" + - "**.py" +exclude_paths: [] diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..2d207351 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,30 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true + +[{*.go, *.c, *.cpp}] +charset = utf-8 +indent_style = tab +tab_width = 4 +trim_trailing_whitespace = true + +[*.js] +indent_style = tab +tab_width = 2 +trim_trailing_whitespace = true + +[{*.py, *.java}] +charset = utf-8 +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.yml] +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.travis.yml b/.travis.yml index 729c87f3..810e6003 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ +dist: trusty language: python python: - "3.6" + env: GOPATH: $HOME/go PATH: $GOPATH/bin:$PATH @@ -8,6 +10,10 @@ env: install: - sudo apt-get update - sudo apt-get install golang-go + - sudo apt-get install ghc-mod hlint + - curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - + - sudo apt-get install -y nodejs + - sudo npm install -g happiness - go get -u github.com/golang/lint/golint - cd $GOPATH/src/github.com/golang/lint - go install . diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2826529f..a4c8950f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,8 +32,9 @@ * Filename should be derived from the folder name. (eg `longest_common_subsequence` becomes `longestCommonSubsequence.c` or `LongestCommonSubsequence.java`) * Name of master function of the code should be kept same as filename to the best extent possible. * Prefer classes instead of multiple helper functions (where applicable). +* Currently we are accepting contributions in C, C++, Java, Python and Go but other languages may be considered after a discussion. * Define `tester` code only in `main` routine. -* Use meaningful variable names and comments. +* Use meaningful variable, method and function names and comments. * No profanity. * Use external libraries only when no other solution is possible/plausible. * We have defined [skeleton codes](#samples) for some popular languages below. Please follow them whenever possible. diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 5e437e55..47594f61 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -16,4 +16,4 @@ Fixes #{ISSUE_NUMBER} - [ ] I have followed the [coding guidelines](https://github.com/iiitv/algos/blob/master/CONTRIBUTING.md#cs) for this project. - [ ] My code follows the [skeleton code structure](https://github.com/iiitv/algos/blob/master/CONTRIBUTING.md#sample). - [ ] This pull request has a descriptive title. For example, `Added {Algorithm/DS name} [{Language}]`, not `Update README.md` or `Added new code`. -- [ ] This pull request will be closed if I fail to update it even once in a continuous timespan of 7 days. +- [ ] This pull request will be closed if I fail to update it even once in a continuous time span of 7 days. diff --git a/README.md b/README.md index 5a257b21..b9ba8bd9 100644 --- a/README.md +++ b/README.md @@ -5,43 +5,50 @@ Community (college) maintained list of Algorithms and Data Structures implementa [![Join the chat at https://gitter.im/iiitv/algos](https://badges.gitter.im/iiitv/algos.svg)](https://gitter.im/iiitv/algos?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Code Climate](https://codeclimate.com/github/iiitv/algos/badges/gpa.svg)](https://codeclimate.com/github/iiitv/algos) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/c10c3fd13edb475ca1bf77d4291d54b4)](https://www.codacy.com/app/aviaryan/algos?utm_source=github.com&utm_medium=referral&utm_content=iiitv/algos&utm_campaign=Badge_Grade) +[![Build Status](https://travis-ci.org/iiitv/algos.svg?branch=master)](https://travis-ci.org/iiitv/algos) + +[![js-happiness-style](https://cdn.rawgit.com/JedWatson/happiness/master/badge.svg)](https://github.com/JedWatson/happiness) ## Implemented Algorithms -| Algorithm | C | CPP | Java | Python | Golang | -|:--------------|:----------------:|:----------------:|:----------------:|:-----------------:|:-----------------:| -| [Binary Search](https://en.wikipedia.org/wiki/Binary_search_algorithm) | [\[X\]](binary_search/binary_search.c) | | [\[X\]](binary_search/BinarySearch.java) | [\[X\]](binary_search/binary_search.py) | | -| [Coin Change Problem](http://www.algorithmist.com/index.php/Coin_Change) | [\[X\]](coin_change_problem/coin_change_problem.c) | | | | | -| [Counting Sort](http://www.geeksforgeeks.org/counting-sort/)| [\[X\]](counting_sort/counting_sort.c) | | [\[X\]](counting_sort/CountingSort.java) | | | -| [Depth First Traversal](http://www.geeksforgeeks.org/depth-first-traversal-for-a-graph/) | | | [\[X\]](depth_first_traversal/DepthFirstTraversal.java) | | | -| [Dijkstra Algorithm](https://en.wikipedia.org/wiki/Dijkstra's_algorithm/) | | |[\[X\]](dijkstra/Dijkstra.java) | | | -| [Euclidean GCD](https://en.wikipedia.org/wiki/Euclidean_algorithm) | [\[X\]](euclidean_gcd/euclidean_gcd.c) | | [\[X\]](euclidean_gcd/EuclideanGCD.java) | [\[X\]](euclidean_gcd/euclidean_gcd.py) | | -| [Exponentation by Squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring) | [\[X\]](exponentation_by_squaring/exponentation_by_squaring.c) |||| | -| [Heap Sort](https://en.wikipedia.org/wiki/Heapsort) | [\[X\]](heap_sort/heap_sort.c) | | [\[X\]](heap_sort/HeapSort.java) | | | -| [Insertion Sort](https://en.wikipedia.org/wiki/Insertion_sort) | [\[X\]](insertion_sort/insertion_sort.c) | | [\[X\]](insertion_sort/InsertionSort.java)| [\[X\]](insertion_sort/insertion_sort.py) | | -| [k-NN](https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm) | | | | [\[X\]](k_nn/k_nn.py) | | -| [Largest Sum Contiguous Subarray](http://www.geeksforgeeks.org/largest-sum-contiguous-subarray/) | [\[X\]](largest_sum_contiguous_subarray/largestSumContiguousSubarray.c) | | [\[X\]](largest_sum_contiguous_subarray/LargestSumContiguousSubarray.java) | | [\[X\]](largest_sum_contiguous_subarray/largestSumContiguousSubarray.go) | -| [Linear Search](https://en.wikipedia.org/wiki/Linear_search) | [\[X\]](linear_search/linear_search.c) | | [\[X\]](linear_search/LinearSearch.java) | [\[X\]](linear_search/linear_search.py) | [\[X\]](linear_search/linear-search.go) | -| [Longest Common Subsequence](http://www.geeksforgeeks.org/dynamic-programming-set-4-longest-common-subsequence) | [\[X\]](longest_common_subsequence/longestCommonSubsequence.c) | | [\[X\]](longest_common_subsequence/LongestCommonSubsequence.java) | | [\[X\]](longest_common_subsequence/longestCommonSubsequence.go) | -| [Merge Sort](https://www.khanacademy.org/computing/computer-science/algorithms/merge-sort/a/overview-of-merge-sort) | [\[X\]](merge_sort/merge_sort.c) | | [\[X\]](merge_sort/MergeSort.java) | [\[X\]](merge_sort/merge_sort.py) | | -| [Modular Exponential](http://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/) | | | [\[X\]](modular_exponential/ModularExponential.java) | [\[X\]](modular_exponential/modular_exponential.py) | | -| [N-Queen Problem](https://en.wikipedia.org/wiki/Eight_queens_puzzle) | | [\[X\]](n_queen_problem/NQueenProblem.cpp) | | | | | -| [Prime Factor](https://en.wikipedia.org/wiki/Prime_factor) | [\[X\]](prime_factor/prime_factor.c) | | | | | -| [Prims](https://en.wikipedia.org/wiki/Prim%27s_algorithm) | [\[X\]](prims/prims.c) | | [\[X\]](prims/Prims.java) | | | -| [Quick Select](https://en.wikipedia.org/wiki/Quickselect) | [\[X\]](quick_select/quick_select.c) | | | | | -| [Quicksort](https://en.wikipedia.org/wiki/Quicksort) | [\[X\]](quicksort/quicksort.c) | | [\[X\]](quicksort/QuickSort.java) | [\[X\]](quicksort/quick_sort.py) | | -| [Rod Cutting Problem](http://www.geeksforgeeks.org/dynamic-programming-set-13-cutting-a-rod/) | | |[\[X\]](rod_cutting_problem/RodCutting.java) | | | -| [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) | [\[X\]](sieve_of_eratosthenes/sieveOfEratosthenes.c) | | | [\[X\]](sieve_of_eratosthenes/sieve_of_eratosthenes.py) | [\[X\]](sieve_of_eratosthenes/sieve_of_eratosthenes.go) | + +| Algorithm | C | CPP | Java | Python | Golang | JavaScript | +|:--------------|:----------------:|:----------------:|:----------------:|:-----------------:|:-----------------:|:-----------------:| +| [Bin Sort](http://www.cdn.geeksforgeeks.org/bucket-sort-2/)| | |[\[X\]](bin_sort/BinSort.java)| | | | +| [Binary Search](https://en.wikipedia.org/wiki/Binary_search_algorithm) | [\[X\]](binary_search/binary_search.c) | | [\[X\]](binary_search/BinarySearch.java) | [\[X\]](binary_search/binary_search.py) | [\[X\]](binary_search/binary_search.go) | | +| [Coin Change Problem](http://www.algorithmist.com/index.php/Coin_Change) | [\[X\]](coin_change_problem/coin_change_problem.c) | | | | | | +| [Counting Sort](http://www.geeksforgeeks.org/counting-sort/)| [\[X\]](counting_sort/counting_sort.c) | | [\[X\]](counting_sort/CountingSort.java) | | | | +| [Depth First Traversal](http://www.geeksforgeeks.org/depth-first-traversal-for-a-graph/) | | | [\[X\]](depth_first_traversal/DepthFirstTraversal.java) | | | | +| [Dijkstra Algorithm](https://en.wikipedia.org/wiki/Dijkstra's_algorithm/) | [\[X\]](dijkstra/dijkstra.c) | | [\[X\]](dijkstra/Dijkstra.java) | | | | +| [Euclidean GCD](https://en.wikipedia.org/wiki/Euclidean_algorithm) | [\[X\]](euclidean_gcd/euclidean_gcd.c) | | [\[X\]](euclidean_gcd/EuclideanGCD.java) | [\[X\]](euclidean_gcd/euclidean_gcd.py) | | | +| [Exponentation by Squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring) | [\[X\]](exponentation_by_squaring/exponentation_by_squaring.c) |||| | | +| [Heap Sort](https://en.wikipedia.org/wiki/Heapsort) | [\[X\]](heap_sort/heap_sort.c) | | [\[X\]](heap_sort/HeapSort.java) | | | | +| [Insertion Sort](https://en.wikipedia.org/wiki/Insertion_sort) | [\[X\]](insertion_sort/insertion_sort.c) | | [\[X\]](insertion_sort/InsertionSort.java)| [\[X\]](insertion_sort/insertion_sort.py) | | | +| [k-NN](https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm) | | | | [\[X\]](k_nn/k_nn.py) | | | +| [Largest Sum Contiguous Subarray](http://www.geeksforgeeks.org/largest-sum-contiguous-subarray/) | [\[X\]](largest_sum_contiguous_subarray/largestSumContiguousSubarray.c) | | [\[X\]](largest_sum_contiguous_subarray/LargestSumContiguousSubarray.java) | | [\[X\]](largest_sum_contiguous_subarray/largestSumContiguousSubarray.go) | | +| [Linear Search](https://en.wikipedia.org/wiki/Linear_search) | [\[X\]](linear_search/linear_search.c) | | [\[X\]](linear_search/LinearSearch.java) | [\[X\]](linear_search/linear_search.py) | [\[X\]](linear_search/linear-search.go) | | +| [Longest Common Subsequence](http://www.geeksforgeeks.org/dynamic-programming-set-4-longest-common-subsequence) | [\[X\]](longest_common_subsequence/longestCommonSubsequence.c) | | [\[X\]](longest_common_subsequence/LongestCommonSubsequence.java) | | [\[X\]](longest_common_subsequence/longestCommonSubsequence.go) | | +| [Merge Sort](https://www.khanacademy.org/computing/computer-science/algorithms/merge-sort/a/overview-of-merge-sort) | [\[X\]](merge_sort/merge_sort.c) | | [\[X\]](merge_sort/MergeSort.java) | [\[X\]](merge_sort/merge_sort.py) | | | +| [Modular Exponential](http://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/) | [\[X\]](modular_exponential/modular_exponential.c) | | [\[X\]](modular_exponential/ModularExponential.java) | [\[X\]](modular_exponential/modular_exponential.py) | | | +| [N-Queen Problem](https://en.wikipedia.org/wiki/Eight_queens_puzzle) | | [\[X\]](n_queen_problem/NQueenProblem.cpp) | [\[X\]](n_queen_problem/NQueenProblem.java) | | | | +| [Prime Factor](https://en.wikipedia.org/wiki/Prime_factor) | [\[X\]](prime_factor/prime_factor.c) | | | | | | +| [Prims](https://en.wikipedia.org/wiki/Prim%27s_algorithm) | [\[X\]](prims/prims.c) | | [\[X\]](prims/Prims.java) | | | | +| [Quick Select](https://en.wikipedia.org/wiki/Quickselect) | [\[X\]](quick_select/quick_select.c) | | | | | | +| [Quicksort](https://en.wikipedia.org/wiki/Quicksort) | [\[X\]](quicksort/quicksort.c) | | [\[X\]](quicksort/QuickSort.java) | [\[X\]](quicksort/quick_sort.py) | | | +| [Rod Cutting Problem](http://www.geeksforgeeks.org/dynamic-programming-set-13-cutting-a-rod/) | [\[X\]](rod_cutting_problem/rod_cutting.c) | | [\[X\]](rod_cutting_problem/RodCutting.java) | [\[X\]](rod_cutting_problem/rod_cutting.py) | | | +| [Shell Sort](https://en.wikipedia.org/wiki/Shellsort) | | [\[X\]](shell_sort/ShellSort.cpp) | | [\[X\]](/shell_sort/shell_sort.py) | [\[X\]](shell_sort/shell_sort.go) | | +| [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) | [\[X\]](sieve_of_eratosthenes/sieveOfEratosthenes.c) | | [\[X\]](sieve_of_eratosthenes/SieveOfEratosthenes.java) | [\[X\]](sieve_of_eratosthenes/sieve_of_eratosthenes.py) | [\[X\]](sieve_of_eratosthenes/sieve_of_eratosthenes.go) | | ## Implemented Data Structures -| Data Structure | C | CPP | Java | Python | Golang | -|:--------------|:----------------:|:----------------:|:----------------:|:-----------------:|:-----------------:| -| [Binary Search Tree](https://en.wikipedia.org/wiki/Binary_search_tree) | | | [\[X\]](binary_search_tree/BinarySearchTree.java) | | | -| [Linked List](https://en.wikipedia.org/wiki/Linked_list) | | | [\[X\]](linked_list/LinkedList.java) | | | -| [Stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)) | | | [\[X\]](stack/Stack.java) | [\[X\]](stack/stack.py) | | +| Data Structure | C | CPP | Java | Python | Golang | JavaScript | +|:--------------|:----------------:|:----------------:|:----------------:|:-----------------:|:-----------------:|:-----------------:| +| [AVL Tree](http://www.geeksforgeeks.org/avl-tree-set-1-insertion)| | |[\[X\]](avl_tree/AvlTree.java) | | | | +| [Binary Search Tree](https://en.wikipedia.org/wiki/Binary_search_tree) | | | [\[X\]](binary_search_tree/BinarySearchTree.java) | | | | +| [Linked List](https://en.wikipedia.org/wiki/Linked_list) | | | [\[X\]](linked_list/LinkedList.java) | | | | +| [Stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)) | | | [\[X\]](stack/Stack.java) | [\[X\]](stack/stack.py) | [\[X\]](stack/stack.go) | [\[X\]](stack/stack.js) | ## Resources diff --git a/avl_tree/AvlTree.java b/avl_tree/AvlTree.java new file mode 100644 index 00000000..b61dba31 --- /dev/null +++ b/avl_tree/AvlTree.java @@ -0,0 +1,272 @@ +import java.util.NoSuchElementException; +import java.util.Random; + +public class AvlTree { + + public static void main(String[] args) { + AVL avl = new AVL(); + Random rand = new Random(); + int inp = 10; + System.out.println(avl.isEmpty()); + for (int i = 0; i < inp; i++) { + avl.root = avl.insert(avl.root, rand.nextInt(100)); + } + avl.prntIn(avl.root); + System.out.println(" "); + System.out.println(avl.isEmpty()); + avl.delNode(avl.root,avl.root.data); + avl.prntIn(avl.root); + System.out.println(" "); + avl.delNode(avl.root,1111); + } +} + +class AVL { + public NodeAVL root; + + public AVL(){ + root = null; + } + + public NodeAVL insert(NodeAVL node, int data) { + // These method takes care of rotation needed after insertion + if (node == null) { + node = new NodeAVL(data); + return node; + } else { + if (node.data > data) { + node.left = insert(node.left, data); + if (node.left == null) + node.hLeft = 0; + else + node.hLeft = Math.max(node.left.hLeft, node.left.hRight) + 1; + } else { + node.right = insert(node.right, data); + if (node.right == null) + node.hRight = 0; + else + node.hRight = Math.max(node.right.hLeft, node.right.hRight) + 1; + } + node = isRotate(node); + } + return node; + } + + private NodeAVL rotateLR(NodeAVL node) { + NodeAVL sec = node.left; + NodeAVL temp = sec.right; + node.left = temp; + sec.right = temp.left; + temp.left = sec; + node.left = temp.right; + temp.right = node; + if (node.left == null) + node.hLeft = 0; + else + node.hLeft = Math.max(node.left.hLeft, node.left.hRight) + 1; + if (sec.right == null) + sec.hRight = 0; + else + sec.hRight = Math.max(sec.right.hLeft, sec.right.hRight) + 1; + temp.hLeft = Math.max(sec.hLeft, sec.hRight) + 1; + temp.hRight = Math.max(node.hLeft, node.hRight) + 1; + return temp; + } + + private NodeAVL rotateRL(NodeAVL node) { + NodeAVL sec = node.right; + NodeAVL temp = sec.left; + node.right = temp; + sec.left = temp.right; + temp.right = sec; + node.right = temp.left; + temp.left = node; + if (node.right == null) + node.hRight = 0; + else + node.hRight = Math.max(node.right.hLeft, node.right.hRight) + 1; + if (sec.left == null) + sec.hLeft = 0; + else + sec.hLeft = Math.max(sec.left.hLeft, sec.left.hRight) + 1; + temp.hRight = Math.max(sec.hLeft, sec.hRight) + 1; + temp.hLeft = Math.max(node.hLeft, node.hRight) + 1; + return temp; + } + + private NodeAVL rotateLL(NodeAVL node) { + NodeAVL temp = node.left; + node.left = temp.right; + temp.right = node; + if (node.left == null) + node.hLeft = 0; + else + node.hLeft = Math.max(node.left.hRight, node.left.hLeft) + 1; + temp.hRight = Math.max(node.hRight, node.hLeft) + 1; + return temp; + } + + private NodeAVL rotateRR(NodeAVL node) { + NodeAVL temp = node.right; + node.right = temp.left; + temp.left = node; + if (node.right == null) + node.hRight = 0; + else + node.hRight = Math.max(node.right.hRight, node.right.hLeft) + 1; + temp.hLeft = Math.max(node.hRight, node.hLeft) + 1; + return temp; + } + + private NodeAVL isRotate(NodeAVL node) { + // This Method see if there is nessesity for rotation and if + // there is need, it'll do suitable rotation + if (node.hRight - node.hLeft >= 2) { + if (node.right.hRight - node.right.hLeft >= 1) + node = rotateRR(node); + else if (node.right.hRight - node.right.hLeft <= -1) + node = rotateRL(node); + } else if (node.hRight - node.hLeft <= -2) { + if (node.left.hRight - node.left.hLeft <= -1) + node = rotateLL(node); + else if (node.left.hRight - node.left.hLeft >= 1) + node = rotateLR(node); + } + return node; + } + + public boolean isEmpty() { + return root == null; + } + + public void prntIn(NodeAVL node) { + if (node == null) + return; + else if (node.left == null && node.right == null) + System.out.print(node.data + " "); + else { + prntIn(node.left); + System.out.print(node.data + " "); + prntIn(node.right); + } + } + + public void delNode(NodeAVL node, int data) { + // These is the method to delete node if it exist + // Otherwise it throws an exception + if (root == null) { + throw new NoSuchElementException("AVL Tree is Empty!!!"); + } + if (root.data == data) { + NodeAVL temp = root.right; + if (root.left == null && root.right == null) + root = null; + else if (root.left == null) + root = root.right; + else if (temp == null) + root = root.left; + else { + int dta = 0; + if (root.right.left == null) { + root.right.left = root.left; + root = root.right; + } else { + dta = transverseLeftmost(temp); + root.data = dta; + } + if (root.right == null) + root.hRight = 0; + else + root.hRight = Math.max(root.right.hLeft, root.right.hLeft); + root = isRotate(root); + } + } + else if (node.right == null && node.left == null) { + throw new NoSuchElementException("element you wanna delete not exist"); + } + else if (node.right != null && node.right.data == data) { + NodeAVL del = node.right; + if (del.right == null && del.left == null) + node.right = null; + else if (del.left == null) + node.right = del.right; + else if (del.right == null) + node.right = del.left; + else { + NodeAVL temp = del.right; + if (temp.left == null) + node.right = node.right.right; + else + del.data = transverseLeftmost(temp); + del.hRight = Math.max(del.right.hLeft, del.right.hRight); + } + } else if (node.left != null && node.left.data == data) { + NodeAVL del = node.left; + if (del.right == null && del.left == null) + node.left = null; + else if (del.left == null) + node.left = del.right; + else if (del.right == null) + node.left = del.left; + else { + NodeAVL temp = del.right; + if (temp.left == null) + node.left = node.left.right; + del.data = transverseLeftmost(temp); + del.hRight = Math.max(del.right.hLeft, del.right.hRight); + } + } else if (node.data > data) { + delNode(node.left, data); + if (node.left == null) + node.hLeft = 0; + else + node.hLeft = Math.max(node.left.hLeft, node.left.hRight) + 1; + } else if (node.data < data) { + delNode(node.right, data); + if (node.right == null) + node.hRight = 0; + else + node.hRight = Math.max(node.right.hLeft, node.right.hRight) + 1; + } + node = isRotate(node); + } + + private int transverseLeftmost(NodeAVL node) { + // These method is special method which comes + // in play when we have to delete a node + // which have both childeren. + if (node.left.left == null) { + int data; + if (node.left != null) + data = node.left.data; + else + data = node.data; + node.left = null; + return data; + } + node = node.left; + int data = transverseLeftmost(node); + if (node.left == null) + node.hLeft = 0; + else + node.hLeft = Math.max(node.left.hLeft, node.left.hLeft); + node = isRotate(node); + return data; + } +} + +class NodeAVL { + protected int hLeft; + protected int hRight; + public int data; + public NodeAVL left; + public NodeAVL right; + + public NodeAVL(int data) { + hLeft = 0; + hRight = 0; + this.data = data; + left = null; + right = null; + } +} diff --git a/bin_sort/BinSort.java b/bin_sort/BinSort.java new file mode 100644 index 00000000..c55ea126 --- /dev/null +++ b/bin_sort/BinSort.java @@ -0,0 +1,75 @@ +import java.util.Random; + +class Node { + public double data; + public Node next; + + public Node(double data) { + this.data = data; + next = null; + } +} + +// Time Complexity O(n)-> avg case and O(n^2)-> Worst Case +// constraints:- 0<=A[i]<1 +public class BinSort { + public static void binSort(Node[] b, double[] a) { + for (int i = 0; i < a.length; i++) { + int ins = (int) (a[i] * b.length); + if (b[ins] == null) { + b[ins] = new Node(a[i]); + } else { + boolean check = true; + Node temp = b[ins]; + while (temp.next != null) { + if (a[i] > temp.next.data) { + temp = temp.next; + } else { + if (a[i] < temp.data) + break; + Node newNode = new Node(a[i]); + newNode.next = temp.next; + temp.next = newNode; + check = false; + break; + } + } + if (check) { + if (a[i] >= temp.data) { + Node newNode = new Node(a[i]); + temp.next = newNode; + } else { + double loc = temp.data; + temp.data = a[i]; + Node newNode = new Node(loc); + newNode.next = temp.next; + temp.next = newNode; + } + } + } + } + int j = 0; + for (int i = 0; i < b.length; i++) { + while (b[i] != null) { + a[j++] = b[i].data; + b[i] = b[i].next; + } + } + } + + public static void main(String[] args) { + Node[] b = new Node[10]; + Random ran = new Random(); + int n = 100; + double[] a = new double[n]; + for (int i = 0; i < n; i++) { + a[i] = ran.nextDouble(); + } + binSort(b, a); + for (int i = 0; i < n; i++) { + System.out.print(a[i] + " "); + } + System.out.println(" "); + } +} + diff --git a/binary_search/binary_search.c b/binary_search/binary_search.c index 89c54582..8fc87399 100644 --- a/binary_search/binary_search.c +++ b/binary_search/binary_search.c @@ -5,6 +5,39 @@ * @arr_size Size of array * @search_element Element to be searched */ + +/* function to perform recursive binary search + * input parameters: + * @ar - user-input array. + * @l - left index of array. + * @r - right index of array. + * @ele - element to be searched. + */ +int binary_search_recursive(const int *ar, int l, int r, int ele) { + if (r >= l) { + + int mid = l + (r - l) / 2; //calculate mid point of the array + + // If the element is present at the middle itself + if (ar[mid] == ele) { + return mid; + } + + // If element is smaller than mid, then it can only be present + // in left subarray + if (ar[mid] > ele) { + return binary_search_recursive(ar, l, mid - 1, ele); + } + + // Else the element can only be present in right subarray + return binary_search_recursive(ar, mid + 1, r, ele); + } + + // We reach here when element is not present in array + return -1; +} + +//Function to perform iterative binary search int binary_search(const int *arr, int arr_size, int search_element) { int left = 0, right = arr_size - 1; @@ -23,17 +56,26 @@ int binary_search(const int *arr, int arr_size, int search_element) { } int main() { - int arr[] = {1, 5, 35, 112, 258, 324}, - search_arr[] = {1, 35, 112, 324, 67}, - pos, i; + int arr[] = {1, 5, 35, 112, 258, 324}; + int search_arr[] = {1, 35, 112, 324, 67}; + int i; - for (i = 0 ; i < 5 ; i ++) { + for (i = 0 ; i < 5 ; i++) { + + int pos; pos = binary_search(arr, 6, search_arr[i]); - - if (pos >= 0) + if (pos >= 0) { printf("%d found at index %d.\n", search_arr[i], pos); - else + } else { + printf("%d not found.\n", search_arr[i]); + } + + pos = binary_search_recursive(arr, 0, 5, search_arr[i]); + if (pos >= 0) { + printf("%d found at index %d, recursively\n", search_arr[i], pos); + } else { printf("%d not found.\n", search_arr[i]); + } } return 0; diff --git a/binary_search/binary_search.go b/binary_search/binary_search.go new file mode 100644 index 00000000..27d68495 --- /dev/null +++ b/binary_search/binary_search.go @@ -0,0 +1,31 @@ +package main + +import "fmt" + +// BinarySearch perform Binary Search by Iterative Method. +// Time Complexity : O(log(len(array))) +func BinarySearch(array []int, target int) int { + left, right := 0, len(array)-1 + for left <= right { + mid := (left + right) / 2 + if array[mid] == target { + return mid + } + if array[mid] < target { + left = mid + 1 + } else { + right = mid - 1 + } + } + return -1 +} + +func main() { + array := []int{1, 5, 35, 112, 258, 324, 456, 512} + index := BinarySearch(array, 112) + if index == -1 { + fmt.Println("Element is not present in array") + } else { + fmt.Println("Element is present at index :", index) + } +} diff --git a/breadth_first_search/BreadhFirstSearch b/breadth_first_search/BreadhFirstSearch new file mode 100755 index 0000000000000000000000000000000000000000..52884c22926e631d3ce21570bb80ed5103cfd9e5 GIT binary patch literal 22928 zcmeHPeRNyZk$cV_O)+`0EXz571tX(Iba3;8p}+C9WG=(fnp&+(pTzu;xdyW zP}7_WLG8%a#%1af(5X%Y9%nn0QHo;H2~F)bbGyylPT+AiOrZ3S`bK|UEY}WOL8C(; z@zUXYB@v|a=?m3m0jywoS!l9pH=!NbdAdh6Gj_1PQhqtY`UG-!wQKsrJuB+3=?^aJ z4@Z*2%Z3|QEL&0Uibq{_s^27^cyHX;tu%=row%a@Ex;e;0MX}q`YLXk7~WU$!k2#& z9Qv#0p1Js%dBk6XKZ%>BRjYHt(Q)2Gb6d=_;{P8+!*hy|E-!&6d!0r2FDZe44ESR5 zzf}TXSwin6=x8xHMOD}nz$@MmimXwF(EBqGajtq$aOJP{0Bbrt3G3e7OK4n!kHJmHTe z3_~;44;dYyt>Jhg6l>}C$K#>6W_Y{WjbJFo=&tsb{%9oBb;S0qSfsg(hT6E{c(?PT}NlM)9{c5!^6g4C>D=K{Qcp?c4Md(T)}=HF-QCZ z_`fqzABqI~y@Aez+a2ih$BabGA5O%*0gtBxxaH6h4j9pRA{O!wc)N_QTEo-10{uZ# z_e#S^^u?mvU`f#M_xDEwrWrQ#T1@jI+ejlBZ=lx+f4JY>V6?#_MkE>xsotzI+KptS zFB-j5b*MAZANQV~Wq~f()nNEG1Wu)6C3GkazRp^+AN7G~GNGE0|H2v~xit_l;uJ`? zW^_lkg(E>kFP_=mx#&Zu^lWBxNKvjOKQ8r4aM_AGK&>X`5H?U=#mXe+2G4hQ(sOs~cD zf^c{q&7{|ZPHmDGhR-1BdX~Q&ZA=<~_LJ}2iD`GXn$L(oH1lO}mTLyLPb_@^Q(u`D z;r24G%6zzcE=kd}CZ0b9e?gUr*KPPan7@+8rSQwO?;59SNOPVHSwd{K;Mo+#cZUT} z^Nt*S7QD>CL>si=t?P|p3*I{4-ebYf5#fNlEO_Yyk;g4~I6iwkWWk@A#cJAa3!ax| ziu$kx&n{E=y%szIojvwh@Ksr?rcGGz^DX!z7CgmWjwuWNY(WAZv*4|D{PGN;H9op3}x*=WPRj~N_}+Jmc>p@|I9?9EHkB# z9Iia1Wg4yoDs$P@_<#N-O*o_L-tio~mapw_E#o_E@D{#473^U?6G|7{Z+cTdx?NAb zq>sEj?dxhAoAq85tRI^# zL+7EpkAaW6d&ZW`@m|Hh9I_rQzx?^FAO@0aVTY5idO2Ho+D z{-gI3H4wI)h0QgEneFZJ?pgCgh|`i+=p$=3p#emuUP;W=N7vkotMo74&t%eiCX?Cn z%&gsDbi7??&m&G4J#vGVJnPll!D-qJ{f{g%JM$`u%uH>0wFy)@M{J!zeYE1TCFqi# z^31p=^fAxz12n$%)MPpcpAq5-N|pooQ&_5w3R`By{x}ay4M@U%!BXP`)PS(x6f6~( zEOtB(OC;jmp|B0@7@KhUm(Z2;!9Qj)dg^KPY!me?^^BhSkMvPOlJTPCGibOELNtA} zeI}?cpR0PAn3etqaQ^TR_rE%I_lZ<;X5{V@j%3}Z?w-kH5QC-Aw1&KXqY`>vC8-%} zxDqHRz4xP}bTVBB;QhnpbmJBKng@proRK1 zj(YZxqETQSQ_pD7(7nf`KTj-gsQmEkrStQlQJOk&J~HjtIWd1{jme@UUIz52mV!)H z(L)H&9wgD&nnovLzMO0rYxpT96_VLSmoU-nvoa;G&yFL+wVpJmV8tmp`%TUXbOV26 zx9Y~<0!_BAp%5zcWcpb$P0MwD{`brtB~}T?BQ_4@9@7_}S9+c{yQx$>O=E#Y`#^nl z6X_zqq65kIlwRedn<%kCNMqEPwIT7**DuslhfHCU=~@~V$UttF_EF=J!<%p2V&*b} zU2V;CiiKo?op$vpXs~036j5>)$S_BjqA#Ezrw;0)oT91cs8!4=T}Iv{907wYqg3T| zwNka}>G@xn$o0dCe!vg;H4?5N;dH}}pijds({z0inK0T-#b$vNn}*+0u~8%3-gBC* zRT-lWst7HzT8r9TO802BsZuoxp%E;fwwJjlQOk0gi_7XxTLdjEAtL+O(~G`Xf89*6kemUnX@xT1?g$!P&58C&I{ttxlx(#w_5n^ z7>vUoG$2-Vy4sUY+>A3sj;uBcWWhNp37drlxvcMK+@f>&`QoPmrRc5-B80)n9v&rCG*$GNEvi8V8 zzBzJfL?Io^vYZ^{TzWdQflnd9;Sac;DghEwxqeA8J(Oa=s{weWGEr)|O&lqoOuNC7 zt?5WsswXs>u&OH7@6o18y34r4WYpnLYM@zj?FMt+<3QMzLiA+%lWNrj2jq3OilmHLMM<(JO~vD6r?fvV%E%1_aaN_w2qm2OQ_HTktla)tT@H*L%*E3{m3TuYX% z_Ds)zU}EP4?i6>dm(|8;8bo`rbZ-zK}d{;8Z==0?@Q&*DJ7gU8hq$qzy;5 zI(uW$0q0OChDUhLI%hcU1ph_ltLe9s8^G;^IkaNj3rK6ZD!r1 zHP*}50}g}k1AGXuA8;SwY((fd;CetO+BITc>I3Wo+yzMU)Wd)e0UiN-4loV)GGHae z_`frmC4d_Nb-=p-`v8vs?gFgF3guzII=~}<9e`=TLBPsckPEm3@NqyL(1k_WAmDX? zj7)<@ai7GM! z8V|SX0BZqn1M~q70S*E_05}e~A8;?=vw%~8?*UE&UWme9jR~;}uom!sKp)@{z(K%Y z0geM!U`E&rcn;tc;KhK`fX#r_h|8UTwSYSSeSil52LX=(jsq@6ZP^Q02RH@j1FS_H zX{|lX57p#ZlVeAR<`}MaTr_u1<+x)`HR0(u$6aq_GFJi0QJf#Tz(D**-h^$$TvffU zs%HKCv$j>MNHoUPNf(X~o|GGMR=&T=(FyI?;cHVppYzpu7_1kW{WtqV zx)!1Ro2dE~0R&EL@r;z0|I(oZQGe*(WE_4{4`79->4Q1?)a|&h)>q(l_VmM_GO;|GooyALJK{ALU3J=t0nT;JjiZ3XAx-ENLnMp5lBRYToz2 zhbNXf9&gT$+d$s~`W7p_%runrP(NM*eH+dzUaQE-Kt7fYuNIvkX=k($eGwh1q z2KsfNm-0tH=w!#`Bv9J>b9PWaYC)&^RPhongr_%W$70al0I42)FA?7X3m^IIn8{1_ zz5so1f$wUZXJu{8(NBQ>9_UN0^k9y@5TUR5U1`5x2m1SHUo4ME|81b3O#WRgU;Qp2 zeO;f^|25FxhJ2URzHpAdAM`TVS8ANR!1Ptt_K95k6QD0d`_)$ZP>#M3bK^?TOSQia zbRX!Y^6oa!H=cxk7wB!Em&%u~fqpIMrSfe*=$C_jsn!15bN0Ug`clxZw9-R4`U%jN zpG5ycOc9GfZ?U#Vj%|ksHU2?g2YRV-c^l|WpqHwXcY)r268&ET{T9&G94+~=DQEwF z(9>x=JGR4(RM9{A7$A9~4?XaI?E!h8 z=>oMV!+o0d8f z%%;hERJ5+4gPtwW@w@jk^i)!#=T~&d0-}abu*6fx1k>3JZ3kbgwIw*@9U8S(;x+_u zccG5PYn%#V$)t|WY=GFYo8{rLj5STG*tsB6)S$0F+b z0jA^8m%7HS%b(?t_rL!v!v7zH%6oO98gDXQ>s->^lZ+&i&K0gYSM9Qfq`Gp~Ej1C& zx?1-NcWteD{37j&L3)$0k>hTqmuqF&_v7>NNb^Z93KlDGNz*_z~cK7NiS zd6JK>)Fi+1@n>j~$NBg(H5sq@__MTX888+?IYzm&D1KgczlDVzW2#D%@t=>MuT98+ zw-Cxv4P@Vd1r0f8Yco<1EQE5riM{hO3xZF}wR5xkBdpYN+{H+J$;Y3k`Ib4YD0N=0 zosWGJ#qb}|q)u2Hl~Z-$_xSShx%ad4@r6#Ha$2GN2JbE9A5>o*cr(y$C)L$5ZJst| ziwo6P!dFXSW^we4f$;WvPxpxqROwo`Q*lat?^O6gzwH2?Xl|Q5uK=(5%M*;cCkF03G$g#tXHwrw`Ew}<4&>E6w)|PC@P&Sc zilX+nkb)w4d$W>Lm?!;;|J;H+yqobdKax~B==WDgkvx15^MtcVzWojOKU!9!$@`=- zZ+#c|MexrOe%V##UwVdYeb3d@iq|KY|C2nisb@nVu0~xu2Xgjuyrj%+P>2*bhwB z+>Ec{h03MO9|yjee?G_jw=zF3qqOfczKIdy=jR#UYV&_3CU~;vHs=2d>-DI971q!5 z!C%at)huTb$3=ec*~a)YZE@Vo_<`{#`k^3TRXknGvTc_sdLG2YGbQqKw@s~>nL%d~=B zz>95G{J*iBGL|D{*MU4Iy$`dUf^Pu+Y%Mq6!M*BeW&VZCFa8e!Urg^d;GNvo3jP}S z>LPXE>nwjC3)8vLQ;ffs^{U?rK>H2jTiO4sng3E0kVRI7e13z%&(j`fITEiOjDM0} zZg(;NQ;dI%{l;mkz0P>MKQF-ooBX+e2k1*Ihjw|We6!j4RmMMW%jf-!zn2FD{RTtF zyNth@@#?o5;IGGx1If3K$2Q>4MqRC`byD-}v6=bp{=Ap?i|ot#d*PpNilE;p={U&p z?d#a*fT#M|#10FY?AnVgC(Ztsx=QOavj1Z4m&D~}#@p+_{fxKQtH&6RrIb1(2WXu^ z@^^84XkdGO4}7t_U4iuh@%J-v1M`2J@x7cUGERpWU&j5CJo#tF+vl$-#=pjL)Ndrv z;lTQU^xEZI2YfZ+VvnQF{O_{ETG-Alj2~osRx&;Xe6jw1gZUq2dpOM6D~w;n_@yjo z81W~28hM?=XzhI1QA~b4@YJuh92fQ5C>nK?;2&mw`+WCB#@pxLCk1b-|Nm7&{!(<1 z?D+(bYw_C<@Kl%Ve!iRe_ptptxWnHDzF2>sW&TCXFY!$?{(5e-jOEP71BGI87L~wX z3q09xpD#Yf_#@me$=fe7-k!Jr!uU3hujK8Ej9JPWF7- zmM7OS-afw^Q}v@wCOQ{O{9bg({4yyVP~u#dn$t= zvmIU6hQpe1W80>+&24Cs>@mEC+9zok>pGg-J%(pvEA69Iu99sc@#q2B(|jMk5DY;O0qXssV}#X`NV61!)yeHFW21H;2^cYQzh zu6o0res9?0X{obp!3{SxsSTaxeoeKrG~r&MHpu!BJlSK5me|}{o7)3Rf;_9T-t>mo zcWfZkP)BE-;p;M52RC8=Ev#32Ndxhu3a%;t^fuMz8AcmP)rMT@k=Q~Ti?bb5n|DuR zGc)Zd&J%xX*={%X;)WyG7K<&i9^M`7t~VVL#!hMS7M#Kxh&Qf6P$Eg?{pFF+Hgn6d z;wki_yEYhNkB2-y_>aWX-e6pu%Hy~U#f?{{=Ar~SgEGN4s5Ae$h? z+$p#)My_nzZn!b#AM8U0VE`0v?xxP$ZQi)ygSet`z&~udn73zR-?jKI6f_1Cu@aqz zYL$7NZtnQ$HuQITS|j)GHi=Qm118I)uO22*B&~ z34tMhKav`;qdoSv6d+d=|E_`&^e6o04*mSB%PaKD@x27eij&n%F^ket`U_)EbL8>J zpzjIDCj@N$u+|~bWgS~}R9m-(62?aQxI%XB5z|jQm-6bUR0CD2EfFsqLIa)^&~HWo zVY2X^vT|pq(rh8k3jpSab|Zj=Ng|{^9O30j(pQiQG+lnc!etq3)_Hj#Kdtg=Ql4>* zunp5zJmi5jg%jCH@`~~{9Es!IbLr4fQ4!fr@vPydS;OdRZ;=JksS-nyMJ1*=XW=U# z^a+fDF>R`FH}=pnFkxK>Dy6}A)ab)9jy_kCTaxg?&oWJlMr(SisedqOe)|LSvwaxD zQ&?&BMq}Ijv7nchL5O7s4fhqX&_Hx3ghAYkPp3ozAunp2r#`WLFobWOsETl!gA9o# z34M~lNJ?xd8jeWF)3L$)kcg$nc{#CaFd6T|=S>24f>oyYlAl1y`#ecrL<*K`d0HBJ z@EMs15AR|NOG^u=OK8 zc?m$`if17^6d8&L*gwfrAfsp^7gpV3K|DP!9x{LG$Atbwg9s-TO z6-4Ta4RE;u`5@lPtrQ1*8_c_dVxlGN7SV-Mez@e6U&uR9u)-D>70Ws`O5!LTx%)(m zC8u0aNChu(>)w!y0SzxPBrjGCp@G4~c7#)N#kUV6{5^n)m!9X}L=zzw zKHRh{;or(vxNUXyB*XanT{x(@=&H{j@6%kt?GeZ`VIpQyu>UNM2O@bF257NRzn>at zE;Yrv2Ky5l{pZ>m#R;~o;eUGA1J0<*a#yI2AMf-9(O#|~7+<#v4F^Jl2?Jfg^sOYC zPku}pa{h?`8bYUkARNF6jU5+iujay|rvW@p;)h)S3qa4q=usSgep83M_aV^!8UjDI zV{T2m6leG;CELD>1qpO!In5LKJxI`QoLJi@xV^x|!pP9xz7=?E&x?xv^1hTnX^)@J z)PbL0@{WzT!lV4G{Sz!m;AXzY&tS?=(w={I(QXDFKXqo?%lj(=<$Wx$sKf5R+kvHb zqr`rB&qZJzw-ft?PvD)P)4Nu3E$_n!9Ow3AKiMhvGg_nP(d1KUFYnC=+|2~hFYTrO zJJFWpUD5O_bXtnKA}9f8BlFF@>< z>xXRZcT+Op5O@xryIT*@E4Z)Y#HwH3{}G6v-SQ55|Mzfv@xQz$B=DNN)`jtV)Ye|! zClV;%9ThQl{ZH81%X>!x@3T3~cBvh65%7+bjY>9w}2y?q`kav-|k*Yf_9e1G;h zcUZ=U=#_pwh&ERJ@}5;A2mS~NwH(r3;0e&I?X&M=)tZfDoQeo(C)Z_YOgQPke1EM* z+Oz$_@01gUb3i8+X3tWkz5Grk1Q92YewGp4!b33QGq1AW_hh29<4dJm#*W|!>S7R& iU;5pUYN_;J{6gcin11~R5O92-e>XC(%)ZJw!T$lmR+2&h literal 0 HcmV?d00001 diff --git a/breadth_first_search/BreadhFirstSearch.cpp b/breadth_first_search/BreadhFirstSearch.cpp index ef1675a1..972c6256 100644 --- a/breadth_first_search/BreadhFirstSearch.cpp +++ b/breadth_first_search/BreadhFirstSearch.cpp @@ -44,6 +44,7 @@ class Graph { } } } + free(visited); } }; diff --git a/dijkstra/dijkstra.c b/dijkstra/dijkstra.c new file mode 100644 index 00000000..2aeb458e --- /dev/null +++ b/dijkstra/dijkstra.c @@ -0,0 +1,65 @@ +/* +* Following implementation of dijsktra's algorithm prints the minimum distance from given source to destination using adjacency matrix. +* Time complexity : O(V^2). +* Space Complexity : O(V). +*/ + +#include +#include // For using INT_MAX +#include // bool datatype +#include // for using memset() + +#define VERTICES 8 +#define INFINITY INT_MAX + +// This function will find the minimum distance from the unselected vertices +int minimum_distance(const int min_distances[], const bool shortest_paths[]) { + int i; + int minimum = INFINITY, index; + for (int i = 0; i < VERTICES; ++i) { + if (!shortest_paths[i] && min_distances[i] <= minimum) { + minimum = min_distances[i]; + index = i; + } + } + return index; +} + +// This function returns the minimum distance from given source to destination +int dijkstra(const int graph[VERTICES][VERTICES], int souce, int destination) { + int i, j; + int min_distances[VERTICES]; + bool shortest_paths[VERTICES]; + memset(shortest_paths, false, VERTICES); + for (i = 0; i < VERTICES; ++i) { + min_distances[i] = INFINITY; // Initiallt set all distances to INFINITY + } + min_distances[souce] = 0; // Distance from source to itself is zero + for (i = 0; i < VERTICES - 1; ++i) { + int temp = minimum_distance(min_distances, shortest_paths); + shortest_paths[temp] = true; + for (j = 0; j < VERTICES; ++j) { + if ((!shortest_paths[j]) && (graph[temp][j] != 0) && (min_distances[temp] != INFINITY) && (min_distances[temp] + graph[temp][j]) < min_distances[j]) { + min_distances[j] = min_distances[temp] + graph[temp][j]; + } + } + } + return min_distances[destination]; +} + +int main() { + int source = 0; + int destination = 4; + int graph[VERTICES][VERTICES] = { + {0, 4, 0, 0, 0, 0, 0, 8}, + {4, 0, 8, 0, 0, 0, 0, 11}, + {0, 8, 0, 7, 0, 4, 0, 0}, + {0, 0, 7, 0, 9, 14, 0, 0}, + {0, 0, 0, 9, 0, 10, 0, 0}, + {0, 0, 4, 14, 10, 0, 2, 0}, + {0, 0, 0, 0, 0, 2, 0, 1}, + {8, 11, 0, 0, 0, 0, 1, 0}, + }; + printf("The minimum distance from %d to %d is %d\n", source, destination, dijkstra(graph, source, destination)); + return 0; +} diff --git a/insertion_sort/insertion_sort.py b/insertion_sort/insertion_sort.py index f54315a7..0ce5f79e 100644 --- a/insertion_sort/insertion_sort.py +++ b/insertion_sort/insertion_sort.py @@ -1,15 +1,15 @@ def insertionSort(alist): """ - Performs a insertion sort + Performs a insertion sort :type alist: object """ for index in range(1, len(alist)): current_value = alist[index] position = index - while position > 0 and alist[position-1] > current_value: - alist[position] = alist[position-1] - position -= 1 - alist[position] = current_value + while position > 0 and alist[position-1] > current_value: + alist[position] = alist[position-1] + position -= 1 + alist[position] = current_value def main(): diff --git a/merge_sort/merge_sort.py b/merge_sort/merge_sort.py index bf6b4bf7..da19b618 100644 --- a/merge_sort/merge_sort.py +++ b/merge_sort/merge_sort.py @@ -48,5 +48,6 @@ def main(): merge_sort(a, 0, len(a) - 1) print(a) + if __name__ == '__main__': main() diff --git a/modular_exponential/modular_exponential.c b/modular_exponential/modular_exponential.c new file mode 100644 index 00000000..7b6fee18 --- /dev/null +++ b/modular_exponential/modular_exponential.c @@ -0,0 +1,23 @@ +#include + +// Time Complexity : O(log (power)) +long long modularExponential(long long base, long power, long long mod) { + long long answer = 1; + base = base % mod; + while (power) { + if (power & 1) { + answer = (answer * base) % mod; + } + power = power >> 1; + base = (base * base) % mod; + } + return answer; +} + +int main() { + long long base = 2; + long power = 10; + long long mod = 100000; + printf("%lld\n", modularExponential(base, power, mod)); + return 0; +} diff --git a/modular_exponential/modular_exponential.py b/modular_exponential/modular_exponential.py index 773954bf..6451a39e 100644 --- a/modular_exponential/modular_exponential.py +++ b/modular_exponential/modular_exponential.py @@ -2,6 +2,7 @@ Modular Exponential """ + def mod_exponent(base, power, mod): """ Modular exponential of a number diff --git a/n_queen_problem/NQueenProblem.java b/n_queen_problem/NQueenProblem.java new file mode 100644 index 00000000..8191c228 --- /dev/null +++ b/n_queen_problem/NQueenProblem.java @@ -0,0 +1,64 @@ +/* + * Following code is the implementation of the N-queen problem. + * The solution is to place the queens on board such that no queen is under attack by another queen. + * There can be a number of possible solutions for a given length of board. + * This implementation prints only one valid solution, it can be extended to print all possible valid solutions. + */ + +import java.util.Arrays; + +public class NQueenProblem { + + private static boolean isQueenSafe(int[][] board, int row, int column) { + int i; + int j; + int boardLength = board[0].length; + for (i = 0; i < column; ++i) + if (board[row][i] == 1) + return false; // If there's another Queen present in the same row. + + for (i = row, j = column; i >= 0 && j >= 0; --i, --j) + if (board[i][j] == 1) + return false; // If there's another Queen present in the upper diagonal. + + for (i = row, j = column; j >= 0 && i < boardLength; ++i, --j) + if (board[i][j]==1) + return false; // If there's another Queen present in the lower diagonal. + + return true; + } + + private static boolean solveNQueen(int[][] board, int column) { + int boardLength = board[0].length; + if (column >= boardLength) + return true; + + for (int i = 0; i < boardLength; ++i) { + if (isQueenSafe(board, i, column)) { + board[i][column] = 1; // Place queen on (row, column) = (i, column). + if (solveNQueen(board, column + 1)) // Recurse for remaining board + return true; + else + board[i][column] = 0; + } + } + return false; + } + + public static final boolean solveNQueen(int[][] board) { + return solveNQueen(board, 0); + } + + public static void main(String[] args) { + int boardLength = 8; + int[][] board = new int[boardLength][boardLength]; + if (!solveNQueen(board)) { + System.out.println("There is no possible answer for this boardLength"); + } else { + System.out.println("A possible answer for given boardLength is:"); + for (int i = 0; i < boardLength; ++i) { + System.out.println(Arrays.toString(board[i])); + } + } + } +} diff --git a/quicksort/quick_sort.py b/quicksort/quick_sort.py index c962ed29..210e1b8f 100644 --- a/quicksort/quick_sort.py +++ b/quicksort/quick_sort.py @@ -63,5 +63,6 @@ def main(): quick_sort(a, 0, len(a) - 1) print(a) + if __name__ == '__main__': main() diff --git a/rod_cutting_problem/rod_cutting.c b/rod_cutting_problem/rod_cutting.c new file mode 100644 index 00000000..72193ad6 --- /dev/null +++ b/rod_cutting_problem/rod_cutting.c @@ -0,0 +1,32 @@ +/* +* Given a rod of length n and an array of prices that contains prices of all pieces of size smaller than n. +* Determine the maximum new_prices obtainable by cutting up the rod and selling the pieces. +* Time Complexity: O(n^2) +* Space Complexity: O(n) +*/ + +#include +#include + +#define max(a, b) (a > b) ? a : b; + +int rod_cutting(const int *prices) { + unsigned int i, j; + unsigned int n = sizeof(prices); + int new_prices[n + 1]; + memset(new_prices, 0, n + 1); + for (i = 1; i < n + 1; ++i) { + int maxi = -1; + for (j = 0; j < i; ++j) { + maxi = max(maxi, (prices[j] + new_prices[i - j - 1])); + } + new_prices[i] = maxi; + } + return new_prices[n]; +} + +int main() { + int prices[] = {10, 52, 84, 93, 101, 17, 117, 20}; + printf("%d\n", rod_cutting(prices)); + return 0; +} diff --git a/rod_cutting_problem/rod_cutting.py b/rod_cutting_problem/rod_cutting.py new file mode 100644 index 00000000..e4fb5181 --- /dev/null +++ b/rod_cutting_problem/rod_cutting.py @@ -0,0 +1,36 @@ +""" + This module calculates optimized solution for rod cutting + by function rod_cutting() with arguments as defined + in main() +""" + + +def rod_cutting(price): + """ + Computes maximum money that can be earned by cutting + a rod of length len(price) (Bottom-Up Approach). + + Time Complexity : O((len(price))^2) + Space Complexity : O(len(price)) + :param price: List in which price[i] denotes price of rod of length i. + :return: returns optimal solution for rod of length len(price). + """ + length = len(price) + opt_price = [0] * (length + 1) + + for i in range(1, length + 1): + opt_price[i] = max( + [-1] + [price[j] + opt_price[i - j - 1] for j in range(i)]) + return opt_price[length] + + +def main(): + """ + Main Function of this program. + """ + price = [1, 5, 8, 9, 10, 17, 17, 20, 24, 30] + print(rod_cutting(price)) + + +if __name__ == '__main__': + main() diff --git a/shell_sort/ShellSort.cpp b/shell_sort/ShellSort.cpp new file mode 100644 index 00000000..1f8b1875 --- /dev/null +++ b/shell_sort/ShellSort.cpp @@ -0,0 +1,43 @@ +#include +#include +#include + +// Use '-std=c++11' or higher flag while compiling +// g++ -std=c++11 -o ShellSort ShellSort.cpp + +using namespace std; + +// Worst case time complexity = O(n^2) +// Best case complexity = O(nlog(n)) + +vector shellSort(vector data) { + for (int i = static_cast(data.size() / 2); i > 0; i /= 2) { + for (int j = i; j < data.size(); ++j) { + for (int k = j - i; k >= 0; k -= i) { + if (data[k+i] >= data[k]) { + break; + } else { + swap(data[k], data[k+i]); + } + } + } + } + return data; +} + +void print(vector data) { + for (auto item : data) { + cout << item << " "; + } + cout << '\n'; +} + +int main() { + vector data = {1000, 45, -45, 121, 47, 45, 65, 121, -1, 103, 45, 34}; + cout << "Data to be sorted:" << '\n'; + print(data); + cout << "Sorted data:" << '\n'; + data = shellSort(data); + print(data); + return 0; +} diff --git a/shell_sort/shell_sort.go b/shell_sort/shell_sort.go new file mode 100644 index 00000000..7e4712e2 --- /dev/null +++ b/shell_sort/shell_sort.go @@ -0,0 +1,28 @@ +package main + +import "fmt" + +// ShellSort function returns sorted data +// Worst case time complexity = O(n^2) +// Best case complexity = O(nlog(n)) +func ShellSort(data []int) []int { + for i := len(data) / 2; i > 0; i /= 2 { + for j := i; j < len(data); j++ { + for k := j - i; k >= 0; k -= i { + if data[k+i] >= data[k] { + break + } else { + data[k], data[k+i] = data[k+i], data[k] + } + } + } + } + return data +} + +func main() { + data := []int{1000, 45, -45, 121, 47, 45, 65, 121, -1, 103, 45, 34} + fmt.Println("Data to be sorted: ", data) + data = ShellSort(data) + fmt.Println("Sorted data:", data) +} diff --git a/shell_sort/shell_sort.py b/shell_sort/shell_sort.py new file mode 100644 index 00000000..6df0b52c --- /dev/null +++ b/shell_sort/shell_sort.py @@ -0,0 +1,41 @@ +def shell_sort(array): + """ + Sorts the given array of integers using the Shell Sort algorithm + Time Complexity : O((len(array))^2) + Space Complexity : O(len(array)) + :param array: A List of integers. + :return: returns the array sorted + """ + + # calculate the gap using Knuth's formula + gap = 1 + while gap < len(array) // 3: + gap = (gap * 3) + 1 + + while gap > 0: + # using this gap, exchange elements while you can + for idx in range(gap, len(array)): + val_to_insert = array[idx] + candidate_idx = idx + + # shift all bigger elements to the right, creating a hole + while candidate_idx > gap - 1 and array[candidate_idx - gap] > val_to_insert: + array[candidate_idx] = array[candidate_idx - gap] + candidate_idx -= gap + + # insert our element at the hole + array[candidate_idx] = val_to_insert + + # decrease gap, math alert + gap = (gap - 1) // 3 + + return array + + +def main(): + sample_arr = [1, -312, 4, 12, 3, 17, 2542, 20, 18] + print(shell_sort(sample_arr)) + + +if __name__ == '__main__': + main() diff --git a/sieve_of_eratosthenes/SieveOfEratosthenes.java b/sieve_of_eratosthenes/SieveOfEratosthenes.java new file mode 100644 index 00000000..a1a973d6 --- /dev/null +++ b/sieve_of_eratosthenes/SieveOfEratosthenes.java @@ -0,0 +1,35 @@ +/* +* Following implementation of sieve of eratosthenes returns a boolean array which contains true is its index is prime +* less than or equal to a number n. +* Space complexity : O(n). +* Time complexity : O(n). +*/ + +public class SieveOfEratosthenes { + + public static boolean[] sieveOfEratosthenes(int n) { + int sqrtOfn = (int)Math.sqrt(n) + 1; + boolean[] primes = new boolean[n + 1]; + for (int i = 2; i < n + 1; ++i) { + primes[i] = true; + } + for (int i = 2; i <= sqrtOfn; ++i) { + if (primes[i]) { + for (int j = 2 * i; j < n + 1; j += i) { + primes[j] = false; + } + } + } + return primes; + } + + public static void main(String[] args) { + int n = 100; + boolean[] primes = sieveOfEratosthenes(n); + for (int i = 2; i < n + 1; ++i) { + if (primes[i]) { + System.out.print(i + " "); + } + } + } +} diff --git a/stack/stack.go b/stack/stack.go new file mode 100644 index 00000000..56f0e1ce --- /dev/null +++ b/stack/stack.go @@ -0,0 +1,39 @@ +package main + +import ( + "errors" + "fmt" +) + +// Stack implements stack DS +type Stack struct { + list []int +} + +// Push pushes to stack +func (s *Stack) Push(data int) error { + s.list = append(s.list, data) + return nil +} + +// Pop pops from stack +func (s *Stack) Pop() (int, error) { + if len(s.list) == 0 { + return -1, errors.New("pop from empty stack") + } + last := s.list[len(s.list)-1] + s.list = s.list[:len(s.list)-1] + return last, nil +} + +func main() { + var s Stack + s.Push(2) + s.Push(3) + s.Push(5) + last, err := s.Pop() + for err == nil { + fmt.Println(last) + last, err = s.Pop() + } +} diff --git a/stack/stack.js b/stack/stack.js new file mode 100644 index 00000000..98bad5f6 --- /dev/null +++ b/stack/stack.js @@ -0,0 +1,37 @@ +class Stack { + constructor (size = 0) { + this._array = []; + this._size = size; + } + + push (argument) { + if (this._size > 0 && this._array.length === this._size) { + throw new Error('Unable to push to full stack'); + } + this._array.push(argument); + } + + pop () { + if (this._array.length === 0) { + throw new Error('Unable to pop from empty stack'); + } + return this._array.pop(); + } +} + +function main () { + let st = new Stack(); + st.push('Hello World!'); + st.push(1223); + st.push('last one'); + console.log(st.pop()); + console.log(st.pop()); + console.log(st.pop()); + try { + console.log(st.pop()); + } catch (error) { + console.log('Error: ' + error.message); + } +} + +main(); diff --git a/stack/stack.py b/stack/stack.py index dfcacf40..4fa6a262 100644 --- a/stack/stack.py +++ b/stack/stack.py @@ -1,4 +1,5 @@ class Stack(object): + def __init__(self): self._list = [] From b0fd22d6c61b54342dba264ce357f31555023206 Mon Sep 17 00:00:00 2001 From: TarunISCO <201552063@iiitvadodara.ac.in> Date: Mon, 12 Jun 2017 15:11:08 +0530 Subject: [PATCH 4/9] unnecessary files removed --- breadth_first_search/BreadhFirstSearch | Bin 22928 -> 0 bytes breadth_first_search/BreadhFirstSearch.cpp | 63 --------------------- 2 files changed, 63 deletions(-) delete mode 100755 breadth_first_search/BreadhFirstSearch delete mode 100644 breadth_first_search/BreadhFirstSearch.cpp diff --git a/breadth_first_search/BreadhFirstSearch b/breadth_first_search/BreadhFirstSearch deleted file mode 100755 index 52884c22926e631d3ce21570bb80ed5103cfd9e5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22928 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 diff --git a/breadth_first_search/BreadhFirstSearch.cpp b/breadth_first_search/BreadhFirstSearch.cpp deleted file mode 100644 index 972c6256..00000000 --- a/breadth_first_search/BreadhFirstSearch.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Program to print Breadth First Traversal of a Graph -// Time Complexity : O( no_of_vertices + no_of_edges) -// Space Complexity : O( no_of_vertices + no_of_edges) - -#include -#include - -using namespace std; - -class Graph { - int v; - list *adjlist; - public : - - // Constructor Function - Graph(int v) { - this->v = v; - adjlist = new list[v]; - } - - // Function to add edge from source node to dest node - void addEdge (int source, int dest) { - adjlist[source].push_back(dest); - } - - // Function to print Breadth First Traversal of graph starting from source node - void breadthFirstSearch (int source) { - bool *visited = new bool[v]; - list node_queue; - - visited[source] = true; - node_queue.push_back(source); - - list::iterator itr; - while (!node_queue.empty()) { - source = node_queue.front(); - node_queue.pop_front(); - cout << source << "->"; - - for(itr = adjlist[source].begin(); itr != adjlist[source].end(); ++itr) { - if(!visited[*itr]) { - visited[*itr] = true; - node_queue.push_back(*itr); - } - } - } - free(visited); - } -}; - -int main () { - Graph testGraph(4); - testGraph.addEdge(0, 1); - testGraph.addEdge(0, 2); - testGraph.addEdge(1, 2); - testGraph.addEdge(2, 0); - testGraph.addEdge(2, 3); - testGraph.addEdge(3, 3); - - cout << "BFS starting from vertex 2 is " << endl; - testGraph.breadthFirstSearch(2); - return 0; -} From 41c0283d05868ae7460b53f913644ceda7240649 Mon Sep 17 00:00:00 2001 From: TarunISCO <201552063@iiitvadodara.ac.in> Date: Tue, 13 Jun 2017 19:56:06 +0530 Subject: [PATCH 5/9] unnecessary files removed --- insertion_sort/insertion_sort.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/insertion_sort/insertion_sort.py b/insertion_sort/insertion_sort.py index 0ce5f79e..093d620a 100644 --- a/insertion_sort/insertion_sort.py +++ b/insertion_sort/insertion_sort.py @@ -1,22 +1,22 @@ def insertionSort(alist): - """ - Performs a insertion sort - :type alist: object - """ - for index in range(1, len(alist)): - current_value = alist[index] - position = index - while position > 0 and alist[position-1] > current_value: - alist[position] = alist[position-1] - position -= 1 - alist[position] = current_value + """ + Performs a insertion sort + :type alist: object + """ + for index in range(1, len(alist)): + current_value = alist[index] + position = index + while position > 0 and alist[position-1] > current_value: + alist[position] = alist[position-1] + position -= 1 + alist[position] = current_value def main(): - alist = [54, 26, 93, 17, 77, 31, 44, 55, 20] - insertionSort(alist) - print(alist) + alist = [54, 26, 93, 17, 77, 31, 44, 55, 20] + insertionSort(alist) + print(alist) if __name__ == '__main__': - main() + main() From f7b1159c8f35ee586bace9db1c4de7a0dddf358c Mon Sep 17 00:00:00 2001 From: TarunISCO <201552063@iiitvadodara.ac.in> Date: Wed, 14 Jun 2017 12:07:56 +0530 Subject: [PATCH 6/9] issues in readme solved --- README.md | 23 +---------------------- insertion_sort/insertion_sort.py | 4 ++-- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 44b79778..fe904e64 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,7 @@ Community (college) maintained list of Algorithms and Data Structures implementa | Algorithm | C | CPP | Java | Python | Golang | JavaScript | |:--------------|:----------------:|:----------------:|:----------------:|:-----------------:|:-----------------:|:-----------------:| -<<<<<<< HEAD -| [Bin Sort](http://www.cdn.geeksforgeeks.org/bucket-sort-2/)| | |[\[X\]](bin_sort/BinSort.java)| | | | -======= | [Bin Sort](http://www.cdn.geeksforgeeks.org/bucket-sort-2/)| | |[\[X\]](bin_sort/BinSort.java) | [\[X\]](bin_sort/bin_sort.py) | | | ->>>>>>> 7fdb1bfefa2ec9880c65cd470224fde4a3a4e811 | [Binary Search](https://en.wikipedia.org/wiki/Binary_search_algorithm) | [\[X\]](binary_search/binary_search.c) | | [\[X\]](binary_search/BinarySearch.java) | [\[X\]](binary_search/binary_search.py) | [\[X\]](binary_search/binary_search.go) | | | [Coin Change Problem](http://www.algorithmist.com/index.php/Coin_Change) | [\[X\]](coin_change_problem/coin_change_problem.c) | | | | | | | [Counting Sort](http://www.geeksforgeeks.org/counting-sort/)| [\[X\]](counting_sort/counting_sort.c) | | [\[X\]](counting_sort/CountingSort.java) | | | | @@ -27,33 +23,20 @@ Community (college) maintained list of Algorithms and Data Structures implementa | [Dijkstra Algorithm](https://en.wikipedia.org/wiki/Dijkstra's_algorithm/) | [\[X\]](dijkstra/dijkstra.c) | | [\[X\]](dijkstra/Dijkstra.java) | | | | | [Euclidean GCD](https://en.wikipedia.org/wiki/Euclidean_algorithm) | [\[X\]](euclidean_gcd/euclidean_gcd.c) | | [\[X\]](euclidean_gcd/EuclideanGCD.java) | [\[X\]](euclidean_gcd/euclidean_gcd.py) | | | | [Exponentation by Squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring) | [\[X\]](exponentation_by_squaring/exponentation_by_squaring.c) |||| | | -<<<<<<< HEAD -| [Heap Sort](https://en.wikipedia.org/wiki/Heapsort) | [\[X\]](heap_sort/heap_sort.c) | | [\[X\]](heap_sort/HeapSort.java) | | | | -| [Insertion Sort](https://en.wikipedia.org/wiki/Insertion_sort) | [\[X\]](insertion_sort/insertion_sort.c) | | [\[X\]](insertion_sort/InsertionSort.java)| [\[X\]](insertion_sort/insertion_sort.py) | | | -======= | [Heap Sort](https://en.wikipedia.org/wiki/Heapsort) | [\[X\]](heap_sort/heap_sort.c) | | [\[X\]](heap_sort/HeapSort.java) | [\[X\]](heap_sort/heap_sort.py) | | | | [Insertion Sort](https://en.wikipedia.org/wiki/Insertion_sort) | [\[X\]](insertion_sort/insertion_sort.c) | | [\[X\]](insertion_sort/InsertionSort.java)| [\[X\]](insertion_sort/insertion_sort.py) | [\[X\]](insertion_sort/insertion_sort.go) | | ->>>>>>> 7fdb1bfefa2ec9880c65cd470224fde4a3a4e811 | [k-NN](https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm) | | | | [\[X\]](k_nn/k_nn.py) | | | | [Largest Sum Contiguous Subarray](http://www.geeksforgeeks.org/largest-sum-contiguous-subarray/) | [\[X\]](largest_sum_contiguous_subarray/largestSumContiguousSubarray.c) | | [\[X\]](largest_sum_contiguous_subarray/LargestSumContiguousSubarray.java) | | [\[X\]](largest_sum_contiguous_subarray/largestSumContiguousSubarray.go) | | | [Linear Search](https://en.wikipedia.org/wiki/Linear_search) | [\[X\]](linear_search/linear_search.c) | | [\[X\]](linear_search/LinearSearch.java) | [\[X\]](linear_search/linear_search.py) | [\[X\]](linear_search/linear-search.go) | | | [Longest Common Subsequence](http://www.geeksforgeeks.org/dynamic-programming-set-4-longest-common-subsequence) | [\[X\]](longest_common_subsequence/longestCommonSubsequence.c) | | [\[X\]](longest_common_subsequence/LongestCommonSubsequence.java) | | [\[X\]](longest_common_subsequence/longestCommonSubsequence.go) | | | [Merge Sort](https://www.khanacademy.org/computing/computer-science/algorithms/merge-sort/a/overview-of-merge-sort) | [\[X\]](merge_sort/merge_sort.c) | | [\[X\]](merge_sort/MergeSort.java) | [\[X\]](merge_sort/merge_sort.py) | | | -<<<<<<< HEAD -| [Modular Exponential](http://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/) | [\[X\]](modular_exponential/modular_exponential.c) | | [\[X\]](modular_exponential/ModularExponential.java) | [\[X\]](modular_exponential/modular_exponential.py) | | | -======= | [Modular Exponential](http://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/) | [\[X\]](modular_exponential/modular_exponential.c) | | [\[X\]](modular_exponential/ModularExponential.java) | [\[X\]](modular_exponential/modular_exponential.py) | [\[X\]](modular_exponential/modular_exponential.go) | | ->>>>>>> 7fdb1bfefa2ec9880c65cd470224fde4a3a4e811 | [N-Queen Problem](https://en.wikipedia.org/wiki/Eight_queens_puzzle) | | [\[X\]](n_queen_problem/NQueenProblem.cpp) | [\[X\]](n_queen_problem/NQueenProblem.java) | | | | | [Prime Factor](https://en.wikipedia.org/wiki/Prime_factor) | [\[X\]](prime_factor/prime_factor.c) | | | | | | | [Prims](https://en.wikipedia.org/wiki/Prim%27s_algorithm) | [\[X\]](prims/prims.c) | | [\[X\]](prims/Prims.java) | | | | | [Quick Select](https://en.wikipedia.org/wiki/Quickselect) | [\[X\]](quick_select/quick_select.c) | | | | | | | [Quicksort](https://en.wikipedia.org/wiki/Quicksort) | [\[X\]](quicksort/quicksort.c) | | [\[X\]](quicksort/QuickSort.java) | [\[X\]](quicksort/quick_sort.py) | | | -<<<<<<< HEAD -| [Rod Cutting Problem](http://www.geeksforgeeks.org/dynamic-programming-set-13-cutting-a-rod/) | [\[X\]](rod_cutting_problem/rod_cutting.c) | | [\[X\]](rod_cutting_problem/RodCutting.java) | [\[X\]](rod_cutting_problem/rod_cutting.py) | | | -======= | [Rod Cutting Problem](http://www.geeksforgeeks.org/dynamic-programming-set-13-cutting-a-rod/) | [\[X\]](rod_cutting_problem/rod_cutting.c) | | [\[X\]](rod_cutting_problem/RodCutting.java) | [\[X\]](rod_cutting_problem/rod_cutting.py) | [\[X\]](rod_cutting_problem/rod_cutting.go) | | ->>>>>>> 7fdb1bfefa2ec9880c65cd470224fde4a3a4e811 | [Shell Sort](https://en.wikipedia.org/wiki/Shellsort) | | [\[X\]](shell_sort/ShellSort.cpp) | | [\[X\]](/shell_sort/shell_sort.py) | [\[X\]](shell_sort/shell_sort.go) | | | [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) | [\[X\]](sieve_of_eratosthenes/sieveOfEratosthenes.c) | | [\[X\]](sieve_of_eratosthenes/SieveOfEratosthenes.java) | [\[X\]](sieve_of_eratosthenes/sieve_of_eratosthenes.py) | [\[X\]](sieve_of_eratosthenes/sieve_of_eratosthenes.go) | | @@ -64,10 +47,6 @@ Community (college) maintained list of Algorithms and Data Structures implementa |:--------------|:----------------:|:----------------:|:----------------:|:-----------------:|:-----------------:|:-----------------:| | [AVL Tree](http://www.geeksforgeeks.org/avl-tree-set-1-insertion)| | |[\[X\]](avl_tree/AvlTree.java) | | | | | [Binary Search Tree](https://en.wikipedia.org/wiki/Binary_search_tree) | | | [\[X\]](binary_search_tree/BinarySearchTree.java) | | | | -<<<<<<< HEAD -| [Linked List](https://en.wikipedia.org/wiki/Linked_list) | | | [\[X\]](linked_list/LinkedList.java) | | | | -| [Stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)) | | | [\[X\]](stack/Stack.java) | [\[X\]](stack/stack.py) | [\[X\]](stack/stack.go) | [\[X\]](stack/stack.js) | -======= | [Linked List](https://en.wikipedia.org/wiki/Linked_list) | | | [\[X\]](linked_list/LinkedList.java) | | [\[X\]](linked_list/linked_list.go) | | | [Stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)) | [\[X\]](stack/stack.c) | | [\[X\]](stack/Stack.java) | [\[X\]](stack/stack.py) | [\[X\]](stack/stack.go) | [\[X\]](stack/stack.js) | @@ -82,7 +61,7 @@ Community (college) maintained list of Algorithms and Data Structures implementa | Python |
python [filename.py]
| | Golang |
go run [filename.go]
| | JavaScript |
node [filename.js]
| ->>>>>>> 7fdb1bfefa2ec9880c65cd470224fde4a3a4e811 + ## Resources diff --git a/insertion_sort/insertion_sort.py b/insertion_sort/insertion_sort.py index 093d620a..68dfee3e 100644 --- a/insertion_sort/insertion_sort.py +++ b/insertion_sort/insertion_sort.py @@ -6,8 +6,8 @@ def insertionSort(alist): for index in range(1, len(alist)): current_value = alist[index] position = index - while position > 0 and alist[position-1] > current_value: - alist[position] = alist[position-1] + while position > 0 and alist[position - 1] > current_value: + alist[position] = alist[position - 1] position -= 1 alist[position] = current_value From dc38cf88f45aae2c2272858d648dd97b374d1a76 Mon Sep 17 00:00:00 2001 From: TarunISCO <201552063@iiitvadodara.ac.in> Date: Fri, 16 Jun 2017 14:32:45 +0530 Subject: [PATCH 7/9] replaced tabs with spaces --- insertion_sort/insertion_sort.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/insertion_sort/insertion_sort.py b/insertion_sort/insertion_sort.py index 68dfee3e..5e7c168d 100644 --- a/insertion_sort/insertion_sort.py +++ b/insertion_sort/insertion_sort.py @@ -1,22 +1,22 @@ def insertionSort(alist): - """ - Performs a insertion sort - :type alist: object - """ - for index in range(1, len(alist)): - current_value = alist[index] - position = index - while position > 0 and alist[position - 1] > current_value: - alist[position] = alist[position - 1] - position -= 1 - alist[position] = current_value + """ + Performs a insertion sort + :type alist: object + """ + for index in range(1, len(alist)): + current_value = alist[index] + position = index + while position > 0 and alist[position - 1] > current_value: + alist[position] = alist[position - 1] + position -= 1 + alist[position] = current_value def main(): - alist = [54, 26, 93, 17, 77, 31, 44, 55, 20] - insertionSort(alist) - print(alist) + alist = [54, 26, 93, 17, 77, 31, 44, 55, 20] + insertionSort(alist) + print(alist) if __name__ == '__main__': - main() + main() From b99da59e0c7c8b211b9ae5cf84cf58ab456357c2 Mon Sep 17 00:00:00 2001 From: TarunISCO <201552063@iiitvadodara.ac.in> Date: Fri, 16 Jun 2017 16:27:40 +0530 Subject: [PATCH 8/9] Extra line in readme removed --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index fe904e64..7f174b74 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,6 @@ Community (college) maintained list of Algorithms and Data Structures implementa | JavaScript |
node [filename.js]
| - ## Resources * [Algorithms - Learneroo](https://www.learneroo.com/subjects/8) From 6c436749ea48deeab951a1c78550c31d81ce55ad Mon Sep 17 00:00:00 2001 From: TarunISCO <201552063@iiitvadodara.ac.in> Date: Mon, 26 Jun 2017 12:15:17 +0530 Subject: [PATCH 9/9] Added Floyd Warshall [Java] --- .bin/install_apt.sh | 3 + .bin/install_go.sh | 4 + .bin/install_npm.sh | 2 + .bin/test_running.sh | 60 + .coafile | 5 - .codeclimate.yml | 3 + .editorconfig | 15 +- .gitignore | 3 + .travis.yml | 25 +- CONTRIBUTING.md | 22 +- ISSUE_TEMPLATE.md | 2 + LICENSE | 7 + README.md | 58 +- apt-requirements.txt | 9 + avl_tree/AvlTree.java | 549 ++-- bin_sort/BinSort.java | 150 +- binary_search/BinarySearch.java | 8 +- binary_search/binarySearch.js | 62 + binary_search/binary_search.c | 22 +- binary_search/binary_search.py | 16 +- binary_search_tree/BinarySearchTree.java | 326 +- coin_change_problem/CoinChange.java | 37 + coin_change_problem/coinChangeProblem.js | 27 + coin_change_problem/coin_change_problem.py | 26 + counting_sort/CountingSort.java | 62 +- counting_sort/counting_sort.c | 56 +- counting_sort/counting_sort.go | 36 + .../DepthFirstTraversal.java | 22 +- dijkstra/Dijkstra.java | 18 +- dijkstra/dijkstra.c | 12 +- dijkstra/dijkstra.py | 75 + euclidean_gcd/EuclideanGCD.java | 16 +- euclidean_gcd/euclideanGCD.js | 37 + euclidean_gcd/euclidean_gcd.c | 42 +- .../exponentation_by_squaring.c | 31 - .../ExponentiationBySquaring.java | 27 + .../exponentiationBySquaring.js | 28 + .../exponentiation_by_squaring.c | 32 + .../exponentiation_by_squaring.go | 23 + .../exponentiation_by_squaring.py | 31 + floyd_warshall/FloydWarshall.java | 68 + heap_sort/HeapSort.java | 72 +- heap_sort/heap_sort.c | 83 +- insertion_sort/InsertionSort.java | 48 +- insertion_sort/insertion_sort.c | 56 +- .../LargestSumContiguousSubarray.java | 46 +- .../largest_sum_contiguous_subarray.py | 23 + linear_search/LinearSearch.java | 50 +- linear_search/linearSearch.js | 29 + linear_search/linear_search.c | 10 +- linked_list/LinkedList.java | 108 +- .../LongestCommonSubsequence.java | 76 +- .../longestCommonSubsequence.c | 45 +- .../longest_common_subsequence.py | 48 + merge_sort/MergeSort.java | 4 +- merge_sort/merge_sort.c | 8 +- modular_exponential/ModularExponential.java | 38 +- modular_exponential/modularExponential.js | 30 + modular_exponential/modular_exponential.c | 34 +- n_queen_problem/NQueenProblem.cpp | 87 +- n_queen_problem/n_queen_problem.py | 76 + npm-requirements.txt | 2 + pip2-requirements.txt | 2 + pip3-requirements.txt | 3 + prime_factor/PrimeFactor.java | 25 + prime_factor/primeFactor.js | 31 + prime_factor/prime_factor.c | 68 +- prime_factor/prime_factor.go | 30 + prime_factor/prime_factor.py | 32 + prims/prims.c | 72 +- quick_select/QuickSelect.java | 64 + quick_select/quick_select.c | 71 +- quick_select/quick_select.py | 56 + quicksort/QuickSort.java | 16 +- quicksort/quick_sort.go | 50 + rod_cutting_problem/RodCutting.java | 4 +- rod_cutting_problem/rod_cutting.c | 40 +- shell_sort/shellSort.js | 30 + .../SieveOfEratosthenes.java | 58 +- sieve_of_eratosthenes/sieveOfEratosthenes.c | 6 +- sieve_of_eratosthenes/sieveOfEratosthenes.js | 31 + .../sieve_of_eratosthenes.py | 10 +- sleep_sort/sleep_sort.cpp | 42 + sleep_sort/sleep_sort.py | 58 + stack/Stack.java | 10 +- trie/trie.cpp | 130 + "u\033\033\033q" | 2885 +++++++++++++++++ 87 files changed, 5568 insertions(+), 1286 deletions(-) create mode 100755 .bin/install_apt.sh create mode 100755 .bin/install_go.sh create mode 100755 .bin/install_npm.sh create mode 100755 .bin/test_running.sh create mode 100644 LICENSE create mode 100644 apt-requirements.txt create mode 100644 binary_search/binarySearch.js create mode 100644 coin_change_problem/CoinChange.java create mode 100644 coin_change_problem/coinChangeProblem.js create mode 100644 coin_change_problem/coin_change_problem.py create mode 100644 counting_sort/counting_sort.go create mode 100644 dijkstra/dijkstra.py create mode 100644 euclidean_gcd/euclideanGCD.js delete mode 100644 exponentation_by_squaring/exponentation_by_squaring.c create mode 100644 exponentiation_by_squaring/ExponentiationBySquaring.java create mode 100644 exponentiation_by_squaring/exponentiationBySquaring.js create mode 100644 exponentiation_by_squaring/exponentiation_by_squaring.c create mode 100644 exponentiation_by_squaring/exponentiation_by_squaring.go create mode 100644 exponentiation_by_squaring/exponentiation_by_squaring.py create mode 100644 floyd_warshall/FloydWarshall.java create mode 100644 largest_sum_contiguous_subarray/largest_sum_contiguous_subarray.py create mode 100644 linear_search/linearSearch.js create mode 100644 longest_common_subsequence/longest_common_subsequence.py create mode 100644 modular_exponential/modularExponential.js create mode 100644 n_queen_problem/n_queen_problem.py create mode 100644 npm-requirements.txt create mode 100644 pip2-requirements.txt create mode 100644 pip3-requirements.txt create mode 100644 prime_factor/PrimeFactor.java create mode 100644 prime_factor/primeFactor.js create mode 100644 prime_factor/prime_factor.go create mode 100644 prime_factor/prime_factor.py create mode 100644 quick_select/QuickSelect.java create mode 100644 quick_select/quick_select.py create mode 100644 quicksort/quick_sort.go create mode 100644 shell_sort/shellSort.js create mode 100644 sieve_of_eratosthenes/sieveOfEratosthenes.js create mode 100644 sleep_sort/sleep_sort.cpp create mode 100644 sleep_sort/sleep_sort.py create mode 100644 trie/trie.cpp create mode 100644 "u\033\033\033q" diff --git a/.bin/install_apt.sh b/.bin/install_apt.sh new file mode 100755 index 00000000..cd980c54 --- /dev/null +++ b/.bin/install_apt.sh @@ -0,0 +1,3 @@ +#!/bin/bash +sudo apt-get update +sudo apt-get install -y $(grep -vE "^\s*#" apt-requirements.txt | tr "\n" " ") diff --git a/.bin/install_go.sh b/.bin/install_go.sh new file mode 100755 index 00000000..2143da8d --- /dev/null +++ b/.bin/install_go.sh @@ -0,0 +1,4 @@ +#!/bin/bash +go get -u github.com/golang/lint/golint +cd $GOPATH/src/github.com/golang/lint +go install . diff --git a/.bin/install_npm.sh b/.bin/install_npm.sh new file mode 100755 index 00000000..70275658 --- /dev/null +++ b/.bin/install_npm.sh @@ -0,0 +1,2 @@ +#!/bin/bash +npm install -g $(grep -vE "^\s*#" npm-requirements.txt | tr "\n" " ") diff --git a/.bin/test_running.sh b/.bin/test_running.sh new file mode 100755 index 00000000..8d3cb5fe --- /dev/null +++ b/.bin/test_running.sh @@ -0,0 +1,60 @@ +#!/bin/bash +set -e + +echo "Testing C files..." +for i in $(ls -1 **/*.c); do + echo " Compiling $i - gcc $i -lm -std=c11" + gcc $i -lm -std=c11 + echo " Running $i - ./a.out > /dev/null" + ./a.out > /dev/null + rm -f a.out + echo "" +done + +echo "" +echo "Testing C++ files..." +for i in $(ls -1 **/*.cpp); do + echo " Compiling $i - g++ $i -lm -pthread -std=c++11" + g++ $i -lm -pthread -std=c++11 + echo " Running $i - ./a.out > /dev/null" + ./a.out > /dev/null + rm -f a.out + echo "" +done + +echo "" +echo "Testing Java files..." +for i in $(ls -1 **/*.java); do + echo " Compiling $i - javac -Werror -Xlint:all $i -d ." + javac -Werror -Xlint:all $i -d . + filename="${i##*/}" + classname="${filename%.*}" + echo " Running $i - java $classname > /dev/null" + java $classname > /dev/null + echo "" +done +rm -f *.class + +echo "Testing Python files..." +for i in $(ls -1 **/*.py); do + echo " Running $i - python2 $i > /dev/null" + python2 $i > /dev/null + echo " Running $i - python3 $i > /dev/null" + python3 $i > /dev/null + echo "" +done + +echo "" +echo "Running Go files..." +for i in $(ls -1 **/*.go); do + echo " Running $i - go run $i > /dev/null" + go run $i > /dev/null + echo "" +done + +echo "" +echo "Running JavaScript files..." +for i in $(ls -1 **/*.js); do + echo " Running $i - node --use-strict --harmony $i > /dev/null" + node --use-strict --harmony $i > /dev/null +done diff --git a/.coafile b/.coafile index 532c520e..49a0538f 100644 --- a/.coafile +++ b/.coafile @@ -38,8 +38,3 @@ bears = GhcModBear [happiness] files = **/*.js bears = HappinessLintBear - -# yaml -[yml] -files = **/*.yml -bears = YAMLLintBear diff --git a/.codeclimate.yml b/.codeclimate.yml index 1a427b59..2d205f39 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -13,6 +13,9 @@ engines: enabled: true radon: enabled: true + checks: + Complexity: + enabled: false ratings: paths: - "**.js" diff --git a/.editorconfig b/.editorconfig index 2d207351..d820a8bb 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,11 +1,11 @@ root = true [*] +charset = utf-8 end_of_line = lf insert_final_newline = true -[{*.go, *.c, *.cpp}] -charset = utf-8 +[*.{go,c,cpp}] indent_style = tab tab_width = 4 trim_trailing_whitespace = true @@ -15,16 +15,17 @@ indent_style = tab tab_width = 2 trim_trailing_whitespace = true -[{*.py, *.java}] -charset = utf-8 +[*.{py,java}] indent_style = space indent_size = 4 trim_trailing_whitespace = true +[*.{c,cpp,java,js}] +block_comment_start = /* +block_comment = * +block_comment_end = */ + [*.yml] indent_style = space indent_size = 2 trim_trailing_whitespace = true - -[*.md] -trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore index ace73e98..d8548799 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ .DS_Store # coala *.orig + +# Jetbrains +.idea/ diff --git a/.travis.yml b/.travis.yml index 810e6003..8da89498 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,21 @@ dist: trusty -language: python -python: - - "3.6" +sudo: required +language: node_js +node_js: + "7" env: GOPATH: $HOME/go PATH: $GOPATH/bin:$PATH install: - - sudo apt-get update - - sudo apt-get install golang-go - - sudo apt-get install ghc-mod hlint - - curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - - - sudo apt-get install -y nodejs - - sudo npm install -g happiness - - go get -u github.com/golang/lint/golint - - cd $GOPATH/src/github.com/golang/lint - - go install . - - pip install coala-bears - - cd $TRAVIS_BUILD_DIR + - ./.bin/install_apt.sh + - ./.bin/install_go.sh + - ./.bin/install_npm.sh + - pip3 install -r pip3-requirements.txt + - pip2 install -r pip2-requirements.txt script: + - ./.bin/test_running.sh - coala --ci + - eclint check "**/*.{java,c,cpp,js}" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a4c8950f..06379ddb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,7 +32,7 @@ * Filename should be derived from the folder name. (eg `longest_common_subsequence` becomes `longestCommonSubsequence.c` or `LongestCommonSubsequence.java`) * Name of master function of the code should be kept same as filename to the best extent possible. * Prefer classes instead of multiple helper functions (where applicable). -* Currently we are accepting contributions in C, C++, Java, Python and Go but other languages may be considered after a discussion. +* Currently we are accepting contributions in C, C++, Java, Python, Go and JavaScript but other languages may be considered after a discussion. * Define `tester` code only in `main` routine. * Use meaningful variable, method and function names and comments. * No profanity. @@ -137,3 +137,23 @@ func main() { fmt.Println(sortedArray) } ``` + +#### JavaScript + +```JavaScript +function quickSort (arr) { + /* + Your implementation here + */ +} + +function main () { + let input = [2, 3, 0, 4]; + quickSort(input); + for (let x in input) { + console.log(input[x] + ' '); + } +} + +main(); +``` diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 85e08646..3f2ff1d6 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -5,7 +5,9 @@ - [ ] I searched or browsed the repo’s other issues to ensure this is not a duplicate. - [ ] This Algo/DS is worth adding to this repository. - [ ] Assign this issue to me (I want to work on this). + - [ ] I ensure that I am not already assigned to 2 or more issues. - [ ] I will send my PR only after I'm assigned to this issue by any maintainer. +- [ ] I understand that I will be unassigned from this issue if I fail to send a PR for this within a week. diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..565272f6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2017 IIITV GitHub Group + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 7f174b74..b3eea7c2 100644 --- a/README.md +++ b/README.md @@ -15,40 +15,42 @@ Community (college) maintained list of Algorithms and Data Structures implementa | Algorithm | C | CPP | Java | Python | Golang | JavaScript | |:--------------|:----------------:|:----------------:|:----------------:|:-----------------:|:-----------------:|:-----------------:| -| [Bin Sort](http://www.cdn.geeksforgeeks.org/bucket-sort-2/)| | |[\[X\]](bin_sort/BinSort.java) | [\[X\]](bin_sort/bin_sort.py) | | | -| [Binary Search](https://en.wikipedia.org/wiki/Binary_search_algorithm) | [\[X\]](binary_search/binary_search.c) | | [\[X\]](binary_search/BinarySearch.java) | [\[X\]](binary_search/binary_search.py) | [\[X\]](binary_search/binary_search.go) | | -| [Coin Change Problem](http://www.algorithmist.com/index.php/Coin_Change) | [\[X\]](coin_change_problem/coin_change_problem.c) | | | | | | -| [Counting Sort](http://www.geeksforgeeks.org/counting-sort/)| [\[X\]](counting_sort/counting_sort.c) | | [\[X\]](counting_sort/CountingSort.java) | | | | -| [Depth First Traversal](http://www.geeksforgeeks.org/depth-first-traversal-for-a-graph/) | | | [\[X\]](depth_first_traversal/DepthFirstTraversal.java) | | | | -| [Dijkstra Algorithm](https://en.wikipedia.org/wiki/Dijkstra's_algorithm/) | [\[X\]](dijkstra/dijkstra.c) | | [\[X\]](dijkstra/Dijkstra.java) | | | | -| [Euclidean GCD](https://en.wikipedia.org/wiki/Euclidean_algorithm) | [\[X\]](euclidean_gcd/euclidean_gcd.c) | | [\[X\]](euclidean_gcd/EuclideanGCD.java) | [\[X\]](euclidean_gcd/euclidean_gcd.py) | | | -| [Exponentation by Squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring) | [\[X\]](exponentation_by_squaring/exponentation_by_squaring.c) |||| | | -| [Heap Sort](https://en.wikipedia.org/wiki/Heapsort) | [\[X\]](heap_sort/heap_sort.c) | | [\[X\]](heap_sort/HeapSort.java) | [\[X\]](heap_sort/heap_sort.py) | | | -| [Insertion Sort](https://en.wikipedia.org/wiki/Insertion_sort) | [\[X\]](insertion_sort/insertion_sort.c) | | [\[X\]](insertion_sort/InsertionSort.java)| [\[X\]](insertion_sort/insertion_sort.py) | [\[X\]](insertion_sort/insertion_sort.go) | | -| [k-NN](https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm) | | | | [\[X\]](k_nn/k_nn.py) | | | -| [Largest Sum Contiguous Subarray](http://www.geeksforgeeks.org/largest-sum-contiguous-subarray/) | [\[X\]](largest_sum_contiguous_subarray/largestSumContiguousSubarray.c) | | [\[X\]](largest_sum_contiguous_subarray/LargestSumContiguousSubarray.java) | | [\[X\]](largest_sum_contiguous_subarray/largestSumContiguousSubarray.go) | | -| [Linear Search](https://en.wikipedia.org/wiki/Linear_search) | [\[X\]](linear_search/linear_search.c) | | [\[X\]](linear_search/LinearSearch.java) | [\[X\]](linear_search/linear_search.py) | [\[X\]](linear_search/linear-search.go) | | -| [Longest Common Subsequence](http://www.geeksforgeeks.org/dynamic-programming-set-4-longest-common-subsequence) | [\[X\]](longest_common_subsequence/longestCommonSubsequence.c) | | [\[X\]](longest_common_subsequence/LongestCommonSubsequence.java) | | [\[X\]](longest_common_subsequence/longestCommonSubsequence.go) | | -| [Merge Sort](https://www.khanacademy.org/computing/computer-science/algorithms/merge-sort/a/overview-of-merge-sort) | [\[X\]](merge_sort/merge_sort.c) | | [\[X\]](merge_sort/MergeSort.java) | [\[X\]](merge_sort/merge_sort.py) | | | -| [Modular Exponential](http://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/) | [\[X\]](modular_exponential/modular_exponential.c) | | [\[X\]](modular_exponential/ModularExponential.java) | [\[X\]](modular_exponential/modular_exponential.py) | [\[X\]](modular_exponential/modular_exponential.go) | | -| [N-Queen Problem](https://en.wikipedia.org/wiki/Eight_queens_puzzle) | | [\[X\]](n_queen_problem/NQueenProblem.cpp) | [\[X\]](n_queen_problem/NQueenProblem.java) | | | | -| [Prime Factor](https://en.wikipedia.org/wiki/Prime_factor) | [\[X\]](prime_factor/prime_factor.c) | | | | | | -| [Prims](https://en.wikipedia.org/wiki/Prim%27s_algorithm) | [\[X\]](prims/prims.c) | | [\[X\]](prims/Prims.java) | | | | -| [Quick Select](https://en.wikipedia.org/wiki/Quickselect) | [\[X\]](quick_select/quick_select.c) | | | | | | -| [Quicksort](https://en.wikipedia.org/wiki/Quicksort) | [\[X\]](quicksort/quicksort.c) | | [\[X\]](quicksort/QuickSort.java) | [\[X\]](quicksort/quick_sort.py) | | | -| [Rod Cutting Problem](http://www.geeksforgeeks.org/dynamic-programming-set-13-cutting-a-rod/) | [\[X\]](rod_cutting_problem/rod_cutting.c) | | [\[X\]](rod_cutting_problem/RodCutting.java) | [\[X\]](rod_cutting_problem/rod_cutting.py) | [\[X\]](rod_cutting_problem/rod_cutting.go) | | -| [Shell Sort](https://en.wikipedia.org/wiki/Shellsort) | | [\[X\]](shell_sort/ShellSort.cpp) | | [\[X\]](/shell_sort/shell_sort.py) | [\[X\]](shell_sort/shell_sort.go) | | -| [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) | [\[X\]](sieve_of_eratosthenes/sieveOfEratosthenes.c) | | [\[X\]](sieve_of_eratosthenes/SieveOfEratosthenes.java) | [\[X\]](sieve_of_eratosthenes/sieve_of_eratosthenes.py) | [\[X\]](sieve_of_eratosthenes/sieve_of_eratosthenes.go) | | +| [Bin Sort](http://www.cdn.geeksforgeeks.org/bucket-sort-2/)| | |[:white_check_mark:](bin_sort/BinSort.java) | [:white_check_mark:](bin_sort/bin_sort.py) | | | +| [Binary Search](https://en.wikipedia.org/wiki/Binary_search_algorithm) | [:white_check_mark:](binary_search/binary_search.c) | | [:white_check_mark:](binary_search/BinarySearch.java) | [:white_check_mark:](binary_search/binary_search.py) | [:white_check_mark:](binary_search/binary_search.go) | [:white_check_mark:](binary_search/binarySearch.js) | +| [Coin Change Problem](http://www.algorithmist.com/index.php/Coin_Change) | [:white_check_mark:](coin_change_problem/coin_change_problem.c) | | [:white_check_mark:](coin_change_problem/CoinChange.java) | [:white_check_mark:](coin_change_problem/coin_change_problem.py) | | [:white_check_mark:](coin_change_problem/coinChangeProblem.js) | +| [Counting Sort](http://www.geeksforgeeks.org/counting-sort/)| [:white_check_mark:](counting_sort/counting_sort.c) | | [:white_check_mark:](counting_sort/CountingSort.java) | | [:white_check_mark:](counting_sort/counting_sort.go) | | +| [Depth First Traversal](http://www.geeksforgeeks.org/depth-first-traversal-for-a-graph/) | | | [:white_check_mark:](depth_first_traversal/DepthFirstTraversal.java) | | | | +| [Dijkstra Algorithm](https://en.wikipedia.org/wiki/Dijkstra's_algorithm) | [:white_check_mark:](dijkstra/dijkstra.c) | | [:white_check_mark:](dijkstra/Dijkstra.java) | [:white_check_mark:](dijkstra/dijkstra.py) | | | +| [Euclidean GCD](https://en.wikipedia.org/wiki/Euclidean_algorithm) | [:white_check_mark:](euclidean_gcd/euclidean_gcd.c) | | [:white_check_mark:](euclidean_gcd/EuclideanGCD.java) | [:white_check_mark:](euclidean_gcd/euclidean_gcd.py) | | [:white_check_mark:](euclidean_gcd/euclideanGCD.js) | +| [Exponentiation by Squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring) | [:white_check_mark:](exponentiation_by_squaring/exponentiation_by_squaring.c) | | [:white_check_mark:](exponentiation_by_squaring/ExponentiationBySquaring.java) | [:white_check_mark:](exponentiation_by_squaring/exponentiation_by_squaring.py) | [:white_check_mark:](exponentiation_by_squaring/exponentiation_by_squaring.go) | [:white_check_mark:](exponentiation_by_squaring/exponentiationBySquaring.js) | +| [Heap Sort](https://en.wikipedia.org/wiki/Heapsort) | [:white_check_mark:](heap_sort/heap_sort.c) | | [:white_check_mark:](heap_sort/HeapSort.java) | [:white_check_mark:](heap_sort/heap_sort.py) | | | +| [Insertion Sort](https://en.wikipedia.org/wiki/Insertion_sort) | [:white_check_mark:](insertion_sort/insertion_sort.c) | | [:white_check_mark:](insertion_sort/InsertionSort.java)| [:white_check_mark:](insertion_sort/insertion_sort.py) | [:white_check_mark:](insertion_sort/insertion_sort.go) | | +| [k-NN](https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm) | | | | [:white_check_mark:](k_nn/k_nn.py) | | | +| [Largest Sum Contiguous Subarray](http://www.geeksforgeeks.org/largest-sum-contiguous-subarray/) | [:white_check_mark:](largest_sum_contiguous_subarray/largestSumContiguousSubarray.c) | | [:white_check_mark:](largest_sum_contiguous_subarray/LargestSumContiguousSubarray.java) | [:white_check_mark:](largest_sum_contiguous_subarray/largest_sum_contiguous_subarray.py) | [:white_check_mark:](largest_sum_contiguous_subarray/largestSumContiguousSubarray.go) | | +| [Linear Search](https://en.wikipedia.org/wiki/Linear_search) | [:white_check_mark:](linear_search/linear_search.c) | | [:white_check_mark:](linear_search/LinearSearch.java) | [:white_check_mark:](linear_search/linear_search.py) | [:white_check_mark:](linear_search/linear-search.go) | [:white_check_mark:](linear_search/linearSearch.js) | +| [Longest Common Subsequence](http://www.geeksforgeeks.org/dynamic-programming-set-4-longest-common-subsequence) | [:white_check_mark:](longest_common_subsequence/longestCommonSubsequence.c) | | [:white_check_mark:](longest_common_subsequence/LongestCommonSubsequence.java) | [:white_check_mark:](longest_common_subsequence/longest_common_subsequence.py) | [:white_check_mark:](longest_common_subsequence/longestCommonSubsequence.go) | | +| [Merge Sort](https://www.khanacademy.org/computing/computer-science/algorithms/merge-sort/a/overview-of-merge-sort) | [:white_check_mark:](merge_sort/merge_sort.c) | | [:white_check_mark:](merge_sort/MergeSort.java) | [:white_check_mark:](merge_sort/merge_sort.py) | | | +| [Modular Exponential](http://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/) | [:white_check_mark:](modular_exponential/modular_exponential.c) | | [:white_check_mark:](modular_exponential/ModularExponential.java) | [:white_check_mark:](modular_exponential/modular_exponential.py) | [:white_check_mark:](modular_exponential/modular_exponential.go) | [:white_check_mark:](modular_exponential/modularExponential.js) | +| [N-Queen Problem](https://en.wikipedia.org/wiki/Eight_queens_puzzle) | | [:white_check_mark:](n_queen_problem/NQueenProblem.cpp) | [:white_check_mark:](n_queen_problem/NQueenProblem.java) | [:white_check_mark:](n_queen_problem/n_queen_problem.py) | | | +| [Prime Factor](https://en.wikipedia.org/wiki/Prime_factor) | [:white_check_mark:](prime_factor/prime_factor.c) | | [:white_check_mark:](prime_factor/PrimeFactor.java) | [:white_check_mark:](prime_factor/prime_factor.py) | [:white_check_mark:](prime_factor/prime_factor.go) | [:white_check_mark:](prime_factor/primeFactor.js) | +| [Prims](https://en.wikipedia.org/wiki/Prim%27s_algorithm) | [:white_check_mark:](prims/prims.c) | | [:white_check_mark:](prims/Prims.java) | | | | +| [Quick Select](https://en.wikipedia.org/wiki/Quickselect) | [:white_check_mark:](quick_select/quick_select.c) | | [:white_check_mark:](quick_select/QuickSelect.java) | [:white_check_mark:](quick_select/quick_select.py) | | | +| [Quicksort](https://en.wikipedia.org/wiki/Quicksort) | [:white_check_mark:](quicksort/quicksort.c) | | [:white_check_mark:](quicksort/QuickSort.java) | [:white_check_mark:](quicksort/quick_sort.py) | [:white_check_mark:](quicksort/quick_sort.go) | | +| [Rod Cutting Problem](http://www.geeksforgeeks.org/dynamic-programming-set-13-cutting-a-rod/) | [:white_check_mark:](rod_cutting_problem/rod_cutting.c) | | [:white_check_mark:](rod_cutting_problem/RodCutting.java) | [:white_check_mark:](rod_cutting_problem/rod_cutting.py) | [:white_check_mark:](rod_cutting_problem/rod_cutting.go) | | +| [Shell Sort](https://en.wikipedia.org/wiki/Shellsort) | | [:white_check_mark:](shell_sort/ShellSort.cpp) | | [:white_check_mark:](/shell_sort/shell_sort.py) | [:white_check_mark:](shell_sort/shell_sort.go) | [:white_check_mark:](shell_sort/shellSort.js) | +| [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) | [:white_check_mark:](sieve_of_eratosthenes/sieveOfEratosthenes.c) | | [:white_check_mark:](sieve_of_eratosthenes/SieveOfEratosthenes.java) | [:white_check_mark:](sieve_of_eratosthenes/sieve_of_eratosthenes.py) | [:white_check_mark:](sieve_of_eratosthenes/sieve_of_eratosthenes.go) | [:white_check_mark:](sieve_of_eratosthenes/sieveOfEratosthenes.js) | +| [Sleep Sort](http://www.geeksforgeeks.org/sleep-sort-king-laziness-sorting-sleeping/) | | [:white_check_mark:](sleep_sort/sleep_sort.cpp) | | [:white_check_mark:](sleep_sort/sleep_sort.py) | | | ## Implemented Data Structures | Data Structure | C | CPP | Java | Python | Golang | JavaScript | |:--------------|:----------------:|:----------------:|:----------------:|:-----------------:|:-----------------:|:-----------------:| -| [AVL Tree](http://www.geeksforgeeks.org/avl-tree-set-1-insertion)| | |[\[X\]](avl_tree/AvlTree.java) | | | | -| [Binary Search Tree](https://en.wikipedia.org/wiki/Binary_search_tree) | | | [\[X\]](binary_search_tree/BinarySearchTree.java) | | | | -| [Linked List](https://en.wikipedia.org/wiki/Linked_list) | | | [\[X\]](linked_list/LinkedList.java) | | [\[X\]](linked_list/linked_list.go) | | -| [Stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)) | [\[X\]](stack/stack.c) | | [\[X\]](stack/Stack.java) | [\[X\]](stack/stack.py) | [\[X\]](stack/stack.go) | [\[X\]](stack/stack.js) | +| [AVL Tree](http://www.geeksforgeeks.org/avl-tree-set-1-insertion)| | |[:white_check_mark:](avl_tree/AvlTree.java) | | | | +| [Binary Search Tree](https://en.wikipedia.org/wiki/Binary_search_tree) | | | [:white_check_mark:](binary_search_tree/BinarySearchTree.java) | | | | +| [Linked List](https://en.wikipedia.org/wiki/Linked_list) | | | [:white_check_mark:](linked_list/LinkedList.java) | | [:white_check_mark:](linked_list/linked_list.go) | | +| [Stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)) | [:white_check_mark:](stack/stack.c) | | [:white_check_mark:](stack/Stack.java) | [:white_check_mark:](stack/stack.py) | [:white_check_mark:](stack/stack.go) | [:white_check_mark:](stack/stack.js) | +| [Trie](https://en.wikipedia.org/wiki/Trie) | | [:white_check_mark:](trie/trie.cpp) | | | | | ## How to run them diff --git a/apt-requirements.txt b/apt-requirements.txt new file mode 100644 index 00000000..c118bee6 --- /dev/null +++ b/apt-requirements.txt @@ -0,0 +1,9 @@ +# Go linting +golang-go +ghc-mod +hlint + +# Python 3 +python3-dev +python3-pip +python3-setuptools diff --git a/avl_tree/AvlTree.java b/avl_tree/AvlTree.java index b61dba31..6246c1a6 100644 --- a/avl_tree/AvlTree.java +++ b/avl_tree/AvlTree.java @@ -1,272 +1,277 @@ -import java.util.NoSuchElementException; -import java.util.Random; - -public class AvlTree { - - public static void main(String[] args) { - AVL avl = new AVL(); - Random rand = new Random(); - int inp = 10; - System.out.println(avl.isEmpty()); - for (int i = 0; i < inp; i++) { - avl.root = avl.insert(avl.root, rand.nextInt(100)); - } - avl.prntIn(avl.root); - System.out.println(" "); - System.out.println(avl.isEmpty()); - avl.delNode(avl.root,avl.root.data); - avl.prntIn(avl.root); - System.out.println(" "); - avl.delNode(avl.root,1111); - } -} - -class AVL { - public NodeAVL root; - - public AVL(){ - root = null; - } - - public NodeAVL insert(NodeAVL node, int data) { - // These method takes care of rotation needed after insertion - if (node == null) { - node = new NodeAVL(data); - return node; - } else { - if (node.data > data) { - node.left = insert(node.left, data); - if (node.left == null) - node.hLeft = 0; - else - node.hLeft = Math.max(node.left.hLeft, node.left.hRight) + 1; - } else { - node.right = insert(node.right, data); - if (node.right == null) - node.hRight = 0; - else - node.hRight = Math.max(node.right.hLeft, node.right.hRight) + 1; - } - node = isRotate(node); - } - return node; - } - - private NodeAVL rotateLR(NodeAVL node) { - NodeAVL sec = node.left; - NodeAVL temp = sec.right; - node.left = temp; - sec.right = temp.left; - temp.left = sec; - node.left = temp.right; - temp.right = node; - if (node.left == null) - node.hLeft = 0; - else - node.hLeft = Math.max(node.left.hLeft, node.left.hRight) + 1; - if (sec.right == null) - sec.hRight = 0; - else - sec.hRight = Math.max(sec.right.hLeft, sec.right.hRight) + 1; - temp.hLeft = Math.max(sec.hLeft, sec.hRight) + 1; - temp.hRight = Math.max(node.hLeft, node.hRight) + 1; - return temp; - } - - private NodeAVL rotateRL(NodeAVL node) { - NodeAVL sec = node.right; - NodeAVL temp = sec.left; - node.right = temp; - sec.left = temp.right; - temp.right = sec; - node.right = temp.left; - temp.left = node; - if (node.right == null) - node.hRight = 0; - else - node.hRight = Math.max(node.right.hLeft, node.right.hRight) + 1; - if (sec.left == null) - sec.hLeft = 0; - else - sec.hLeft = Math.max(sec.left.hLeft, sec.left.hRight) + 1; - temp.hRight = Math.max(sec.hLeft, sec.hRight) + 1; - temp.hLeft = Math.max(node.hLeft, node.hRight) + 1; - return temp; - } - - private NodeAVL rotateLL(NodeAVL node) { - NodeAVL temp = node.left; - node.left = temp.right; - temp.right = node; - if (node.left == null) - node.hLeft = 0; - else - node.hLeft = Math.max(node.left.hRight, node.left.hLeft) + 1; - temp.hRight = Math.max(node.hRight, node.hLeft) + 1; - return temp; - } - - private NodeAVL rotateRR(NodeAVL node) { - NodeAVL temp = node.right; - node.right = temp.left; - temp.left = node; - if (node.right == null) - node.hRight = 0; - else - node.hRight = Math.max(node.right.hRight, node.right.hLeft) + 1; - temp.hLeft = Math.max(node.hRight, node.hLeft) + 1; - return temp; - } - - private NodeAVL isRotate(NodeAVL node) { - // This Method see if there is nessesity for rotation and if - // there is need, it'll do suitable rotation - if (node.hRight - node.hLeft >= 2) { - if (node.right.hRight - node.right.hLeft >= 1) - node = rotateRR(node); - else if (node.right.hRight - node.right.hLeft <= -1) - node = rotateRL(node); - } else if (node.hRight - node.hLeft <= -2) { - if (node.left.hRight - node.left.hLeft <= -1) - node = rotateLL(node); - else if (node.left.hRight - node.left.hLeft >= 1) - node = rotateLR(node); - } - return node; - } - - public boolean isEmpty() { - return root == null; - } - - public void prntIn(NodeAVL node) { - if (node == null) - return; - else if (node.left == null && node.right == null) - System.out.print(node.data + " "); - else { - prntIn(node.left); - System.out.print(node.data + " "); - prntIn(node.right); - } - } - - public void delNode(NodeAVL node, int data) { - // These is the method to delete node if it exist - // Otherwise it throws an exception - if (root == null) { - throw new NoSuchElementException("AVL Tree is Empty!!!"); - } - if (root.data == data) { - NodeAVL temp = root.right; - if (root.left == null && root.right == null) - root = null; - else if (root.left == null) - root = root.right; - else if (temp == null) - root = root.left; - else { - int dta = 0; - if (root.right.left == null) { - root.right.left = root.left; - root = root.right; - } else { - dta = transverseLeftmost(temp); - root.data = dta; - } - if (root.right == null) - root.hRight = 0; - else - root.hRight = Math.max(root.right.hLeft, root.right.hLeft); - root = isRotate(root); - } - } - else if (node.right == null && node.left == null) { - throw new NoSuchElementException("element you wanna delete not exist"); - } - else if (node.right != null && node.right.data == data) { - NodeAVL del = node.right; - if (del.right == null && del.left == null) - node.right = null; - else if (del.left == null) - node.right = del.right; - else if (del.right == null) - node.right = del.left; - else { - NodeAVL temp = del.right; - if (temp.left == null) - node.right = node.right.right; - else - del.data = transverseLeftmost(temp); - del.hRight = Math.max(del.right.hLeft, del.right.hRight); - } - } else if (node.left != null && node.left.data == data) { - NodeAVL del = node.left; - if (del.right == null && del.left == null) - node.left = null; - else if (del.left == null) - node.left = del.right; - else if (del.right == null) - node.left = del.left; - else { - NodeAVL temp = del.right; - if (temp.left == null) - node.left = node.left.right; - del.data = transverseLeftmost(temp); - del.hRight = Math.max(del.right.hLeft, del.right.hRight); - } - } else if (node.data > data) { - delNode(node.left, data); - if (node.left == null) - node.hLeft = 0; - else - node.hLeft = Math.max(node.left.hLeft, node.left.hRight) + 1; - } else if (node.data < data) { - delNode(node.right, data); - if (node.right == null) - node.hRight = 0; - else - node.hRight = Math.max(node.right.hLeft, node.right.hRight) + 1; - } - node = isRotate(node); - } - - private int transverseLeftmost(NodeAVL node) { - // These method is special method which comes - // in play when we have to delete a node - // which have both childeren. - if (node.left.left == null) { - int data; - if (node.left != null) - data = node.left.data; - else - data = node.data; - node.left = null; - return data; - } - node = node.left; - int data = transverseLeftmost(node); - if (node.left == null) - node.hLeft = 0; - else - node.hLeft = Math.max(node.left.hLeft, node.left.hLeft); - node = isRotate(node); - return data; - } -} - -class NodeAVL { - protected int hLeft; - protected int hRight; - public int data; - public NodeAVL left; - public NodeAVL right; - - public NodeAVL(int data) { - hLeft = 0; - hRight = 0; - this.data = data; - left = null; - right = null; - } -} +import java.util.NoSuchElementException; +import java.util.Random; + +public class AvlTree { + + public static void main(String[] args) { + AVL avl = new AVL(); + Random rand = new Random(); + int inp = 10; + System.out.println(avl.isEmpty()); + for (int i = 0; i < inp; i++) { + avl.root = avl.insert(avl.root, rand.nextInt(100)); + } + avl.prntIn(avl.root); + System.out.println(" "); + System.out.println(avl.isEmpty()); + avl.delNode(avl.root,avl.root.data); + avl.prntIn(avl.root); + System.out.println(" "); + try { + avl.delNode(avl.root,1111); + } catch(NoSuchElementException e) { + System.out.println("Cannot delete element"); + } + } +} + +class AVL { + public NodeAVL root; + + public AVL(){ + root = null; + } + + public NodeAVL insert(NodeAVL node, int data) { + // These method takes care of rotation needed after insertion + if (node == null) { + node = new NodeAVL(data); + return node; + } else { + if (node.data > data) { + node.left = insert(node.left, data); + if (node.left == null) + node.hLeft = 0; + else + node.hLeft = Math.max(node.left.hLeft, node.left.hRight) + 1; + } else { + node.right = insert(node.right, data); + if (node.right == null) + node.hRight = 0; + else + node.hRight = Math.max(node.right.hLeft, node.right.hRight) + 1; + } + node = isRotate(node); + } + return node; + } + + private NodeAVL rotateLR(NodeAVL node) { + NodeAVL sec = node.left; + NodeAVL temp = sec.right; + node.left = temp; + sec.right = temp.left; + temp.left = sec; + node.left = temp.right; + temp.right = node; + if (node.left == null) + node.hLeft = 0; + else + node.hLeft = Math.max(node.left.hLeft, node.left.hRight) + 1; + if (sec.right == null) + sec.hRight = 0; + else + sec.hRight = Math.max(sec.right.hLeft, sec.right.hRight) + 1; + temp.hLeft = Math.max(sec.hLeft, sec.hRight) + 1; + temp.hRight = Math.max(node.hLeft, node.hRight) + 1; + return temp; + } + + private NodeAVL rotateRL(NodeAVL node) { + NodeAVL sec = node.right; + NodeAVL temp = sec.left; + node.right = temp; + sec.left = temp.right; + temp.right = sec; + node.right = temp.left; + temp.left = node; + if (node.right == null) + node.hRight = 0; + else + node.hRight = Math.max(node.right.hLeft, node.right.hRight) + 1; + if (sec.left == null) + sec.hLeft = 0; + else + sec.hLeft = Math.max(sec.left.hLeft, sec.left.hRight) + 1; + temp.hRight = Math.max(sec.hLeft, sec.hRight) + 1; + temp.hLeft = Math.max(node.hLeft, node.hRight) + 1; + return temp; + } + + private NodeAVL rotateLL(NodeAVL node) { + NodeAVL temp = node.left; + node.left = temp.right; + temp.right = node; + if (node.left == null) + node.hLeft = 0; + else + node.hLeft = Math.max(node.left.hRight, node.left.hLeft) + 1; + temp.hRight = Math.max(node.hRight, node.hLeft) + 1; + return temp; + } + + private NodeAVL rotateRR(NodeAVL node) { + NodeAVL temp = node.right; + node.right = temp.left; + temp.left = node; + if (node.right == null) + node.hRight = 0; + else + node.hRight = Math.max(node.right.hRight, node.right.hLeft) + 1; + temp.hLeft = Math.max(node.hRight, node.hLeft) + 1; + return temp; + } + + private NodeAVL isRotate(NodeAVL node) { + // This Method see if there is nessesity for rotation and if + // there is need, it'll do suitable rotation + if (node.hRight - node.hLeft >= 2) { + if (node.right.hRight - node.right.hLeft >= 1) + node = rotateRR(node); + else if (node.right.hRight - node.right.hLeft <= -1) + node = rotateRL(node); + } else if (node.hRight - node.hLeft <= -2) { + if (node.left.hRight - node.left.hLeft <= -1) + node = rotateLL(node); + else if (node.left.hRight - node.left.hLeft >= 1) + node = rotateLR(node); + } + return node; + } + + public boolean isEmpty() { + return root == null; + } + + public void prntIn(NodeAVL node) { + if (node == null) + return; + else if (node.left == null && node.right == null) + System.out.print(node.data + " "); + else { + prntIn(node.left); + System.out.print(node.data + " "); + prntIn(node.right); + } + } + + public void delNode(NodeAVL node, int data) { + // These is the method to delete node if it exist + // Otherwise it throws an exception + NodeAVL root = node; + if (root == null) { + throw new NoSuchElementException("AVL Tree is Empty!!!"); + } + if (root.data == data) { + NodeAVL temp = root.right; + if (root.left == null && root.right == null) + root = null; + else if (root.left == null) + root = root.right; + else if (temp == null) + root = root.left; + else { + int dta = 0; + if (root.right.left == null) { + root.right.left = root.left; + root = root.right; + } else { + dta = transverseLeftmost(temp); + root.data = dta; + } + if (root.right == null) + root.hRight = 0; + else + root.hRight = Math.max(root.right.hLeft, root.right.hLeft); + root = isRotate(root); + } + } + else if (node.right == null && node.left == null) { + throw new NoSuchElementException("element you wanna delete not exist"); + } + else if (node.right != null && node.right.data == data) { + NodeAVL del = node.right; + if (del.right == null && del.left == null) + node.right = null; + else if (del.left == null) + node.right = del.right; + else if (del.right == null) + node.right = del.left; + else { + NodeAVL temp = del.right; + if (temp.left == null) + node.right = node.right.right; + else + del.data = transverseLeftmost(temp); + del.hRight = Math.max(del.right.hLeft, del.right.hRight); + } + } else if (node.left != null && node.left.data == data) { + NodeAVL del = node.left; + if (del.right == null && del.left == null) + node.left = null; + else if (del.left == null) + node.left = del.right; + else if (del.right == null) + node.left = del.left; + else { + NodeAVL temp = del.right; + if (temp.left == null) + node.left = node.left.right; + del.data = transverseLeftmost(temp); + del.hRight = Math.max(del.right.hLeft, del.right.hRight); + } + } else if (node.data > data) { + delNode(node.left, data); + if (node.left == null) + node.hLeft = 0; + else + node.hLeft = Math.max(node.left.hLeft, node.left.hRight) + 1; + } else if (node.data < data) { + delNode(node.right, data); + if (node.right == null) + node.hRight = 0; + else + node.hRight = Math.max(node.right.hLeft, node.right.hRight) + 1; + } + node = isRotate(node); + } + + private int transverseLeftmost(NodeAVL node) { + // These method is special method which comes + // in play when we have to delete a node + // which have both childeren. + if (node.left.left == null) { + int data; + if (node.left != null) + data = node.left.data; + else + data = node.data; + node.left = null; + return data; + } + node = node.left; + int data = transverseLeftmost(node); + if (node.left == null) + node.hLeft = 0; + else + node.hLeft = Math.max(node.left.hLeft, node.left.hLeft); + node = isRotate(node); + return data; + } +} + +class NodeAVL { + protected int hLeft; + protected int hRight; + public int data; + public NodeAVL left; + public NodeAVL right; + + public NodeAVL(int data) { + hLeft = 0; + hRight = 0; + this.data = data; + left = null; + right = null; + } +} diff --git a/bin_sort/BinSort.java b/bin_sort/BinSort.java index c55ea126..78c1969e 100644 --- a/bin_sort/BinSort.java +++ b/bin_sort/BinSort.java @@ -1,75 +1,75 @@ -import java.util.Random; - -class Node { - public double data; - public Node next; - - public Node(double data) { - this.data = data; - next = null; - } -} - -// Time Complexity O(n)-> avg case and O(n^2)-> Worst Case -// constraints:- 0<=A[i]<1 -public class BinSort { - public static void binSort(Node[] b, double[] a) { - for (int i = 0; i < a.length; i++) { - int ins = (int) (a[i] * b.length); - if (b[ins] == null) { - b[ins] = new Node(a[i]); - } else { - boolean check = true; - Node temp = b[ins]; - while (temp.next != null) { - if (a[i] > temp.next.data) { - temp = temp.next; - } else { - if (a[i] < temp.data) - break; - Node newNode = new Node(a[i]); - newNode.next = temp.next; - temp.next = newNode; - check = false; - break; - } - } - if (check) { - if (a[i] >= temp.data) { - Node newNode = new Node(a[i]); - temp.next = newNode; - } else { - double loc = temp.data; - temp.data = a[i]; - Node newNode = new Node(loc); - newNode.next = temp.next; - temp.next = newNode; - } - } - } - } - int j = 0; - for (int i = 0; i < b.length; i++) { - while (b[i] != null) { - a[j++] = b[i].data; - b[i] = b[i].next; - } - } - } - - public static void main(String[] args) { - Node[] b = new Node[10]; - Random ran = new Random(); - int n = 100; - double[] a = new double[n]; - for (int i = 0; i < n; i++) { - a[i] = ran.nextDouble(); - } - binSort(b, a); - for (int i = 0; i < n; i++) { - System.out.print(a[i] + " "); - } - System.out.println(" "); - } -} - +import java.util.Random; + +class Node { + public double data; + public Node next; + + public Node(double data) { + this.data = data; + next = null; + } +} + +// Time Complexity O(n)-> avg case and O(n^2)-> Worst Case +// constraints:- 0<=A[i]<1 +public class BinSort { + public static void binSort(Node[] b, double[] a) { + for (int i = 0; i < a.length; i++) { + int ins = (int) (a[i] * b.length); + if (b[ins] == null) { + b[ins] = new Node(a[i]); + } else { + boolean check = true; + Node temp = b[ins]; + while (temp.next != null) { + if (a[i] > temp.next.data) { + temp = temp.next; + } else { + if (a[i] < temp.data) + break; + Node newNode = new Node(a[i]); + newNode.next = temp.next; + temp.next = newNode; + check = false; + break; + } + } + if (check) { + if (a[i] >= temp.data) { + Node newNode = new Node(a[i]); + temp.next = newNode; + } else { + double loc = temp.data; + temp.data = a[i]; + Node newNode = new Node(loc); + newNode.next = temp.next; + temp.next = newNode; + } + } + } + } + int j = 0; + for (int i = 0; i < b.length; i++) { + while (b[i] != null) { + a[j++] = b[i].data; + b[i] = b[i].next; + } + } + } + + public static void main(String[] args) { + Node[] b = new Node[10]; + Random ran = new Random(); + int n = 100; + double[] a = new double[n]; + for (int i = 0; i < n; i++) { + a[i] = ran.nextDouble(); + } + binSort(b, a); + for (int i = 0; i < n; i++) { + System.out.print(a[i] + " "); + } + System.out.println(" "); + } +} + diff --git a/binary_search/BinarySearch.java b/binary_search/BinarySearch.java index fd359618..f10ddd58 100644 --- a/binary_search/BinarySearch.java +++ b/binary_search/BinarySearch.java @@ -5,12 +5,12 @@ static int binarySearch(int[] arr, int searchElement) { int right = arr.length - 1; while (left <= right) { int mid = (left + right) / 2; - if (arr[mid] == searchElement) { // Element found + if (arr[mid] == searchElement) { // Element found return mid; } - if (arr[mid] < searchElement) { // Look in right half + if (arr[mid] < searchElement) { // Look in right half left = mid + 1; - } else { // Look in left half + } else { // Look in left half right = mid - 1; } } @@ -23,7 +23,7 @@ public static void main(String[] args) { int[] searchArr = new int[] {1, 35, 112, 324, 67}; int pos; for (int i = 0; i < searchArr.length; i++) { - pos = binarySearch(arr, searchArr[i]); //search key and get poistion + pos = binarySearch(arr, searchArr[i]); //search key and get poistion if (pos >= 0) { System.out.println(searchArr[i] + "-> found at index : " + pos); } else { diff --git a/binary_search/binarySearch.js b/binary_search/binarySearch.js new file mode 100644 index 00000000..dece598a --- /dev/null +++ b/binary_search/binarySearch.js @@ -0,0 +1,62 @@ +function binarySearchIterative (arr, item) { + /* + Performs a binary search iteratively + :param arr: List of elements to search from + :param item: Element to search for + :return: returns index if element found else -1 + */ + let begin = 0; + let end = arr.length - 1; + while (begin <= end) { + let mid = Math.floor((begin + end) / 2); + if (arr[mid] === item) { + return mid; + } else if (arr[mid] > item) { + end = mid - 1; + } else { + begin = mid + 1; + } + } + return -1; +} + +function binarySearchRecursive (arr, item, begin, end) { + /* + Performs a binary search recursively + :param arr: List of elements to search from + :param item: Element to search for + :param begin: Left limit of array + :param end: Right limit of array + :return: returns index if element found else -1 + */ + if (begin <= end) { + let mid = Math.floor((begin + end) / 2); + if (arr[mid] === item) { + return mid; + } else if (arr[mid] > item) { + return binarySearchRecursive(arr, item, begin, mid - 1); + } else { + return binarySearchRecursive(arr, item, mid + 1, end); + } + } else { + return -1; + } +} + +function main () { + let arr = [2, 5, 6, 7, 8, 9, 10]; + let item = 5; + if (binarySearchIterative(arr, item) === -1) { + console.log('Element is not found'); + } else { + console.log('Element is found'); + } + + if (binarySearchRecursive(arr, item, 0, arr.length - 1) === -1) { + console.log('Element is not found'); + } else { + console.log('Element is found'); + } +} + +main(); diff --git a/binary_search/binary_search.c b/binary_search/binary_search.c index 8fc87399..6a5b8b03 100644 --- a/binary_search/binary_search.c +++ b/binary_search/binary_search.c @@ -5,7 +5,7 @@ * @arr_size Size of array * @search_element Element to be searched */ - + /* function to perform recursive binary search * input parameters: * @ar - user-input array. @@ -15,24 +15,24 @@ */ int binary_search_recursive(const int *ar, int l, int r, int ele) { if (r >= l) { - + int mid = l + (r - l) / 2; //calculate mid point of the array - + // If the element is present at the middle itself - if (ar[mid] == ele) { - return mid; + if (ar[mid] == ele) { + return mid; } - + // If element is smaller than mid, then it can only be present // in left subarray - if (ar[mid] > ele) { + if (ar[mid] > ele) { return binary_search_recursive(ar, l, mid - 1, ele); } - + // Else the element can only be present in right subarray return binary_search_recursive(ar, mid + 1, r, ele); } - + // We reach here when element is not present in array return -1; } @@ -61,7 +61,7 @@ int main() { int i; for (i = 0 ; i < 5 ; i++) { - + int pos; pos = binary_search(arr, 6, search_arr[i]); if (pos >= 0) { @@ -69,7 +69,7 @@ int main() { } else { printf("%d not found.\n", search_arr[i]); } - + pos = binary_search_recursive(arr, 0, 5, search_arr[i]); if (pos >= 0) { printf("%d found at index %d, recursively\n", search_arr[i], pos); diff --git a/binary_search/binary_search.py b/binary_search/binary_search.py index 657d37de..71be4352 100644 --- a/binary_search/binary_search.py +++ b/binary_search/binary_search.py @@ -10,9 +10,9 @@ def binary_search(array, element): :return: returns value of index of element (if found) else return None """ left = 0 - right = len(array) + right = len(array) - 1 while left <= right: - mid = int((right + left) / 2) + mid = (right + left) // 2 # indices of a list must be integer if array[mid] == element: return mid @@ -33,9 +33,9 @@ def binary_search_recursive(array, element, left=0, right=None): :param element: element to be searched :return: returns value of index of element (if found) else return None """ - right = len(array) if right is None else right + right = len(array) - 1 if right is None else right if right >= left: - mid = int((right + left) / 2) + mid = (right + left) // 2 if array[mid] == element: return mid elif array[mid] > element: @@ -49,13 +49,9 @@ def binary_search_recursive(array, element, left=0, right=None): def main(): size = 100 # user can change it domain = 100 # user can change it - array = [randint(0, domain) for i in range(size)] - # print ("Array :", array) + array = [1, 9, 11, 13, 5, 7, 8, 5, 17, 1156, 114] array.sort() - # print("Sorted Array :", array) - element = randint(0, domain) - # i.e. a random element can be selected from domain - print('Element = ', element) + element = 13 result = binary_search_recursive(array, element) if result is None: print('Recursive Binary Search : Element not present in array') diff --git a/binary_search_tree/BinarySearchTree.java b/binary_search_tree/BinarySearchTree.java index c614ba45..68206eb7 100644 --- a/binary_search_tree/BinarySearchTree.java +++ b/binary_search_tree/BinarySearchTree.java @@ -1,183 +1,183 @@ import java.util.NoSuchElementException; class Node { // Node for Binary Search Tree - public int data; - public Node left; - public Node right; + public int data; + public Node left; + public Node right; - public Node(int data) { // Initializes node with given data and no chlid - this.data = data; - this.left = null; - this.right = null; - } + public Node(int data) { // Initializes node with given data and no chlid + this.data = data; + this.left = null; + this.right = null; + } } class BST { - private Node root; // Root of Binary Search Tree + private Node root; // Root of Binary Search Tree - public BST() { // Initializes empty BST - root = null; - } + public BST() { // Initializes empty BST + root = null; + } - public BST(int data) { // Initializes root of BST - root = new Node(data); - } + public BST(int data) { // Initializes root of BST + root = new Node(data); + } - public void insert(int data) { - if (root == null) { - root = new Node(data); // Initialize root with the given data - return; - } - Node newNode = new Node(data); // Create Node for new entry - Node iterator = root; // Temp Node for iterating from root to leaf - Node parent = null; // To store the future parent of new node - while (iterator != null) { - parent = iterator; - if (data <= iterator.data) { - iterator = iterator.left; - } - else { - iterator = iterator.right; - } - } - if (data <= parent.data) { - parent.left = newNode; - } - else { - parent.right = newNode; - } - } + public void insert(int data) { + if (root == null) { + root = new Node(data); // Initialize root with the given data + return; + } + Node newNode = new Node(data); // Create Node for new entry + Node iterator = root; // Temp Node for iterating from root to leaf + Node parent = null; // To store the future parent of new node + while (iterator != null) { + parent = iterator; + if (data <= iterator.data) { + iterator = iterator.left; + } + else { + iterator = iterator.right; + } + } + if (data <= parent.data) { + parent.left = newNode; + } + else { + parent.right = newNode; + } + } - public Node search(int data) { // Returns the Node if element is found else will throw an Exception - Node iterator = root; - while (iterator != null) { - if (iterator.data == data) - return iterator; - else if (data <= iterator.data) - iterator = iterator.left; - else - iterator = iterator.right; - } - throw new NoSuchElementException("Element is not found in BST"); - } + public Node search(int data) { // Returns the Node if element is found else will throw an Exception + Node iterator = root; + while (iterator != null) { + if (iterator.data == data) + return iterator; + else if (data <= iterator.data) + iterator = iterator.left; + else + iterator = iterator.right; + } + throw new NoSuchElementException("Element is not found in BST"); + } - public boolean delete(int data) { // Finds the parent of the node to be deleted. - if (root == null) { - throw new NoSuchElementException("Cannot perform delete operation, BST is empty"); - } - Node iterator = root; - Node parent = null; - while (iterator != null) { - if (data == iterator.data) { - return deleteNode(data, parent); - } else { - parent = iterator; - if (data <= iterator.data) - iterator = iterator.left; - else - iterator = iterator.right; - } - } - throw new NoSuchElementException("Delete Unsuccessful! Element was not found in BST"); - } + public boolean delete(int data) { // Finds the parent of the node to be deleted. + if (root == null) { + throw new NoSuchElementException("Cannot perform delete operation, BST is empty"); + } + Node iterator = root; + Node parent = null; + while (iterator != null) { + if (data == iterator.data) { + return deleteNode(data, parent); + } else { + parent = iterator; + if (data <= iterator.data) + iterator = iterator.left; + else + iterator = iterator.right; + } + } + throw new NoSuchElementException("Delete Unsuccessful! Element was not found in BST"); + } - private boolean deleteNode(int data, Node parent) { - Node child = null; - boolean position = false; // Indicates position of child wrt to parent, true is left child, false is right child - if (data <= parent.data) { - child = parent.left; - position = true; - } - else - child = parent.right; + private boolean deleteNode(int data, Node parent) { + Node child = null; + boolean position = false; // Indicates position of child wrt to parent, true is left child, false is right child + if (data <= parent.data) { + child = parent.left; + position = true; + } + else + child = parent.right; - if (child.left == child.right) { // Condition for leaf node - child = null; - if (position) - parent.left = null; - else - parent.right = null; - return true; - } else if (child.right == null) { // Condition for non-leaf with no right sub-tree - if (position) - parent.left = child.left; - else - parent.right = child.left; - child.left = null; - child = null; - return true; - } else if (child.left == null) { // Condition for non-leaf with no left sub-tree - if (position) - parent.left = child.right; - else - parent.right = child.right; - child.right = null; - child = null; - return true; - } - else { // Conditon when Node has both subtree avaliable - Node iterator = child.right; - Node parentOfIterator = null; - while(iterator.left != null) { // Finding the leftmost child of right sub-tree - parentOfIterator = iterator; - iterator = iterator.left; - } - child.data = iterator.data; - parentOfIterator.left = null; - iterator = null; - return true; - } - } + if (child.left == child.right) { // Condition for leaf node + child = null; + if (position) + parent.left = null; + else + parent.right = null; + return true; + } else if (child.right == null) { // Condition for non-leaf with no right sub-tree + if (position) + parent.left = child.left; + else + parent.right = child.left; + child.left = null; + child = null; + return true; + } else if (child.left == null) { // Condition for non-leaf with no left sub-tree + if (position) + parent.left = child.right; + else + parent.right = child.right; + child.right = null; + child = null; + return true; + } + else { // Conditon when Node has both subtree avaliable + Node iterator = child.right; + Node parentOfIterator = null; + while(iterator.left != null) { // Finding the leftmost child of right sub-tree + parentOfIterator = iterator; + iterator = iterator.left; + } + child.data = iterator.data; + parentOfIterator.left = null; + iterator = null; + return true; + } + } - public void printInOrder() { // Function to call inorder printing using root - if (root == null) - throw new NoSuchElementException("Cannot print! BST is empty"); - print(root); - System.out.println(""); - } + public void printInOrder() { // Function to call inorder printing using root + if (root == null) + throw new NoSuchElementException("Cannot print! BST is empty"); + print(root); + System.out.println(""); + } - private void print(Node iterator) { - if (iterator != null) { - print(iterator.left); - System.out.print(iterator.data + " "); - print(iterator.right); - } - } + private void print(Node iterator) { + if (iterator != null) { + print(iterator.left); + System.out.print(iterator.data + " "); + print(iterator.right); + } + } } public class BinarySearchTree { - public static void main(String[] args) { - // Created an empty tree - BST tree = new BST(); - // Adding a few test entries - tree.insert(10); - tree.insert(9); - tree.insert(3); - tree.insert(12); - tree.insert(14); - tree.insert(7); - tree.insert(6); - tree.insert(11); - tree.insert(1); - tree.insert(2); - // Test printing - tree.printInOrder(); - // Deleting a valid node - tree.delete(9); - // Print again - tree.printInOrder(); - // Searching an invalid node, same can be tested for delete as both use same logic - // but with a slight different approach to find the node - try { - tree.search(4); - System.out.println("Node was found successfully."); - } catch (NoSuchElementException e) { - System.out.println("Invalid Search"); - } - try { - tree.delete(9); - } catch (NoSuchElementException e) { - System.out.println("Cannot delete, Node not present."); - } - } + public static void main(String[] args) { + // Created an empty tree + BST tree = new BST(); + // Adding a few test entries + tree.insert(10); + tree.insert(9); + tree.insert(3); + tree.insert(12); + tree.insert(14); + tree.insert(7); + tree.insert(6); + tree.insert(11); + tree.insert(1); + tree.insert(2); + // Test printing + tree.printInOrder(); + // Deleting a valid node + tree.delete(9); + // Print again + tree.printInOrder(); + // Searching an invalid node, same can be tested for delete as both use same logic + // but with a slight different approach to find the node + try { + tree.search(4); + System.out.println("Node was found successfully."); + } catch (NoSuchElementException e) { + System.out.println("Invalid Search"); + } + try { + tree.delete(9); + } catch (NoSuchElementException e) { + System.out.println("Cannot delete, Node not present."); + } + } } diff --git a/coin_change_problem/CoinChange.java b/coin_change_problem/CoinChange.java new file mode 100644 index 00000000..ee9cf8e1 --- /dev/null +++ b/coin_change_problem/CoinChange.java @@ -0,0 +1,37 @@ +/* + * Implementation of famous dynamic programming problem + * that aims to find out the maximum number of ways in + * which a value can be achieved using some fixed valued + * coins. + * + * In the implementation, the time complexity is O(mn) + * and extra space required is O(n). + */ +import java.util.Arrays; +/* + * coin: Array containing value of coins + * n: Value to find the change for + */ +public class CoinChange { + public static int coinChangeProblem(int[] C, int n) { + int[] possibilities = new int[n+1]; + Arrays.fill(possibilities, 0); + possibilities[0] = 1; + // Build the possibilities table in bottom-up manner + // For all coins, + // Update array if the current coin is capable of + // incrementing the possibility + for (int i = 0; i < C.length; i++){ + for (int j = C[i]; j <= n; j++){ + possibilities[j] += possibilities[j - C[i]]; + } + } + return possibilities[n]; + } + + public static void main(String[] args) { + int[] coin = {2, 5, 3, 6}; + int n = 10; + System.out.println(coinChangeProblem(coin, n)); + } +} diff --git a/coin_change_problem/coinChangeProblem.js b/coin_change_problem/coinChangeProblem.js new file mode 100644 index 00000000..43bc25e7 --- /dev/null +++ b/coin_change_problem/coinChangeProblem.js @@ -0,0 +1,27 @@ +function coinChangeProblem (coins, amount) { + /* + * Find out maximum number of ways in which a amount can + * be obtained using fixed value coins. + * Time Complexity : O((type of coins)*amount) + * :param coins: Iterable of elements containing value of coins. + * :param amount: It is value which is to be obtained with coins. + * :return: returns maximum number of ways amount can be arranged in. + */ + let possibilities = new Array(amount + 1); + possibilities.fill(0); + possibilities[0] = 1; + for (let i = 0; i < coins.length; i++) { + for (let j = coins[i]; j <= amount; j++) { + possibilities[j] += possibilities[j - coins[i]]; + } + } + return possibilities[amount]; +} + +function main () { + let coins = [1, 2, 3]; + let amount = 10; + console.log(coinChangeProblem(coins, amount)); +} + +main(); diff --git a/coin_change_problem/coin_change_problem.py b/coin_change_problem/coin_change_problem.py new file mode 100644 index 00000000..ac6f4fbb --- /dev/null +++ b/coin_change_problem/coin_change_problem.py @@ -0,0 +1,26 @@ +def coin_change_problem(coins, amount): + """ + Find out maximum number of ways in which a amount can + be obtained using fixed value coins. + + Time Complexity : O((type of coins)*amount) + :param coins: Iterable of elements containing value of coins. + :param amount: It is value which is to be obtained with coins. + :return: returns maximum number of ways amount can be arranged in. + """ + possibilities = [0] * (amount + 1) + possibilities[0] = 1 + for i in coins: + for j in range(i, amount + 1): + possibilities[j] += possibilities[j - i] + return possibilities[amount] + + +def main(): + coins = [1, 2, 5] + amount = 10 + print(coin_change_problem(coins, amount)) + + +if __name__ == '__main__': + main() diff --git a/counting_sort/CountingSort.java b/counting_sort/CountingSort.java index de49dc46..5b9cdf34 100644 --- a/counting_sort/CountingSort.java +++ b/counting_sort/CountingSort.java @@ -1,33 +1,35 @@ import java.util.Random; -class CountingSort { //Time complexity = O(n) - private static void countOccurences(int[] a, int[] c) { //Basically counting occurences of particular number and store in its index - for (int i = 0; i < a.length; i++) //Counting occurence of each number - c[a[i]]++; - for(int i = 1; i < c.length; i++) //counting total number of numbers less then or equal to that number - c[i] = c[i-1] + c[i]; - } - public static int[] countingSort(int[] a, int k) { // For Sorting - int[] b = new int[a.length]; //b Array stores sorted array - int[] c = new int[k+1]; //array c count occurences - countOccurences(a, c); - for (int i = a.length-1; i >= 0; i--) { //storing number in ascending order in b - b[c[a[i]]-1] = a[i]; //Stores number to it respective position - c[a[i]]--; //Decrease c - } - return b; //Return sorted array - } - public static void main(String[] args) { - int[] A = new int[10000]; - int k = 0; - Random rand = new Random(); - for (int i = 0; i < A.length; i++) { - A[i] = rand.nextInt(100); - if(k < A[i]) //Every number must be between 0 to k - k = A[i]; //K is max number - } - A = countingSort(A, k); - for (int i = 0; i < A.length; i++) - System.out.print(A[i] + " "); - } +class CountingSort { //Time complexity = O(n) + private static void countOccurences(int[] a, int[] c) { //Basically counting occurences of particular number and store in its index + for (int i = 0; i < a.length; i++) //Counting occurence of each number + c[a[i]]++; + for(int i = 1; i < c.length; i++) //counting total number of numbers less then or equal to that number + c[i] = c[i-1] + c[i]; + } + + public static int[] countingSort(int[] a, int k) { // For Sorting + int[] b = new int[a.length]; //b Array stores sorted array + int[] c = new int[k+1]; //array c count occurences + countOccurences(a, c); + for (int i = a.length-1; i >= 0; i--) { //storing number in ascending order in b + b[c[a[i]]-1] = a[i]; //Stores number to it respective position + c[a[i]]--; //Decrease c + } + return b; //Return sorted array + } + + public static void main(String[] args) { + int[] A = new int[10000]; + int k = 0; + Random rand = new Random(); + for (int i = 0; i < A.length; i++) { + A[i] = rand.nextInt(100); + if (k < A[i]) //Every number must be between 0 to k + k = A[i]; //K is max number + } + A = countingSort(A, k); + for (int i = 0; i < A.length; i++) + System.out.print(A[i] + " "); + } } diff --git a/counting_sort/counting_sort.c b/counting_sort/counting_sort.c index 073bb3d3..22e016c9 100644 --- a/counting_sort/counting_sort.c +++ b/counting_sort/counting_sort.c @@ -1,38 +1,38 @@ /* Following algorithm sorts the input array in ascending order -* Time complexity is O(n+k) -* Auxiliary space is O(n+k) -* n is number of elements and k is the range of input -* max is the maximum element in array -*/ + * Time complexity is O(n+k) + * Auxiliary space is O(n+k) + * n is number of elements and k is the range of input + * max is the maximum element in array + */ #include #include void counting_sort(int arr[], int n, int max) { - // Function to sort input array arr. - int i; - int count[max + 1]; // Array to store count's of elements. - memset(count, 0, sizeof(count)); - int temp[n]; - for (i = 0; i < n; ++i) // Count the occurences of contents of array. - count[arr[i]]++; - for (i = 1; i <= max; ++i) - count[i] += count[i-1]; - for (i = 0; i < n; ++i) { // Sort the array according to occurences of elements. - temp[count[arr[i]] - 1] = arr[i]; - count[arr[i]]--; - } - for (i = 0; i < n; ++i) // Copy the sorted array back to original array. - arr[i] = temp[i]; + // Function to sort input array arr. + int i; + int count[max + 1]; // Array to store count's of elements. + memset(count, 0, sizeof(count)); + int temp[n]; + for (i = 0; i < n; ++i) // Count the occurences of contents of array. + count[arr[i]]++; + for (i = 1; i <= max; ++i) + count[i] += count[i-1]; + for (i = 0; i < n; ++i) { // Sort the array according to occurences of elements. + temp[count[arr[i]] - 1] = arr[i]; + count[arr[i]]--; + } + for (i = 0; i < n; ++i) // Copy the sorted array back to original array. + arr[i] = temp[i]; } int main() { - int i; - int max = 10; // max is the maximum number in the array - int arr[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; - int n = sizeof(arr) / sizeof(arr[0]); - counting_sort(arr, n, max); - for (i = 0; i < n; ++i) - printf("%d ", arr[i]); - return 0; + int i; + int max = 10; // max is the maximum number in the array + int arr[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; + int n = sizeof(arr) / sizeof(arr[0]); + counting_sort(arr, n, max); + for (i = 0; i < n; ++i) + printf("%d ", arr[i]); + return 0; } diff --git a/counting_sort/counting_sort.go b/counting_sort/counting_sort.go new file mode 100644 index 00000000..045550ac --- /dev/null +++ b/counting_sort/counting_sort.go @@ -0,0 +1,36 @@ +package main + +import "fmt" + +// CountingSort sorts the input array in ascending order +// Time complexity is O(z) where z = max(len(data), max(data)) +func CountingSort(data []int) { + size := len(data) + temp := make([]int, size) + max := 0 + for _, elem := range data { + if elem > max { + max = elem + } + } + count := make([]int, max+1) + for _, item := range data { + count[item]++ + } + for i := 1; i <= max; i++ { + count[i] += count[i-1] + } + for i := 0; i < size; i++ { + temp[count[data[i]]-1] = data[i] + count[data[i]]-- + } + for i := 0; i < size; i++ { + data[i] = temp[i] + } +} + +func main() { + data := []int{1, 202, 2, 675, 901, 116, 312, 1, 2} + CountingSort(data) + fmt.Println(data) +} diff --git a/depth_first_traversal/DepthFirstTraversal.java b/depth_first_traversal/DepthFirstTraversal.java index fe28c922..c3bc0623 100644 --- a/depth_first_traversal/DepthFirstTraversal.java +++ b/depth_first_traversal/DepthFirstTraversal.java @@ -2,23 +2,25 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.Set; +import java.util.ArrayList; + public class DepthFirstTraversal { - // Array of lists for Adjacency List Representation - public static LinkedList[] adj; + // ArrayList for Adjacency List Representation + public static ArrayList> adj; - //Function to add an edge into the DepthFirstTraversal + // Function to add an edge into the DepthFirstTraversal private static void addEdge(int v, int w) { - adj[v].add(w); + adj.get(v).add(w); } // A function used by DFS - private static void depthFirstTraversal(int v, Set visited) { - // Mark the current node as visited + private static void depthFirstTraversal(int v, Set visited) { + // Mark the current node as visited visited.add(v); System.out.println(v); - Iterator i = adj[v].listIterator(); + Iterator i = adj.get(v).listIterator(); while (i.hasNext()) { int n = i.next(); if (!visited.contains(n)) { @@ -29,15 +31,15 @@ private static void depthFirstTraversal(int v, Set visited) { public static void dfs(int v) { // false by default in java) - Set visited = new HashSet(); + Set visited = new HashSet(); // Call the recursive helper function to print DFS traversal depthFirstTraversal(v, visited); } public static void initEdges(int n) { - adj = new LinkedList[n]; + adj = new ArrayList>(); for (int i = 0; i < n; ++i) { - adj[i] = new LinkedList(); + adj.add(new LinkedList()); } } diff --git a/dijkstra/Dijkstra.java b/dijkstra/Dijkstra.java index d6c2258a..ea71dbec 100644 --- a/dijkstra/Dijkstra.java +++ b/dijkstra/Dijkstra.java @@ -1,11 +1,9 @@ -/** - Problem Statement: Implementation of Dijkstra Algorithm. - Time Complexity: O(|V|^2) - Space Complexity: O(|V|) for priority Queue. - - Matrix representation is used here. Linked List representation would reduce time complexity to O(Elog(V)), - if implemented using binary heaps. - +/* + * Problem Statement: Implementation of Dijkstra Algorithm. + * Time Complexity: O(|V|^2) + * Space Complexity: O(|V|) for priority Queue. + * Matrix representation is used here. Linked List representation would reduce time complexity to O(Elog(V)), + * if implemented using binary heaps. */ import java.util.Comparator; @@ -17,7 +15,7 @@ public class Dijkstra { public int[][] graph; public Node[] nodes; - + public static class Node { public Node parent; public int cost; @@ -29,7 +27,7 @@ public Node(Node parent, int cost, int id) { this.id = id; } } - + public Dijkstra() { graph = new int[][]{{0, 4, 0, 0, 0, 0, 0, 8, 0}, {4, 0, 8, 0, 0, 0, 0, 11, 0}, diff --git a/dijkstra/dijkstra.c b/dijkstra/dijkstra.c index 2aeb458e..99a5b5aa 100644 --- a/dijkstra/dijkstra.c +++ b/dijkstra/dijkstra.c @@ -1,8 +1,8 @@ /* -* Following implementation of dijsktra's algorithm prints the minimum distance from given source to destination using adjacency matrix. -* Time complexity : O(V^2). -* Space Complexity : O(V). -*/ + * Following implementation of dijsktra's algorithm prints the minimum distance from given source to destination using adjacency matrix. + * Time complexity : O(V^2). + * Space Complexity : O(V). + */ #include #include // For using INT_MAX @@ -16,7 +16,7 @@ int minimum_distance(const int min_distances[], const bool shortest_paths[]) { int i; int minimum = INFINITY, index; - for (int i = 0; i < VERTICES; ++i) { + for (i = 0; i < VERTICES; ++i) { if (!shortest_paths[i] && min_distances[i] <= minimum) { minimum = min_distances[i]; index = i; @@ -50,7 +50,7 @@ int dijkstra(const int graph[VERTICES][VERTICES], int souce, int destination) { int main() { int source = 0; int destination = 4; - int graph[VERTICES][VERTICES] = { + const int graph[VERTICES][VERTICES] = { {0, 4, 0, 0, 0, 0, 0, 8}, {4, 0, 8, 0, 0, 0, 0, 11}, {0, 8, 0, 7, 0, 4, 0, 0}, diff --git a/dijkstra/dijkstra.py b/dijkstra/dijkstra.py new file mode 100644 index 00000000..d901c4d0 --- /dev/null +++ b/dijkstra/dijkstra.py @@ -0,0 +1,75 @@ +""" +Dijktra's shortest path algorithm. Finds the path and distance from source to target. +To add an edge between vertex a and b with distance dist: + graph[a].append((b, dist)) and graph[b].append((a, dist)). +""" + + +import heapq + + +def dijkstra(graph, source, target): + """ + Finds the shortest path and shortest distance from source to target + + :param graph: Dictionary linking the vertices using list of tuples + :param source: The vertex to start the path. + :param target: The vertex to end the path. + :return: shortest path and distance from source to target + """ + INF = float('Inf') + predecessors = {x: x for x in graph} + distances = {x: INF for x in graph} + distances[source] = 0 + temp = [] + heapq.heappush(temp, [source, distances[source]]) + + while temp: + u = heapq.heappop(temp) + u_dist = u[1] + u_idx = u[0] + if u_dist == distances[u_idx]: + for v in graph[u_idx]: + v_idx = v[0] + u2v = v[1] + if distances[u_idx] + u2v < distances[v_idx]: + distances[v_idx] = distances[u_idx] + u2v + heapq.heappush(temp, [v_idx, distances[v_idx]]) + predecessors[v_idx] = u_idx + + if distances[target] == INF: + return None, None + else: + path = [] + vertex = target + while True: + path.append(str(vertex)) + if vertex == predecessors[vertex]: + break + vertex = predecessors[vertex] + return path[::-1], distances[target] + + +def main(): + """ + driver function to test the dijkstra's algorithm + """ + graph = {'s': [('a', 2), ('b', 1)], + 'a': [('s', 3), ('b', 4), ('c', 8)], + 'b': [('s', 4), ('a', 2), ('d', 2)], + 'c': [('a', 2), ('d', 7), ('t', 4)], + 'd': [('b', 1), ('c', 11), ('t', 5)], + 't': [('c', 3), ('d', 5)] + } + source = 'a' + target = 't' + path, cost = dijkstra(graph, source, target) + print('The path from ' + source + ' to ' + target + ' :') + if path is None or cost is None: + print('does not exist') + else: + print(str(path) + ' with cost: ' + str(cost)) + + +if __name__ == "__main__": + main() diff --git a/euclidean_gcd/EuclideanGCD.java b/euclidean_gcd/EuclideanGCD.java index 22796f0f..cc2f4551 100644 --- a/euclidean_gcd/EuclideanGCD.java +++ b/euclidean_gcd/EuclideanGCD.java @@ -1,14 +1,14 @@ /* -* first --> First number -* second --> Second number -* There are two implementations: -* Recursive(euclideanGCDRecursive) and Non-Recursive(euclideanGCD) -*/ + * first --> First number + * second --> Second number + * There are two implementations: + * Recursive(euclideanGCDRecursive) and Non-Recursive(euclideanGCD) + */ public class EuclideanGCD { static int euclideanGCD(int first, int second) { while(second != 0) { // Iterate till second becomes zero - int temp = second; // Temporary variable to hold value of second + int temp = second; // Temporary variable to hold value of second second = first % second; first = temp; } @@ -25,9 +25,9 @@ public static void main(String[] args) { int second = 5; int answerIterative = EuclideanGCD.euclideanGCD(first, second); int answerRecursive = EuclideanGCD.euclideanGCDRecursive(first, second); - System.out.printf("GCD of %d and %d is : %d by recursive algo.\n", first, + System.out.printf("GCD of %d and %d is : %d by recursive algo.\n", first, second, answerRecursive); - System.out.printf("GCD of %d and %d is : %d by iterative algo.\n", first, + System.out.printf("GCD of %d and %d is : %d by iterative algo.\n", first, second, answerIterative); } } diff --git a/euclidean_gcd/euclideanGCD.js b/euclidean_gcd/euclideanGCD.js new file mode 100644 index 00000000..c28c1fa0 --- /dev/null +++ b/euclidean_gcd/euclideanGCD.js @@ -0,0 +1,37 @@ +function euclideanGCDRecursive (first, second) { + /* + Calculates GCD of two numbers using Euclidean Recursive Algorithm + :param first: First number + :param second: Second number + :return: GCD of the numbers + */ + if (second === 0) { + return first; + } else { + return euclideanGCDRecursive(second, (first % second)); + } +} + +function euclideanGCDIterative (first, second) { + /* + Calculates GCD of two numbers using Euclidean Iterative Algorithm + :param first: First number + :param second: Second number + :return: GCD of the numbers + */ + while (second !== 0) { + let temp = second; + second = first % second; + first = temp; + } + return first; +} + +function main () { + let first = 20; + let second = 30; + console.log('Recursive GCD for %d and %d is %d', first, second, euclideanGCDRecursive(first, second)); + console.log('Iterative GCD for %d and %d is %d', first, second, euclideanGCDIterative(first, second)); +} + +main(); diff --git a/euclidean_gcd/euclidean_gcd.c b/euclidean_gcd/euclidean_gcd.c index 98e1f6df..491a08f6 100644 --- a/euclidean_gcd/euclidean_gcd.c +++ b/euclidean_gcd/euclidean_gcd.c @@ -1,32 +1,34 @@ #include /* -* first --> First number -* second --> Second number -* There are two implementations: Recursive (euclidean_gcd_recursive) and Non-Recursive (euclidean_gcd) -*/ + * first --> First number + * second --> Second number + * There are two implementations: Recursive (euclidean_gcd_recursive) and Non-Recursive (euclidean_gcd) + */ int euclidean_gcd_recursive(int first, int second) { - if(second == 0) - return first; // First becomes gcd if second becomes zero - else - return gcd_recursive(second, (first % second)); + if(second == 0) { + return first; // First becomes gcd if second becomes zero + } else { + return euclidean_gcd_recursive(second, (first % second)); + } } int euclidean_gcd(int first, int second) { - while(second != 0) { // Iterate till second becomes zero - int temp = second; // Temporary variable to hold value of second which is to be assigned to first later - second = first % second; - first = temp; - } - return first; // When second becomes 0, first becomes gcd of both + while(second != 0) { // Iterate till second becomes zero + int temp = second; // Temporary variable to hold value of second which is to be assigned to first later + second = first % second; + first = temp; + } + return first; // When second becomes 0, first becomes gcd of both } int main() { - int first = 49; - int second = 7; - int answer_recursive = euclidean_gcd_recursive(first, second); - int answer_iterative = euclidean_gcd(first, second); - printf("GCD of %d and %d is : %d by recursive algo.\n", first, second, answer_recursive); - printf("GCD of %d and %d is : %d by iterative algo.\n", first, second, answer_iterative); + int first = 49; + int second = 7; + int answer_recursive = euclidean_gcd_recursive(first, second); + int answer_iterative = euclidean_gcd(first, second); + printf("GCD of %d and %d is : %d by recursive algo.\n", first, second, answer_recursive); + printf("GCD of %d and %d is : %d by iterative algo.\n", first, second, answer_iterative); + return 0; } diff --git a/exponentation_by_squaring/exponentation_by_squaring.c b/exponentation_by_squaring/exponentation_by_squaring.c deleted file mode 100644 index 4f5cb318..00000000 --- a/exponentation_by_squaring/exponentation_by_squaring.c +++ /dev/null @@ -1,31 +0,0 @@ -#include - -/* Algorithm to calculate x raised to power k very efficiently -* Can be used as a great alternative to normal pow function -* base - base of the expression -* power - power of expression -*/ - -long double exponentation_by_squaring(long double base, int power) { - if (power < 0) // Negative power case - return exponentation_by_squaring(1 / base, -power); - else if (power == 0) // Base case1 - return 1; - else if (power == 1) // Base case2 - return base; - else if (power % 2 == 0) - return exponentation_by_squaring(base * base, power / 2); - else if (power % 2 == 1) - return base * exponentation_by_squaring(base * base, (power - 1) / 2); -} - -int main() { - long double base = 2; - int power = 31; - printf("%LG raised to %d is %LG\n", base, power, exponentation_by_squaring(base, power)); - - base = 2; - power = -2; - printf("%LG raised to %d is %LG\n", base, power, exponentation_by_squaring(base, power)); - return 0; -} diff --git a/exponentiation_by_squaring/ExponentiationBySquaring.java b/exponentiation_by_squaring/ExponentiationBySquaring.java new file mode 100644 index 00000000..5156ced8 --- /dev/null +++ b/exponentiation_by_squaring/ExponentiationBySquaring.java @@ -0,0 +1,27 @@ +/* Algorithm to calculate base raised to power power very efficiently +* Can be used as a great alternative to normal pow function +* base - base of the expression +* power - power of expression +*/ + +public class ExponentiationBySquaring { + public static double exponentiationBySquaring(double base, int power) { + if (power < 0) { // Negative powers + return exponentiationBySquaring(1.0 / base, -power); + } else if (power == 0) { // Base case 1 + return 1; + } else if (power == 1) { // Base case 2 + return base; + } else if (power % 2 == 0){ // Even powers + return exponentiationBySquaring(base * base, power / 2); + } else { // Odd powers + return base * exponentiationBySquaring(base * base, (power - 1) / 2); + } + } + + public static void main(String[] args) { + double base = 2; + int power = -1; + System.out.println(base + " raised to " + power + " is: " + exponentiationBySquaring(base, power)); + } +} diff --git a/exponentiation_by_squaring/exponentiationBySquaring.js b/exponentiation_by_squaring/exponentiationBySquaring.js new file mode 100644 index 00000000..61085071 --- /dev/null +++ b/exponentiation_by_squaring/exponentiationBySquaring.js @@ -0,0 +1,28 @@ +function exponentiationBySquaring (base, power) { + /* + Performs Exponentiation By Squaring. + :param base: Base of expression. + :param power: Power of expression. + :return: Returns (base ^ power). + */ + if (power < 0) { // When Power is Negative + return exponentiationBySquaring(1 / base, -power); + } else if (power === 0) { // Power = 0 (Base Case 1) + return 1; + } else if (power === 1) { // Power = 1 (Base Case 2) + return base; + } else if (power % 2 === 0) { // When Power is Even + return exponentiationBySquaring(base * base, power >> 1); + } else { // When Power is Odd + return base * exponentiationBySquaring(base * base, (power - 1) >> 1); + } +} + +function main () { + let base = 3; + let power = 6; + let res = exponentiationBySquaring(base, power); + console.log('%d\n', res); +} + +main(); diff --git a/exponentiation_by_squaring/exponentiation_by_squaring.c b/exponentiation_by_squaring/exponentiation_by_squaring.c new file mode 100644 index 00000000..4e455684 --- /dev/null +++ b/exponentiation_by_squaring/exponentiation_by_squaring.c @@ -0,0 +1,32 @@ +#include + +/* Algorithm to calculate x raised to power k very efficiently + * Can be used as a great alternative to normal pow function + * base - base of the expression + * power - power of expression + */ + +long double exponentation_by_squaring(long double base, int power) { + if (power < 0) { // Negative power case + return exponentation_by_squaring(1 / base, -power); + } else if (power == 0) { // Base case1 + return 1; + } else if (power == 1) { // Base case2 + return base; + } else if (power % 2 == 0) { + return exponentation_by_squaring(base * base, power / 2); + } else if (power % 2 == 1) { + return base * exponentation_by_squaring(base * base, (power - 1) / 2); + } +} + +int main() { + long double base = 2; + int power = 31; + printf("%LG raised to %d is %LG\n", base, power, exponentation_by_squaring(base, power)); + + base = 2; + power = -2; + printf("%LG raised to %d is %LG\n", base, power, exponentation_by_squaring(base, power)); + return 0; +} diff --git a/exponentiation_by_squaring/exponentiation_by_squaring.go b/exponentiation_by_squaring/exponentiation_by_squaring.go new file mode 100644 index 00000000..271123f0 --- /dev/null +++ b/exponentiation_by_squaring/exponentiation_by_squaring.go @@ -0,0 +1,23 @@ +package main + +import "fmt" + +// ExponentiationBySquaring calculates base^power efficiently. +func ExponentiationBySquaring(base int, power int) int { + if power < 0 { // Negative power case + return ExponentiationBySquaring((1 / base), -power) + } else if power == 0 { // Base case1 + return 1 + } else if power == 1 { // Base case2 + return base + } else if power%2 == 0 { + return ExponentiationBySquaring(base*base, power/2) + } else { + return base * ExponentiationBySquaring(base*base, (power-1)/2) + } +} + +func main() { + base, power := 5, 10 + fmt.Println(ExponentiationBySquaring(base, power)) +} diff --git a/exponentiation_by_squaring/exponentiation_by_squaring.py b/exponentiation_by_squaring/exponentiation_by_squaring.py new file mode 100644 index 00000000..cad91cd2 --- /dev/null +++ b/exponentiation_by_squaring/exponentiation_by_squaring.py @@ -0,0 +1,31 @@ +def exponentation_by_squaring(base, power): + """ + Calculates base ^ power using recursion, efficient algorithm to inbuilt pow() function + :param base: Base of expression + :param power: Power of expression + :return: returns base ^ power + """ + + if power < 0: # Negative powers + return exponentation_by_squaring(1. / base, -power) + elif power == 0: # Base case + return 1 + elif power % 2 == 0: + return exponentation_by_squaring(base * base, power // 2) + elif power % 2 == 1: + return base * exponentation_by_squaring(base * base, (power - 1) // 2) + + +def main(): + """ + driver function to calculate base ^ power + """ + + base = 2 + power = 3 + print(str(base) + ' raised to ' + str(power) + ' is ' + + str(exponentation_by_squaring(base, power))) + + +if __name__ == '__main__': + main() diff --git a/floyd_warshall/FloydWarshall.java b/floyd_warshall/FloydWarshall.java new file mode 100644 index 00000000..7c09bb0a --- /dev/null +++ b/floyd_warshall/FloydWarshall.java @@ -0,0 +1,68 @@ +import java.util.*; +import java.lang.*; +import java.io.*; + + +class FloydWarshall { + final static int INF = 99999, V = 4; + + void floydWarshall(int graph[][]) { + int dist[][] = new int[V][V]; + int i, j, k; + + // Initialize the Solution Matrix as Input Graph MAtrix + for (i = 0; i < V; i++) + for (j = 0; j < V; j++) + dist[i][j] = graph[i][j]; + + /* Add all vertices one by one to the set of intermediate + * vertices. + * + * Before start of a iteration, we have {0, 1, 2, .. k-1} as intermediate vertices. + * + * After the end of a iteration, k is added to the set of intermediate vertices and the set + * becomes {0, 1, 2, .. k} + */ + for (k = 0; k < V; k++) { + // Pick all vertices as source one by one + for (i = 0; i < V; i++) { + // Pick all vertices as destination + for (j = 0; j < V; j++) { + // If vertex k is on the shortest path from i to j, then update the value of dist[i][j] + if (dist[i][k] + dist[k][j] < dist[i][j]) { + dist[i][j] = dist[i][k] + dist[k][j]; + } + } + } + } + + // Print the shortest distance matrix + printSolution(dist); + } + + void printSolution(int dist[][]) { + System.out.println("Solution Matrix for shortest path b/w each pair or vertices:"); + for (int i=0; i arr[largest]) // Left child is greater than parent - largest = left; - if (right < size && arr[right] > arr[largest]) // Right child is greater than parent - largest = right; - if (largest != parent) { // If parent is largest then subtree is max-heap - int temp = arr[parent]; - arr[parent] = arr[largest]; // Swap largest child with parent - arr[largest] = temp; - maxHeapify(arr, size, largest); // Convert upper subtree to max-heap - } - } + public static void maxHeapify(int[] arr, int size, int parent) { // Build max-heap of subtree of parent index + int left = 2 * parent; + int right = left + 1; + int largest = parent; // Initially considering parent as largest + if (left < size && arr[left] > arr[largest]) // Left child is greater than parent + largest = left; + if (right < size && arr[right] > arr[largest]) // Right child is greater than parent + largest = right; + if (largest != parent) { // If parent is largest then subtree is max-heap + int temp = arr[parent]; + arr[parent] = arr[largest]; // Swap largest child with parent + arr[largest] = temp; + maxHeapify(arr, size, largest); // Convert upper subtree to max-heap + } + } - public static void heapSort(int[] arr) { - for (int i = arr.length / 2 - 1; i >= 0; --i) - maxHeapify(arr, arr.length, i); // Create max-heap + public static void heapSort(int[] arr) { + for (int i = arr.length / 2 - 1; i >= 0; --i) + maxHeapify(arr, arr.length, i); // Create max-heap - for (int i = arr.length - 1; i >= 0; --i) { - int temp = arr[0]; // Swap first and last element - arr[0] = arr[i]; - arr[i] = temp; - maxHeapify(arr, i, 0); // Create Max-Heap on reduced array - } - } + for (int i = arr.length - 1; i >= 0; --i) { + int temp = arr[0]; // Swap first and last element + arr[0] = arr[i]; + arr[i] = temp; + maxHeapify(arr, i, 0); // Create Max-Heap on reduced array + } + } - public static void main(String[] args) { - int[] arr = new int[] {10, 4, 3, 13, 1, 123}; // Creating Test array + public static void main(String[] args) { + int[] arr = new int[] {10, 4, 3, 13, 1, 123}; // Creating Test array - heapSort(arr); // Sort the array - for (int element : arr) // Printing sorted array - System.out.print(element + " "); - } + heapSort(arr); // Sort the array + for (int element : arr) // Printing sorted array + System.out.print(element + " "); + } } diff --git a/heap_sort/heap_sort.c b/heap_sort/heap_sort.c index 9a835d06..0a14411f 100644 --- a/heap_sort/heap_sort.c +++ b/heap_sort/heap_sort.c @@ -8,53 +8,56 @@ // root = index root of the subtree, a is an array, heapsize = size of heap void max_heapify(int a[], int root, int heapsize) { - int largest = root; - int l = (2 * root) + 1; // left child - int r = (2 * root) + 2; // Right child - // Check if left child is larger than root. - if ((l < heapsize) && (a[l] > a[root])) - largest = l; - // Check if right child is larger than largest. - if ((r < heapsize) && (a[r] > a[largest])) - largest = r ; - // If root is not the largest. - if (largest != root) { - int tmp = a[root]; - a[root] = a[largest]; - a[largest] = tmp; - max_heapify(a, largest, heapsize); - } + int largest = root; + int l = (2 * root) + 1; // left child + int r = (2 * root) + 2; // Right child + // Check if left child is larger than root. + if ((l < heapsize) && (a[l] > a[root])) { + largest = l; + } + // Check if right child is larger than largest. + if ((r < heapsize) && (a[r] > a[largest])) { + largest = r ; + } + // If root is not the largest. + if (largest != root) { + int tmp = a[root]; + a[root] = a[largest]; + a[largest] = tmp; + max_heapify(a, largest, heapsize); + } } // a is the array. void heap_sort(int a[], int heapsize) { - int i; - // Building max heap. - for (i = (heapsize / 2) - 1; i >= 0; i--) { - max_heapify(a, i, heapsize); - } - // One by one extract an element from heap - for (i = heapsize - 1; i > 0; i--) { - int tmp = a[i]; - a[i] = a[0]; - a[0] = tmp; - heapsize--; - // Again build max heap with the reduced array. - max_heapify(a, 0, heapsize); - } + int i; + // Building max heap. + for (i = (heapsize / 2) - 1; i >= 0; i--) { + max_heapify(a, i, heapsize); + } + // One by one extract an element from heap + for (i = heapsize - 1; i > 0; i--) { + int tmp = a[i]; + a[i] = a[0]; + a[0] = tmp; + heapsize--; + // Again build max heap with the reduced array. + max_heapify(a, 0, heapsize); + } } int main() { - int i, r; - // Unsorted data - int a[] = {10000, -999, 240, 1111111, 3, 2, 452, -65}; - int size = sizeof(a) / sizeof(a[0]); - // Calling heap_sort function - heap_sort(a, size); - printf("After Sorting:\t"); + int i, r; + // Unsorted data + int a[] = {10000, -999, 240, 1111111, 3, 2, 452, -65}; + int size = sizeof(a) / sizeof(a[0]); + // Calling heap_sort function + heap_sort(a, size); + printf("After Sorting:\t"); - for (i = 0; i < size; i++) - printf("%d ", a[i]); + for (i = 0; i < size; i++) { + printf("%d ", a[i]); + } - return 0; + return 0; } diff --git a/insertion_sort/InsertionSort.java b/insertion_sort/InsertionSort.java index 74708d9d..7d8b2e0a 100644 --- a/insertion_sort/InsertionSort.java +++ b/insertion_sort/InsertionSort.java @@ -1,27 +1,27 @@ public class InsertionSort { - - private static void insertionSort(int[] arr) { - for (int i = 1; i < arr.length; i++) { - int j = i - 1; - int key = arr[i]; // Element to be compared - /* Move elements of arr[0...i-1], that are - greater than key, to one position ahead - of their current position */ - while(j >= 0 && arr[j] > key) { - arr[j+1] = arr[j]; - j--; - } - arr[j+1] = key; // Putting key to the position where all numbers before it are sorted - } - } - - public static void main(String[] args) { - int[] arr = {12, 11, 13, 5, 6}; - insertionSort(arr); - - for (int x: arr) { // Printing sorted array - System.out.print(x+" "); - } - } + private static void insertionSort(int[] arr) { + for (int i = 1; i < arr.length; i++) { + int j = i - 1; + int key = arr[i]; // Element to be compared + + /* Move elements of arr[0...i-1], that are + greater than key, to one position ahead + of their current position */ + while(j >= 0 && arr[j] > key) { + arr[j+1] = arr[j]; + j--; + } + arr[j+1] = key; // Putting key to the position where all numbers before it are sorted + } + } + + public static void main(String[] args) { + int[] arr = {12, 11, 13, 5, 6}; + insertionSort(arr); + + for (int x: arr) { // Printing sorted array + System.out.print(x+" "); + } + } } diff --git a/insertion_sort/insertion_sort.c b/insertion_sort/insertion_sort.c index e80272c7..910e1699 100644 --- a/insertion_sort/insertion_sort.c +++ b/insertion_sort/insertion_sort.c @@ -1,35 +1,35 @@ /* -* arr - array to be sorted -* arr_size - size of array -*/ + * arr - array to be sorted + * arr_size - size of array + */ #include - + void insertion_sort(int *arr, int arr_size) { - int i, key, j; - for (i = 1; i < arr_size; i++) { - key = arr[i]; - j = i - 1; - - /* Move elements of arr[0...i-1], that are - greater than key, to one position ahead - of their current position */ - while (j >= 0 && arr[j] > key) { - arr[j+1] = arr[j]; - j--; - } - arr[j+1] = key; - } + int i, key, j; + for (i = 1; i < arr_size; i++) { + key = arr[i]; + j = i - 1; + /* Move elements of arr[0...i-1], that are + greater than key, to one position ahead + of their current position */ + while (j >= 0 && arr[j] > key) { + arr[j+1] = arr[j]; + j--; + } + arr[j+1] = key; + } } - + int main() { - int arr[] = {12, 11, 13, 5, 6}; - int arr_size = sizeof(arr) / sizeof(arr[0]); - int i; - - insertion_sort(arr, arr_size); + int arr[] = {12, 11, 13, 5, 6}; + int arr_size = sizeof(arr) / sizeof(arr[0]); + int i; + + insertion_sort(arr, arr_size); - for (i = 0; i < arr_size; i++) // Printing the sorted array - printf("%d ", arr[i]); - printf("\n"); - return 0; + for (i = 0; i < arr_size; i++) { // Printing the sorted array + printf("%d ", arr[i]); + } + printf("\n"); + return 0; } diff --git a/largest_sum_contiguous_subarray/LargestSumContiguousSubarray.java b/largest_sum_contiguous_subarray/LargestSumContiguousSubarray.java index c61334ce..74b08eed 100644 --- a/largest_sum_contiguous_subarray/LargestSumContiguousSubarray.java +++ b/largest_sum_contiguous_subarray/LargestSumContiguousSubarray.java @@ -1,32 +1,32 @@ -/* +/* * Implementation of famous dynamic programming problem * Largest Sum Contiguous Subarray - * Kadane Algorithm + * Kadane Algorithm * Time complexity O(n) */ public class LargestSumContiguousSubarray { - public static int largestSumContiguousSubarray(int[] array) { // maximum sum method implemention - int prevSum; - int currentSum; - int i; - prevSum = array[0]; // initialize current sum amd previous sum - currentSum = array[0]; - for (i = 1; i < array.length; i++) { - currentSum += array[i]; // add values in current sum - if (currentSum < 0) { // if current sum is negative , make it zero - currentSum = 0; - } else if (currentSum > prevSum) { // if current sum is greate than previous sum - prevSum = currentSum; // update previous sum - } - } - return prevSum; - } + public static int largestSumContiguousSubarray(int[] array) { // maximum sum method implemention + int prevSum; + int currentSum; + int i; + prevSum = array[0]; // initialize current sum amd previous sum + currentSum = array[0]; + for (i = 1; i < array.length; i++) { + currentSum += array[i]; // add values in current sum + if (currentSum < 0) { // if current sum is negative , make it zero + currentSum = 0; + } else if (currentSum > prevSum) { // if current sum is greate than previous sum + prevSum = currentSum; // update previous sum + } + } + return prevSum; + } - public static void main(String[] args) { - - int[] array = new int[] {-2, 1, -3, 4, -1, 2, 1, -5, 4}; - System.out.println("Largest Sum of Contiguous Subarray:" + "\t" + largestSumContiguousSubarray(array)); - } + public static void main(String[] args) { + + int[] array = new int[] {-2, 1, -3, 4, -1, 2, 1, -5, 4}; + System.out.println("Largest Sum of Contiguous Subarray:" + "\t" + largestSumContiguousSubarray(array)); + } } diff --git a/largest_sum_contiguous_subarray/largest_sum_contiguous_subarray.py b/largest_sum_contiguous_subarray/largest_sum_contiguous_subarray.py new file mode 100644 index 00000000..91a7e359 --- /dev/null +++ b/largest_sum_contiguous_subarray/largest_sum_contiguous_subarray.py @@ -0,0 +1,23 @@ +def largest_sum_contiguous_subarray(arr): + """ + Find the subarray with maximum sum from all subarrays. + + :param arr: List of numbers to form subarray from. + :return: The maximum sum in all subarrays. + """ + max_now = 0 + max_next = 0 + for i in arr: + max_next += i + max_now = max(max_next, max_now) + max_next = max(0, max_next) + return max_now + + +def main(): + arr = [-2, -3, 4, -1, -2, 1, 5, -3] + print('Maximum contiguous sum is', largest_sum_contiguous_subarray(arr)) + + +if __name__ == '__main__': + main() diff --git a/linear_search/LinearSearch.java b/linear_search/LinearSearch.java index 03440d1f..bb544119 100644 --- a/linear_search/LinearSearch.java +++ b/linear_search/LinearSearch.java @@ -1,30 +1,30 @@ /* -* Linear Search algorithm searches for a given number in array -* Time complexity is O(n) , n is size of array -*/ + * Linear Search algorithm searches for a given number in array + * Time complexity is O(n) , n is size of array + */ public class LinearSearch { - public static int linearSearch(int[] arr, int searchElement) { - for(int i = 0; i < arr.length; i++) { - if(arr[i] == searchElement) - return i; // Element found - } - return -1; // Element not found - } + public static int linearSearch(int[] arr, int searchElement) { + for(int i = 0; i < arr.length; i++) { + if(arr[i] == searchElement) + return i; // Element found + } + return -1; // Element not found + } - public static void main(String[] args) { - int[] array = new int[100]; - // Initializing array with 1,2,....,100 - for(int i = 1; i <= 100; i++) - array[i-1] = i; - // Elements to be searched in the array - int[] search = {12,55,34,102,78}; - for(int i = 0; i < 5; i++) { - int index = linearSearch(array, search[i]); - if(index >= 0) - System.out.println(search[i] + " found at index " + index); - else - System.out.println(search[i] + " not found in the list"); - } - } + public static void main(String[] args) { + int[] array = new int[100]; + // Initializing array with 1,2,....,100 + for(int i = 1; i <= 100; i++) + array[i-1] = i; + // Elements to be searched in the array + int[] search = {12,55,34,102,78}; + for(int i = 0; i < 5; i++) { + int index = linearSearch(array, search[i]); + if(index >= 0) + System.out.println(search[i] + " found at index " + index); + else + System.out.println(search[i] + " not found in the list"); + } + } } diff --git a/linear_search/linearSearch.js b/linear_search/linearSearch.js new file mode 100644 index 00000000..7321a5fa --- /dev/null +++ b/linear_search/linearSearch.js @@ -0,0 +1,29 @@ +function linearSearch (arr, x) { + /* + Performs a linear search + :param arr: List of elements to search from + :param x: Element to search for + :return: Index if element found else -1 + */ + for (let it = 0; it < arr.length; it++) { + if (x === arr[it]) { + return it; + } + } + return -1; +} + +function main () { + let data = []; + for (let i = 1; i <= 100; i++) { + data.push(i); + } + let index = linearSearch(data, 12); + if (index === -1) { + console.log('Element was not found'); + } else { + console.log('Element was found at %dth index', index); + } +} + +main(); diff --git a/linear_search/linear_search.c b/linear_search/linear_search.c index cbb790eb..e150b10b 100644 --- a/linear_search/linear_search.c +++ b/linear_search/linear_search.c @@ -1,10 +1,10 @@ #include /* -* Algorithm to find a given number in an array -* *arr : given array to search in -* search_element : Element to be searched -* size : size of array -*/ + * Algorithm to find a given number in an array + * *arr : given array to search in + * search_element : Element to be searched + * size : size of array + */ int linear_search(const int *arr, int size, int search_element) { int i; for (i = 0; i < size; i++) { diff --git a/linked_list/LinkedList.java b/linked_list/LinkedList.java index 2eb21288..014f9fa9 100644 --- a/linked_list/LinkedList.java +++ b/linked_list/LinkedList.java @@ -1,17 +1,17 @@ /* -* Following is the code for Linked List -* T defines the type of Linked List to be created -*/ + * Following is the code for Linked List + * T defines the type of Linked List to be created + */ import java.util.NoSuchElementException; -// Class to create a Node that contains data and pointer to next Node +// Class to create a Node that contains data and pointer to next Node class Node { public T data; // Data of type T public Node next; // Pointer to next Node // Constructor to create a Node - public Node(T input) { + public Node(T input) { this.data = input; this.next = null; } @@ -19,87 +19,87 @@ public Node(T input) { // Class containing methods to be performed on Linked List class LinkedList { - + private Node head; // Pointer to first node of the Linked List private int sizeOfList = 0; // Size of the Linked List - + // Constructor to create an empty Linked List - public LinkedList() { + public LinkedList() { head = null; } - + // Method to add an element to the start of the Linked List public void addFront(T input) { - Node newNode = new Node(input); - newNode.next = head; - head = newNode; - sizeOfList++; + Node newNode = new Node(input); + newNode.next = head; + head = newNode; + sizeOfList++; } - + // Method to add an element to the end of the Linked List public void addLast(T input) { - if (head == null) { + if (head == null) { Node newNode = new Node(input); head = newNode; sizeOfList = 1; } else { - Node temp = head; + Node temp = head; while (temp.next != null) - temp = temp.next; + temp = temp.next; Node newNode = new Node(input); - temp.next = newNode; + temp.next = newNode; sizeOfList++; } } - + // Method to add an element at a given index public void add(T input, int index) { - if (index < 0 || index > sizeOfList) - throw new IndexOutOfBoundsException("Invalid Index"); + if (index < 0 || index > sizeOfList) + throw new IndexOutOfBoundsException("Invalid Index"); Node temp = head; if (index == 0) addFront(input); else { - for (int i = 0; i < index-1; i++) + for (int i = 0; i < index-1; i++) temp = temp.next; Node newNode = new Node(input); - newNode.next = temp.next; - temp.next = newNode; + newNode.next = temp.next; + temp.next = newNode; sizeOfList++; } } - + // Method to remove the front element from the Linked List public T removeFront() { - if (isEmpty()) + if (isEmpty()) throw new NoSuchElementException(); - T removedElement = head.data; - head = head.next; + T removedElement = head.data; + head = head.next; sizeOfList--; return removedElement; } - + // Method to remove the last element from the Linked List public T removeLast() { if (isEmpty()) throw new NoSuchElementException(); T removedElement; - if (head.next == null) { + if (head.next == null) { removedElement = head.data; head = null; } - else { + else { Node temp = head; - while (temp.next.next != null) + while (temp.next.next != null) temp = temp.next; - removedElement = temp.next.data; - temp.next = null; + removedElement = temp.next.data; + temp.next = null; } sizeOfList--; return removedElement; } - + // Method to remove element at specific index from the Linked List public T remove(int index) { if (isEmpty()) @@ -108,28 +108,28 @@ public T remove(int index) { throw new IndexOutOfBoundsException("Invalid Index"); if (index > 0) { Node temp = head; - for (int i = 0; i < index-1; i++) - temp = temp.next; - T removedElement = temp.next.data; - temp.next = temp.next.next; + for (int i = 0; i < index-1; i++) + temp = temp.next; + T removedElement = temp.next.data; + temp.next = temp.next.next; sizeOfList--; return removedElement; } return removeFront(); - } - + } + // Method to search a element in the Linked List returns its index i public int search(T input) { Node temp = head; for (int i = 0; i < sizeOfList; i++) { if (temp.data == input) - return i; + return i; else temp = temp.next; } return -1; // Will return -1 if not found } - + // Method to display the Linked List public void display() { Node temp = head; @@ -142,12 +142,12 @@ public void display() { System.out.print("\b\b]\n"); } } - + // Method to display the size of Linked List public int size() { return sizeOfList; } - + // Method to check whether the Linked List is empty public boolean isEmpty() { return sizeOfList == 0; @@ -156,25 +156,25 @@ public boolean isEmpty() { public static void main(String[] args) { LinkedList list = new LinkedList(); // Creating an empty Linked List - + // Adding element to the list list.addFront(3); list.display(); - + // Adding elements at the end list.addLast(5); list.addLast(6); list.display(); - + // Adding elements to front list.addFront(2); list.addFront(1); list.display(); - + // Adding element at a given index (Adding 4 at index 3) list.add(4, 3); list.display(); - + // Removing First Element list.removeFront(); list.display(); @@ -182,18 +182,18 @@ public static void main(String[] args) { // Removing Last Element list.removeLast(); list.display(); - + // Removing an element from a index list.remove(2); list.display(); - + // Searching for an element in the Linked List int found = list.search(5); if (found >= 0) System.out.println("Element found at index: " + list.search(5)); else System.out.println("Element not found"); - + // Checking size of list and whether it is empty if (list.isEmpty()) System.out.println("List is empty"); @@ -212,4 +212,4 @@ public static void main(String[] args) { } } } - \ No newline at end of file + diff --git a/longest_common_subsequence/LongestCommonSubsequence.java b/longest_common_subsequence/LongestCommonSubsequence.java index cefc6050..275202a8 100644 --- a/longest_common_subsequence/LongestCommonSubsequence.java +++ b/longest_common_subsequence/LongestCommonSubsequence.java @@ -1,41 +1,41 @@ public class LongestCommonSubsequence { - //Function that returns Longest Common Subsequence of two strings - //Time Complexity - O( len(str1) * len(str2) ) - //Space Complexity - O( len(str1)*len(str2) ) - private static String longestCommonSubsequence(String str1, String str2) { - int[][] arr = new int[str1.length() + 1][str2.length() + 1]; - for (int i = str1.length() - 1; i >= 0; i--) { - for (int j = str2.length() - 1; j >= 0; j--) { - if (str1.charAt(i) == str2.charAt(j)) { - arr[i][j] = arr[i + 1][j + 1] + 1; - } - else { - arr[i][j] = Math.max(arr[i + 1][j], arr[i][j + 1]); - } - } - } - String res = ""; - int i = 0; - int j = 0; - while (i < str1.length() && j < str2.length()) { - if (str1.charAt(i) == str2.charAt(j)) { - res = res + str1.charAt(i); - i++; - j++; - } - else if (arr[i + 1][j] >= arr[i][j + 1]) { - i++; - } - else { - j++; - } - } - return res; - } + //Function that returns Longest Common Subsequence of two strings + //Time Complexity - O( len(str1) * len(str2) ) + //Space Complexity - O( len(str1)*len(str2) ) + private static String longestCommonSubsequence(String str1, String str2) { + int[][] arr = new int[str1.length() + 1][str2.length() + 1]; + for (int i = str1.length() - 1; i >= 0; i--) { + for (int j = str2.length() - 1; j >= 0; j--) { + if (str1.charAt(i) == str2.charAt(j)) { + arr[i][j] = arr[i + 1][j + 1] + 1; + } + else { + arr[i][j] = Math.max(arr[i + 1][j], arr[i][j + 1]); + } + } + } + String res = ""; + int i = 0; + int j = 0; + while (i < str1.length() && j < str2.length()) { + if (str1.charAt(i) == str2.charAt(j)) { + res = res + str1.charAt(i); + i++; + j++; + } + else if (arr[i + 1][j] >= arr[i][j + 1]) { + i++; + } + else { + j++; + } + } + return res; + } - public static void main(String[] args) { - String s1 = "applebanana"; - String s2 = "alphabet"; - System.out.println(longestCommonSubsequence(s1, s2)); - } + public static void main(String[] args) { + String s1 = "applebanana"; + String s2 = "alphabet"; + System.out.println(longestCommonSubsequence(s1, s2)); + } } diff --git a/longest_common_subsequence/longestCommonSubsequence.c b/longest_common_subsequence/longestCommonSubsequence.c index f0cdc48b..4b05fa40 100755 --- a/longest_common_subsequence/longestCommonSubsequence.c +++ b/longest_common_subsequence/longestCommonSubsequence.c @@ -6,32 +6,33 @@ // Function that computes the longest common subsequence // Complexity: O( len(string1) * len(string2) ) int longestCommonSubsequence(char *string1, char *string2) { - int len1 = (int) strlen(string1); - int len2 = (int) strlen(string2); - int lcs[len1 + 1][len2 + 1]; + int len1 = (int) strlen(string1); + int len2 = (int) strlen(string2); + int lcs[len1 + 1][len2 + 1]; - for (int i = 0; i <= len1; ++i) { - for (int j = 0; j <= len2; ++j) { - if (i == 0 || j == 0) - lcs[i][j] = 0; - else if (string1[i - 1] == string2[j - 1]) - lcs[i][j] = lcs[i - 1][j - 1] + 1; - else - lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]); - } - } + for (int i = 0; i <= len1; ++i) { + for (int j = 0; j <= len2; ++j) { + if (i == 0 || j == 0) { + lcs[i][j] = 0; + } else if (string1[i - 1] == string2[j - 1]) { + lcs[i][j] = lcs[i - 1][j - 1] + 1; + } else { + lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]); + } + } + } - return lcs[len1][len2]; + return lcs[len1][len2]; } int main() { - // String from which Longest common subsequence have to find - // Maximum length of string should be 100 char long - char str1[100]; - char str2[100]; - scanf("%s", str1); - scanf("%s", str2); - printf("%d\n", longestCommonSubsequence(str1, str2)); - return 0; + // String from which Longest common subsequence have to find + // Maximum length of string should be 100 char long + char str1[100]; + char str2[100]; + strcpy(str1, "mathematicians study maths"); + strcpy(str2, "people study matrix multiplication"); + printf("%d\n", longestCommonSubsequence(str1, str2)); + return 0; } diff --git a/longest_common_subsequence/longest_common_subsequence.py b/longest_common_subsequence/longest_common_subsequence.py new file mode 100644 index 00000000..89ba32c9 --- /dev/null +++ b/longest_common_subsequence/longest_common_subsequence.py @@ -0,0 +1,48 @@ +def longest_common_subsequence(seq1, seq2): + """ + Returns the longest common subsequence + :param seq1: First sequence + :param seq2: Second sequence + :return: The longest common subsequence of two input sequences + """ + len1 = len(seq1) + len2 = len(seq2) + sequences = [[0 for x in range(len2 + 1)] for x in range(len1 + 1)] + for i in range(len1 + 1): + for j in range(len2 + 1): + if i == 0 or j == 0: + sequences[i][j] = 0 + elif seq1[i - 1] == seq2[j - 1]: + sequences[i][j] = sequences[i - 1][j - 1] + 1 + else: + sequences[i][j] = max(sequences[i - 1][j], sequences[i][j - 1]) + prev_selected = sequences[len1][len2] + lcs = [''] * (prev_selected + 1) + lcs[prev_selected] = '\0' # End of line char + i = len1 + j = len2 + while i > 0 and j > 0: + if seq1[i - 1] == seq2[j - 1]: + lcs[prev_selected - 1] = seq1[i - 1] + i -= 1 + j -= 1 + prev_selected -= 1 + elif sequences[i - 1][j] > sequences[i][j - 1]: + i -= 1 + else: + j -= 1 + return lcs + + +def main(): + """ + Driver function for testing. + """ + seq1 = 'iiitv/algos' + seq2 = 'iiitv/Odyssy' + print('longest common subsequence is', + longest_common_subsequence(seq1, seq2)) + + +if __name__ == '__main__': + main() diff --git a/merge_sort/MergeSort.java b/merge_sort/MergeSort.java index 6279309e..fe777848 100644 --- a/merge_sort/MergeSort.java +++ b/merge_sort/MergeSort.java @@ -15,7 +15,7 @@ static void merge(int[] a, int first, int mid, int last) { int i = 0; int j = 0; int k = first; - while (i < l && j < r) { //merging + while (i < l && j < r) { //merging if (left[i] <= right[j]) { a[k] = left[i]; i++; @@ -40,7 +40,7 @@ static void merge(int[] a, int first, int mid, int last) { static void mergeSort(int[] a, int first, int last) { if (first < last) { int mid = (first + last) / 2; //find the middle - mergeSort(a, first, mid); //sort left half + mergeSort(a, first, mid); //sort left half mergeSort(a, mid + 1, last); //sort right half merge(a, first, mid, last); //merge above two sorted halves } diff --git a/merge_sort/merge_sort.c b/merge_sort/merge_sort.c index ee18df4b..bf37868d 100644 --- a/merge_sort/merge_sort.c +++ b/merge_sort/merge_sort.c @@ -1,7 +1,7 @@ /* -* Following Algorithm sorts the given array in worst case time complexity O(n*log(n)) -* and space complexity O(n), n being size of array. -*/ + * Following Algorithm sorts the given array in worst case time complexity O(n*log(n)) + * and space complexity O(n), n being size of array. + */ #include @@ -54,7 +54,7 @@ int main() { int arr[] = {7, 10, 14, 1, 2, 6, 17, 0}; int size = sizeof(arr) / sizeof(arr[0]); merge_sort(arr, 0, size - 1); - for (i = 0; i < n; i++) { + for (i = 0; i < size; i++) { printf("%d ", arr[i]); } return 0; diff --git a/modular_exponential/ModularExponential.java b/modular_exponential/ModularExponential.java index 639efce0..28a49c63 100644 --- a/modular_exponential/ModularExponential.java +++ b/modular_exponential/ModularExponential.java @@ -1,24 +1,24 @@ import java.math.BigInteger; public class ModularExponential { - public static BigInteger modularExponential(long base, long power, long mod) { - BigInteger result = BigInteger.ONE; - base = base % mod; - while(power > 0) { - if(power % 2 == 1) { - result = result.multiply(BigInteger.valueOf(base)); - result = result.mod(BigInteger.valueOf(mod)); - } - power = power / 2; - base = (base * base) % mod; - } - return result; - } + public static BigInteger modularExponential(long base, long power, long mod) { + BigInteger result = BigInteger.ONE; + base = base % mod; + while(power > 0) { + if(power % 2 == 1) { + result = result.multiply(BigInteger.valueOf(base)); + result = result.mod(BigInteger.valueOf(mod)); + } + power = power / 2; + base = (base * base) % mod; + } + return result; + } - public static void main(String[] args) { - long base = 78; - long pow = 20; - long mod = 65; - System.out.println(modularExponential(base, pow, mod)); - } + public static void main(String[] args) { + long base = 78; + long pow = 20; + long mod = 65; + System.out.println(modularExponential(base, pow, mod)); + } } diff --git a/modular_exponential/modularExponential.js b/modular_exponential/modularExponential.js new file mode 100644 index 00000000..bbd8db0c --- /dev/null +++ b/modular_exponential/modularExponential.js @@ -0,0 +1,30 @@ +function modularExponential (base, power, mod) { + /* + Performs Modular Exponential. + Time Complexity : O(log (power)) + :param base: Number that is going to be raised. + :param power: Power to which the number is raised. + :param mod: Number by which modulo has to be performed. + :return: Returns (base ^ power) % mod + */ + let answer = 1; + base = base % mod; + while (power) { + if (power & 1) { + answer = (answer * base) % mod; + } + power = power >> 1; + base = (base * base) % mod; + } + return answer; +} + +function main () { + let base = 3; + let power = 5; + let mod = 61; + let res = modularExponential(base, power, mod); + console.log('%d\n', res); +} + +main(); diff --git a/modular_exponential/modular_exponential.c b/modular_exponential/modular_exponential.c index 7b6fee18..e4832c8e 100644 --- a/modular_exponential/modular_exponential.c +++ b/modular_exponential/modular_exponential.c @@ -1,23 +1,23 @@ #include - -// Time Complexity : O(log (power)) + +// Time Complexity : O(log (power)) long long modularExponential(long long base, long power, long long mod) { - long long answer = 1; - base = base % mod; - while (power) { - if (power & 1) { - answer = (answer * base) % mod; - } - power = power >> 1; - base = (base * base) % mod; - } - return answer; + long long answer = 1; + base = base % mod; + while (power) { + if (power & 1) { + answer = (answer * base) % mod; + } + power = power >> 1; + base = (base * base) % mod; + } + return answer; } int main() { - long long base = 2; - long power = 10; - long long mod = 100000; - printf("%lld\n", modularExponential(base, power, mod)); - return 0; + long long base = 2; + long power = 10; + long long mod = 100000; + printf("%lld\n", modularExponential(base, power, mod)); + return 0; } diff --git a/n_queen_problem/NQueenProblem.cpp b/n_queen_problem/NQueenProblem.cpp index a3c3263b..12673171 100644 --- a/n_queen_problem/NQueenProblem.cpp +++ b/n_queen_problem/NQueenProblem.cpp @@ -10,7 +10,7 @@ #include using namespace std; -#define SIDE 8 /* Size of the board = (SIDE X SIDE) */ +#define SIDE 8 /* Size of the board = (SIDE X SIDE) */ /* The Queen is safe, if * There's no other Queen in the same row. @@ -18,54 +18,63 @@ using namespace std; * There's no other Queen in the same diagonal. */ bool queen_is_safe(int board[SIDE][SIDE], int row, int col) { - int i,j; - for (i = 0; i < col; i++) - if (board[row][i]==1) - return false; // * return false, if there's another Queen present in the same row. + int i,j; + for (i = 0; i < col; i++) { + if (board[row][i] == 1) { + return false; // * return false, if there's another Queen present in the same row. + } + } - for (i=row, j=col; i>=0 && j>=0; i--, j--) - if (board[i][j]==1) - return false; // * return false, if there's another Queen present in the upper diagonal. + for (i = row, j = col; i >= 0 && j >= 0; i--, j--) { + if (board[i][j] == 1) { + return false; // * return false, if there's another Queen present in the upper diagonal. + } + } - for (i=row, j=col; j>=0 && i= 0 && i < SIDE; i++, j--) { + if (board[i][j]==1) { + return false; // * return false, if there's another Queen present in the lower diagonal. + } + } - return true; + return true; } bool n_queen_solution(int board[SIDE][SIDE], int col) { - if (col >= SIDE) - return true; // * return true, + if (col >= SIDE) { + return true; // * return true, + } - for (int i = 0; i < SIDE; i++) { - if ( queen_is_safe(board, i, col) ) { - board[i][col] = 1; // * A queen is placed on (i, col). - if ( n_queen_solution(board, col + 1) ) // * Calling n_queen_solution() to place the rest of the queens. - return true; - else - board[i][col] = 0; // * Backtrack - } - } - return false; + for (int i = 0; i < SIDE; i++) { + if ( queen_is_safe(board, i, col) ) { + board[i][col] = 1; // * A queen is placed on (i, col). + if (n_queen_solution(board, col + 1)) { // * Calling n_queen_solution() to place the rest of the queens. + return true; + } else { + board[i][col] = 0; // * Backtrack + } + } + } + return false; } int main() { - int board[SIDE][SIDE]; // * A chess board of rows = SIDE & columns = SIDE. - memset(board, 0, sizeof(board)); // * Initially the board is empty, so all elements of 2-D array board are 0. + int board[SIDE][SIDE]; // * A chess board of rows = SIDE & columns = SIDE. + memset(board, 0, sizeof(board)); // * Initially the board is empty, so all elements of 2-D array board are 0. - if ( n_queen_solution(board, 0) == false ) { - cout << "No possible configuration exists.\n\n"; - return 0; - } - // * Printing the answer. - cout << "\n No. of queens = " << SIDE << "\n"; - cout << "\n Chess board size = " << SIDE << " X " << SIDE << "\n\n"; + if ( n_queen_solution(board, 0) == false ) { + cout << "No possible configuration exists.\n\n"; + return 0; + } + // * Printing the answer. + cout << "\n No. of queens = " << SIDE << "\n"; + cout << "\n Chess board size = " << SIDE << " X " << SIDE << "\n\n"; - for (int i = 0; i < SIDE; i++) { - for (int j = 0; j < SIDE; j++) - cout << " "< board_size: # more queens than the board can contain + return [] # pigeonhole principle -> 0 solutions + + return get_solutions(board_size, queens) + + +def main(): + board_size = 10 + solutions = n_queen_problem(board_size, board_size) + print(len(solutions)) + + +if __name__ == '__main__': + main() diff --git a/npm-requirements.txt b/npm-requirements.txt new file mode 100644 index 00000000..6681e303 --- /dev/null +++ b/npm-requirements.txt @@ -0,0 +1,2 @@ +happiness +eclint@2.2.0 diff --git a/pip2-requirements.txt b/pip2-requirements.txt new file mode 100644 index 00000000..945b4703 --- /dev/null +++ b/pip2-requirements.txt @@ -0,0 +1,2 @@ +numpy +requests diff --git a/pip3-requirements.txt b/pip3-requirements.txt new file mode 100644 index 00000000..6a58861d --- /dev/null +++ b/pip3-requirements.txt @@ -0,0 +1,3 @@ +coala-bears +numpy +requests diff --git a/prime_factor/PrimeFactor.java b/prime_factor/PrimeFactor.java new file mode 100644 index 00000000..de87a384 --- /dev/null +++ b/prime_factor/PrimeFactor.java @@ -0,0 +1,25 @@ +import java.util.ArrayList; + +public class PrimeFactor { + + public static ArrayList primeFactor(int n) { + ArrayList primeNo = new ArrayList(); + for (int i = 2; i <= n; i++) { + if (n % i == 0) { + primeNo.add(i); + while (n % i == 0) { + n = n / i; + } + } + } + return primeNo; + } + + public static void main(String[] args) { + int n = 8; + System.out.println("Prime Factors are:"); + for (Integer i : primeFactor(n)) { + System.out.println(i); + } + } +} diff --git a/prime_factor/primeFactor.js b/prime_factor/primeFactor.js new file mode 100644 index 00000000..e74fde1c --- /dev/null +++ b/prime_factor/primeFactor.js @@ -0,0 +1,31 @@ +function primeFactor (n) { + /* + Finding all the prime factors of a given number + :param n: Number whose prime factors are going to be found + :returns: Array with prime numbers + */ + let primes = []; + for (let i = 2; i <= Math.sqrt(n); i++) { + if (n % i === 0) { + primes.push(i); + while (n % i === 0) { + n = n / i; + } + } + } + if (n !== 1) { + primes.push(n); + } + return primes; +} + +function main () { + let n = 582; + console.log('Prime factors are:'); + let primes = primeFactor(n); + for (let i = 0; i < primes.length; i++) { + console.log(primes[i]); + } +} + +main(); diff --git a/prime_factor/prime_factor.c b/prime_factor/prime_factor.c index 90b24447..7ad46bf1 100644 --- a/prime_factor/prime_factor.c +++ b/prime_factor/prime_factor.c @@ -1,43 +1,43 @@ #include -#include // for memset -#include // for bool type +#include // for memset +#include // for bool type #include int prime_factors(int num, int *primes) { - int cnt = 0; // index to the last location in the array - bool flag[num]; - memset(flag, true, sizeof(flag)); - flag[0] = false; - flag[1] = false; - for (int i = 2; i*i < num; ++i) { - if (flag[i]) { - if (num % i == 0) { - for (int j = 2 * i; j < num; j += i) { - flag[j] = false; // Non prime number; flag is unset - } - } else { - flag[i] = false; // Not a multiple; flag is unset - } - } - } - for (int i = 0; i < num; ++i) { - if (flag[i] && num % i == 0) { - primes[cnt] = i; - cnt += 1; - } - } - return cnt; // returns the size of the prime array + int cnt = 0; // index to the last location in the array + bool flag[num]; + memset(flag, true, sizeof(flag)); + flag[0] = false; + flag[1] = false; + for (int i = 2; i*i < num; ++i) { + if (flag[i]) { + if (num % i == 0) { + for (int j = 2 * i; j < num; j += i) { + flag[j] = false; // Non prime number; flag is unset + } + } else { + flag[i] = false; // Not a multiple; flag is unset + } + } + } + for (int i = 0; i < num; ++i) { + if (flag[i] && num % i == 0) { + primes[cnt] = i; + cnt += 1; + } + } + return cnt; // returns the size of the prime array } int main() { - int no = 1562; - int primes[(int)(sqrt(no))]; // array size is sqrt(no) - int idx = prime_factors(no, primes); - printf("Prime Factors: "); // printing of primes - for (int i = 0; i < idx; i++) { - printf("%d ", primes[i]); - } - printf("\n"); - return 0; + int no = 1562; + int primes[(int)(sqrt(no))]; // array size is sqrt(no) + int idx = prime_factors(no, primes); + printf("Prime Factors: "); // printing of primes + for (int i = 0; i < idx; i++) { + printf("%d ", primes[i]); + } + printf("\n"); + return 0; } diff --git a/prime_factor/prime_factor.go b/prime_factor/prime_factor.go new file mode 100644 index 00000000..670478c3 --- /dev/null +++ b/prime_factor/prime_factor.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "math" +) + +// PrimeFactor finds all the prime factor of given number +func PrimeFactor(n int) []int { + var primes []int + sqrt := int(math.Sqrt(float64(n))) + for i := 2; i <= sqrt; i++ { + if n%i == 0 { + primes = append(primes, i) + for n%i == 0 { + n = n / i + } + } + } + if n != 1 { + primes = append(primes, n) + } + return primes +} + +func main() { + n := 8 + fmt.Println("Prime Factors are :") + fmt.Println(PrimeFactor(n)) +} diff --git a/prime_factor/prime_factor.py b/prime_factor/prime_factor.py new file mode 100644 index 00000000..01606969 --- /dev/null +++ b/prime_factor/prime_factor.py @@ -0,0 +1,32 @@ +import math + + +def prime_factor(num): + """ + Finds all the prime factor of a number. + + :param num : number whose prime factors we want to find. + :return : return a list of prime factors of number. + """ + factor_list = [] + sqrt_num = int(math.sqrt(num)) + 1 + for start in range(2, sqrt_num): + if num % start == 0: + factor_list.append(start) + while (num % start == 0): + num /= start + if num != 1: + factor_list.append(num) + return factor_list + + +def main(): + """ + Driver function + """ + num = 362880 + print("Prime Factors are :", prime_factor(num)) + + +if __name__ == '__main__': + main() diff --git a/prims/prims.c b/prims/prims.c index a0eba16e..ec01b8f9 100644 --- a/prims/prims.c +++ b/prims/prims.c @@ -6,42 +6,44 @@ // This function finds the minimal spanning tree by Prim's Algorithm void prims(int G[SIZE][SIZE], int *parent) { - int select[SIZE], i, j, k; - int v1 = 0, v2 = 0; - for (i = 0; i < SIZE; ++i) // Initialize the selected vertices list - select[i] = 0; - select[0] = 1; - for (k = 1; k < SIZE; ++k) { - int min_dist = INT_MAX; - for (i = 0; i < SIZE; ++i) { // Select an edge such that one vertex is selected and other is not and the edge - for (j = 0; j < SIZE; ++j) { // has the least weight. - if (G[i][j] && ((select[i] && !select[j]) || (!select[i] && select[j]))) { - if (G[i][j] < min_dist) { //obtained edge with minimum wt - min_dist = G[i][j]; - v1 = i; - parent[j] = v1; - v2 = j; //picking up those vertices - } - } - } - } - select[v1] = select[v2] = 1; - } + int select[SIZE], i, j, k; + int v1 = 0, v2 = 0; + for (i = 0; i < SIZE; ++i) { // Initialize the selected vertices list + select[i] = 0; + } + select[0] = 1; + for (k = 1; k < SIZE; ++k) { + int min_dist = INT_MAX; + for (i = 0; i < SIZE; ++i) { // Select an edge such that one vertex is selected and other is not and the edge + for (j = 0; j < SIZE; ++j) { // has the least weight. + if (G[i][j] && ((select[i] && !select[j]) || (!select[i] && select[j]))) { + if (G[i][j] < min_dist) { //obtained edge with minimum wt + min_dist = G[i][j]; + v1 = i; + parent[j] = v1; + v2 = j; //picking up those vertices + } + } + } + } + select[v1] = select[v2] = 1; + } } int main() { - int G[SIZE][SIZE] = {{0, 2, 0, 6, 0}, - {2, 0, 3, 8, 5}, - {0, 3, 0, 0, 7}, - {6, 8, 0, 0, 9}, - {0, 5, 7, 9, 0}, - }; - int i, j; - int parent[SIZE]; - memset(parent, 0, SIZE); - printf("Edge\tWeight\n"); - prims(G,parent); - for (i = 1; i < SIZE; ++i) - printf("%d - %d\t%d \n", parent[i], i, G[i][parent[i]]); - return 0; + int G[SIZE][SIZE] = { + {0, 2, 0, 6, 0}, + {2, 0, 3, 8, 5}, + {0, 3, 0, 0, 7}, + {6, 8, 0, 0, 9}, + {0, 5, 7, 9, 0}}; + int i, j; + int parent[SIZE]; + memset(parent, 0, SIZE); + printf("Edge\tWeight\n"); + prims(G,parent); + for (i = 1; i < SIZE; ++i) { + printf("%d - %d\t%d \n", parent[i], i, G[i][parent[i]]); + } + return 0; } diff --git a/quick_select/QuickSelect.java b/quick_select/QuickSelect.java new file mode 100644 index 00000000..3b1f1e31 --- /dev/null +++ b/quick_select/QuickSelect.java @@ -0,0 +1,64 @@ +public class QuickSelect { + /* + * partition function + * array : array on which partitioning has to be done + * left : left index of the partitioning subarray + * right : right index of the partitioning subarray + * pivotIndex : pivot index from which partition has to done + * return : the index of the last element of the left subarray + */ + private static int partition(int[] array, int left, int right, int pivotIndex) { + int pivotValue = array[pivotIndex]; + int temp = array[right]; + array[right] = array[pivotIndex]; + array[pivotIndex] = temp; + int storeIndex = left; + while (left < right) { + if (array[left] < pivotValue) { + temp = array[storeIndex]; + array[storeIndex] = array[left]; + array[left] = temp; + storeIndex++; + } + left++; + } + temp = array[right]; + array[right] = array[storeIndex]; + array[storeIndex] = temp; + return storeIndex; + } + + /* + * Quick Select function + * left : left index of the subarray + * right : right index of the subarray + * pos : position to find the element using quick sort + * return : the value of element at pos place in the sorted array + */ + public static int quickSelect(int[] array, int left, int right, int pos) { + int pivotIndex; + if(pos < 0 || pos >= array.length) { + throw new IndexOutOfBoundsException("index: " + pos); + } + if (left == right) { + return array[left]; + } + pivotIndex = right - 1; + pivotIndex = partition(array, left, right, pivotIndex); + if (pos == pivotIndex) { + return array[pivotIndex]; + } + else if (pos < pivotIndex) { + return quickSelect(array, left, pivotIndex - 1, pos); + } + else { + return quickSelect(array, pivotIndex + 1, right, pos); + } + } + + public static void main(String[] args) { + int[] array = {10, 5, 1, 6, 7, 3, 2, 4, 8, 9}; + System.out.println(quickSelect(array, 0, array.length - 1, 3)); + } + +} diff --git a/quick_select/quick_select.c b/quick_select/quick_select.c index abb221e3..302455ba 100644 --- a/quick_select/quick_select.c +++ b/quick_select/quick_select.c @@ -6,29 +6,29 @@ * left : left index of the partitioning subarray * right : right index of the partitioning subarray * pivot_idx : pivot index from which partition has to done - * store_idx : index of the last element of the left subarray + * store_idx : index of the last element of the left subarray * return : the index of the last element of the left subarray */ int partition(int *ar, int left, int right, int pivot_idx) { - int pivot_value = ar[pivot_idx]; - int temp = ar[right]; - ar[right] = ar[pivot_idx]; - ar[pivot_idx] = temp; + int pivot_value = ar[pivot_idx]; + int temp = ar[right]; + ar[right] = ar[pivot_idx]; + ar[pivot_idx] = temp; - int store_idx = left; - while (left < right) { - if (ar[left] < pivot_value) { - temp = ar[store_idx]; - ar[store_idx] = ar[left]; - ar[left] = temp; - store_idx++; - } - left++; - } - temp = ar[right]; - ar[right] = ar[store_idx]; - ar[store_idx] = temp; - return store_idx; + int store_idx = left; + while (left < right) { + if (ar[left] < pivot_value) { + temp = ar[store_idx]; + ar[store_idx] = ar[left]; + ar[left] = temp; + store_idx++; + } + left++; + } + temp = ar[right]; + ar[right] = ar[store_idx]; + ar[store_idx] = temp; + return store_idx; } /* @@ -36,27 +36,26 @@ int partition(int *ar, int left, int right, int pivot_idx) { * left : left index of the subarray * right : right index of the subarray * pos : position to find the element using quick sort - * pivot_index : pivot index + * pivot_index : pivot index * return : the value of element at pos place in the sorted array */ int quick_select(int *ar, int left, int right, int pos) { - int pivot_index; - if (left == right) - return ar[left]; - pivot_index = right - 1; - pivot_index = partition(ar, left, right, pivot_index); - if (pos == pivot_index) { - return ar[pivot_index]; - } else if (pos < pivot_index) { - return quick_select(ar, left, pivot_index - 1, pos); - } else { - return quick_select(ar, pivot_index + 1, right, pos); - } + int pivot_index; + if (left == right) + return ar[left]; + pivot_index = right - 1; + pivot_index = partition(ar, left, right, pivot_index); + if (pos == pivot_index) { + return ar[pivot_index]; + } else if (pos < pivot_index) { + return quick_select(ar, left, pivot_index - 1, pos); + } else { + return quick_select(ar, pivot_index + 1, right, pos); + } } int main() { - int ar[] = {10, 5, 1, 6, 7, 3, 2, 4, 8, 9}; - printf("%d\n", quick_select(ar, 0, 9, 3)); - return 0; + int ar[] = {10, 5, 1, 6, 7, 3, 2, 4, 8, 9}; + printf("%d\n", quick_select(ar, 0, 9, 3)); + return 0; } - diff --git a/quick_select/quick_select.py b/quick_select/quick_select.py new file mode 100644 index 00000000..b06a4798 --- /dev/null +++ b/quick_select/quick_select.py @@ -0,0 +1,56 @@ +def partition(array, start, end): + """ + Perform Partition Operation on array a. + Time Complexity: O(nLogn) + Auxiliary Space: O(n) + :param a: Iterable of elements + :param start: pivot value for array + :param end: right limit of array + :return: return i value for function, used in partitioning of array. + """ + i = start - 1 + pivot = array[end] + for j in range(start, end): + if array[j] <= pivot: + i += 1 + array[i], array[j] = array[j], array[i] + i += 1 + array[i], array[end] = array[end], array[i] + return i + + +def quick_select(array, k): + """ + Perform quick select operation i.e find kth minimum element from array + Time Complexity: O(n) for average case and O(n^2) for worst cases + param a: Array on which operation would perfom + param k: kth minimun element have to find + return: returns kth minimum value + """ + start = 0 + end = len(array) - 1 + is_found = False + while not is_found: + pos = partition(array, start, end) + if pos == k: + is_found = True + return array[pos] + elif pos < k: + start = pos + 1 + else: + end = pos - 1 + + +def main(): + a = [2, 4, 6, 2, 1, 4, 2, 7, 8, 9, 5, -4, 23, 0, 8] + k = 10 + if a is None: + print("Array doesn't exist") + elif k >= len(a): + print("k is greater than size of array") + else: + print(quick_select(a, k)) + + +if __name__ == '__main__': + main() diff --git a/quicksort/QuickSort.java b/quicksort/QuickSort.java index fb4e3925..e6b66fec 100644 --- a/quicksort/QuickSort.java +++ b/quicksort/QuickSort.java @@ -5,24 +5,24 @@ private static int partition(int[] arr, int start, int end) { int p_idx = start - 1; int tmp; for (int i = start; i < end; ++i) { - if (arr[i] <= pivot) { - p_idx++; - tmp = arr[i]; - arr[i] = arr[p_idx]; - arr[p_idx] = tmp; - } + if (arr[i] <= pivot) { + p_idx++; + tmp = arr[i]; + arr[i] = arr[p_idx]; + arr[p_idx] = tmp; + } } tmp = arr[p_idx + 1]; arr[p_idx + 1] = arr[end]; arr[end] = tmp; return p_idx + 1; - } + } public static void quickSort(int[] a, int left, int right) { if (left < right) { int pi = partition(a, left, right); //pi index of pivot quickSort(a, left, pi - 1); //sort left of pivot - quickSort(a, pi + 1, right); //sort right of pivot + quickSort(a, pi + 1, right); //sort right of pivot } } diff --git a/quicksort/quick_sort.go b/quicksort/quick_sort.go new file mode 100644 index 00000000..53677731 --- /dev/null +++ b/quicksort/quick_sort.go @@ -0,0 +1,50 @@ +package main + +import "fmt" + +// partitionArray finds the pivot index +func partitionArray(data []int, left int, right int) int { + pivotIndex := left + for true { + for data[pivotIndex] <= data[right] && pivotIndex != right { + right-- + } + if pivotIndex == right { + break + } else if data[pivotIndex] > data[right] { + data[right], data[pivotIndex] = data[pivotIndex], data[right] + pivotIndex = right + } + for data[pivotIndex] >= data[left] && pivotIndex != left { + left++ + } + if pivotIndex == left { + break + } else if data[pivotIndex] < data[left] { + data[left], data[pivotIndex] = data[pivotIndex], data[left] + pivotIndex = left + } + } + return pivotIndex +} + +func quickSort(data []int, begin int, end int) { + if begin < end { + pivotIndex := partitionArray(data, begin, end) + quickSort(data, begin, pivotIndex-1) + quickSort(data, pivotIndex+1, end) + } +} + +// QuickSort sorts data by quicksort algorithm +// Time complexity : O(n log n) +// Space Complexity : O(n) +func QuickSort(data []int) { + quickSort(data, 0, len(data)-1) +} + +func main() { + data := []int{1, 1122002, 2, 88171, 6754, 79901, 119856, -312, 1, -2} + QuickSort(data) + fmt.Println(data) +} diff --git a/rod_cutting_problem/RodCutting.java b/rod_cutting_problem/RodCutting.java index 53b7c3ac..46a1c8f0 100644 --- a/rod_cutting_problem/RodCutting.java +++ b/rod_cutting_problem/RodCutting.java @@ -1,10 +1,10 @@ /** -Problem Statement: Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n. +Problem Statement: Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n. Determine the maximum value obtainable by cutting up the rod and selling the pieces. Time Complexity: O(n^2) Space Complexity: O(n) -*/ + */ public class RodCutting { diff --git a/rod_cutting_problem/rod_cutting.c b/rod_cutting_problem/rod_cutting.c index 72193ad6..042b6d16 100644 --- a/rod_cutting_problem/rod_cutting.c +++ b/rod_cutting_problem/rod_cutting.c @@ -1,9 +1,9 @@ /* -* Given a rod of length n and an array of prices that contains prices of all pieces of size smaller than n. -* Determine the maximum new_prices obtainable by cutting up the rod and selling the pieces. -* Time Complexity: O(n^2) -* Space Complexity: O(n) -*/ + * Given a rod of length n and an array of prices that contains prices of all pieces of size smaller than n. + * Determine the maximum new_prices obtainable by cutting up the rod and selling the pieces. + * Time Complexity: O(n^2) + * Space Complexity: O(n) + */ #include #include @@ -11,22 +11,22 @@ #define max(a, b) (a > b) ? a : b; int rod_cutting(const int *prices) { - unsigned int i, j; - unsigned int n = sizeof(prices); - int new_prices[n + 1]; - memset(new_prices, 0, n + 1); - for (i = 1; i < n + 1; ++i) { - int maxi = -1; - for (j = 0; j < i; ++j) { - maxi = max(maxi, (prices[j] + new_prices[i - j - 1])); - } - new_prices[i] = maxi; - } - return new_prices[n]; + unsigned int i, j; + unsigned int n = sizeof(prices); + int new_prices[n + 1]; + memset(new_prices, 0, n + 1); + for (i = 1; i < n + 1; ++i) { + int maxi = -1; + for (j = 0; j < i; ++j) { + maxi = max(maxi, (prices[j] + new_prices[i - j - 1])); + } + new_prices[i] = maxi; + } + return new_prices[n]; } int main() { - int prices[] = {10, 52, 84, 93, 101, 17, 117, 20}; - printf("%d\n", rod_cutting(prices)); - return 0; + int prices[] = {10, 52, 84, 93, 101, 17, 117, 20}; + printf("%d\n", rod_cutting(prices)); + return 0; } diff --git a/shell_sort/shellSort.js b/shell_sort/shellSort.js new file mode 100644 index 00000000..99282fcb --- /dev/null +++ b/shell_sort/shellSort.js @@ -0,0 +1,30 @@ +/* + * Worst case time complexity = O(n^2) + * Best case complexity = O(nlog(n)) + * @param {Array} data + * returns sorted data + */ +function shellSort (data) { + let temp; + for (let i = Math.floor(data.length / 2); i > 0; i = Math.floor(i / 2)) { + for (let j = i; j < data.length; j++) { + for (let k = j - i; k >= 0; k -= i) { + if (data[k + i] >= data[k]) { + break; + } else { + temp = data[k]; + data[k] = data[k + i]; + data[k + i] = temp; + } + } + } + } + return data; +} + +function main () { + let data = [1000, 45, -45, 121, 47, 45, 65, 121, -1, 103, 45, 34]; + console.log(shellSort(data)); +} + +main(); diff --git a/sieve_of_eratosthenes/SieveOfEratosthenes.java b/sieve_of_eratosthenes/SieveOfEratosthenes.java index a1a973d6..5c705eab 100644 --- a/sieve_of_eratosthenes/SieveOfEratosthenes.java +++ b/sieve_of_eratosthenes/SieveOfEratosthenes.java @@ -1,35 +1,35 @@ /* -* Following implementation of sieve of eratosthenes returns a boolean array which contains true is its index is prime -* less than or equal to a number n. -* Space complexity : O(n). -* Time complexity : O(n). -*/ + * Following implementation of sieve of eratosthenes returns a boolean array which contains true is its index is prime + * less than or equal to a number n. + * Space complexity : O(n). + * Time complexity : O(n). + */ public class SieveOfEratosthenes { - public static boolean[] sieveOfEratosthenes(int n) { - int sqrtOfn = (int)Math.sqrt(n) + 1; - boolean[] primes = new boolean[n + 1]; - for (int i = 2; i < n + 1; ++i) { - primes[i] = true; - } - for (int i = 2; i <= sqrtOfn; ++i) { - if (primes[i]) { - for (int j = 2 * i; j < n + 1; j += i) { - primes[j] = false; - } - } - } - return primes; - } + public static boolean[] sieveOfEratosthenes(int n) { + int sqrtOfn = (int)Math.sqrt(n) + 1; + boolean[] primes = new boolean[n + 1]; + for (int i = 2; i < n + 1; ++i) { + primes[i] = true; + } + for (int i = 2; i <= sqrtOfn; ++i) { + if (primes[i]) { + for (int j = 2 * i; j < n + 1; j += i) { + primes[j] = false; + } + } + } + return primes; + } - public static void main(String[] args) { - int n = 100; - boolean[] primes = sieveOfEratosthenes(n); - for (int i = 2; i < n + 1; ++i) { - if (primes[i]) { - System.out.print(i + " "); - } - } - } + public static void main(String[] args) { + int n = 100; + boolean[] primes = sieveOfEratosthenes(n); + for (int i = 2; i < n + 1; ++i) { + if (primes[i]) { + System.out.print(i + " "); + } + } + } } diff --git a/sieve_of_eratosthenes/sieveOfEratosthenes.c b/sieve_of_eratosthenes/sieveOfEratosthenes.c index 8b834d88..2fb48d99 100644 --- a/sieve_of_eratosthenes/sieveOfEratosthenes.c +++ b/sieve_of_eratosthenes/sieveOfEratosthenes.c @@ -1,7 +1,7 @@ #include #include -#include // for using square root -#include // to include bool datatype +#include // for using square root +#include // to include bool datatype void sieveOfEratosthenes(int n, bool *primes) { int i, sqrtOfn = sqrt(n)+1, j; @@ -20,7 +20,7 @@ void sieveOfEratosthenes(int n, bool *primes) { int main() { int n, k; - scanf("%d", &n); + n = 100; bool primes[n+1]; sieveOfEratosthenes(n, primes); for (k = 2; k < n; k++) { diff --git a/sieve_of_eratosthenes/sieveOfEratosthenes.js b/sieve_of_eratosthenes/sieveOfEratosthenes.js new file mode 100644 index 00000000..130754c8 --- /dev/null +++ b/sieve_of_eratosthenes/sieveOfEratosthenes.js @@ -0,0 +1,31 @@ +function sieveOfEratosthenes (n) { + /* + * Calculates prime numbers till a number n + * :param n: Number upto which to calculate primes + * :return: A boolean list contaning only primes + */ + let primes = new Array(n + 1); + primes.fill(true); // set all as true initially + primes[0] = primes[1] = false; // Handling case for 0 and 1 + let sqrtn = Math.ceil(Math.sqrt(n)); + for (let i = 2; i <= sqrtn; i++) { + if (primes[i]) { + for (let j = 2 * i; j <= n; j += i) { + primes[j] = false; + } + } + } + return primes; +} + +function main () { + let n = 319; // number till where we wish to find primes + let primes = sieveOfEratosthenes(n); + for (let i = 2; i <= n; i++) { + if (primes[i]) { + console.log(i); + } + } +} + +main(); diff --git a/sieve_of_eratosthenes/sieve_of_eratosthenes.py b/sieve_of_eratosthenes/sieve_of_eratosthenes.py index f1b66f15..e1d8c039 100644 --- a/sieve_of_eratosthenes/sieve_of_eratosthenes.py +++ b/sieve_of_eratosthenes/sieve_of_eratosthenes.py @@ -7,20 +7,20 @@ def sieve_of_eratosthenes(n): :param n: Number upto which to calculate primes :return: A boolean list contaning only primes """ - primes = [True] * (n+1) # Setting all as True initially + primes = [True] * (n + 1) # Setting all as True initially primes[0] = primes[1] = False # Since 0 and 1 are not primes - sqrt_n = math.ceil(math.sqrt(n)) + sqrt_n = int(math.ceil(math.sqrt(n))) for i in range(2, sqrt_n, 1): if primes[i]: - for j in range(2*i, n+1, i): + for j in range(2 * i, n + 1, i): primes[j] = False return primes def main(): - n = int(input()) + n = 425 primes = sieve_of_eratosthenes(n) - for i in range(n+1): # Printing primes + for i in range(n + 1): # Printing primes if primes[i]: print(i) diff --git a/sleep_sort/sleep_sort.cpp b/sleep_sort/sleep_sort.cpp new file mode 100644 index 00000000..d4349f30 --- /dev/null +++ b/sleep_sort/sleep_sort.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include + +using namespace std; +/* + * Function implementing sleep sort + * args: + * ar : Initial array containing elements (unsorted) + * ans : sorted array elements vector + * threads : vector containing threads for each array element + * Time Complexity : O(max(input)) + */ +void sleep_sort(int ar[], vector &ans) { + vector threads; + for (int i = 0; i < 4; ++i) { + threads.emplace_back([i, &ar, &ans]() { + this_thread::sleep_for(chrono::seconds(ar[i])); + ans.push_back(ar[i]); + }); + } + + for (auto& th : threads) { + th.join(); + } +} + +/* + * Driver function + * For compilation of the code use -pthread + * compilation looks like : g++ -std=c++11 sleep_sort.cpp -o sleep_sort -pthread + */ +int main() { + int ar[] = {8, 4, 9, 1}; + vector sorted; + sleep_sort(ar, sorted); + for (auto& item : sorted) { + cout << item << endl; + } + return 0; +} diff --git a/sleep_sort/sleep_sort.py b/sleep_sort/sleep_sort.py new file mode 100644 index 00000000..55c44e4d --- /dev/null +++ b/sleep_sort/sleep_sort.py @@ -0,0 +1,58 @@ +""" +Sleep sort is a proof of concept sorting algorithm that creates threads for +each number in the sorting queue and sleeps for the amount of time before +giving the result. + +It has no practical usage and doesn't works for negative numbers. Also for +very close positive numbers, results are not guaranteed to be consistent. +""" +try: + import queue +except ImportError: + import Queue as queue +import threading +import time + + +def sleeper(number, sorted_numbers): + """ + Worker function for sleep sort's thread. + :param number: Number for the thread + :param sorted_numbers: Queue which contains the sorted numbers + """ + time.sleep(number) + sorted_numbers.put(number) + + +def sleep_sort(numbers, reverse=False): + """ + Sorts the numbers using sleep sort algorithm. + :param numbers: Iterable object containing numbers + :param reverse: Whether results need to be reverse + :returns: A generator with sorted numbers + """ + threads = [] + sorted_numbers = queue.LifoQueue() if reverse else queue.Queue() + for number in numbers: + thread = threading.Thread(target=sleeper, + args=(number, sorted_numbers)) + thread.start() + threads.append(thread) + for thread in threads: + thread.join() + while not sorted_numbers.empty(): + yield sorted_numbers.get() + + +def main(): + numbers = [2, 3, 4, 1] + print("Ascending order: ") + for number in sleep_sort(numbers): + print(number) + print("Descending order: ") + for number in sleep_sort(numbers, reverse=True): + print(number) + + +if __name__ == '__main__': + main() diff --git a/stack/Stack.java b/stack/Stack.java index b3d07331..0e0c7c9b 100644 --- a/stack/Stack.java +++ b/stack/Stack.java @@ -1,8 +1,8 @@ /* -* Following implementation of Stack uses LinkedList -* The last element of LinkedList is considered as the Top of Stack -* T defines the type of Stack we wish to create -*/ + * Following implementation of Stack uses LinkedList + * The last element of LinkedList is considered as the Top of Stack + * T defines the type of Stack we wish to create + */ import java.util.LinkedList; import java.util.NoSuchElementException; @@ -21,7 +21,7 @@ public void push(T data) { // Add element to Top of Stack public T pop() throws NoSuchElementException { // Remove element from top of Stack return stack.removeLast(); } - + public static void main(String[] args) { Stack obj = new Stack<>(); System.out.println("Putting element in the stack."); diff --git a/trie/trie.cpp b/trie/trie.cpp new file mode 100644 index 00000000..8b52a677 --- /dev/null +++ b/trie/trie.cpp @@ -0,0 +1,130 @@ +#include +#include +using namespace std; + +// Determine size of array +#define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0]) +// Alphabet size (# of symbols) +#define ALPHABET_SIZE 26 +// Convert char to int value +// only 'a' to 'z' are allowed chars +#define CHAR_TO_INT(c) ((int)c - (int)'a') + +// TrieNode class +class TrieNode { + private: + // Children of every Node + class TrieNode *children[ALPHABET_SIZE]; + // Status of Leaf Node + bool isLeaf; + + public: + // Default Constructor + TrieNode() { + this->isLeaf = false; + for (int i = 0; i < ALPHABET_SIZE; ++i) + this->children[i] = NULL; + } + + // Get leaf node status + bool get_leaf_status() { return isLeaf; } + // Set leaf node status + void set_leaf_status(bool status) { this->isLeaf = status; } + // Get Child status + // Check if it is null or not + bool get_child_status(int index) { + if (!(this->children[index])) + return true; + return false; + } + + // Initialize the child node, at specific index + void initialize_child(int index) { + this->children[index] = new TrieNode(); + } + + // Get child node at specific index + class TrieNode *get_children(int index) { + return this->children[index]; + } + + // Insert into the Trie, Implemetation is below + void insert(string key); + + // Search into the Trie, Implementation is below + bool search(string key); +}; + +/* Insert into the Trie + * args : + * key : String to insert into Trie + * Time Complexity: O(len(key)) + */ +void TrieNode::insert(string key) { + // Determines the length of the key + int length = key.length(); + + // Temp variable for Crawling into the Trie + class TrieNode *pCrawl = this; + for (int level = 0; level < length; ++level) { + // determine the index of the child node to use + int index = CHAR_TO_INT(key[level]); + /* Check status of that child node + * If it is empty, them fill it + * If it is present, them use this as the next root + */ + if (pCrawl->get_child_status(index)) + pCrawl->initialize_child(index); + pCrawl = pCrawl->get_children(index); + } + // set the last node status as leaf node + pCrawl->set_leaf_status(true); +}; + +/* Searches into the Trie + * args: + * key : string to search into Trie + * Time complexity : O(len(key)) + */ +bool TrieNode::search(string key) { + // determines the length of the key + int length = key.length(); + + // Temp variable for crawling into the Trie + class TrieNode *pCrawl = this; + for (int level = 0; level < length; ++level) { + // determine index of the child node to use + int index = CHAR_TO_INT(key[level]); + /* Check status of the child node + * If it is empty, them return false i.e. key not present into Trie + * If it is present, them start crawling from that node + */ + if (pCrawl->get_child_status(index)) + return false; + pCrawl = pCrawl->get_children(index); + } + + // Check that the last node reached is leaf node and not null as well + return (pCrawl != NULL && pCrawl->get_leaf_status()); +}; + +// Driver function +int main() { + // keys to insert into Trie + char keys[][8] = {"the", "a", "there", "answer", "any", + "by", "bye", "their"}; + // Output the status of key + char output[][32] = {"Not present in trie", "Present in trie"}; + // Root of Trie (Crawling starts from root, insertion as well) + class TrieNode *root = new TrieNode(); + // Insertion into Trie + for (unsigned long i = 0; i < ARRAY_SIZE(keys); ++i) + root->insert(keys[i]); + // Output of searched keys + cout << output[root->search("the")] << endl; + cout << output[root->search("these")] << endl; + cout << output[root->search("thaw")] << endl; + cout << output[root->search("their")] << endl; + return 0; +} + diff --git "a/u\033\033\033q" "b/u\033\033\033q" new file mode 100644 index 00000000..84d6e691 --- /dev/null +++ "b/u\033\033\033q" @@ -0,0 +1,2885 @@ +commit b99da59e0c7c8b211b9ae5cf84cf58ab456357c2 +Author: TarunISCO <201552063@iiitvadodara.ac.in> +Date: Fri Jun 16 16:27:40 2017 +0530 + + Extra line in readme removed + + README.md | 1 - + 1 file changed, 1 deletion(-) + +commit dc38cf88f45aae2c2272858d648dd97b374d1a76 +Author: TarunISCO <201552063@iiitvadodara.ac.in> +Date: Fri Jun 16 14:32:45 2017 +0530 + + replaced tabs with spaces + + insertion_sort/insertion_sort.py | 30 +++++++++++++++--------------- + 1 file changed, 15 insertions(+), 15 deletions(-) + +commit f7b1159c8f35ee586bace9db1c4de7a0dddf358c +Author: TarunISCO <201552063@iiitvadodara.ac.in> +Date: Wed Jun 14 12:07:56 2017 +0530 + + issues in readme solved + + README.md | 23 +---------------------- + insertion_sort/insertion_sort.py | 4 ++-- + 2 files changed, 3 insertions(+), 24 deletions(-) + +commit 41c0283d05868ae7460b53f913644ceda7240649 +Author: TarunISCO <201552063@iiitvadodara.ac.in> +Date: Tue Jun 13 19:56:06 2017 +0530 + + unnecessary files removed + + insertion_sort/insertion_sort.py | 30 +++++++++++++++--------------- + 1 file changed, 15 insertions(+), 15 deletions(-) + +commit 620488803cd7b103abdeb6b25d28bbae41934321 +Merge: b0fd22d 7fdb1bf +Author: TarunISCO <201552063@iiitvadodara.ac.in> +Date: Tue Jun 13 12:56:08 2017 +0530 + + unnecessory files removed + +commit 7fdb1bfefa2ec9880c65cd470224fde4a3a4e811 +Author: Aashutosh Rathi +Date: Tue Jun 13 12:10:05 2017 +0530 + + Added Modular Exponential [Go] (#267) + + * Added Modular Exponential [Go] + + changes suggested by travis + + comment edited + + Added Linked List [Go] (#232) + + * [Go] Added Linked List implementation + + * Added Go Linked List link to README.md + + * Modified linked_list.go to pass golint + + * Ran gofmt on linked_list.go + + * Fixed error messages to comply with gofmt bear + + * Added driver function to linked_list.go + + * changed int to int64 + + README.md | 2 +- + modular_exponential/modular_exponential.go | 23 +++++++++++++++++++++++ + 2 files changed, 24 insertions(+), 1 deletion(-) + +commit 1460b68dbc12a26d066346df3859aeabd57a2063 +Author: Pratyush Singh +Date: Tue Jun 13 07:28:08 2017 +0530 + + Fix #268: Add Stack [C] (#270) + + README.md | 2 +- + stack/stack.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 58 insertions(+), 1 deletion(-) + +commit d8e9189bf07a208b2dff98728cc46d9e3126356c +Author: Monal Shadi +Date: Mon Jun 12 23:36:17 2017 +0530 + + Added Insertion Sort [Go] (#252) + + * Added Insertion Sort [Go] Fixed #242 + + * fixed travis issues + + * semicolon remove => fixes travis build + + README.md | 2 +- + insertion_sort/insertion_sort.go | 25 +++++++++++++++++++++++++ + 2 files changed, 26 insertions(+), 1 deletion(-) + +commit 303ddf5ee84c25e036fdafbbb961e9673b48520e +Author: Stefano Fogarollo +Date: Mon Jun 12 20:03:56 2017 +0200 + + Added bin sort [python] (#261) + + * added bin sort [python] + + * added bin sort [python] entry in README + + * added get_buckets(..) helper method + + * Removed ugly math.floor(..) and a.append(..) + + * Prettified placing back buckets in array + + * fitted in one line buckets filling + + * restored use of int(..) to handle float inputs + + * fixed theta notation in alg complexity + + README.md | 2 +- + bin_sort/bin_sort.py | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 85 insertions(+), 1 deletion(-) + +commit 96c07d0b8ddbcc7c1d0044c9ce91a43b1c8f90f9 +Author: Stanislav Kozlovski +Date: Mon Jun 12 20:59:42 2017 +0300 + + Added Linked List [Go] (#232) + + * [Go] Added Linked List implementation + + * Added Go Linked List link to README.md + + * Modified linked_list.go to pass golint + + * Ran gofmt on linked_list.go + + * Fixed error messages to comply with gofmt bear + + * Added driver function to linked_list.go + + README.md | 2 +- + linked_list/linked_list.go | 115 +++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 116 insertions(+), 1 deletion(-) + +commit a33f730390f9ec7a301218c29f2f13ced778b2f0 +Author: Shagun Khemka +Date: Mon Jun 12 20:11:11 2017 +0530 + + Added 'how to run them' in README.md (#251) + + * Added 'how to run them' in README.md + + Fixes #243 + + README.md | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +commit fed2b09d806198a8147ac71e4e4c565dea649fc3 +Author: Aashutosh Rathi +Date: Mon Jun 12 19:18:45 2017 +0530 + + Added Rod Cutting [Go] (#263), fixes #254 + + updated as per Travis + + updated as per Travis 2 + + removed blank line + + README.md | 2 +- + rod_cutting_problem/rod_cutting.go | 26 ++++++++++++++++++++++++++ + 2 files changed, 27 insertions(+), 1 deletion(-) + +commit 6b96fbe9ffcd75448d0d4d8257f83557c87064be +Author: Aashutosh Rathi +Date: Mon Jun 12 16:23:08 2017 +0530 + + Fix #255: Add Issue Template (#260) + + changes done + + ISSUE_TEMPLATE.md | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +commit 0817575140ea281e9fef1539e14fce4cab40ca0a +Author: Stefano Fogarollo +Date: Mon Jun 12 12:50:18 2017 +0200 + + Fix #248: Add Heap Sort [Python] (#249) + + * Added Heap Sort [Python] + + * fixed pep8 in heap_sort/heap_sort.py + + * Fixed code style in len(array) // 2 + + * Added entry in README.md + + * Added get_children_of_node() + + * Added find_largest_in_family(..) + + * fixed spurious non-pep8 line between methods + + * removed mistake empty file + + * changed range(..) to 0 <= .. <= len(..) + + * unsorted list made visually better + + * removed global vars + + * fixed spurious non-pep8 line between methods + + README.md | 2 +- + heap_sort/heap_sort.py | 128 +++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 129 insertions(+), 1 deletion(-) + +commit b0fd22d6c61b54342dba264ce357f31555023206 +Author: TarunISCO <201552063@iiitvadodara.ac.in> +Date: Mon Jun 12 15:11:08 2017 +0530 + + unnecessary files removed + + breadth_first_search/BreadhFirstSearch | Bin 22928 -> 0 bytes + breadth_first_search/BreadhFirstSearch.cpp | 63 ----------------------------- + 2 files changed, 63 deletions(-) + +commit 3540973bbda8897ecd1a9cb710ccc97cbd9bb518 +Author: TarunISCO <201552063@iiitvadodara.ac.in> +Date: Mon Jun 12 14:49:55 2017 +0530 + + indentation improved + + .coafile | 25 +++ + .codeclimate.yml | 20 ++ + .editorconfig | 30 +++ + .travis.yml | 6 + + CONTRIBUTING.md | 3 +- + PULL_REQUEST_TEMPLATE.md | 2 +- + README.md | 65 +++--- + avl_tree/AvlTree.java | 272 +++++++++++++++++++++++++ + bin_sort/BinSort.java | 75 +++++++ + binary_search/binary_search.c | 56 ++++- + binary_search/binary_search.go | 31 +++ + breadth_first_search/BreadhFirstSearch | Bin 0 -> 22928 bytes + breadth_first_search/BreadhFirstSearch.cpp | 1 + + dijkstra/dijkstra.c | 65 ++++++ + insertion_sort/insertion_sort.py | 10 +- + merge_sort/merge_sort.py | 1 + + modular_exponential/modular_exponential.c | 23 +++ + modular_exponential/modular_exponential.py | 1 + + n_queen_problem/NQueenProblem.java | 64 ++++++ + quicksort/quick_sort.py | 1 + + rod_cutting_problem/rod_cutting.c | 32 +++ + rod_cutting_problem/rod_cutting.py | 36 ++++ + shell_sort/ShellSort.cpp | 43 ++++ + shell_sort/shell_sort.go | 28 +++ + shell_sort/shell_sort.py | 41 ++++ + sieve_of_eratosthenes/SieveOfEratosthenes.java | 35 ++++ + stack/stack.go | 39 ++++ + stack/stack.js | 37 ++++ + stack/stack.py | 1 + + 29 files changed, 1000 insertions(+), 43 deletions(-) + +commit 21dd266cef95a8f1c8f800f4a5c06daec4f8f801 +Author: Aashutosh Rathi +Date: Mon Jun 12 14:28:53 2017 +0530 + + fix type in PR template (#258) + + PULL_REQUEST_TEMPLATE.md | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit fd8de740fccde6370b00701d449d80f7df389009 +Author: Harsh Khatore +Date: Mon Jun 12 13:46:51 2017 +0530 + + Added RecursiveBinarySearch [ C ] (#246) + + * added binary_search.cpp + + A program in C++ to perform a recursive binary search. + + * Create README.md + + * Created binary_search.cpp + + C++ implementation of recursive binary search. + + * Deleted binary_search.cpp + + Adding this program to the recursive_binary_search directory. + + * Update binary_search.cpp + + Updated the program for recursive binary search [C++]. + + * Updated the link for binary_search.cpp [C++] + + Updated the link for recursive binary search because it was added to a new directory. + + * Update BinarySearch.cpp + + Corrected the indentation according to the standards. + + * Updated binary_search.c [ C ] + + Added recursive implementation to binary_search.c [ C ] + + * Delete binary_search.cpp + + Added it to binary_search.c + + * Updated README.md + + Removed binary_search link for C++ because the file was merged with binary_search.c [ C ] + + * Update binary_search.c + + Updated the name of binarySearch function to recursive_binary_search + + * Update binary_search.c + + Corrected indentation in recursive_binary_search.c + + * Update binary_search.c + + Updated with proper brackets + + * Update binary_search.c + + Added required white spaces. + + * Updated binary_search.c + + Whitespace around binary operator + + * Update binary_search.c + + Corrected various syntactical inaccuracy + + * Update binary_search.c + + Corrected calling for recursive_binary_search function + + * Update binary_search.c + + Resolved the variable pos issue. + + * Update binary_search.c + + Resolved scope for variable pos + + * Update binary_search.c + + Resolved issues relating to format. + + binary_search/binary_search.c | 56 +++++++++++++++++++++++++++++++++++++------ + 1 file changed, 49 insertions(+), 7 deletions(-) + +commit 39de02d610ded1bacfb9dc5efae0b7888f360190 +Author: Monal Shadi +Date: Mon Jun 12 08:41:59 2017 +0530 + + Added Sieve of Eratosthenes [Java] (#245), fixes #234 + + * Update CONTRIBUTING.md for mentioning accepted languages + 1 more (#218), fixes #216 + + * Update CONTRIBUTING.md for mentioning accepted languages and meaningful function/method names. + + * Added Sieve of Eratosthenes [Java] Fixes #234 + + * newline at end + + * added comments + + README.md | 3 ++- + sieve_of_eratosthenes/SieveOfEratosthenes.java | 35 ++++++++++++++++++++++++++ + 2 files changed, 37 insertions(+), 1 deletion(-) + +commit 4069dfdf202e23af43740e6f29e9ce1ba6d6f089 +Author: Avi Aryan +Date: Mon Jun 12 07:18:27 2017 +0530 + + fix lint issues in .codecilmate.yml + + .codeclimate.yml | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +commit f44f7695a70af9bd3e4061cad94ba79a29e90762 +Author: Avi Aryan +Date: Mon Jun 12 07:09:08 2017 +0530 + + add .codeclimate.yml + + .codeclimate.yml | 20 ++++++++++++++++++++ + 1 file changed, 20 insertions(+) + +commit 6ef09b1ba57ce4c93bd36094261d227c4361e2fd +Author: Avi Aryan +Date: Sun Jun 11 18:19:44 2017 +0530 + + fix mis-aligned badges + + README.md | 1 + + 1 file changed, 1 insertion(+) + +commit 643704b5221caab26f91d606b79f53a266ccaa60 +Author: Pratyush Singh +Date: Sun Jun 11 18:07:05 2017 +0530 + + Add Stack [JavaScript] (#240), fixes #239 + + Edit .editorconfig for JS + + .editorconfig | 5 +++++ + README.md | 64 +++++++++++++++++++++++++++++----------------------------- + stack/stack.js | 37 +++++++++++++++++++++++++++++++++ + 3 files changed, 74 insertions(+), 32 deletions(-) + +commit 297da0f966d3f1a8bbb4e3e4f5e2d7b7c22dfb9a +Author: Aashutosh Rathi +Date: Sun Jun 11 14:53:04 2017 +0530 + + Fix #241: Add HappinessLintBear to .coafile (#244) + + * HappinessLintBear added + + * added badge and installed happiness + + * installed node.js to travis + + * nodeJS package install + + * nodeJS package install - 2 + + * nodeJS package install - 3 + + * nodeJS package install - 4 + + * nodeJS package install - 5 + + * nodeJS package install - 6 + + * npm install + + * Create .travis.yml + + * Make dist as trusty + + * Remove node_js descriptor and add version log + + * Update .travis.yml + + .coafile | 5 +++++ + .travis.yml | 5 +++++ + README.md | 1 + + 3 files changed, 11 insertions(+) + +commit 7c61a361e55325d135057bb23b313c515ca7b466 +Author: Heet Sankesara +Date: Sun Jun 11 13:53:06 2017 +0530 + + Added AVL Tree [Java] (#196) + + * Add AVL Tree[JAVA] + Add AVL tree + + Update Readme + + Update README.md + + Update README.md + + * Some Minor Changes + + * Some Minor changes + + * Throw Exceptions + + * Add Some Changes + + * Some minor Changes + + * Some changes according to @Monal5031 + + * make some changes + + * Update README.md + + README.md | 1 + + avl_tree/AvlTree.java | 272 ++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 273 insertions(+) + +commit c7464c5a070f83f0ad5a5db855f9d87b84b1ffa8 +Author: Aashutosh Rathi +Date: Sun Jun 11 12:52:19 2017 +0530 + + Added Binary Search [Go] (#238) + + minor fixes + + Changes as per comments + + minor fix + + changes suggested by Travis + + file name changed + + README.md | 2 +- + binary_search/binary_search.go | 31 +++++++++++++++++++++++++++++++ + 2 files changed, 32 insertions(+), 1 deletion(-) + +commit e9bf9779e96248d21ea4df2606a73a5c9dc708af +Author: Pratyush Singh +Date: Sat Jun 10 23:21:10 2017 +0530 + + Fix #229: Remove pylint + + .coafile | 5 ----- + 1 file changed, 5 deletions(-) + +commit 991ed3b55ca983425039be328dd2599bb25ac928 +Author: Monal Shadi +Date: Sat Jun 10 22:12:23 2017 +0530 + + Fix #197: Add Dijkstra [C] (#225) + + * Update CONTRIBUTING.md for mentioning accepted languages + 1 more (#218), fixes #216 + + * Update CONTRIBUTING.md for mentioning accepted languages and meaningful function/method names. + + * Added Dijkstra [C] + Fixes #197 + + * Made changes + + * Revert "Update CONTRIBUTING.md for mentioning accepted languages + 1 more (#218), fixes #216" + + This reverts commit fcc603849ceacb09366ad144a5b3d5a79a0efa15. + + README.md | 2 +- + dijkstra/dijkstra.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 66 insertions(+), 1 deletion(-) + +commit 836ec4a97086469a3b8d429537a6bc61f9169dde +Author: Stanislav Kozlovski +Date: Sat Jun 10 19:36:39 2017 +0300 + + Fix #226: Add Shell Sort [Python] (#227) + + * #226 Adds Shell Sort [Python] + + * Shell Sort [Python] - removed assert statement and empty new line to comply with PEP8 + + * Shell Sort [Python] - small code style changes + + * Removing trailing whitespace + + * Updated README.md to add shell sort + + * Added type hinting to shell sort + + * Updated shell_sort docstring and type hints + + * Removed type hinting so that its python 2 compatible + + README.md | 2 +- + shell_sort/shell_sort.py | 41 +++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 42 insertions(+), 1 deletion(-) + +commit 28f6bb11694249299a2e079ff43f615fa12992bf +Author: Aashutosh Rathi +Date: Sat Jun 10 20:39:10 2017 +0530 + + Fix #210: Add Rod Cutting [Python] (#219) + + * rod cutting [python] added + + * added spaces around binary operators + + updated as per linter suggestions + + * added module docstring + + * fixes + + * max over aggregated list taken + + * minor fix + + * final changes + + * Make the default value as the full size of rod + + * made default rod_len as full rod + + * fixed as per PEP8 + + * changes as per review + + * minor fix + + * added new variable for len(price) + + README.md | 2 +- + rod_cutting_problem/rod_cutting.py | 36 ++++++++++++++++++++++++++++++++++++ + 2 files changed, 37 insertions(+), 1 deletion(-) + +commit e0faaffaadec8c99af9378d385a528bac16138fe +Author: Aashutosh Rathi +Date: Sat Jun 10 20:33:13 2017 +0530 + + Fix #222: Add Haskell and Pylint to .coala (#223) + + * added haskell and pylint + + * GhcModBear added + + * add hlint check + + * adding numpy to whitelist try 1 + + * adding numpy to whitelist try 2 + + * adding numpy to whitelist try 3 + + * Try 5 + + * reverted attempts + + * reverted changes final + + .coafile | 15 +++++++++++++++ + .travis.yml | 1 + + 2 files changed, 16 insertions(+) + +commit b405d3aad3d9f3ea883d508b993f25622326aee3 +Author: Monal Shadi +Date: Sat Jun 10 01:06:13 2017 +0530 + + Update CONTRIBUTING.md (#218), fixes #216 + + * Update CONTRIBUTING.md for mentioning accepted languages and meaningful function/method names. + + CONTRIBUTING.md | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +commit c67e482c194780d91a32b98471895b4e1a6ed264 +Author: Mohit Kumar Yadav +Date: Fri Jun 9 11:32:16 2017 +0530 + + Added Shell Sort [Golang] (#217), fixes #203 + + * Added Shel Sort [GoLang] + + * Function name changed to ShellSort + + * Exported function comment + + * Exported func comment on top + + * Removed empty line + + * Added changes to README + + Readme was restored by mistake in a rebase. + + * Renamed shell_sort.go + + README.md | 2 +- + shell_sort/shell_sort.go | 28 ++++++++++++++++++++++++++++ + 2 files changed, 29 insertions(+), 1 deletion(-) + +commit 251dc20ca9c5597d9dfe357056abc22036e23ea4 +Author: Monal Shadi +Date: Fri Jun 9 08:51:24 2017 +0530 + + Fix #220: Remove typing errors in rod_cutting.c (#221) + + rod_cutting_problem/rod_cutting.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +commit 2d5aa08485d955acf9284d8393f798193abff447 +Author: Monal Shadi +Date: Thu Jun 8 21:17:14 2017 +0530 + + Adding Rod Cutting [C] (#214), fixes #209 + + * Add Rod Cutting Problem [C] + Fixes #209 + + * changes + + README.md | 2 +- + rod_cutting_problem/rod_cutting.c | 32 ++++++++++++++++++++++++++++++++ + 2 files changed, 33 insertions(+), 1 deletion(-) + +commit 169fe1d0d75456e38e500b0b7bf6b0e4515b4e8c +Author: Avi Aryan +Date: Thu Jun 8 12:25:31 2017 +0530 + + Add Stack [Golang] + + Fixes #202 + + README.md | 2 +- + stack/stack.go | 39 +++++++++++++++++++++++++++++++++++++++ + 2 files changed, 40 insertions(+), 1 deletion(-) + +commit f9856ba366256e7e4cb39a3c7904e5df31b2eca4 +Author: Aashutosh Rathi +Date: Thu Jun 8 07:00:03 2017 +0000 + + Added Modular Exponential [C] (#211), fixes #208 + + * Mod Exp [C] added + + { added to if block + + * base marked as long long to avoid overflow + + README.md | 2 +- + modular_exponential/modular_exponential.c | 23 +++++++++++++++++++++++ + 2 files changed, 24 insertions(+), 1 deletion(-) + +commit 390fb9e89c2a005bce2637118b8d3cabfa7c0544 +Author: Monal Shadi +Date: Thu Jun 8 10:28:34 2017 +0530 + + Added travis CI badge to Readme + Fixed #206 + + README.md | 1 + + 1 file changed, 1 insertion(+) + +commit 8c9ca7447dfb08a1f71a9f0d7e7dea8ef34a391c +Author: Aashutosh Rathi +Date: Wed Jun 7 07:16:49 2017 -0700 + + Added .editorconfig (#205), fixes #199 + + * .editorconfig added + + * added tab_width + + changed py acc to pep8 + + * c/c++ and java added + + .editorconfig | 25 +++++++++++++++++++++++++ + 1 file changed, 25 insertions(+) + +commit cc4a8ad0a315f271cc22bb26fbe9e0ead2bfd74b +Author: Mohit Kumar Yadav +Date: Wed Jun 7 10:04:26 2017 +0530 + + Added Shell Sort [CPP] (#198) + + * Added shell_sort + + * Removed `floor()`, following `lowerCamelCase` + + * safe integer casting + + * Added compiling description + + * using tab indentaion + + * pre-increment + + * Added print() function + + README.md | 3 ++- + shell_sort/ShellSort.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 45 insertions(+), 1 deletion(-) + +commit b7d216c9d1318afe78264bcf17607292842434fd +Author: Monal Shadi +Date: Wed Jun 7 10:03:12 2017 +0530 + + Fixed Issues raised by PEP8Bear (#201) + + Fixes #200 + + merge_sort/merge_sort.py | 1 + + modular_exponential/modular_exponential.py | 1 + + quicksort/quick_sort.py | 1 + + stack/stack.py | 1 + + 4 files changed, 4 insertions(+) + +commit 4a3fc3c8afa02062d184ba92cffa18aa69523d46 +Author: Monal Shadi +Date: Wed Jun 7 09:03:32 2017 +0530 + + Fix #191: Add PEP8Bear and YAMLLintBear to .coafile (#194) + + Fixes #191 + + .coafile | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +commit d61b1a54408aa2144d1f5dbb5f1c1a1a66a25886 +Author: Monal Shadi +Date: Wed Jun 7 00:49:22 2017 +0530 + + Fix #119: Add N-Queen Problem [Java] (#188) + + Fixes #119 + + README.md | 2 +- + n_queen_problem/NQueenProblem.java | 64 ++++++++++++++++++++++++++++++++++++++ + 2 files changed, 65 insertions(+), 1 deletion(-) + +commit 389a596ecfc945c126b7aac787e3bd90e4ba2193 +Author: Heet Sankesara +Date: Fri Jun 2 08:10:09 2017 +0530 + + Added bin sort [Java] (#167), fixes #108 + + * Added bin sort + + * Some indentation improvement + + * Del Bin Sort + + * Add Bin Sort + + * Change Readme.md + + * Update README.md + + * Change Readme.md + + * Change README.md + + * Improve some mistakes + + * Change Readme.md + + * Again Change Readme.md + + * Add Bin Sort + + * Some Changes + + * Update README.md + + * Improve some mistake + + * Update README.md according to @Monal5031 + + * Change to Bottom Up approach + + * Some changes according to @singhpratyush + + * Remove unnecessary newlines + + * Some Minor changes + + * Changes according to previous reviews + + README.md | 1 + + bin_sort/BinSort.java | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 76 insertions(+) + +commit f4399094155b5d84c7d9d7efb9c42321983ff89e +Author: TarunISCO <201552063@iiitvadodara.ac.in> +Date: Thu May 25 12:27:23 2017 +0530 + + modified + + breadth_first_search/BreadhFirstSearch.cpp | 52 +++++++++++++++++------------- + 1 file changed, 30 insertions(+), 22 deletions(-) + +commit ba30f55d0da5f373421d46ffc3743d42feb1afba +Author: TarunISCO <201552063@iiitvadodara.ac.in> +Date: Wed May 24 23:45:22 2017 +0530 + + Added Breadth First Search [C++] + + breadth_first_search/BreadhFirstSearch.cpp | 54 ++++++++++++++++++++++++++++++ + 1 file changed, 54 insertions(+) + +commit 89badd64d9628139ed50b6a50b94628963c29e94 +Author: Pratyush Singh +Date: Wed May 24 18:18:02 2017 +0530 + + Correct link to LCS Java in README + + README.md | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit a33eb82b16cf10a6b204fefb4887d55e6db6d724 +Author: Tarun Bhardwaj <201552063@iiitvadodara.ac.in> +Date: Wed May 24 18:15:10 2017 +0530 + + Fix #168: Add longest common Subsequence [Java] (#180) + + * Added longest common Subsequence + + * please review again + + * please check again + + * hope final review now + + * check + + * is it acceptable now? + + * all changes done + + * made class public and formatting done + + * changed class name and file name + + * updated readme.md + + * updated readme.md + + * updated readme.md linear search + + * readme.md changed + + README.md | 4 +-- + .../LongestCommonSubsequence.java | 41 ++++++++++++++++++++++ + 2 files changed, 43 insertions(+), 2 deletions(-) + +commit f95de61b688926ed0fec9069ebd5974c539edc98 +Author: Prakash Rai <201551009@iiitvadodara.ac.in> +Date: Wed May 24 00:02:41 2017 +0530 + + Fix #181: Add Dijkstra Algorithm [Java] (#186) + + * Update Dijkstra.java + + * Added Dijkstra Algorithm + + * Updated Dijkstra.java + + README.md | 1 + + dijkstra/Dijkstra.java | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 95 insertions(+) + +commit a9d846ee00f79cc17d3ce712b38e65c5ee67a10f +Author: Himanshu Sharma +Date: Tue May 23 23:55:39 2017 +0530 + + Fix #184: Add prims [C] (#185) + + * Added prims + + * Indentation fixed + + * Indentation and Error fixed + + * Error fixed + + * variable error deleted + + * tabspace fixed + + * tabspace fixed + + * Indentation fixed + + * Runtime error fixed + + * int's max value changed + + * INT_MAX taken instead of INFINITY + + README.md | 2 +- + prims/prims.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 48 insertions(+), 1 deletion(-) + +commit 6a144ba82f300b9ccda94d33479e8fc952ac1aad +Author: Mohit Kumar Yadav +Date: Mon May 15 17:44:40 2017 +0530 + + Added Longest Common Subsequence [Golang] (#178), fixes #170 + + * Added Longest Common Subsequence [GoLang] + + * Strings hardcoded + + * Update longestCommonSubsequence.go + + * Strings hardcoded + Update longestCommonSubsequence.go + + README.md | 2 +- + .../longestCommonSubsequence.go | 36 ++++++++++++++++++++++ + 2 files changed, 37 insertions(+), 1 deletion(-) + +commit 80fd1509b22378426212162ffe383e10a34da8ee +Author: Monal Shadi +Date: Mon May 15 17:41:30 2017 +0530 + + add *.orig, *.exe, *.out to gitignore (#172), fixes #171 + + .gitignore | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +commit 5d38945fba7133ca765de3519cbb771f746c049d +Author: Prakash Rai <201551009@iiitvadodara.ac.in> +Date: Mon May 15 17:39:39 2017 +0530 + + Fix issues in Stack implementation [Python] (#174), fixes #125 + + stack/stack.py | 40 +++++++--------------------------------- + 1 file changed, 7 insertions(+), 33 deletions(-) + +commit 12c542023d4bfe6e2e9dbcfea6a5233f38885918 +Author: Aashutosh Rathi +Date: Sun May 14 11:06:21 2017 +0530 + + Change HTTPS to HTTP for counting sort (#176) + + * Dead Link Fixed + + * HTTPS switched to HTTP + + * Fixes + + * Update README.md + + README.md | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit 74a2e8beec5a99ea4bc29f2108acf4d09f337471 +Author: Aashutosh Rathi +Date: Sun May 14 10:36:40 2017 +0530 + + Dead Link Fixed (#175), fixes #173 + + README.md | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit 15e38f3564939522efb51e4926c68064d0a55800 +Author: Monal Shadi +Date: Sun May 14 06:21:53 2017 +0530 + + fixes #164: Add solution to counting sort [C] (#165) + + Fixed #164 + + README.md | 2 +- + counting_sort/counting_sort.c | 38 ++++++++++++++++++++++++++++++++++++++ + 2 files changed, 39 insertions(+), 1 deletion(-) + +commit 6f9686af1000246ce8d89bd176ff7d5ed60c2d8f +Author: Prakash Rai <201551009@iiitvadodara.ac.in> +Date: Sun May 14 06:18:48 2017 +0530 + + fixes #166: Add solution to rod cutting problem [Java] (#166) + + * Added Rod Cutting Problem [Java] + + * Update README.md + + README.md | 1 + + rod_cutting_problem/RodCutting.java | 26 ++++++++++++++++++++++++++ + 2 files changed, 27 insertions(+) + +commit 206de85b7d22b5fe1a1e9677d7e9e4b5ebf3c7a0 +Author: Avi Aryan +Date: Sat May 13 16:30:35 2017 +0530 + + [coala] add gofmt check + + .coafile | 5 +++++ + linear_search/linear-search.go | 28 ++++++++++++++-------------- + 2 files changed, 19 insertions(+), 14 deletions(-) + +commit 8c9ac96cb397993efd3071c8d4038297403d28a3 +Author: Avi Aryan +Date: Sat May 13 16:21:12 2017 +0530 + + [coala] add golint check + + commit 1c88fa9985b8d804eea1fe59c9ce4f947187b96a + Author: Avi Aryan + Date: Sat May 13 16:01:30 2017 +0530 + + install golang in travis and install golint manually + + commit 7d40c06a388484e61b4917ad3784b7d110f6a320 + Author: Avi Aryan + Date: Sat May 13 15:46:19 2017 +0530 + + [coala] add golint check + + .coafile | 5 +++++ + .travis.yml | 11 +++++++++++ + 2 files changed, 16 insertions(+) + +commit c892617f5c9eca960334fd6345197e3825c44ec0 +Author: Avi Aryan +Date: Sat May 13 15:32:23 2017 +0530 + + Revert "[coala] add C indent check" + + This reverts commit cca8d34852dddc70305c7d3d5e8ea018f53edd93. + + This is being done because GNU Indent is a very feature rich program and not suitable for checking if C code is indented using tabs or not. + + .coafile | 7 ------- + .travis.yml | 2 -- + 2 files changed, 9 deletions(-) + +commit cca8d34852dddc70305c7d3d5e8ea018f53edd93 +Author: Avi Aryan +Date: Sat May 13 15:06:53 2017 +0530 + + [coala] add C indent check + + .coafile | 7 +++++++ + .travis.yml | 2 ++ + 2 files changed, 9 insertions(+) + +commit 4c1e1c45a00ee56a4ce91f1f8d6eae9e875df089 +Author: Avi Aryan +Date: Sat May 13 13:58:06 2017 +0530 + + add coala with travis integration + + .coafile | 10 ++++++++++ + .travis.yml | 7 +++++++ + euclidean_gcd/euclidean_gcd.py | 6 +++--- + 3 files changed, 20 insertions(+), 3 deletions(-) + +commit 9715cb1fd771e8b196b3791c6afbe561223b8028 +Author: Pratyush Singh +Date: Thu May 11 03:13:50 2017 +0530 + + Remove label adding instruction for new issues + + CONTRIBUTING.md | 1 - + 1 file changed, 1 deletion(-) + +commit cf543bab2dc45a7270afd382249247c6c4a1d719 +Author: Pratyush Singh +Date: Thu May 11 03:05:09 2017 +0530 + + Change CONTIBUTING for global contributors + + CONTRIBUTING.md | 6 +----- + 1 file changed, 1 insertion(+), 5 deletions(-) + +commit 982d68f87d43322da8378ec2ac49cf365d976b9c +Author: Pratyush Singh +Date: Thu May 11 03:02:39 2017 +0530 + + Remove IIITV only from README + + README.md | 1 - + 1 file changed, 1 deletion(-) + +commit 353cee14bb56d96b71bb80ce613f5ecc538217a0 +Author: Prakash Rai <201551009@iiitvadodara.ac.in> +Date: Tue May 9 10:20:10 2017 +0530 + + Updated Stack.java (#161). Related #125 + + * Updated Stack.java + + Removed peek() + Removed size + Removed getSize() + Removed displayStack() + + * Updated Stack.java + + * Update Stack.java + + stack/Stack.java | 77 ++++++++++++++------------------------------------------ + 1 file changed, 19 insertions(+), 58 deletions(-) + +commit 5cd280b02f7010cf60dc0b6f6b345a9c9575487b +Author: Aashutosh Rathi +Date: Mon May 8 20:38:19 2017 +0530 + + Added Randomized Pivot using 3 Pivot Technique in Quick Sort [Python] (#147). Closes #144 + + * Quick Sort [Python] Randomize Pivot + + changed p to l + + Documentation of functions changed + + * Update quick_sort.py + + quicksort/quick_sort.py | 45 ++++++++++++++++++++++++++++++++++----------- + 1 file changed, 34 insertions(+), 11 deletions(-) + +commit cb970bf97e7247f6b0622e4736ef563640db8608 +Author: Monal Shadi +Date: Thu May 4 13:05:49 2017 +0530 + + Made changes in QuickSort.java. Closes #145 + + Fixed #145 + + quicksort/QuickSort.java | 38 +++++++++++++++++++------------------- + 1 file changed, 19 insertions(+), 19 deletions(-) + +commit 3814db0a4b569ac3ebedd282534bcdf0828d4536 +Author: Mohit Kumar Yadav +Date: Sun Apr 30 15:53:12 2017 +0530 + + Largest Sum Contiguous Subarray [Golang] (#157), fixes #156 + + * Create largestSumContiguousSubarray.go + Added largestSumContiguousSubarray.go + fixed underscored variable declarations + + * Passing array + + passing array as function param + + README.md | 2 +- + .../largestSumContiguousSubarray.go | 25 ++++++++++++++++++++++ + 2 files changed, 26 insertions(+), 1 deletion(-) + +commit 5908e8f8d923f3b5e89f2022b45aa4e6eff3a061 +Author: Avi Aryan +Date: Sun Apr 23 16:19:49 2017 +0530 + + Add issue number to PR template + + PULL_REQUEST_TEMPLATE.md | 3 +++ + 1 file changed, 3 insertions(+) + +commit 1c70465e6786fc4d1227627c3fe72ce1db8d0c77 +Author: Mohit Kumar Yadav +Date: Sun Apr 23 16:16:17 2017 +0530 + + Added Sieve Of Eratosthenes [Golang] (#153), fixes #152 + + * Create sieve_of_eratosthenes.go + + Created sieve_of_eratosthenes.go + + * Update sieve_of_eratosthenes.go + + Fixed some linting issues + Added Sieve Of Eratosthenes + Update sieve_of_eratosthenes.go + + Added comments + Update sieve_of_eratosthenes.go + + Trying to resolve codacy issues + Update sieve_of_eratosthenes.go + Update sieve_of_eratosthenes.go + + * add skeleton code for golang, fixes #154 + + * Tested with golint + + * add skeleton code for golang, fixes #154 + + * Update sieve_of_eratosthenes.go + + Corrected comments + + * Checked with GoSublime + + Corrected some linting errors + + * Improved + + README.md | 2 +- + sieve_of_eratosthenes/sieve_of_eratosthenes.go | 34 ++++++++++++++++++++++++++ + 2 files changed, 35 insertions(+), 1 deletion(-) + +commit fa74d43c4827394f323133641e98521aade82b39 +Author: Avi Aryan +Date: Sat Apr 22 01:13:21 2017 +0530 + + add skeleton code for golang, fixes #154 + + CONTRIBUTING.md | 22 +++++++++++++++++++++- + 1 file changed, 21 insertions(+), 1 deletion(-) + +commit 0d6ebbcb7f682cb3278fe12b76e88de149a2f911 +Author: Pratyush Singh +Date: Fri Apr 21 00:13:58 2017 +0530 + + Add Linear Search [Golang] (#151), fixes #150 + + * Add Linear Search [Golang]. Closes #150 + + * Remove space in print statement + + * Remove trailing space in README table header + + README.md | 54 +++++++++++++++++++++--------------------- + linear_search/linear-search.go | 22 +++++++++++++++++ + 2 files changed, 49 insertions(+), 27 deletions(-) + +commit 30c0e426b84c323f07c9459dbd9154e0f7d37219 +Author: Monal Shadi +Date: Thu Apr 20 23:39:24 2017 +0530 + + Added Binary Search Tree [Java] (#149), fixes #146 + + Fixed #146 + + README.md | 3 +- + binary_search_tree/BinarySearchTree.java | 183 +++++++++++++++++++++++++++++++ + 2 files changed, 185 insertions(+), 1 deletion(-) + +commit 3c57b6f3c8e1c40feaed0860e0b8ca8f2cd22b48 +Author: Aashutosh Rathi +Date: Mon Apr 17 21:53:02 2017 +0530 + + [Refractor] Update Merge Sort to be more Pythonic + + Related: #137 #139 + + Commits - + * Added Merge Sort [Python] + + * Added Merge Sort [Python] + + * Changed Merge Sort [Python] + + * Added new line + + * removed blank line + + * Update merge_sort.py + + * Update merge_sort.py + + merge_sort/merge_sort.py | 52 +++++++++++++++++------------------------------- + 1 file changed, 18 insertions(+), 34 deletions(-) + +commit 679b2bc5df782e062cb0568c4b61244dcc0c3fc8 +Author: Aashutosh Rathi +Date: Mon Apr 17 21:49:07 2017 +0530 + + Added Quick Sort [Python] (#141). Closes #140 + + removed brackets to make it more pythonish + + minor changes + + minor fixes + + removed extra file + + README.md | 2 +- + quicksort/quick_sort.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 45 insertions(+), 1 deletion(-) + +commit 1bfc6360a85753ba54af84f879b3319da3763094 +Author: Aashutosh Rathi +Date: Sun Apr 16 22:33:11 2017 +0530 + + Added Merge Sort [Python] (#139), fixes #137 + + * Added Merge Sort [Python] + + * Added Merge Sort [Python] + + README.md | 2 +- + merge_sort/merge_sort.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 69 insertions(+), 1 deletion(-) + +commit 62f317d3d8bf2f1fabc07b9187707f4095c8a908 +Author: Piyush Pawar +Date: Sat Apr 15 01:22:22 2017 +0530 + + Added Singly Linked List [Java] (#128). Closes #126 + + * Added Linked List + + * Added spaces + + * Removed temp var and java.lang library + + * Changed name of main class + + * Methods class renamed + + * Changed main class + + * Updates + + * Added Spaces + + README.md | 1 + + linked_list/LinkedList.java | 215 ++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 216 insertions(+) + +commit 3793598dfc7f1dd8050517d4a076a10936ff4563 +Author: Monal Shadi +Date: Fri Apr 14 09:18:57 2017 +0530 + + Added Merge Sort [C] (#138). Closes #17 + + Fixed #17 + + README.md | 2 +- + merge_sort/merge_sort.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 62 insertions(+), 1 deletion(-) + +commit e6fd1056bd5ecac18e770e1820a5712f1e9faf9b +Author: Aashutosh Rathi +Date: Wed Apr 12 15:00:48 2017 +0530 + + Added Modular Exponentiation [JAVA] (#136), closes #135 + + * Updating + + * added mod expo + + * minor changes + + * Added Modular Exponentation [Java] + Fixed #135 + + README.md | 2 +- + modular_exponential/ModularExponential.java | 24 ++++++++++++++++++++++++ + 2 files changed, 25 insertions(+), 1 deletion(-) + +commit 9c3edc598d8f92dcb2439be47ec50b4b9f7a9ae2 +Author: Piyush Pawar +Date: Wed Apr 12 14:58:03 2017 +0530 + + Added Insertion Sort [Java] (#134), closes #109 + + * Added Insertion Sort + + * Removed blank lines + + * Updated Readme + + README.md | 2 +- + insertion_sort/InsertionSort.java | 27 +++++++++++++++++++++++++++ + 2 files changed, 28 insertions(+), 1 deletion(-) + +commit 322733db515efb5ea59cdf5abf0625d32e06efb1 +Author: Avi Aryan +Date: Wed Apr 12 09:55:14 2017 +0530 + + Added PR closing information (#133). Closes #130 + + * chore: add PR closing information + + * docs: improve language + + PULL_REQUEST_TEMPLATE.md | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +commit 59fe57c8ce8da96711004fadeee1fd876bee96ce +Author: Jitendra Singh +Date: Wed Apr 12 00:08:37 2017 +0530 + + Added Depth First Traversal [Java] (#100), fixes #99 + + * added quick sort in java + + * commenting + + * update with code conventions + + * declare public class : Codacy + + * rename varible + + * Added depth first traversal + + * link added + + * link added + + * link added + + * blank line space + + * implement using stack + + * remove extra line + + * bracket + + * space + + * Using list and set + + * fixed codacy + + * define public Constructor + + * update + + * update + + * dFS to dfs + + README.md | 1 + + depth_first_traversal/DepthFirstTraversal.java | 55 ++++++++++++++++++++++++++ + 2 files changed, 56 insertions(+) + +commit 43c80b4882e24180eafac14efa1d95ba87327618 +Author: Monal Shadi +Date: Fri Apr 7 17:01:02 2017 +0530 + + Added Heap Sort [Java] (#129). Closes #127 + + Fixed #127 + + README.md | 2 +- + heap_sort/HeapSort.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 46 insertions(+), 1 deletion(-) + +commit 1537e8c2e7a8780cbb32cc35c13b2594539098ac +Author: Mohit Kumar Yadav +Date: Fri Apr 7 11:09:56 2017 +0530 + + Added Heap sort [C] (#124), fixes #91 + + * Added Heap sort [c] + + first commit + + * Added Heap sort [c] + + * Update HeapSort.c + + * Update HeapSort.c + + * Changes done. + + Added an extra blank line before "return 0". + Removed extra whitespace from line 53 + Removed hard coded 7 from line 55 + + * Update HeapSort.c + + No need to change "SIZE" everytime. + + * Update HeapSort.c + + No need to change "SIZE" every time. + Changed i to root in line no 11. + + * Rename HeapSort.c to heap_sort.c + + * Update heap_sort.c + + Small caps for SIZE and HEAPSIZE. + + * Changes requested by @Monal5031 + + * Updated + + * Update README.md + + README.md | 1 + + heap_sort/heap_sort.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 61 insertions(+) + +commit c00703b107af6b19aa8660d7a50823a535883ede +Author: Yash Ladha <201551061@iiitvadodara.ac.in> +Date: Tue Apr 4 02:57:51 2017 +0530 + + Added Prims [Java] (#118), closes #116 + + * Added Prims [Java] + Closes #116 + + * Removed Public before class + + * Added public + + * Minor changes + + README.md | 1 + + prims/Prims.java | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 75 insertions(+) + +commit ed57e01e15eb99ead41fb61c18bc53cfe9064471 +Author: Monal Shadi +Date: Tue Apr 4 02:55:53 2017 +0530 + + Added Stack [Java] (#117) + + * Added Stack implementation + + * new line at end + + * Removed extra tabspace + + * public keyword removed + + * Exception thrown from methods + + * minor indentation fixed + + * Descriptive messages in Exception + + * Minor spacing fix + + * spacing fixed + + README.md | 2 +- + stack/Stack.java | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 84 insertions(+), 1 deletion(-) + +commit 91e6df6a1fd03454527fff008aa50c69c07417d1 +Author: Piyush Pawar +Date: Mon Apr 3 23:45:43 2017 +0530 + + Added Linear Search [Java] (#123). Closes #122 + + * Added Linear Search + + * changes updated + + * added spaces + + * Removed blank line + + README.md | 2 +- + linear_search/LinearSearch.java | 30 ++++++++++++++++++++++++++++++ + 2 files changed, 31 insertions(+), 1 deletion(-) + +commit 73888961b7e84261e1b8c508fcc57c2521bc5029 +Author: Heet Sankesara +Date: Mon Apr 3 23:12:53 2017 +0530 + + Added Counting Sort [Java] (#114). Closes #101 + + * Adding counting Sort + + * Updated Readme.md + + * new line at end + + * Changes according to @Monal5031 + + * Fixed Indentations + + * Update CountingSort.java + + * Use Bottom down approach + + * Update CountingSort.java + + * Update CountingSort.java + + * Update CountingSort.java + + * solve alignment issues and other.... + + * Add Comments in Code + + * commit changes according to previous review + + * Update CountingSort.java + + README.md | 1 + + counting_sort/CountingSort.java | 33 +++++++++++++++++++++++++++++++++ + 2 files changed, 34 insertions(+) + +commit b232c7e4ad668974bffeda39a533d310592d391d +Author: Divyesh Puri +Date: Sat Apr 1 01:18:33 2017 +0530 + + Added Largest Sum Contiguous SubArray [C] (#112), closes #111 + + * Added Largest Sum Continous SubArray [C] + + * updated Readme.md + + * updated changes as per requested + + * updated + + * minor fixes + + README.md | 2 +- + .../largestSumContiguousSubarray.c | 25 ++++++++++++++++++++++ + 2 files changed, 26 insertions(+), 1 deletion(-) + +commit 77b770472e8afb10fe2cbfe87437b983fdfb79b0 +Author: PiyushPawar17 +Date: Wed Mar 29 23:16:02 2017 +0530 + + Added Linear Search [C] (#90), fixes #85 + + * added linear search [C] + + * updated Readme + + * removed blank space + + * changes fixed + + * removed some blank lines + + * Update linear_search.c + + README.md | 2 +- + linear_search/linear_search.c | 36 ++++++++++++++++++++++++++++++++++++ + 2 files changed, 37 insertions(+), 1 deletion(-) + +commit 2e0cda63f475436bfa0d265b40efb2037fc3bcf8 +Author: Yash Ladha <201551061@iiitvadodara.ac.in> +Date: Wed Mar 29 23:09:14 2017 +0530 + + Added Modular Exponential [Python] (#97), closes #96 + + * Added Modular Exponential[Python] Closes #96 + + * Hard Coded Data + + * Changed Arguments name + + * Applied Skeleton Code Changes' + + * Changed Parameter names + + * Made Changes + + * Made Changes + + * Added docstring and Changed Values + + * Explained DocString + + * Explained DocString + + * Explained DocString + + * Removed Extra statements + + * Followed PEP8 guidelines + + README.md | 1 + + modular_exponential/modular_exponential.py | 36 ++++++++++++++++++++++++++++++ + 2 files changed, 37 insertions(+) + +commit bedb759762927526c6f979325f90383e27b85d5a +Author: Monal Shadi +Date: Wed Mar 29 23:07:37 2017 +0530 + + updated CONTRIBUTING.md (#110), fixes #107 + + * updated contributing.md + + * Updated Contributing.md + + CONTRIBUTING.md | 1 + + 1 file changed, 1 insertion(+) + +commit 6083242033aad801ae9893674184477cf9fd4678 +Author: Monal Shadi +Date: Wed Mar 29 04:37:01 2017 +0530 + + Added Sieve of Eratosthenes [Python] (#95), closes #94 + + * added sieve-of-erastosthenes + + * Spelling fixes + + * changes fixed + + * removed duplicate file + + * Minor fixes + + * readme fixed + + * made specified changes + + * Changes Fixed + + README.md | 2 +- + sieve_of_eratosthenes/sieve_of_eratosthenes.py | 29 ++++++++++++++++++++++++++ + 2 files changed, 30 insertions(+), 1 deletion(-) + +commit 5c2cd85fa56fdcf1cda8b3d660c50dbad34ee656 +Author: Aashutosh Rathi +Date: Wed Mar 29 03:53:39 2017 +0530 + + Added Binary Search [Python] (#89), closes #59 + + * Binary Search [Python} + + * Added Binary Search [Python] + + * Added Binary Search + + * Added Binary Search [Python] + + * Update binary_search.py + + * Update binary_search.py + + * Added Binary Search [Python] + + * Added Binary Search [Python] + + * Added Binary Search [Python] + + * Added Binary Search [Python] + + * Added Binary Search [Python] + + * Added Binary Search [Python] + + * Added Binary Search [Python] + + * minor changes + + * Added Binary Search [Python] + + * patched default variables + + * Added Binary Search [Python] + + * added condition when right is None + + * Minor spacing changes + + * Added Binary Search [Python] + + * Added Binary Search [Python] + + README.md | 2 +- + binary_search/binary_search.py | 72 ++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 73 insertions(+), 1 deletion(-) + +commit 2145ca66f9528ec11a3e1463ee0a9e45bec4fdc2 +Author: Avi Aryan +Date: Sat Mar 25 21:42:37 2017 +0530 + + docs: removed duplicate entry of Insertion Sort + + also added Mac DS_Store to gitignore + + .gitignore | 2 ++ + README.md | 1 - + 2 files changed, 2 insertions(+), 1 deletion(-) + +commit ba21d9f4f70f74c83cefbd96720cbb3edf2defea +Author: Yash Ladha <201551061@iiitvadodara.ac.in> +Date: Sat Mar 25 21:40:26 2017 +0530 + + Added Prime Factor [C] (#75) closes #26 + + README.md | 1 + + prime_factor/prime_factor.c | 43 +++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 44 insertions(+) + +commit 599b16ba257365e8e88f5518080745e764d266ef +Author: Jitendra Singh +Date: Sat Mar 25 21:35:27 2017 +0530 + + Added QuickSort [Java] (#83) + + * added quick sort in java + + * commenting + + * update with code conventions + + * declare public class : Codacy + + * rename varible + + README.md | 2 +- + quicksort/QuickSort.java | 36 ++++++++++++++++++++++++++++++++++++ + 2 files changed, 37 insertions(+), 1 deletion(-) + +commit 343bab9a5e434b82f2046fb5debad5d9188c5359 +Author: Monal Shadi +Date: Sat Mar 25 19:46:07 2017 +0530 + + Added fast exponentation [C] (#67) + + * Added exponentation_by_squaring.c + + * Update exponentation_by_squaring.c + + * Negative power case added, return type long double + + * tabs and spaces fixed + + * Logic fixed, test-case changed + + * minor fix + + * -ve case added + + * Changes fixed + + README.md | 2 ++ + .../exponentation_by_squaring.c | 31 ++++++++++++++++++++++ + 2 files changed, 33 insertions(+) + +commit 45e6b7bc0eda01fbe4768551183ff723630b0890 +Author: Mohit Kumar Yadav +Date: Sat Mar 25 14:33:36 2017 +0530 + + [refactor] Removed C methods from NQueenProblem.cpp (#92) + + * Some changes suggested by @singhpratyush + + Removed printf + extra space around << + + I want to use memset so string.h can't be removed. + + * Update NQueenProblem.cpp + + * Update NQueenProblem.cpp + + n_queen_problem/NQueenProblem.cpp | 18 +++++++++--------- + 1 file changed, 9 insertions(+), 9 deletions(-) + +commit 3b3c1aeedb50c0895894a3ac88bd62e5e6a4cff7 +Author: Mohit Kumar Yadav +Date: Sat Mar 25 12:55:35 2017 +0530 + + Added Backtracking algorithm (N-Queen Problem) [CPP] #87 + + commit f7c6af7a8fc39d5ed114c07a38a6729dba37888e + Merge: 6ad43d3 edd810c + Author: Avi Aryan + Date: Sat Mar 25 12:54:12 2017 +0530 + + Merge branch 'master' of https://github.com/mohitkyadav/algos into mohitkyadav-master + + commit edd810c4723b3cc219818070b7e626f71ac4271b + Author: Mohit Kumar Yadav + Date: Fri Mar 24 07:27:18 2017 -0700 + + find_solution is now n_queen_solution + + commit d4266f291c4650e539f4dab3e25ea958e71aa29d + Author: Mohit Kumar Yadav + Date: Fri Mar 24 16:36:33 2017 +0530 + + changed side to SIDE + + commit 39286ee472f7bcf7ddb093e5581573ab3d5fe9a3 + Author: Mohit Kumar Yadav + Date: Fri Mar 24 16:31:16 2017 +0530 + + indentation correction + + commit a10dcbeceb92969df88dade5c7473317fb7e9877 + Author: Mohit Kumar Yadav + Date: Fri Mar 24 16:12:13 2017 +0530 + + Update NQueenProblem.cpp + + commit 5ce3b8f889bd19102d1983a68cdd3a7eb46fceb7 + Author: Mohit Kumar Yadav + Date: Fri Mar 24 16:04:05 2017 +0530 + + Update NQueenProblem.cpp + + commit 266e21f2569e7678006cac7f7693b0b188956e29 + Author: Mohit Kumar Yadav + Date: Fri Mar 24 16:02:05 2017 +0530 + + Update README.md + + commit fb5e569450fcfb91717f70a1874aeb419d543d55 + Author: Mohit Kumar Yadav + Date: Fri Mar 24 16:00:51 2017 +0530 + + Update README.md + + commit 932c45b60070e19f926d3fb39c8bd199491bf5fa + Author: Mohit Kumar Yadav + Date: Fri Mar 24 15:59:01 2017 +0530 + + Update README.md + + commit 35046b23d93fabec1323fddaaeb48c5421762941 + Author: Mohit Kumar Yadav + Date: Fri Mar 24 15:52:36 2017 +0530 + + Brackets are good... + + commit 5d33712b801e80569b2d54ae94396e9cb6998146 + Author: Mohit Kumar Yadav + Date: Fri Mar 24 15:30:55 2017 +0530 + + no double spaces, no capital letters + + commit 62f911e722237db7b34c5a6962dc4f295f3b1a70 + Author: Mohit Kumar Yadav + Date: Fri Mar 24 15:23:18 2017 +0530 + + a few changes + + Find_solution changed to find_solution. + "Size" variable is now "side". + + commit b293c4506ac2bd84dcbd8e72b6218adb27f371c0 + Author: Mohit Kumar Yadav + Date: Thu Mar 23 13:43:54 2017 -0700 + + !st commit + + Added N-Queen problem. + + README.md | 1 + + n_queen_problem/NQueenProblem.cpp | 71 +++++++++++++++++++++++++++++++++++++++ + 2 files changed, 72 insertions(+) + +commit 6ad43d3c559c67d0e4d64abfd1e49e6de88750b8 +Author: R@jeev +Date: Fri Mar 24 22:39:07 2017 +0530 + + Added Insertion Sort [Python] (#86). Closes #84 + + * first experiment in local branch + + * Experiment done + + * inertion_sort added + + * space removed + + * whitespace removed + + * indentent fixed + + * space fixed + + * delete extra file added + + * updated + + * re indent + + README.md | 2 +- + insertion_sort/insertion_sort.py | 22 ++++++++++++++++++++++ + 2 files changed, 23 insertions(+), 1 deletion(-) + +commit fef93c0214f247f9cbe11f60e38d8226b674cb6a +Author: Pratyush Singh +Date: Fri Mar 24 17:07:09 2017 +0530 + + Added Stack [Python]. Closes #80 + + README.md | 1 + + stack/stack.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 63 insertions(+) + +commit 48c6bdba7a91373865a844ef0fe054f539ec64cf +Author: Sandeep Kumar +Date: Fri Mar 24 16:12:06 2017 +0530 + + Added Largest Sum Contiguous Subarray [Java] (#74). Closes #72 + + * Added Largest Sum Contiguous Subarray + + * Added Largest Sum Contiguous Subarray + + * Update Largest Sum Contiguous Subarray + + * Updated Largest Sum Contiguous Subarray + + * updated Read me + + * Added Largest Sum Contiguous Subarray + + * Delete largest_sum_contiguous_subarray.java + + * Update LargestSumContiguousSubarray.java + + * Added Largest Sum Contiguous Subarray + + * Update LargestSumContiguousSubarray.java + + * Updated Read me file + + * Updates Largest Sum Contiguous Subarray + + * Update README.md + + * Updated Largest Sum Contiguous Subarray + + * Update LargestSumContiguousSubarray.java + + * Update LargestSumContiguousSubarray.java + + * Update LargestSumContiguousSubarray.java + + * Update LargestSumContiguousSubarray.java + + * Update LargestSumContiguousSubarray.java + + * Update LargestSumContiguousSubarray.java + + * Update LargestSumContiguousSubarray.java + + README.md | 1 + + .../LargestSumContiguousSubarray.java | 32 ++++++++++++++++++++++ + 2 files changed, 33 insertions(+) + +commit 3f89a87ef7065c10dcd0a8b92d632a9f3968c57b +Author: Pratyush Singh +Date: Sat Mar 18 21:45:59 2017 +0530 + + Added k-NN algorithm [Python]. Closes #41 + + README.md | 1 + + k_nn/k_nn.py | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 96 insertions(+) + +commit a0872ab9a9be364c8947d414b0b5c7a1df282a58 +Author: Avi Aryan +Date: Wed Mar 22 23:11:13 2017 +0530 + + docs: Included DS in documents, fixes #69 + + * docs: included DS with algorithms in the documents + + * docs: updated PR template, added a missing DS a/c review comments + + CONTRIBUTING.md | 12 ++++++------ + PULL_REQUEST_TEMPLATE.md | 4 ++-- + README.md | 10 ++++++++-- + 3 files changed, 16 insertions(+), 10 deletions(-) + +commit f0c2c3b78a699254508274a672e0a6af8c5d6ab3 +Author: Avi Aryan +Date: Wed Mar 22 12:07:31 2017 +0530 + + chore: integrated codacy, fixes #77 + + README.md | 2 ++ + 1 file changed, 2 insertions(+) + +commit b579032aa768fced836f3b0a6e8f6786e1fdcd25 +Author: Avi Aryan +Date: Wed Mar 22 08:11:24 2017 +0530 + + docs: added team membership information in CONTRIBUTING + + This will help people who are not a part of the org + + CONTRIBUTING.md | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +commit 6f63ca706068af0efa3c887dad4f7569c12b0ce6 +Author: jsroyal +Date: Tue Mar 21 19:09:07 2017 +0530 + + Added Merge Sort [Java], closes #64 + + commit 13096073628edd75f26e2f77c6fd94c705001b41 + Author: jsroyal + Date: Sun Mar 19 19:13:36 2017 +0530 + + update list + + commit e96b0cc076fdfac138ac00f1714e44c60c51b887 + Author: jsroyal + Date: Sat Mar 18 16:16:19 2017 +0530 + + removed extra line + + commit 85fd2aff3ef48dd6b70e7c81527e7ef57aa07b97 + Author: jsroyal + Date: Sat Mar 18 15:59:55 2017 +0530 + + adjust list in readme + + commit 5ec2ce7281da3afa12a108de649cbfb62659bc0b + Author: jsroyal + Date: Sat Mar 18 11:34:28 2017 +0530 + + delete binary file + + commit 7c8a34b36ca7e6eae460f134e57119ff9f114fbf + Merge: 8607954 f7baccb + Author: jsroyal + Date: Sat Mar 18 11:27:04 2017 +0530 + + merged + + commit f7baccb4e3d01b2e84be1f334dbc47c241ced605 + Author: jsroyal + Date: Sat Mar 18 10:54:50 2017 +0530 + + added merge sort + + commit 860795406f0a36d108faf79309de1a3a18ba6518 + Author: jsroyal + Date: Fri Mar 17 18:49:27 2017 +0530 + + added merge sort + + commit 447ec6947b4356a37b086035aa294b3b56c12b82 + Author: jsroyal + Date: Wed Mar 15 23:03:29 2017 +0530 + + binary search in java + + README.md | 1 + + merge_sort/MergeSort.java | 56 +++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 57 insertions(+) + +commit df5b092ac1e6cf1833d25c7ab85632156b5eb047 +Author: Aashutosh Rathi +Date: Tue Mar 21 02:08:15 2017 +0530 + + Update sieveOfEratosthenes.c + + sieve_of_eratosthenes/sieveOfEratosthenes.c | 24 +++++++++++------------- + 1 file changed, 11 insertions(+), 13 deletions(-) + +commit be22ff9a694277b7db6be3eb3718383c832e8b8d +Author: Aashutosh Rathi +Date: Wed Mar 15 17:20:57 2017 +0530 + + Update sieveOfEratosthenes.c + + sieve_of_eratosthenes/sieveOfEratosthenes.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +commit 81e83d978948994213976bdb3fb95970c8d31adf +Author: Aashutosh Rathi +Date: Wed Mar 15 17:16:02 2017 +0530 + + Update sieveOfEratosthenes.c + + sieve_of_eratosthenes/sieveOfEratosthenes.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +commit 5c212e76966b60b5fee2f91db1912441ffdbecf5 +Author: Aashutosh Rathi +Date: Wed Mar 15 17:08:32 2017 +0530 + + Update sieveOfEratosthenes.c + + sieve_of_eratosthenes/sieveOfEratosthenes.c | 14 +++++++------- + 1 file changed, 7 insertions(+), 7 deletions(-) + +commit 143de99c188c3df766f3d50031af0b928abcf467 +Author: Aashutosh Rathi +Date: Wed Mar 15 16:21:41 2017 +0530 + + Update README.md + + README.md | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit 6db1fdfd4a166aee65e4d6aaf9b5fd2b0bc1f049 +Author: Aashutosh Rathi +Date: Wed Mar 15 16:20:14 2017 +0530 + + Added Sieve Of Eratosthenes [C] + + sieve_of_eratosthenes/sieveOfEratosthenes.c | 34 +++++++++++++++++++++++++++++ + 1 file changed, 34 insertions(+) + +commit acd4518b9ad21c9f67ca9bfbf13ab2afc0501354 +Author: Aashutosh Rathi +Date: Wed Mar 15 14:08:53 2017 +0530 + + Sieve_of_Eratosthenes/SieveOfEratosthenes.c + + README.md | 1 + + 1 file changed, 1 insertion(+) + +commit 63e2a9a3e6ccede5f0f43b785ccee6ff8bf84e3c +Merge: 8416de9 079e736 +Author: Avi Aryan +Date: Fri Mar 17 13:43:28 2017 +0530 + + Merge remote-tracking branch 'origin/coin-change-problem' + +commit 8416de9def01cd6b26c46214a14601cb10a39abf +Author: Monal Shadi +Date: Fri Mar 17 13:40:05 2017 +0530 + + [refactor] Added ternary operator in EuclideanGCD.java (#58) + + * Added ternary operator in EuclideanGCD.java + + * Fixed variables and array brackets + + * Fixed semicolon + + * Line length fixed + + * Minor fix + + euclidean_gcd/EuclideanGCD.java | 18 +++++++++--------- + 1 file changed, 9 insertions(+), 9 deletions(-) + +commit 079e7364ea454cbac86844cc2f28edf5e285ad6b +Author: Pratyush Singh +Date: Fri Mar 17 01:03:51 2017 +0530 + + Added Coin Change Problem [C]. Closes #9 + + README.md | 1 + + coin_change_problem/coin_change_problem.c | 45 +++++++++++++++++++++++++++++++ + 2 files changed, 46 insertions(+) + +commit ce3ccfa136defeac702af8c0c6c971b5faf0e731 +Author: Pratyush Singh +Date: Fri Mar 17 01:10:10 2017 +0530 + + Removed underscore in implemented algorithm table + + README.md | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +commit 4733102643631fa49ba8a1a9d362c7aac10d0058 +Author: yashladha +Date: Wed Mar 15 19:11:18 2017 +0530 + + Added Quick Select [C] + + Closes https://github.com/iiitv/algos/issues/10 + + README.md | 1 + + quick_select/quick_select.c | 62 +++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 63 insertions(+) + +commit 05050bfe2e6a2a9f3630024cd720a6c5fda62354 +Author: Monal Shadi +Date: Thu Mar 16 22:15:58 2017 +0530 + + Added Insertion Sort [C] (#57). Closes #39 + + * Added Insertion Sort + + * new line at end + + * Minor changes + + README.md | 1 + + insertion_sort/insertion_sort.c | 35 +++++++++++++++++++++++++++++++++++ + 2 files changed, 36 insertions(+) + +commit faad5a83e5c41a0f50a5bd90e625cbf4ba473a5a +Merge: 50e74a3 5f00731 +Author: Pratyush Singh +Date: Thu Mar 16 21:42:37 2017 +0530 + + Merge java-sample-improvement + +commit 50e74a356256a3563988ce6978cad5b14dddc389 +Author: Jitendra Singh +Date: Thu Mar 16 21:40:47 2017 +0530 + + Added Binary Search [Java] (#55). Closes #54 + + * binary search in java + + * changes made + + * file name update + + * Change accoding code of conduct + + * Added in java column + + * Changes code of conduct + + * remove redundant + + * reduce comment line + + * space remove and update link in readme + + * update + + README.md | 2 +- + binary_search/BinarySearch.java | 34 ++++++++++++++++++++++++++++++++++ + 2 files changed, 35 insertions(+), 1 deletion(-) + +commit 5f00731d657dd4408e6983f02a8c9db04239d0c3 +Author: Pratyush Singh +Date: Wed Mar 15 23:33:11 2017 +0530 + + docs: Changed Java code sample to correct array declaration + + CONTRIBUTING.md | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +commit c3c661bb868402ccc34daf15c5b4bc35807e7779 +Author: Monal Shadi +Date: Wed Mar 15 15:24:14 2017 +0530 + + [EuclideanGCD] [JAVA] Added implementation (#44). Closes #22 + + * Added java implementation of Euclidean gcd + + * Minor Fixes + + * Minor Fixes + + * Extra blank line removed + + README.md | 2 +- + euclidean_gcd/EuclideanGCD.java | 33 +++++++++++++++++++++++++++++++++ + 2 files changed, 34 insertions(+), 1 deletion(-) + +commit 73fcc3b65936ca937fdf4c91db6ff48d310bedf4 +Author: Aashutosh Rathi +Date: Wed Mar 15 13:37:06 2017 +0530 + + Updated dead links in PULL_REQUEST_TEMPLATE.md (#48) + + PULL_REQUEST_TEMPLATE.md | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +commit c450bab8af575f55e1793c113e19a4085fd76ca9 +Author: Pratyush Singh +Date: Wed Mar 15 13:29:42 2017 +0530 + + Added Binary Search [C] (#43) + + * [Binary Search] [C] Added implementation + + * [Binary Search] [C] Added entry to README + + README.md | 1 + + binary_search/binary_search.c | 40 ++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 41 insertions(+) + +commit d3f6116a9aa1dd7b82c7f8e7251686b237e0a42a +Author: Monal Shadi +Date: Mon Mar 13 14:54:49 2017 +0530 + + Added euclidean_gcd [python] (#36). Closes #23 + + * Entry added in README, euclidean_gcd.py added + + * newline at end + + * Line spacing corrected, \n removed + + * individual docstring, blank space removed + + * Standardized docstring as mentioned + + * Minor Fixes + + * Used Linting tool to fix errors + + README.md | 2 +- + euclidean_gcd/euclidean_gcd.py | 47 ++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 48 insertions(+), 1 deletion(-) + +commit 35aa1d1aca868ac7da264738324f362f617bab2d +Author: Pratyush Singh +Date: Mon Mar 13 13:43:04 2017 +0530 + + README: Added badges + + README.md | 2 ++ + 1 file changed, 2 insertions(+) + +commit adcb82dc687ae017fd41d34467922279593ab63b +Author: Pratyush Singh +Date: Fri Mar 10 03:06:55 2017 +0530 + + [Linear Search] [Python] Added line break + + linear_search/linear_search.py | 1 + + 1 file changed, 1 insertion(+) + +commit 0fc5b1112d246c47a11d42e9dde58f100ddaa413 +Author: Pratyush Singh +Date: Fri Mar 10 03:05:35 2017 +0530 + + docs: Add line spacing for Python code sample according to PEP8 + + CONTRIBUTING.md | 2 ++ + 1 file changed, 2 insertions(+) + +commit a6011372d88b731b6ab33658135abed079e6a61d +Author: Avi Aryan +Date: Fri Mar 10 02:46:48 2017 +0530 + + docs: added PR template + + CONTRIBUTING.md | 3 +++ + PULL_REQUEST_TEMPLATE.md | 15 +++++++++++++++ + 2 files changed, 18 insertions(+) + +commit 9a3ea1256b2f35e7b6694d8556156ef8e420056b +Author: Pratyush Singh +Date: Fri Mar 10 02:30:42 2017 +0530 + + Added java sample code to CONTRIBUTING.md. Closes #33 (#37) + + CONTRIBUTING.md | 20 ++++++++++++++++++++ + 1 file changed, 20 insertions(+) + +commit db5c8a13e95aaa1945254e89a50377bbdccf1f16 +Author: Lalit Kumar +Date: Fri Mar 10 02:17:39 2017 +0530 + + docs: Added GeeksForGeeks algorithms list (#35) + + * Update README.md + + Adding one more resource for Fundamentals of Algorithms + + * Update README.md + + Creating the alphabetical order of resources. + + * Update README.md + + Alphabetical order of resources. + + * Update README.md + + * Update README.md + + Adding the changes requested. + + README.md | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +commit 5de30bee020872a974dd4d2ffeeeadc565fdb457 +Author: Pratyush Singh +Date: Fri Mar 10 01:13:08 2017 +0530 + + [Euclidean GCD] [C] : Minor comment fix + + euclidean_gcd/euclidean_gcd.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +commit f8bf0b0c286f0c14ab3f43c89c7890cecaa94900 +Author: Monal Shadi +Date: Fri Mar 10 01:11:31 2017 +0530 + + Added gcd implementation [C] (#31) + + * Added gcd implementation + + * Blank spaces removed and tested for both now + + * Called iterative + + * spacingsc corrected + + * euclidean gcd added to READEME.md + + * Function name modified as file name + + * Entry in ascending order + + * I small case done and Comment corrected + + README.md | 1 + + euclidean_gcd/euclidean_gcd.c | 32 ++++++++++++++++++++++++++++++++ + 2 files changed, 33 insertions(+) + +commit 76f0e48e498e46308d7141a6daba01c9d38351a7 +Author: Avi Aryan +Date: Thu Mar 9 20:25:48 2017 +0530 + + docs: updated contributing guidelines + + CONTRIBUTING.md | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +commit 34af9a935d91687f8f59bf2393d0aa280481b7fb +Author: Avi Aryan +Date: Thu Mar 9 20:20:25 2017 +0530 + + docs: minor fix in table row definition + + README.md | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit c91f902e139a24f6f71e53408236f819e9477130 +Author: Yash Ladha <201551061@iiitvadodara.ac.in> +Date: Thu Mar 9 20:18:35 2017 +0530 + + Include: Longest Common Subsequence in C (#32) + + * Include: Longest Common Subsequence in C + + * Applied Requested Changes + + README.md | 1 + + .../longestCommonSubsequence.c | 37 ++++++++++++++++++++++ + 2 files changed, 38 insertions(+) + +commit f074a6e0d51766fd883a44e3128f4b92cf62cd26 +Author: Monal Shadi +Date: Thu Mar 9 14:46:41 2017 +0530 + + README.md : Include Stanford-ACM codes repo link (#30) + + * Updated Readme.md + + * Updated Readme.md + + * Added Blank line + + README.md | 1 + + 1 file changed, 1 insertion(+) + +commit 02257d1ba60881baf653fb94a5f71ad3a9bd7548 +Author: Avi Aryan +Date: Thu Mar 9 13:03:06 2017 +0530 + + Added quicksort C implementation (#16) + + * feat: added quicksort c implementation + + * docs: added entry to README + + * chore: optimized code + + * refactor: added comments + + * refactor: refactored code + + README.md | 1 + + quicksort/quicksort.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 60 insertions(+) + +commit d838d187b37834814f8bd69365f7aff3089604a6 +Merge: b3697c5 970976e +Author: Avi Aryan +Date: Thu Mar 9 02:56:26 2017 +0530 + + Merge pull request #25 from iiitv/python-sample + + docs: Added python sample code + +commit 970976eff3133af1c64e1c677d87a57f1078d7b3 +Author: Pratyush Singh +Date: Thu Mar 9 02:52:16 2017 +0530 + + docs: Added python sample code + + CONTRIBUTING.md | 21 ++++++++++++++++++--- + 1 file changed, 18 insertions(+), 3 deletions(-) + +commit b3697c522d44efa770ed124a91188be9f6b6467a +Merge: b006a36 52117d8 +Author: Pratyush Singh +Date: Thu Mar 9 02:38:26 2017 +0530 + + Merge pull request #24 from iiitv/tables-implementation + + Use tables in implementation section of README + +commit 52117d8399b389a7acd80a98e144011d47b8cf19 +Author: Avi Aryan +Date: Thu Mar 9 02:36:58 2017 +0530 + + docs: left align algorithm column in implementation table + + README.md | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit f54b0efcb71e5d0a56390731a4073689de633397 +Author: Avi Aryan +Date: Thu Mar 9 02:31:13 2017 +0530 + + docs: languages as columns, center align items + + README.md | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +commit a26a67d1a9f9f7614154f268404665bd5d687051 +Author: Avi Aryan +Date: Thu Mar 9 02:19:34 2017 +0530 + + docs: use tables in implementation + + README.md | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +commit b006a36ed1f9ec441bd5d87701402baf60738e6a +Author: Pratyush Singh +Date: Thu Mar 9 01:58:33 2017 +0530 + + Added "different issue for different language" rule to CONTRIBUTING (#18) + + CONTRIBUTING.md | 19 ++++++++++++------- + 1 file changed, 12 insertions(+), 7 deletions(-) + +commit 6016f94c0f1f7e6716420892058a867983975c28 +Author: Avi Aryan +Date: Thu Mar 9 01:45:30 2017 +0530 + + docs: updated contributing guidelines + + anyone can assign an issue to themselves if it is unassigned + + CONTRIBUTING.md | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit bf28bd403fe335c0268c4068f95d9d8f9f7bbf76 +Author: Avi Aryan +Date: Thu Mar 9 00:30:33 2017 +0530 + + chore: added gitignore + + .gitignore | 6 ++++++ + 1 file changed, 6 insertions(+) + +commit 9f56206c225a765a948c8bea57a3688ec3c1157d +Author: Avi Aryan +Date: Thu Mar 9 00:04:48 2017 +0530 + + docs: updated contributing guidelines + + CONTRIBUTING.md | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +commit 9990052cc1cc2913d0eb891d131a1b58c5d3c0af +Author: Avi Aryan +Date: Thu Mar 9 00:01:45 2017 +0530 + + docs: added points for improving an existing code + + CONTRIBUTING.md | 7 +++++++ + 1 file changed, 7 insertions(+) + +commit aaee06631ff25b092b90c6b2345d6098bebc03a3 +Author: Avi Aryan +Date: Wed Mar 8 23:46:52 2017 +0530 + + docs: added project maintainers + + README.md | 8 ++++++++ + 1 file changed, 8 insertions(+) + +commit 998dce17d8f20630066b538c4299a1bb7445aca9 +Author: Yash Ladha <201551061@iiitvadodara.ac.in> +Date: Wed Mar 8 23:38:52 2017 +0530 + + README.md: Include Awesome Algorithms (#14) + + README.md | 1 + + 1 file changed, 1 insertion(+) + +commit c2cf384f02dbf40afae919f5d7992cb24bee29a5 +Author: Avi Aryan +Date: Wed Mar 8 23:33:09 2017 +0530 + + docs: added some helpful points for contributors + + CONTRIBUTING.md | 8 ++++++++ + 1 file changed, 8 insertions(+) + +commit 29bf7392e2da664a83ff6e199b22bc149b86b04d +Author: Avi Aryan +Date: Wed Mar 8 23:24:55 2017 +0530 + + docs: updated contributing guidelines + + CONTRIBUTING.md | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +commit 2871d9551de41bfd299902b3df11ab22ac8b4ee1 +Author: Avi Aryan +Date: Wed Mar 8 23:19:26 2017 +0530 + + docs: added guidelines to suggest an algorithm + + CONTRIBUTING.md | 11 +++++++++++ + README.md | 4 +++- + 2 files changed, 14 insertions(+), 1 deletion(-) + +commit 3eec6d915793cfd96911d3f116a983b28bec4e70 +Author: Pratyush Singh +Date: Wed Mar 8 23:17:39 2017 +0530 + + Added linear search implementation in Python (#6) + + * Added linear search implementation in Python + + * Added space after % in print + + * Added linear search to README + + README.md | 2 +- + linear_search/linear_search.py | 24 ++++++++++++++++++++++++ + 2 files changed, 25 insertions(+), 1 deletion(-) + +commit 1c8c4408607ff99280d4a9ae28b39b58fed380c7 +Author: Lalit Kumar +Date: Wed Mar 8 23:16:54 2017 +0530 + + Update README.md (#11) + + Adding some more useful resources for Algorithms Learning. + + README.md | 2 ++ + 1 file changed, 2 insertions(+) + +commit 7daca562c9b745affab8fe15a540ae2854da3531 +Author: Avi Aryan +Date: Wed Mar 8 22:55:06 2017 +0530 + + chore: create a separate CONTRIBUTING file, keep README clean + + CONTRIBUTING.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ + README.md | 48 ++++++------------------------------------------ + 2 files changed, 50 insertions(+), 42 deletions(-) + +commit a475d3a4c022398450f0c92eb723db7608f78798 +Author: Avi Aryan +Date: Wed Mar 8 22:47:05 2017 +0530 + + docs: improved contribution guidelines + + README.md | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +commit 85da010b79a58cecc9cd41369ffda24d8ca6df0e +Author: Avi Aryan +Date: Wed Mar 8 22:44:05 2017 +0530 + + docs: added resources + + README.md | 5 +++++ + 1 file changed, 5 insertions(+) + +commit b5cd65c9cf37ca08a091a8161e973ba73b6d0236 +Author: Avi Aryan +Date: Wed Mar 8 22:42:12 2017 +0530 + + docs: updated styleguide + + README.md | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +commit 7ef3e09680dde8e1282ed63f96de316857d160f5 +Author: Avi Aryan +Date: Wed Mar 8 22:33:34 2017 +0530 + + docs: added code style info + + README.md | 43 ++++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 42 insertions(+), 1 deletion(-) + +commit 78c887ce2c3595c644ba34ebab888cf4b18c091f +Author: Avi Aryan +Date: Wed Mar 8 22:24:14 2017 +0530 + + docs: update README + + README.md | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +commit 1d4bde610a2e5400b3e5fa0667f6a3162f435868 +Author: Avi Aryan +Date: Wed Mar 8 22:19:57 2017 +0530 + + Initial commit + + README.md | 1 + + 1 file changed, 1 insertion(+)