Coder Social home page Coder Social logo

var-solutions / algorithms Goto Github PK

View Code? Open in Web Editor NEW
775.0 25.0 1.0K 4.38 MB

A repository of different Algorithms and Data Structures implemented in many programming languages.

Home Page: https://var-solutions.github.io/Algorithms/

License: MIT License

C++ 54.71% Ada 0.49% Java 9.45% Python 9.94% Go 2.15% C 9.32% Ruby 1.29% Lua 0.10% Swift 0.66% JavaScript 2.24% Makefile 0.17% R 0.06% C# 2.68% Brainfuck 0.05% Haskell 0.06% Jupyter Notebook 5.45% D 0.04% Common Lisp 0.41% Rust 0.73% TypeScript 0.01%
algorithms data-structures cpp python javascript java ruby swift golang c help-wanted python3 dynamic-programming greedy-algorithms bit-manipulation mathematics go rust csharp

algorithms's Introduction

Data Structures and Algorithms

Clean example implementations of data structures and algorithms written in different languages.

Gitter chat MIT license Issues

List of implementations

Algorithms list(not updated)

Contribution!

  • Contributions are always welcome. Language doesn't matter. Just make sure you're implementing an algorithm.

  • PRs are welcome. To begin developing, follow the structure:

    Algorithm-Type/algorithm-name/language-name/file-name.extension

    e.g

    Sorting/bubble-sort/python/bubble-sort.py

  • If there is an implementation of the same algorithm in your language, do not give a PR for that.

  • Please include a description for the algorithm that you are implementing. It doesn't matter if it's copied from somewhere as long as it helps people that are learning new algorithm.

  • Graphical examples would be very helpful too.

  • You can include tests as well.

  • Don't remove previous implementations of algorithms. You can help in improving the current implementation by adding explanations and examples.

  • Beautify and clean up your code for easier reading

Note:

  • Do not make a new issue unless required.
  • If your PR is closed without any comment, it means that your PR does not meet the above criteria. Make sure your PR is not Duplicate and it should be well-documented.

Resources

The curated list of resources dealing with algorithms.

Project Maintainers.

algorithms's People

Contributors

i-vishi avatar ravivarshney01 avatar antew7 avatar attacker99 avatar agvidit1 avatar asr0104 avatar koliadenko avatar alexandrelamarre avatar valiantone avatar besanidhya avatar praanjalmishra avatar chauhannishh avatar iabhyuday avatar aanchal1308 avatar xis avatar hackyjs avatar rpjayasekara avatar nickpurswani avatar sakchhams avatar kstole avatar emily-gong avatar alex-kuck avatar diproray avatar raibb avatar kinhosz avatar eashsaxena avatar rishabh0098 avatar phantsure avatar ungps avatar michael-b8 avatar

Stargazers

 avatar GIMAM (PI: Samiya Alkhairy) avatar nhatnguyen avatar  avatar Shitao Wu avatar Amit Kumar avatar  avatar Willump avatar  avatar Matthieu S avatar Cavid Abbasaliyev avatar Max avatar  avatar Osema Fadhel avatar Tariq West avatar Katadi Venkata Jaya Vardhan  avatar Abdulkerem Kilic avatar DevFreezy avatar the void avatar Stephanie Asmar avatar NintenHero avatar temik avatar Talles Barrini avatar  avatar Nirison Fabrice avatar Dritan Xhezo avatar  avatar future avatar Riariti avatar  avatar Pejman Azimi avatar Hamadullah . avatar Kevin Chalmers avatar Darvin Harutyunyan avatar Quoc Nguyen  avatar  avatar Mahmudul Haque Sakib avatar Mehul Thuletiya avatar _Nevo_ avatar zbert avatar Tri Duc Nguyen avatar Sujitkumar Rajendra Gaikwad avatar  avatar Deepak Kumar avatar rsky avatar Aishwarya Narayanan avatar Kishore Y avatar moons_repo avatar Nikita avatar Tarek Aloui avatar Nanda Kishore avatar David Nolf avatar Madeline Chan avatar Prithvi Raj avatar Ali Sayed avatar  avatar Gourav Priyadarsan avatar  avatar DavidPham avatar Mohammed OE Abdallah avatar  avatar Daniel Mineev avatar Harshil Patel avatar Labib Shahriar  avatar Hassan Najm avatar  avatar Omar avatar levente kiraly avatar Nilay Kamat avatar Abdelrahman Zahran avatar Karina Mello avatar  avatar Lukachu avatar Muhammed Nael avatar Florian Breit avatar Allan David avatar  avatar David Jándula Sánchez avatar Gabriel Marvin avatar Omar Branez avatar Jyotirmay Shelly avatar KamalkaNipun avatar Bruno avatar Thịnh Nguyễn avatar Aaron King avatar Tung Pham avatar KSS avatar Francesco Micheli avatar  avatar  avatar Monica leonte avatar A Badri Krishnan avatar Ujjwal Tak avatar  avatar FATMA CEYDA GOKCE avatar  avatar Francesco Gaetano Niutta avatar Vivek Kushal avatar  avatar  avatar

