Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
76126ed
Merge pull request #1 from AllAlgorithms/sorting
abranhe Sep 19, 2018
a91b92c
Create LICENSE
abranhe Sep 19, 2018
04b033d
Merge pull request #2 from AllAlgorithms/add-license
abranhe Sep 19, 2018
2deb25a
add readme!
abranhe Sep 26, 2018
e505883
Create binary_search.cpp
abranhe Sep 26, 2018
d217f82
Merge pull request #4 from AllAlgorithms/searches
abranhe Sep 26, 2018
8a056d2
web!!
abranhe Sep 26, 2018
c04b3c5
lucky numbers in c++
abranhe Sep 26, 2018
3728643
Merge pull request #5 from AllAlgorithms/math
abranhe Sep 26, 2018
16d3ab1
Update README.md
Oct 2, 2018
70b5ae4
fix readme
abranhe Oct 2, 2018
8937554
Create insertionSort.cpp
alangberg Oct 2, 2018
bcfb51b
Merge pull request #7 from jidroid404/master
abranhe Oct 2, 2018
8790487
Add quick_sort.cpp
nikunj-taneja Oct 2, 2018
e656807
Merge pull request #8 from alangberg/patch-1
abranhe Oct 2, 2018
3d1768d
Linear Search Added
Bharat-Reddy Oct 2, 2018
0d0d2e2
Update quick_sort.cpp
nikunj-taneja Oct 2, 2018
5c241f9
Merge pull request #9 from Bharat-Reddy/master
abranhe Oct 2, 2018
25f55c2
Merge pull request #10 from underscoreorcus/master
abranhe Oct 2, 2018
d0f9f7d
Create dfs.cpp
nikunj-taneja Oct 2, 2018
75d9f90
Interpolation Search Added
Bharat-Reddy Oct 2, 2018
fa42d78
Merge pull request #11 from underscoreorcus/master
abranhe Oct 2, 2018
485ea2e
Merge pull request #12 from Bharat-Reddy/master
abranhe Oct 2, 2018
37d83fa
Added Dp Programs
suraj-goel Oct 2, 2018
293bef0
Create bellman_ford.cpp
nikunj-taneja Oct 2, 2018
984b281
Euclids GCD Algorithm added
Bharat-Reddy Oct 2, 2018
8202a15
Create bfs.cpp
nikunj-taneja Oct 2, 2018
10b1f34
Algo for finding LCM of array Added
Bharat-Reddy Oct 2, 2018
fc8a70c
fix folder and name
abranhe Oct 2, 2018
58fc6f6
fix folder
abranhe Oct 2, 2018
323c597
fix folder
abranhe Oct 2, 2018
8e61097
fix folder
abranhe Oct 2, 2018
e20fb69
Rename Dyanamic_Programming/longestpath.cpp to dynamic-programminglon…
abranhe Oct 2, 2018
7d3e5a4
Rename dynamic-programminglcs.cpp to dynamic-programming/lcs.cpp
abranhe Oct 2, 2018
8da3517
Rename dynamic-programminglongest_path.cpp to dynamic-programming/lon…
abranhe Oct 2, 2018
4ab02cb
Rename dynamic-programmingways_to_cover.cpp to dynamic-programming/wa…
abranhe Oct 2, 2018
f80f82a
Merge pull request #14 from suraj-goel/dp
abranhe Oct 2, 2018
de17ec3
Merge pull request #13 from underscoreorcus/master
abranhe Oct 2, 2018
0b13f3e
Merge pull request #15 from Bharat-Reddy/master
abranhe Oct 2, 2018
1230d1f
Algorithm for finding GCD of an array of elements Added
Bharat-Reddy Oct 2, 2018
ab23ad1
Create dijkstra.cpp
nikunj-taneja Oct 2, 2018
a682791
Create floyd_warshall.cpp
nikunj-taneja Oct 2, 2018
9f191ea
Merge pull request #16 from Bharat-Reddy/master
abranhe Oct 2, 2018
a917740
Merge pull request #18 from underscoreorcus/master
abranhe Oct 2, 2018
328f722
Create coin_change.cpp
nikunj-taneja Oct 2, 2018
15f3034
added selection_sort.cpp
roopbiswas Oct 2, 2018
35d2cec
Adding strings related algorithms
tusharkanakagiri Oct 2, 2018
7fabf04
Permutations, Remove Duplicates(2 ways), String reversal
tusharkanakagiri Oct 2, 2018
2f81da2
Lexicographic ranking, Anagram Check
tusharkanakagiri Oct 2, 2018
dca7a2e
Longest palindrom subset, remove adjacent duplicates
tusharkanakagiri Oct 2, 2018
41597ae
Add factorial with docs
0xp4blo Oct 2, 2018
bc6b112
Create count_disconnected_components.cpp
roopbiswas Oct 2, 2018
1d9bf7e
Add collatz sequence
0xp4blo Oct 2, 2018
5d2ad57
Create prims_adjacency_list.cpp
pritamnegi Oct 2, 2018
4ce04ab
Unify code style and resolve numerous compile error in sorting
t3ssellate Oct 2, 2018
f3f2d42
Merge pull request #19 from underscoreorcus/patch-1
abranhe Oct 2, 2018
98713cf
Merge pull request #20 from tusharkanakagiri/master
abranhe Oct 2, 2018
05cddc4
Merge pull request #22 from roopbiswas/master
abranhe Oct 2, 2018
f518c5c
Merge pull request #26 from pritamnegi/prims_graph
abranhe Oct 2, 2018
1ba05e9
Merge pull request #27 from lhiny/master
abranhe Oct 2, 2018
2be90a3
Factorial docs removed
0xp4blo Oct 2, 2018
9b3e48c
Collatz sequence docs removed
0xp4blo Oct 2, 2018
527a00a
Merge pull request #23 from pablotrinidad/add-factorial
abranhe Oct 2, 2018
a4032a9
Merge pull request #25 from pablotrinidad/add-collatz-sequence
abranhe Oct 2, 2018
7c9f3ac
Added String algorithm
kavya98527 Oct 2, 2018
319e646
added path to Strings in ReadMe file
kavya98527 Oct 2, 2018
3ae61a3
added path to Strings in ReadMe file
kavya98527 Oct 2, 2018
4250b36
added a new String algorithm
kavya98527 Oct 3, 2018
7fa3db7
added shaker sort.cpp
kavya98527 Oct 3, 2018
55bea59
added stooge sort.cpp
kavya98527 Oct 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Abraham Hernandez (abraham@abranhe.com)

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.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div align="center">
<img width="400" height="270" src="http://konpa.github.io/devicon/devicon.git/icons/cplusplus/cplusplus-original.svg" alt="C Plus Plus Logo">
<br>
<br>
<img src="https://cdn.abranhe.com/projects/algorithms/algorithms.svg" width="400px">
<br>
<br>
<p>All ▲lgorithms implemented in C Plus Plus</p>
<a href="https://algorithms.abranhe.com"><img src="https://img.shields.io/badge/All-%E2%96%B2llgorithms-700606.svg"></a>
<a href="https://github.com/abranhe/algorithms/blob/master/LICENSE"><img src="https://img.shields.io/github/license/abranhe/algorithms.svg" /></a>
<a href="https://cash.me/$abranhe"><img src="https://cdn.abraham.gq/badges/cash-me.svg"></a>
<a href="https://www.patreon.com/abranhe"><img src="https://cdn.abraham.gq/badges/patreon.svg" /></a>
<a href="https://paypal.me/abranhe/10"><img src="https://cdn.abraham.gq/badges/paypal.svg" /></a>
<br>
<br>
<a href="https://algorithms.abranhe.com"><code>algorithms.abranhe.com</code></a>
</div>


