Giter Site home page Giter Site logo

hacktoberfest2k20 / datastructures-and-algorithms Goto Github PK

View Code? Open in Web Editor NEW
17.0 2.0 74.0 92 KB

Structure the Data in a correct and efficient way :fire:

C++ 72.92% C 15.88% Java 9.48% Python 1.72%
hacktoberfest hacktoberfest2020 cpp cplusplus hacktoberfest2021 algorithms hacktoberfest-accepted

datastructures-and-algorithms's Introduction

DataStructures-and-Algorithms

Structure the Data in a correct and efficient way!

This repository will contain all the generic data-structure and algorithms that run in an effiecient time and space complexity. You may get your changes merged here by submitting a Pull Request 🔥

Q. How will I get my changes merged(how should I open a pull request)

A. You may propose your changes via a Pull Request. For how to open a pull request, give this a read, if stuck, please ping anyone of the maintainers for help.

Q. How should I begin contributing here?

A. Well, it is simple enough,follow the procedure

  • Read the repository,
  • Find the algorithm that you think is missing.
  • Now create and issue in this repository via clicking here,
  • Get yourself assigned to it(via commenting on the issue and tagging any of the maintainer)
  • Implement it, and create a pull request, we'll merge your PR very soon with minimal changes needed.

For Contributions

  • In the Pull Requests proposed, please add the Name Of Algorithm you added in the PR and its Space & Time Complexity both right at the top of the File you create/optimize.

  • Don't Create duplicate issues or Pull Requests (ones which already exist on the repository)

  • Star ⭐ the repo for exciting contests and updates!!!

More excited? Join our discord server and ask questions in the #hacktoberfest.

Fun Fact: This repository is independent of languages, which means, you may add the algorithm(s) in the programming language you find yourself comfortable with!

Very soon you'll be getting 'em merged in our Prime branch

datastructures-and-algorithms's People

Contributors

abhi211199 avatar acciptris avatar adarshsr28 avatar aditi-1400 avatar adityasamantaroy avatar akshat05-tech avatar akshay-nagle avatar apoodwivedi avatar chinmaygupta14 avatar gagan-shenoy avatar heisenberg-737 avatar mayank64ce avatar raba-ajeet avatar rishitha24 avatar s-ayush2903 avatar sandesh-3112 avatar sskale1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

datastructures-and-algorithms's Issues

Heap sort

I would like to add heap sort algorithm along with it's time complexity.

Linear search

As linear search is basic algorithm and not present in the repo , it should be added

Exponential Search Needed

Exponential search involves two steps:

  1. Find the range where the element is present
  2. Do Binary Search in above-found range.

Fractional Knapsack | C++

Fractional Knapsack Problem -

Added Solution for the Fractional Knapsack Problem

Type of Issue -

  • Adding New Code
  • Improving Documentation

Programming Language

  • C++

Code For Hashing needed

In a hash table, data is stored in an array format, where each data value has its own unique index value. Access of data becomes very fast if we know the index of the desired data.

bfs

To implement breadth first search in a graph

Insertion Sort

I would like to add the algorithm for insertion sort in C++

Dijkstra's Algorithm

/Given an undirected, connected and weighted graph G(V, E) with V number of vertices (which are numbered from 0 to V-1) and E number of edges. Find and print the shortest distance from the source vertex (i.e. Vertex 0) to all other vertices (including source vertex also) using Dijkstra's Algorithm. Print the ith vertex number and the distance from source in one line separated by space. Print different vertices in different lines./

#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll max(ll a, ll b)
{
if (a < b)
return b;
return a;
}

ll min(ll a, ll b)
{
if (a < b)
return a;
return b;
}

#define pp pair<int, int>
#define vpp vector
#define vecto vector
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
using namespace std;

#define IOS
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0)

#define ull unsigned long long int
#define f(i, n) for (int i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i < b; i++)

// Find the index with minimum weight which is not visited
ll findMinInd(ll n, bool visited[], ll weight[])
{
ll mini = INT_MAX, index = -1;
for (int i = 0; i < n; i++)
{
if (mini > weight[i] && visited[i] == false)
{
mini = weight[i];
index = i;
}
}

return index;

}

void solve()
{
bool visited[100000];
ll weight[100000];
memset(visited, false, sizeof(visited));

// INPUT
ll v, e;
cin >> v >> e;

ll **arr = new ll*[v];
for(int i=0;i<v;i++)
{
    arr[i] = new ll[v];
    for(int j=0;j<v;j++)
    {
        arr[i][j] = 0;
    }
}

for (int i = 0; i < v; i++)
{
    weight[i] = INT_MAX;
}
for (int i = 0; i < e; i++)
{
    ll a, b, c;
    cin >> a >> b >> c;

    arr[a][b] = c;
    arr[b][a] = c;
}

weight[0] = 0;
ll ans[v];

while (1)
{
    ll index = findMinInd(v, visited, weight);

    if (index == -1)
        break;

    visited[index] = true;
    ans[index] = weight[index] ;

    for (int i = 0; i < v; i++)
    {
        if (weight[i] > weight[index] + arr[index][i] && !visited[i] && arr[index][i] != 0)
        {
            weight[i] = weight[index] + arr[index][i];
        }
    }
}

// OUTPUT
for(int i=0;i<v;i++)
{
cout<<i<<" "<<ans[i]<<"\n";
}
}

int main()
{
IOS;
solve();
}

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.