Watchers

 avatar Amila Kumara avatar 栀子花,香... avatar leo avatar Ji Xiangdong avatar Evan avatar Hyunghwan Shin avatar Fan Wu avatar gongchoo avatar nitinmeharia avatar 孙渊 avatar gaotianpeng avatar Bintopia avatar Baktiiar Kukanov avatar Vaniot avatar Obi avatar Kedar Paritkar avatar  avatar John Buck avatar  avatar  avatar  avatar  avatar  avatar  avatar

algorithms's Issues

Centroid of a given Tree | C++

Algorithm to find centroid of a given tree.
Centroid of a Tree is a node which if removed from the tree would split it into a ‘forest’, such that any tree in the forest would have at most half the number of vertices in the original tree.
Language - C++

implement graph algorithms

  • minimum spanning tree

  • single source shortest path

  • all pair shortest path

  • maximum flow

  • any other type of graph algorithms

LCSP

write a program to find the strings that make lcsp length in any language

add description file for every algorithm in Markdown language

  • Add description file for every algorithm in the repository.
  • The file must be written in Markdown language.
  • Name of file should be: algorithm_name.md.
  • Description file should be inside the algorithm's folder as: ALGORITHM_NAME/algorithm_name.md.
  • The file should contain the basic information about the algorithm, i.e., where, why and how it is used.
  • It should also contain the pseudocode of the algorithm.

Wrong folder

The files euclidean_algo_GCD_basic.py and euclidean_algo_GCD_extended.py are placed in wrong folder. They should be place in Algorithms/Mathematics/GCD/ and removed from Algorithms/Mathematics/euclidean distance/.

add efficient algorithms

#1 add cpp, python, java or any language program, also try to save that program in respective algorithm folder

Linear Search & Bubble Sort

Hello,
I have contributed code for Linear Search in C++ and Bubble Sort in C Language.
Hope you'll accept it.

add algorithms and data structures in any language

Dated: Oct-07-2020
Regarding Delay in reviewing PR
Hello, everyone, I am one of the maintainer of this repository. I know most of the PRs are the part of hacktoberfest and most of you are worried will your PRs will be eligible for Hacktoberfest 2020 or not. Since, all the maintainers are busy, it will take some time to review all the PRs. We have to review each PR and it may take some time.
Also, the rules of Hacktoberfest have been changed to reduce spam PRs. There are many SPAM PRs with invalid code or no code. So, we have to review each PR one by one. Due to the changes in rules, the burden has been shifted to maintainers.

About adding and then removing hacktoberfest-accepted label, it was just to check and verify the eligibility of the label. Do not consider it as making your PR invalid.

All the PRs will be checked and reviewed

Thanks and Happy coding 💻 👨‍💻 👩‍💻 💻

Binary search for 2d array in C++

It searches for a value in a 2d m*n matrix.
Properties of matrix:

  1. Integers in each row are sorted from left to right.
  2. The first integer of each row is greater than the last integer of the previous row.

Issue with fork ?

I am trying to clone this repo after forking but its giving me errors.

PR is not getting merged

Why is PR is not getting merged to the main branch?. The last change that is merged is around 3 months old. is the repo not active?

