Skip to content

Commit 93a6842

Browse files
authored
Merge pull request #3 from Py-Contributors/master
Updated From original
2 parents f653869 + 02db7c8 commit 93a6842

File tree

6 files changed

+260
-69
lines changed

6 files changed

+260
-69
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Binary search algorithm
2+
// This algorithm finds the index of an element in a sorted array
3+
// Time complexity : O(log n)
4+
// Space complexity :
5+
// 1. Recursive approach : O(log n)
6+
// 2. Iterative approach : O(1)
7+
8+
#include <iostream>
9+
using namespace std;
10+
11+
// Recursive approach
12+
int binarySearchRecursive(int a[], int l, int r, int t) {
13+
if(l <= r) {
14+
// middle element
15+
int m = l + (r - l) / 2;
16+
17+
if(a[m] == t) {
18+
return m;
19+
}
20+
else if(a[m] > t) {
21+
return binarySearchRecursive(a, l, m - 1, t);
22+
}
23+
else {
24+
return binarySearchRecursive(a, m + 1, r, t);
25+
}
26+
}
27+
28+
// If the element is not found return -1
29+
return -1;
30+
}
31+
32+
33+
// Iterative approach
34+
int binarySearchIterative(int a[], int l, int r, int t) {
35+
while(l <= r) {
36+
int m = l + (r - l) / 2;
37+
38+
if(a[m] == t) {
39+
return m;
40+
}
41+
else if(a[m] > t) {
42+
r = m - 1;
43+
}
44+
else {
45+
l = m + 1;
46+
}
47+
}
48+
49+
return -1;
50+
}
51+
52+
int main() {
53+
int n = 10;
54+
int a[n] = {23, 37, 45, 67, 76, 78, 90, 93, 99, 100};
55+
int t = 37;
56+
57+
cout<<"By recursive approach the index of element "<<t<<" is : ";
58+
cout<<binarySearchRecursive(a, 0, n - 1, t)<<endl;
59+
60+
cout<<"By iterative approach the index of element "<<t<<" is : ";
61+
cout<<binarySearchIterative(a, 0, n - 1, t)<<endl;
62+
63+
return 0;
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Sieve of Eratosthenes:
3+
Given a number n, print all prime numbers less than n
4+
*/
5+
6+
#include <iostream>
7+
using namespace std;
8+
9+
void sieve_of_eratosthenes(int n)
10+
{
11+
/*
12+
This will print all
13+
prime number less than n
14+
*/
15+
16+
// Initially all are prime
17+
bool *prime = new bool[n];
18+
for (int i = 0; i < n; i++)
19+
{
20+
prime[i] = true;
21+
}
22+
23+
// Now we start marking multiples of every number non-prime
24+
for (int i = 2; i * i <= n; i++)
25+
{
26+
// We start from first multiple and go till n
27+
for (int j = 2 * i; j < n; j += i)
28+
{
29+
prime[j] = false;
30+
}
31+
}
32+
for (int i = 2; i < n; i++)
33+
{
34+
if (prime[i])
35+
{
36+
cout << i << " ";
37+
}
38+
}
39+
}
40+
41+
int main()
42+
{
43+
sieve_of_eratosthenes(50);
44+
}

CONTRIBUTING.md

+47-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing to Transcriptase
1+
# Contributing to Algorithms and Data Structures
22

33
We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:
44

@@ -8,48 +8,69 @@ We love your input! We want to make contributing to this project as easy and tra
88
- Proposing new features
99
- Becoming a maintainer
1010

11-
## We Develop with Github
1211

13-
We use github to host code, to track issues and feature requests, as well as accept pull requests.
12+
## Steps to contribute
1413

15-
## We Use [Github Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests
14+
* Comment on the issue you want to work on. Make sure it's not assigned to someone else.
1615

17-
Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests:
16+
* If you think an algorithm is missing, create an issue.
1817

19-
1. Fork the repo and create your branch from `master`.
20-
2. If you've added code that should be tested, add tests.
21-
3. If you've changed APIs, update the documentation.
22-
4. Ensure the test suite passes.
23-
5. Make sure your code lints.
24-
6. Issue that pull request!
18+
### Making a PR
2519

26-
## Any contributions you make will be under the MIT Software License
20+
> - Make sure you have been assigned the issue to which you are making a PR.
21+
> - If you make PR before being assigned, It will be labeled `invalid` and closed without merging.
2722
28-
In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.
23+
* Fork the repo and clone it on your machine.
24+
* Add a upstream link to main branch in your cloned repo
25+
```
26+
git remote add upstream https://github.com/Py-Contributors/AlgorithmsAndDataStructure.git
27+
```
28+
* Keep your cloned repo upto date by pulling from upstream (this will also avoid any merge conflicts while committing new changes)
29+
```
30+
git pull upstream master
31+
```
32+
* Create your feature branch
33+
```
34+
git checkout -b <feature-name>
35+
```
36+
* Commit all the changes
37+
```
38+
git commit -am "Meaningful commit message"
39+
```
40+
* Push the changes for review
41+
```
42+
git push origin <branch-name>
43+
```
44+
* Create a PR from our repo on Github.
2945
30-
## Report bugs using Github's [issues](https://github.com/briandk/transcriptase-atom/issues)
46+
### Additional Notes
3147
32-
We use GitHub issues to track public bugs. Report a bug by [opening a new issue](/ALGORITHM.md); it's that easy!
48+
* Code should be properly commented to ensure it's readability.
49+
* If you've added code that should be tested, add tests as comments.
50+
* In python use docstrings to provide tests.
51+
* Make sure your code properly formatted.
52+
* Issue that pull request!
3353
34-
## Write bug reports with detail, background, and sample code
3554
36-
[This is an example](http://stackoverflow.com/q/12488905/180626) of a bug report I wrote, and I think it's not a bad model. Here's [another example from Craig Hockenberry](http://www.openradar.me/11905408), an app developer whom I greatly respect.
55+
## Issue suggestions/Bug reporting
3756
38-
**Great Bug Reports** tend to have:
57+
When you are creating an issue, make sure it's not already present. Furthermore, provide a proper description of the changes. If you are suggesting any code improvements, provide through details about the improvements.
3958
40-
- A quick summary and/or background
41-
- Steps to reproduce
59+
**Great Issue suggestions** tend to have:
60+
61+
- A quick summary of the changes.
62+
- In case of any bug provide steps to reproduce
4263
- Be specific!
43-
- Give sample code if you can. [My stackoverflow question](http://stackoverflow.com/q/12488905/180626) includes sample code that *anyone* with a base R setup can run to reproduce what I was seeing
44-
- What you expected would happen
45-
- What actually happens
46-
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
64+
- Give sample code if you can.
65+
- What you expected would happen
66+
- What actually happens
67+
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
4768
48-
People *love* thorough bug reports. I'm not even kidding.
4969
5070
## License
5171
52-
By contributing, you agree that your contributions will be licensed under its MIT License.
72+
By contributing, you agree that your contributions will be licensed under its [MIT License](http://choosealicense.com/licenses/mit/).
73+
5374
5475
## References
5576

Python/Algorithms/README.md

+54-35
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,54 @@
1-
# [AlgorithmsImplementation](/ALGORITHM.md)
2-
3-
Data Structure and Algorithm Implementation in Python.
4-
5-
- [AlgorithmsImplementation](#algorithmsimplementation)
6-
- [BackTrackingAlgorithms](#backtrackingalgorithms)
7-
- [DeepLearningAlgorithms](#deeplearningalgorithms)
8-
- [DivideAndConquer](#divideandconquer)
9-
- [DynamicPrograming](#dynamicprograming)
10-
- [GreedyAlgorithms](#greedyalgorithms)
11-
- [MachineLearningAlgorithms](#machinelearningalgorithms)
12-
- [PathFindingAlgorithms](#pathfindingalgorithms)
13-
- [RecursionAlgorithms](#recursionalgorithms)
14-
- [SearchingAlgorithms](#searchingalgorithms)
15-
- [SortingAlgorithms](#sortingalgorithms)
16-
17-
## BackTrackingAlgorithms
18-
19-
## DeepLearningAlgorithms
20-
21-
## DivideAndConquer
22-
23-
## DynamicPrograming
24-
25-
## GreedyAlgorithms
26-
27-
## MachineLearningAlgorithms
28-
29-
## PathFindingAlgorithms
30-
31-
## RecursionAlgorithms
32-
33-
## SearchingAlgorithms
34-
35-
## SortingAlgorithms
1+
# Algorithm Implementation in Python
2+
3+
List of Algorithms in Python contained in this repository
4+
5+
- [Backtracking Algorithms](#backtrackingalgorithms)
6+
- [Deep Learning Algorithms](#deeplearningalgorithms)
7+
- [Divide And Conquer](#divideandconquer)
8+
- [Dynamic Programing](#dynamicprograming)
9+
- [Greedy Algorithms](#greedyalgorithms)
10+
- [Machine Learning Algorithms](#machinelearningalgorithms)
11+
- [Path Finding Algorithms](#pathfindingalgorithms)
12+
- [Recursion Algorithms](#recursionalgorithms)
13+
- [Searching Algorithms](#searchingalgorithms)
14+
- [Sorting Algorithms](#sortingalgorithms)
15+
16+
### Backtracking Algorithms:
17+
Backtracking is a technique for solving problems recursively by trying to build a solution incrementally, one piece at a time, removing those solutions that fail to satisfy the constraints of the problem at any point of time.
18+
Example of implementation- Soduku solving.
19+
20+
### Deep Learning Algorithms:
21+
Deep learning is part of machine learning, whose methods are based on artificial neural networks with representation learning. Learning can be supervised, semi-supervised or unsupervised.
22+
Examples include- CNN, RNN, LSTM, GAN, RBM, etc.
23+
24+
### Divide And Conquer:
25+
Divide and Conquer is an algorithm design paradigm based on multi-branched recursion. A divide-and-conquer algorithm works by recursively breaking down a problem into two or more sub-problems of the same or related type, until these become simple enough to be solved directly.
26+
Example of implementation- Quick Sort, Merge Sort.
27+
28+
### Dynamic Programing:
29+
Dynamic Programming is primarily an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for same inputs, we can optimize it using Dynamic Programming. The idea is to store the results of subproblems, so that we do not have to re-compute them when needed later.
30+
Examples of implementation- Knapsack, Longest Common Subsequence.
31+
32+
### Greedy Algorithms:
33+
A greedy algorithm is a simple, intuitive algorithm that is used in optimization problems. The algorithm makes the optimal choice at each step as it attempts to find the overall optimal way to solve the entire problem.
34+
Examples of implementation- Kruskal's algorithm, Prim's algorithm.
35+
36+
### Machine Learning Algorithms:
37+
A machine learning algorithm is a method that provides systems the ability to automatically learn and improve from experience without being explicitly programmed.
38+
Examples include- Linear Regression, Logistic Regression, Naïve Bayes, KNN, etc
39+
40+
### Path Finding Algorithms:
41+
Pathfinding or pathing is the plotting, by a computer application, of the shortest route between two points. It is a more practical variant on solving mazes.
42+
Example of implemntation- A* search, Dijkstra's algorithm.
43+
44+
### Recursion Algorithms:
45+
Recursion is a method of solving a problem where the solution depends on solutions to smaller instances of the same problem. Such problems can generally be solved by iteration, but this needs to identify and index the smaller instances at programming time.
46+
Examples of implementation- Tower of Hanoi, Tree traversals, DFS.
47+
48+
### Searching Algorithms:
49+
The searching algorithms are used to search or find one or more than one element from a dataset. These type of algorithms are used to find elements from a specific data structures, which maybe sequential or not.
50+
Examples of implementation- Binary Search, Linear Search, Fibonacci Search.
51+
52+
### Sorting Algorithms:
53+
A Sorting algorithm is an algorithm that puts elements of a list in a certain order. The most frequently used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the efficiency of other algorithms that require input data to be in sorted lists.
54+
Examples of implementation- Quick Sort, Merge Sort.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Title : Python3 Program to add two numbers without using arithmetic operator
2+
3+
def Add(a, b):
4+
5+
# Iterate till there is no carry
6+
while (b!= 0):
7+
8+
# carry now contains common set bits of x and y
9+
carry = a & b
10+
11+
# Sum of bits of x and y where at least one of the bits is not set
12+
a = a ^ b
13+
14+
# Carry is shifted by one so that adding it to x gives the required sum
15+
b = carry << 1
16+
17+
return a
18+
19+
# Declear Print statement and Pass Parameter on them i.e Print(Add(20,10))
20+
print(Add(10,20))

README.md

+31-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
# [AlgorithmsAndDataStructure](/Algorithms/README.md)
1+
![header](https://capsule-render.vercel.app/api?type=rect&color=666666&height=100&section=header&text=Algorithms%20And%20Data%20Structures&fontSize=55%&fontColor=ffffff)
2+
3+
![python](https://img.shields.io/badge/language-Python-blue?style=for-the-badge)
4+
![C++](https://img.shields.io/badge/language-C++-blue?style=for-the-badge)
5+
6+
![Discord](https://img.shields.io/discord/758030555005714512?style=for-the-badge)
7+
![last commit](https://img.shields.io/github/last-commit/py-contributors/AlgorithmsAndDataStructure?style=for-the-badge)
8+
![contributors](https://img.shields.io/github/contributors/py-contributors/AlgorithmsAndDataStructure?style=for-the-badge)
9+
10+
![hacktober-issue](https://img.shields.io/github/hacktoberfest/2020/py-contributors/AlgorithmsAndDataStructure?style=for-the-badge)
11+
![forks](https://img.shields.io/github/forks/Py-Contributors/AlgorithmsAndDataStructure?style=for-the-badge)
12+
![stars](https://img.shields.io/github/stars/Py-Contributors/AlgorithmsAndDataStructure?style=for-the-badge)
13+
![license](https://img.shields.io/github/license/Py-Contributors/AlgorithmsAndDataStructure?style=for-the-badge)
14+
15+
![open issues](https://img.shields.io/github/issues-raw/Py-Contributors/AlgorithmsAndDataStructure?style=for-the-badge)
16+
![close issue](https://img.shields.io/github/issues-closed-raw/py-contributors/AlgorithmsAndDataStructure?style=for-the-badge)
17+
![open_pr](https://img.shields.io/github/issues-pr-raw/Py-contributors/AlgorithmsAndDataStructure?style=for-the-badge)
18+
![open_pr](https://img.shields.io/github/issues-pr-closed-raw/Py-contributors/AlgorithmsAndDataStructure?style=for-the-badge)
219

320
- [AlgorithmsAndDataStructure](#algorithmsanddatastructure)
421
- [Introduction](#introduction)
@@ -41,16 +58,21 @@ Check [Contribution](/CONTRIBUTING.md) Guide Before Contribution.
4158

4259
## Project Progress
4360

44-
### Data Structures
61+
<summary><h3>Data Structures</h3></summary>
62+
<details>
63+
4564
| Data Structure | C++ | Python | Status/Remarks |
4665
|---------------- |---------------- |----------------- |-------------------- |
4766
| Linked List | Yes | Yes | Being improved #23 |
4867
| Sets | Yes | Yes | Implemented |
4968
| Stack | Yes | In progress #13 | |
5069
| Queue | In progress #7 | In progress #12 | |
5170

71+
</details>
72+
73+
<summary><h3>Algorithms</h3></summary>
74+
<details>
5275

53-
### Algorithms
5476
| Algorithm | C++ | Python | Remarks |
5577
|-------------------------------- |----------------- |----------------- |-----------------|
5678
| **Searching** | | | |
@@ -105,17 +127,17 @@ Check [Contribution](/CONTRIBUTING.md) Guide Before Contribution.
105127
| Decision Tree | No | In progress #37 | |
106128
| K-Nearest Neighbours | No | In progress #38 | |
107129

130+
</details>
108131

109132
## Contributing
110133

111134
Before submitting a bug, please do the following:
112135
Check [Contribution](/CONTRIBUTING.md) Guide Before Contribution.
113136

114-
Perform basic troubleshooting steps:
115-
116-
- Make sure you are on the latest version. If you are not on the most recent version, your problem may have been solved already! Upgrading is always the best first step.
117-
- Try older versions. If you are already on the latest release, try rolling back a few minor versions (e.g. if on 1.7, try 1.5 or 1.6) and see if the problem goes away. This will help the devs narrow down when the problem first arose in the commit log.
118-
- Try switching up dependency versions. If the software in question has dependencies (other libraries, etc) try upgrading/downgrading those as well.
137+
- Create separate issues for Python and C++.
138+
- You can only work on issues that you have been assigned to.
139+
- Use Flake8 locally for linting Python Code. `pip install flake8`.
140+
(We have linting checks so if your code fails it we will not merge the PR.)
119141

120142
## Authors and acknowledgment
121143

@@ -131,3 +153,4 @@ For open-source projects, Under [MIT License](/LICENSE).
131153
- [ExpressHermes](https://github.com/ExpressHermes)
132154
- [Ayush Modi](https://github.com/hot9cups)
133155
- [rex_divakar](https://github.com/rexdivakar)
156+
- [Shubham Pawar](https://github.com/shubham5351)

0 commit comments

Comments
 (0)