Skip to content

Commit

Permalink
Merge pull request #493 from SurbhiSharma15/master
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
MukulCode authored Oct 29, 2022
2 parents a5adfe5 + 3dd1974 commit d78bcc8
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 2 deletions.
101 changes: 101 additions & 0 deletions Interview Graph Topics/kruskal_algorithm
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
struct DSU{

vector<int> parent ;
vector<int> size ;
int comp;

DSU(int N){
parent.resize(N+1,0);
size.resize(N+1,0);
comp = N;
for(int i=1;i<=N;i++){
make_set(i) ;
}
}
void make_set(int v){
parent[v] = v ;
size[v] = 1 ;
}

int find_set(int v){
if(parent[v] == v){
return v ;
}
return parent[v] = find_set(parent[v]);
}
void union_set(int a, int b){
a = find_set(a) ;
b = find_set(b) ;

if(a!=b){
if(size[a]> size[b]){
swap(a, b);
}
parent[a] = parent[b] ;
size[b] += size[a];
comp--;
}

}

int count_comp(){
return comp;
}

int size_set(int v){
return size[find_set(v)] ;
}
};



struct edge{
int u , v , w ;
edge(int u , int v , int w ){
this->u = u ;
this->v = v ;
this->w = w ;
}
};

bool comp( edge &a , edge &b ){
return a.w < b.w ;
}

void solve(){

int n , m ;
cin >> n >> m ;

vector<edge> edg ;

while(m--){
int u , v , w ;
cin >> u >> v >> w ;
edge newedge(u,v,w) ;
edg.pb(newedge) ;
}

sort(all(edg) , comp ) ;

int mst_sum = 0 ;

DSU vec(n) ;

for(auto x : edg ){
int u = x.u ;
int v = x.v ;
int w = x.w ;

u = vec.find_set(u) ;
v = vec.find_set(v) ;

if(u!=v){
mst_sum += w ;
vec.union_set(u,v) ;
}
}

cout << mst_sum << endl ;

}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@ Jayesh Rajput (Pune)
Purbendu Halder (Kolkata)


Surbhi Sharma (Haryana)


Dhruv Mehta (Faridabad)

Mohd Maaz (Gorakhpur)
Expand Down
3 changes: 1 addition & 2 deletions Snack_game/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function update() {

if (gameOver) {

// Game end screen
// Game end screen to be shown

createText(`Game Over`, board.width / 2, board.height / 2 - 25, 'center', 50);

Expand Down Expand Up @@ -89,7 +89,6 @@ function update() {
tail[0] = [snakeX, snakeY];
}


// Snake position
snakeX += velocityX * blockSize;
snakeY += velocityY * blockSize;
Expand Down
53 changes: 53 additions & 0 deletions boundarytraversalinbinarytree
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class Solution {
public:

bool isleaf(Node *root){
if(root->left == NULL && root->right==NULL) return true ;
return false ;
}

void leftboun(Node *root, vector<int> & ans){
Node * curr= root->left;
while(curr){
if(!isleaf(curr)) ans.push_back(curr->data) ;
if(curr->left) curr=curr->left ;
else curr=curr->right ;
}
}
void rightboun(Node *root, vector<int> & ans){
Node * curr= root->right ;
vector<int> temp ;
while(curr){
if(!isleaf(curr)) temp.push_back(curr->data) ;
if(curr->right) curr=curr->right ;
else curr= curr->left ;
}
for(int i= temp.size()-1;i>=0;i--){
ans.push_back(temp[i]) ;
}
}

void leaves(Node *root, vector<int> & ans){
if(isleaf(root)){
ans.push_back(root->data) ;
return ;
}
if(root->left) leaves(root->left, ans) ;
if(root->right) leaves(root->right,ans) ;

}

vector <int> boundary(Node *root)
{
//Your code here
vector<int> ans ;
if(!root) return ans ;

if(!isleaf(root)) ans.push_back(root->data) ;
leftboun(root,ans) ;
leaves(root,ans) ;
rightboun(root,ans) ;

return ans ;
}
};

0 comments on commit d78bcc8

Please sign in to comment.