Subset Sum Problem in C++

I would like to contribute to the repository by writing the program for the famous subset sum problem for hacktoberfest. Kindly assign the issue to me :)

Longest Increasing Subsequence in O(N log N)

I would like to implement the Longest Increasing Subsequence problem using Binary Search and Dynamic Programming in worst-case complexity of N log N as a part of Hacktober Fest 2020.

Maximize expression | Dynamic Programming | Python

Add an algorithm to maximize an expression by computing and maximizing subexpressions and placing parentheses.
Files that would change after the PR: Dynamic Programming/Maximize Expression/maximize_expression.py

Convert Number to words

I would like to add a algorithm which converts number entered by user into words.
example:
Input 100
Output One Hundred
This will be useful when implementing a feature like automatically making a dummy cheque for user with amount filled.

add README to Searching Directory

Add a README.md file inside the Searching Directory. The file should contain a table that has

  • Columns of searching algorithms and programming languages(C, CPP, Python, Java, etc.)
  • Add a row of each searching algorithm and mark a ✔️ with a LINK to code if it is currently implemented in the corresponding programming language, else leave the cell blank.
  • Do it for each searching algorithm.
  • You can also change file names as per the algorithm to simplify the task. But do not forget to follow the nomenclature as:
    algorithm-name/ProgrammingLanguage/algorithm_code.extension

Refer to Sorting README and implement in the same manner.Refer to Markdown Cheatsheet or Makrdown Guide to get help with writing Markdown.

Example Scrrenshot is given below:
ex-sortingREADME

Create 8_Puzzle_Problem.py

mport copy
from prettytable import PrettyTable

inputMatrix = [[1, 2, 3], [4, 6, 0], [7, 5, 8]]
outputMatrix = [[1, 2, 3], [4, 5, 6], [7, 8, 0]]

class Astar:

def init(self): # Object containing matrix, flag(loc of swap), and elements
self.grid = [] # of the exp f = g + h initialized to zero
self.flag = ""
self.gCost = 0
self.hCost = 0
self.fCost = 0
def generateNeighbours(inMatrix): # Generating neighbours
slot = () # 1. Finding the void place of the current matrix
neighbours = [] # 2. Checking and swapping values to generate neighbours
for i in range(0, len(inMatrix.grid)):
for j in range(0, len(inMatrix.grid)):
if inMatrix.grid[i][j] == 0:
slot = (i, j)
break

x, y = slot

if inMatrix.flag == "":
if x + 1 <= len(inMatrix.grid) - 1:
tobj = Astar()
tobj.grid = copy.deepcopy(inMatrix.grid)
tobj.grid[x][y], tobj.grid[x + 1][y] = tobj.grid[x + 1][y], tobj.grid[x][y]
tobj.flag = "up"
tobj.gCost = inMatrix.gCost + 1
tobj.hCost = findHeuristicValue(tobj.grid)
tobj.fCost = tobj.gCost + tobj.hCost
neighbours.append(tobj)

if x - 1 >= 0:
	tobj = Astar()
	tobj.grid = copy.deepcopy(inMatrix.grid)
	tobj.grid[x][y], tobj.grid[x - 1][y] = tobj.grid[x - 1][y], tobj.grid[x][y]
	tobj.flag = "down"
	tobj.gCost = inMatrix.gCost + 1
	tobj.hCost = findHeuristicValue(tobj.grid)
	tobj.fCost = tobj.gCost + tobj.hCost
	neighbours.append(tobj)

if y - 1 >= 0:
	tobj = Astar()
	tobj.grid = copy.deepcopy(inMatrix.grid)
	tobj.grid[x][y], tobj.grid[x][y - 1] = tobj.grid[x][y - 1], tobj.grid[x][y]
	tobj.flag = "left"
	tobj.gCost = inMatrix.gCost + 1
	tobj.hCost = findHeuristicValue(tobj.grid)
	tobj.fCost = tobj.gCost + tobj.hCost
	neighbours.append(tobj)