## Contents

- [Arithmetic Analysis](arithmetic-analysis)
- [File Transfer Protocol](file-transfer-protocol)
- [Greedy Algorithms](greedy-algorithms)
- [Graphs](graphs)
- [Math](math)
- [Neutral Network](neutral-network)
- [Ciphers](ciphers)
- [Data Structures](data-structures)
- [Dynamic Programming](dynamic-programming)
- [Hashes](hashes)
- [Searches](searches)
- [Sorting](sorting)
- [Strings](https://github.com/AllAlgorithms/cpp/tree/master/Strings)
- [Traversals](traversals)

## License

This work is licensed under a [MIT License](https://github.com/abranhe/algorithms/blob/master/LICENSE)

[![MIT IMG][mit-license]]((https://github.com/abranhe/algorithms/blob/master/LICENSE))

To the extent possible under law, [Carlos Abraham](https://go.abranhe.com/github) has waived all copyright and related or neighboring rights to this work.


[mit-license]: https://cdn.abraham.gq/projects/algorithms/mit-license.png
117 changes: 117 additions & 0 deletions Strings/Rabin_carp_algo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*

* C++ Program to Implement Rabin-Karp Algorithm

*/

#include <iostream>

#include <cstdio>

#include <cstring>

#include <cstdlib>

using namespace std;

#define d 256

/*

* search a substring in a string

*/

void search(char *pat, char *txt, int q)

{

int M = strlen(pat);

int N = strlen(txt);

int i, j;

int p = 0;

int t = 0;

int h = 1;

for (i = 0; i < M - 1; i++)

h = (h * d) % q;

for (i = 0; i < M; i++)

{

p = (d *p + pat[i]) % q;

t = (d * t + txt[i]) % q;

}

for (i = 0; i <= N - M; i++)

{

if (p == t)

{

for (j = 0; j < M; j++)

{

if (txt[i + j] != pat[j])

break;

}

if (j == M)

{

cout<<"Pattern found at index: "<<i<<endl;

}

}

if (i < N - M)

{

t = (d * (t - txt[i] * h) + txt[i + M]) % q;

if (t < 0)

t = (t + q);

}

}

}



/* Main */

int main()

{

char *txt = "This is a sample Testcase";

char *pat = "sam";

int q = 101;

search(pat, txt, q);

return 0;

}
115 changes: 115 additions & 0 deletions Strings/z algo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*

* C++ Program to Implement Z-Algorithm

*/

#include <iostream>

#include <cstring>

#include <vector>

using namespace std;

bool zAlgorithm(string pattern, string target)

{

string s = pattern + '$' + target;

int n = s.length();

vector<int> z(n, 0);

int goal = pattern.length();

int r = 0, l = 0, i;

for (int k = 1; k < n; k++)

{

if (k > r)

{

for (i = k; i < n && s[i] == s[i - k]; i++);

if (i > k)

{

z[k] = i - k;

l = k;

r = i - 1;

}

}

else

{

int kt = k - l, b = r - k + 1;

if (z[kt] > b)

{

for (i = r + 1; i < n && s[i] == s[i - k]; i++);

z[k] = i - k;

l = k;

r = i - 1;

}

}

if (z[k] == goal)

return true;

}

return false;

}



int main()

{

string tar = "This is a sample Testcase";

string pat = "case";

if (zAlgorithm(pat, tar))

cout<<"'"<<pat<<"' found in string '"<<tar<<"'"<<endl;

else

cout<<"'"<<pat<<"' not found in string '"<<tar<<"'"<<endl;

pat = "Kavya";

if (zAlgorithm(pat, tar))

cout<<"'"<<pat<<"' found in string '"<<tar<<"'"<<endl;

else

cout<<"'"<<pat<<"' not found in string '"<<tar<<"'"<<endl;

return 0;

}
41 changes: 41 additions & 0 deletions dynamic-programming/coin_change.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include<iostream>

using namespace std;

int count( int S[], int m, int n )
{
int i, j, x, y;

// We need n+1 rows as the table is constructed
// in bottom up manner using the base case 0
// value case (n = 0)
int table[n+1][m];

// Fill the enteries for 0 value case (n = 0)
for (i=0; i<m; i++)
table[0][i] = 1;

// Fill rest of the table entries in bottom
// up manner
for (i = 1; i < n+1; i++)
{
for (j = 0; j < m; j++)
{
// Count of solutions including S[j]
x = (i-S[j] >= 0)? table[i - S[j]][j]: 0;
// Count of solutions excluding S[j]
y = (j >= 1)? table[i][j-1]: 0;
table[i][j] = x + y;
}
}
return table[n][m-1];
}

int main()
{
int coins[] = {1, 2, 3};
int m = sizeof(coins)/sizeof(int);
int n = 5;
cout << count(coins, m, n);
return 0;
}
Loading