Skip to content

Instantly share code, notes, and snippets.

View shubham100795's full-sized avatar

shubham100795

View GitHub Profile
@shubham100795
shubham100795 / rightview.cpp
Created September 12, 2017 14:57
Right view using level order traversal
#include<bits/stdc++.h>
using namespace std;
struct Node{
int data;
Node *left;
Node *right;
};
Node* newNode(int x)
@shubham100795
shubham100795 / printallpaths.cpp
Created July 31, 2017 12:08
Print all possible paths from source to destination in a directed graph
#include<bits/stdc++.h>
using namespace std;
int adj[10][10];
int visited[10];
void create_graph(int n,int m)
{
int i,j,k,src,dest;
for(j=0;j<n;j++)
@shubham100795
shubham100795 / dijkstras.cpp
Created April 22, 2017 20:58
single source shortest path using stl in c++
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define V 4
using namespace std;
list< pair<int,int> > adj[V];
void addedge(int u,int v,int w)
{
adj[u].push_back(make_pair(v,w));
@shubham100795
shubham100795 / warshalls.cpp
Created April 20, 2017 13:40
Warshall's algorithm to find the path matrix
#include<iostream>
using namespace std;
int main()
{
int ar[4][4]={{0,1,0,1},{1,0,1,1},{0,0,0,1},{1,0,1,0}};
for(int k=0;k<4;k++)
{
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int adj[10][10];
vector<int> indegree;
vector<int> order;
queue<int> q;
void create_graph(int n)
@shubham100795
shubham100795 / DFS.cpp
Created March 8, 2017 20:24
Non recursive DFS for a graph
#include<iostream>
#include<stack>
#define initial 0
#define visited 1
using namespace std;
int adj[10][10];
int state[10];
void create_graph(int n)
@shubham100795
shubham100795 / stronglyconnected.cpp
Last active July 30, 2017 09:12
find strongly connected components in a directed graph using kosaraju's algorithm
#include<iostream>
#include<stack>
#define initial 0
#define visited 1
#define finished 2
using namespace std;
int adj[10][10];
int rev_adj[10][10];
int state[10];
@shubham100795
shubham100795 / BFS.cpp
Created March 7, 2017 20:24
BFS in a graph along with shortest distance and path from the starting vertex to any other vertex
#include<iostream>
#include<queue>
#include<climits>
#define initial 0
#define waiting 1
#define visited 2
#define NIL -1
using namespace std;
int adj[10][10];
@shubham100795
shubham100795 / maxbtw2nodes.c
Created March 5, 2017 18:47
Maximum element between two nodes of a BST
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
struct node{
int data;
struct node *left;
struct node *right;
};
struct node *newnode(int x)
@shubham100795
shubham100795 / findceilfloor.cpp
Created March 2, 2017 14:13
Find ceil and floor of a key in BST
#include<iostream>
#include<cstdlib>
using namespace std;
struct node{
int data;
struct node *left;
struct node *right;
};