if y + 1 <= len(inMatrix.grid) - 1:
	tobj = Astar()
	tobj.grid = copy.deepcopy(inMatrix.grid)
	tobj.grid[x][y], tobj.grid[x][y + 1] = tobj.grid[x][y + 1], tobj.grid[x][y]
	tobj.flag = "right"
	tobj.gCost = inMatrix.gCost + 1
	tobj.hCost = findHeuristicValue(tobj.grid)
	tobj.fCost = tobj.gCost + tobj.hCost
	neighbours.append(tobj)

if inMatrix.flag == "up":
if x + 1 <= len(inMatrix.grid) - 1:
tobj = Astar()
tobj.grid = copy.deepcopy(inMatrix.grid)
tobj.grid[x][y], tobj.grid[x + 1][y] = tobj.grid[x + 1][y], tobj.grid[x][y]
tobj.flag = "up"
tobj.gCost = inMatrix.gCost + 1
tobj.hCost = findHeuristicValue(tobj.grid)
tobj.fCost = tobj.gCost + tobj.hCost
neighbours.append(tobj)

if y - 1 >= 0:
	tobj = Astar()
	tobj.grid = copy.deepcopy(inMatrix.grid)
	tobj.grid[x][y], tobj.grid[x][y - 1] = tobj.grid[x][y - 1], tobj.grid[x][y]
	tobj.flag = "left"
	tobj.gCost = inMatrix.gCost + 1
	tobj.hCost = findHeuristicValue(tobj.grid)
	tobj.fCost = tobj.gCost + tobj.hCost
	neighbours.append(tobj)

if y + 1 <= len(inMatrix.grid) - 1:
	tobj = Astar()
	tobj.grid = copy.deepcopy(inMatrix.grid)
	tobj.grid[x][y], tobj.grid[x][y + 1] = tobj.grid[x][y + 1], tobj.grid[x][y]
	tobj.flag = "right"
	tobj.gCost = inMatrix.gCost + 1
	tobj.hCost = findHeuristicValue(tobj.grid)
	tobj.fCost = tobj.gCost + tobj.hCost
	neighbours.append(tobj)

if inMatrix.flag == "down":
if x - 1 >= 0:
tobj = Astar()
tobj.grid = copy.deepcopy(inMatrix.grid)
tobj.grid[x][y], tobj.grid[x - 1][y] = tobj.grid[x - 1][y], tobj.grid[x][y]
tobj.flag = "down"
tobj.gCost = inMatrix.gCost + 1
tobj.hCost = findHeuristicValue(tobj.grid)
tobj.fCost = tobj.gCost + tobj.hCost
neighbours.append(tobj)

if y - 1 >= 0:
	tobj = Astar()
	tobj.grid = copy.deepcopy(inMatrix.grid)
	tobj.grid[x][y], tobj.grid[x][y - 1] = tobj.grid[x][y - 1], tobj.grid[x][y]
	tobj.flag = "left"
	tobj.gCost = inMatrix.gCost + 1
	tobj.hCost = findHeuristicValue(tobj.grid)
	tobj.fCost = tobj.gCost + tobj.hCost
	neighbours.append(tobj)

if y + 1 <= len(inMatrix.grid) - 1:
	tobj = Astar()
	tobj.grid = copy.deepcopy(inMatrix.grid)
	tobj.grid[x][y], tobj.grid[x][y + 1] = tobj.grid[x][y + 1], tobj.grid[x][y]
	tobj.flag = "right"
	tobj.gCost = inMatrix.gCost + 1
	tobj.hCost = findHeuristicValue(tobj.grid)
	tobj.fCost = tobj.gCost + tobj.hCost
	neighbours.append(tobj)

if inMatrix.flag == "left":
if x + 1 <= len(inMatrix.grid) - 1:
tobj = Astar()
tobj.grid = copy.deepcopy(inMatrix.grid)
tobj.grid[x][y], tobj.grid[x + 1][y] = tobj.grid[x + 1][y], tobj.grid[x][y]
tobj.flag = "up"
tobj.gCost = inMatrix.gCost + 1
tobj.hCost = findHeuristicValue(tobj.grid)
tobj.fCost = tobj.gCost + tobj.hCost
neighbours.append(tobj)

