2.94K subscribers
7 photos
4 files
237 links
This channel is all about programming. Happy coding :)
Download Telegram
Above problem is for Day-6 🙂
Day-6: Solution
Number of Provinces
Leetcode #547

Algorithm: Disjoint Set
Code Implementation: https://gist.github.com/SuryaPratapK/fe865b1680aceda9594a5160f80fb870
Video for Disjoint Set (Union & Find): https://youtu.be/eTaWFhPXPz4
Video for Disjoint Set (Union by RANK & Find->Path Compression): https://youtu.be/kaBX2s3pYO4

Logic:-
1 Use disjoint set to add all edges
2 DSUF array will have -1 value for only absolute parents
3 No of -1 = No of absolute parents = No of components (because all absolute parents belongs to different tree, hence different components 🙃 )

Please go through the video to understand Disjoint Set and then implement in the problem 🙂



#30DaysOfGraph #techdose #interviewpreparation #graphs #dsa
Day-7: Solution
Evaluate Division
Leetcode #399

Algorithm: Disjoint Set
SOLUTION code: https://gist.github.com/SuryaPratapK/b4ea37a86814d08856b4cd4ef41c640f
Video for Disjoint Set (Union & Find): https://youtu.be/eTaWFhPXPz4
Video for Disjoint Set (Union by RANK & Find->Path Compression): https://youtu.be/kaBX2s3pYO4

LOGIC:
1 Build a bidirectional graph with weight as: (If a=4 and b=2 then, a->b (edge wt=4/2) and b->a (edge wt=2/4))
2 For any given a/c, start traversing from a and try reaching c (a/b * b/c = a/c). Keep multiplying values while traversing.


Please go through the video to understand Disjoint Set and then implement in the problem 🙂


#30DaysOfGraph #techdose #interviewpreparation #graphs #dsa
Day-11: (Solution)
Graph Valid Tree
Leetcode #886

Read : When can we call a Graph as TREE ?
SOLUTION code: https://gist.github.com/SuryaPratapK/e9d3dc3063b8c64805ff8adbfcf4cef5
Steps:-
A graph is TREE when:-
1 It is connected (has only 1 component)
2 It has no cycle

Please try the problem yourself and read the properties for a GRAPH to be called a tree 🙂


#30DaysOfGraph #techdose #interviewpreparation #graphs #dsa