if x - 1 >= 0:
	tobj = Astar()
	tobj.grid = copy.deepcopy(inMatrix.grid)
	tobj.grid[x][y], tobj.grid[x - 1][y] = tobj.grid[x - 1][y], tobj.grid[x][y]
	tobj.flag = "down"
	tobj.gCost = inMatrix.gCost + 1
	tobj.hCost = findHeuristicValue(tobj.grid)
	tobj.fCost = tobj.gCost + tobj.hCost
	neighbours.append(tobj)

if y - 1 >= 0:
	tobj = Astar()
	tobj.grid = copy.deepcopy(inMatrix.grid)
	tobj.grid[x][y], tobj.grid[x][y - 1] = tobj.grid[x][y - 1], tobj.grid[x][y]
	tobj.flag = "left"
	tobj.gCost = inMatrix.gCost + 1
	tobj.hCost = findHeuristicValue(tobj.grid)
	tobj.fCost = tobj.gCost + tobj.hCost
	neighbours.append(tobj)

if inMatrix.flag == "right":
if x + 1 <= len(inMatrix.grid) - 1:
tobj = Astar()
tobj.grid = copy.deepcopy(inMatrix.grid)
tobj.grid[x][y], tobj.grid[x + 1][y] = tobj.grid[x + 1][y], tobj.grid[x][y]
tobj.flag = "up"
tobj.gCost = inMatrix.gCost + 1
tobj.hCost = findHeuristicValue(tobj.grid)
tobj.fCost = tobj.gCost + tobj.hCost
neighbours.append(tobj)

if x - 1 >= 0:
	tobj = Astar()
	tobj.grid = copy.deepcopy(inMatrix.grid)
	tobj.grid[x][y], tobj.grid[x - 1][y] = tobj.grid[x - 1][y], tobj.grid[x][y]
	tobj.flag = "down"
	tobj.gCost = inMatrix.gCost + 1
	tobj.hCost = findHeuristicValue(tobj.grid)
	tobj.fCost = tobj.gCost + tobj.hCost
	neighbours.append(tobj)

if y + 1 <= len(inMatrix.grid) - 1:
	tobj = Astar()
	tobj.grid = copy.deepcopy(inMatrix.grid)
	tobj.grid[x][y], tobj.grid[x][y + 1] = tobj.grid[x][y + 1], tobj.grid[x][y]
	tobj.flag = "right"
	tobj.gCost = inMatrix.gCost + 1
	tobj.hCost = findHeuristicValue(tobj.grid)
	tobj.fCost = tobj.gCost + tobj.hCost
	neighbours.append(tobj)

return neighbours
def findHeuristicValue(inMatrix): # Comparing position of values of current matrix to the ones of desired matrix
h = 0
for i in range(0, len(inMatrix)):
for j in range(0, len(inMatrix)):
if inMatrix[i][j] != outputMatrix[i][j]:
h += 1
return h

def findBestMatrix(openList): # Select best matrix from open list and return it
bestmatrix = Astar()
mincost = float("inf")
for matrix in openList:
if matrix.fCost <= mincost:
mincost = matrix.fCost
bestmatrix = matrix
return bestmatrix

def printMatrix(matrix): # Formatting matrices
p = PrettyTable()
for row in matrix:
p.add_row(row)
return p.get_string(header=False, border=False)

def pathFinder():
openList = []
closedList = []
current = Astar()
current.grid = inputMatrix
openList.append(current)
steps = 0

print("Input Matrix -->") # Printing Input Matrix
print(printMatrix(current.grid))
print("Output Matrix -->") # Printing Output Matrix
print(printMatrix(outputMatrix))
print()
print()

while True:
current = findBestMatrix(openList)
openList.remove(current)
closedList.append(current)

print("Step {0}:".format(str(steps)))  # Printing steps
print(printMatrix(current.grid))       # Printing matrices
print()

if findHeuristicValue(current.grid) == 0:
	exit(0)

neighbourList = generateNeighbours(current)     # Generating neighbours from the selected matrix
for neighbour in neighbourList:
	if neighbour not in openList:
		openList.append(neighbour)              # Appending neighbours in the open list
steps += 1                                      # Incrementing steps

pathFinder()
8Puzzle

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.