Lecture 96: Minimum Spanning Tree || Prim's Algorithm

  Рет қаралды 147,011

CodeHelp - by Babbar

CodeHelp - by Babbar

Күн бұрын

Пікірлер: 200
@suyashsingh4338
@suyashsingh4338 2 жыл бұрын
You can directly initialise a vector while creating it vector key(n+1,INT_MAX);
@chandrabhanbahetwar9638
@chandrabhanbahetwar9638 2 жыл бұрын
YES
@muzammilaltafmulla
@muzammilaltafmulla 5 ай бұрын
But then you would be doing it in 3 O(n) loops... While you could just do it all in a single loop as shown by Sir...
@akashjha822
@akashjha822 2 жыл бұрын
Imtehan hogyi thi intzaar ki, finally you are back ❤️
@utkarshsingh3319
@utkarshsingh3319 Жыл бұрын
Wrong lyrics 😂
@usernamewhatsoever4557
@usernamewhatsoever4557 Жыл бұрын
32:50 just noticed lecture - 1 ke 2.6 million views hain almost 40 videos tak 500k se zyada hain and lecture no.90 ke baad not even 1 lakh 60k, 40k, 50k sab videos par But course quality 10 on 10 h bhaiya
@codingindisguise
@codingindisguise Жыл бұрын
0:24 and 32:20 I can completely relate to you bhaiya...completing this course at one shot dedicatedly is impossible...IT TAKES TIME...😇
@Failed5555
@Failed5555 2 жыл бұрын
Bhaiya is back 🔥🔥kitni khusi ho raha hai bhaiya ko firse dakhke
@nishantsah6981
@nishantsah6981 2 жыл бұрын
Bhaiya we really appreciate your efforts and there are geniunly people who wait for your videos on youtube. So never get affected by what people says.... you take your time and bring videos....we all want solid concept from you♥️♥️♥️♥️♥️
@jayantgupta5310
@jayantgupta5310 Жыл бұрын
Code using Priority queue : #include vector calculatePrimsMST(int n, int m, vector &g) { // create adjacency list unordered_map adj; for(auto i : g) { int u = i.first.first; int v = i.first.second; int w = i.second; adj[u].push_back({v, w}); adj[v].push_back({u, w}); } // min heap to get node with minimum weight priority_queue pq; // let source as 1, and inititally distance of source is 0 // {weight, node} pq.push({0, 1}); vector key(n+1, INT_MAX), parent(n+1, -1), visited(n+1, 0); parent[1] = -1; // weight to reach i is key[i] key[1] = 0; while(pq.size()) { int w = pq.top().first; int node = pq.top().second; visited[node] = 1; pq.pop(); // find node with minimum weight and to to its neighbour for(auto neg: adj[node]) { int toGo = neg.first; int toGoWeg = neg.second; // if to react node N from key[N] update weight(key[N]) with distance from node to N if(visited[toGo] == 0 && toGoWeg < key[toGo]) { key[toGo] = toGoWeg; parent[toGo] = node; pq.push({toGoWeg, toGo}); } } } vector ans; // loop from 2 because parent of 1 is -1 (1 is initial node) for(int i = 2; i
@meerakoul4167
@meerakoul4167 2 жыл бұрын
The way of your explanation is completely another level sir literally whenever i study from your lectures when i revise it again there is no need to look back on the notebook for reference everything is crystal clear. Thanku Sir
@varunbatra9706
@varunbatra9706 2 жыл бұрын
Babbar bhaiya is back
@soumya1713
@soumya1713 2 жыл бұрын
One thing i realized that if someone learns all the concepts from u his dsa concepts will be in next level. 🤩
@harshikyadav6035
@harshikyadav6035 2 жыл бұрын
please KZbin k dsa wale course pe bhi focus Karo bhaiya It's a huge request And I really appreciate and happy for your success in edtech
@harshkumar7686
@harshkumar7686 Жыл бұрын
Bhaiya aapko kisi ki baat par dhyan dene ki jaroorat nahin hai aap apni taraf se 100% quality deliver kar rahe ho with full dedication . Thank you so much for your efforts
@lokeshdewangan430
@lokeshdewangan430 Жыл бұрын
Bhaiyya , line no. 31 why we are ending for loop to only i
@deepakjain7259
@deepakjain7259 8 күн бұрын
I think that's because all the nodes in adjacent to last node would be covered in previous iterations as it is undirected graph
@me_079_aashishkumarnayak6
@me_079_aashishkumarnayak6 Жыл бұрын
The people who write bad comments here are those people who have not come here to learn DSA but who are our love babbar bhaiya's enemies and spammers. who just want to stop his progress and success and to decrease his motivation. True learner can't write like these even can't think about these type of bad comments because if someone is watching his playlist from starting then I am dam sure he/she can't think about bad comments. Don't pay attention to these types of bad comments bhaiya you are really doing a lot for us❣❣really appreciate.
@muhammadsuleman8936
@muhammadsuleman8936 Жыл бұрын
The lecture was super babbar bhayyaa... Amazing DSA course ever on the internet...
@KACodes
@KACodes 2 жыл бұрын
Bhaiya hasu ya rou 😂😂 New video ki khushi..... Next video late aane ka darr Par fir bhi #BelieveInBabbar
@sukhjitsingh959
@sukhjitsingh959 2 жыл бұрын
Theek hai Babbar Sir ...we know you will complete your commitment....so thanks
@user-zn3be9ik1x
@user-zn3be9ik1x 2 жыл бұрын
Sir so nicely you have explained this some day this series is going to be popular for sure.
@aashishrangdal9614
@aashishrangdal9614 2 жыл бұрын
Ab ye consistency rukni nhi chahiye😅⚡
@abhishekgamer6097
@abhishekgamer6097 2 жыл бұрын
Bhaia I hope now from this point onwards you will be consistent. Thank you ❤️
@sukhjitsingh959
@sukhjitsingh959 2 жыл бұрын
Babbar sir you are saying true there is other work and things at home ... So I remember that your were making vedio during covid infection.... So really respectful for you .... I can understand everything ..so thanks lot
@PIYUSH-lz1zq
@PIYUSH-lz1zq 2 жыл бұрын
bro ...key[i] < min yeee samaj nahi aaya ...while traversing key arr elements in that are 2 3 6 how it can me smaller than min ??? please tell
@fenil_panseriya9691
@fenil_panseriya9691 2 жыл бұрын
Present bhaiya !! Consistency 🔥🔥🔥 Maza aa gaya 😄
@PRIYANSHUKUMAR-un9zu
@PRIYANSHUKUMAR-un9zu 2 жыл бұрын
Present bhaiya🔥💯 Op bhaiya after long time🤩🔥🔥🔥
@javadotcode
@javadotcode 2 жыл бұрын
I saw your video till the end bhaiya .. and wait for your ba .. Bye .. Your are really a great person .. Love You always ..
@VishalGupta-xw2rp
@VishalGupta-xw2rp 2 жыл бұрын
Heartiest Congratulations in advance bhaiya for 150K Subscriber..... Many Subscriber will come and go but i will stay with you till the end ♥️
@laksh6318
@laksh6318 2 жыл бұрын
Bhai aap SSB mai aisa hi nahi recommend hua hai ,mujhe pata hai agar apne kaha hai series complete hogi .I am also a defence aspirant side by side I am pursuing my MCA watching your series also jaab bhi app par doubt ata hai to SSB ko yadd karleta hoon hope you complete this series and thanks for supporting us who isn't able to join your paid courses.Jai Hind
@akshaykumar192
@akshaykumar192 Жыл бұрын
Avi kya kar rahe ho job lagi ?
@idiotstudent-bw4lf
@idiotstudent-bw4lf Ай бұрын
i will complete this course with end goal of getting a mind that solves dsa promblem easily
@krishchoudhary1259
@krishchoudhary1259 5 ай бұрын
I feel the priority queue solution is easier. I literally wasted a whole day trying to understand the first approach but couldn't understand completely. But I was able to understand the priority queue solution in the first attempt.
@vishwaksentripathi8250
@vishwaksentripathi8250 Жыл бұрын
during explanation, he forgots to point out that, we can't compare and update the key of neighbour which has mst == True
@its_Akash_
@its_Akash_ 2 жыл бұрын
Kudos to your content and the consistency 💯
@thesparkyguy9378
@thesparkyguy9378 2 жыл бұрын
Consistency??
@Profnegi
@Profnegi Жыл бұрын
hum hai bhaiya last tak in every single video. (practice ++)
@_Deepak__Verma
@_Deepak__Verma 8 ай бұрын
29:31 according to the algo we can't change the value whose adjacent node is false in most[v] but babbar said earlier that we have to check only weight if the weight is minimum then key[v] is should be change otherwise we can skip it //check its adjacent nodes for (auto it: adj[u]) { int v=it. first; int w=it.second; if (mst [v] == false && w < key [v] ) { parent [v] = u; key [v] = w; } }
@KrishanKumar-hp5yu
@KrishanKumar-hp5yu 2 жыл бұрын
Bhaiya thank u so much Your quality of content is top notch
@sahiltyagi1999
@sahiltyagi1999 Жыл бұрын
33:00 pahuche hain bhaiyaa, ab to dil dukhane wali baat kr rhe 😢
@vinaysharma6646
@vinaysharma6646 2 жыл бұрын
Ham sb ki bhot hopes h bhaiya aap se so please 🔥🔥
@brajagopalmukherjee1588
@brajagopalmukherjee1588 2 жыл бұрын
Bhai already sab khatam ho gaya na ,aur kitna lecture chaiya Thora sa practice karlo
@unboxtheuniverse5336
@unboxtheuniverse5336 2 жыл бұрын
Love you bhaiya ❤️mattt jayaa karo yaar hamko chord kar 🥺🙌 aapke binaa DSA me mazaa nhi aata
@Aman-fz1ew
@Aman-fz1ew Жыл бұрын
love you bhaiya. for making The Best DSA course . 😘
@chandrabhanbahetwar9638
@chandrabhanbahetwar9638 2 жыл бұрын
ONE OF THE BEST DSA SERIES IN YOU TUBE LOVE YOU BHAIYA JIO 10000++ SALL
@aashishrangdal9614
@aashishrangdal9614 2 жыл бұрын
Finally after 2 weeks bhaiya⚡⚡
@rachit_joshi
@rachit_joshi 5 ай бұрын
Thank You So Much BHRATA SHREE !!!!!!!
@gogood0579
@gogood0579 9 күн бұрын
33:01 pahuncha bhaiya++
@VishalGupta-xw2rp
@VishalGupta-xw2rp 2 жыл бұрын
Thankyou soo much Love Babbar bhai for doing soo much for our sake. We are with you till the end. Right now I'm on Lecture 11. Thankyou soo much for everything. It really means alot. 🔥🌠🤩
@akankshapandey9773
@akankshapandey9773 2 жыл бұрын
Thanku so much sir pls ye series complete kr dijiye 🙏🏻🙏🏻
@priyeshvikramsingh8587
@priyeshvikramsingh8587 2 жыл бұрын
consistency at peak
@girikgarg1268
@girikgarg1268 2 жыл бұрын
Time complexity O(V^2*E) honi chahiye...kyunki minimum cost valli vertex ind karne ke baad hum uss node ke sabhi neighbours par jaa rahe hain
@BhaiRayyanKiDuniya
@BhaiRayyanKiDuniya 2 жыл бұрын
Best part for hard-working
@ShivamKumar-hh9pg
@ShivamKumar-hh9pg 2 жыл бұрын
While checking for every adjacent node first we need to check whether mst[that_node]==0. That u didn't include in your explanation. If mst[adj_node] ==1, we do not need to check it in key array.
@ayush18gupta
@ayush18gupta 2 жыл бұрын
++
@muzdalfazulfiqar4272
@muzdalfazulfiqar4272 11 ай бұрын
This was the point at which i am confused i tried to dry run it for 3 to 4 examples and always the wrong output just because i was updating them in key array too , Can u please explain why we do not need to consider them
@satyamkumar9095
@satyamkumar9095 2 жыл бұрын
Aa gayi yaad iss. Course ki late ho rahe ho phir bhi thankyou
@hardikjain-brb
@hardikjain-brb 11 ай бұрын
28:51 for all the nodes
@harshitagrawal2662
@harshitagrawal2662 2 жыл бұрын
32:58 I went till there , and also following this graph series
@PIYUSH-lz1zq
@PIYUSH-lz1zq 2 жыл бұрын
bro ...key[i] < min yeee samaj nahi aaya ...while traversing key arr elements in that are 2 3 6 how it can me smaller than min ??? please tell
@prakashmohaldar9004
@prakashmohaldar9004 2 жыл бұрын
@@PIYUSH-lz1zq notice min is getting initialized to INT_MAX after every iteration we will get minimum value
@PrakharPandey-no9zs
@PrakharPandey-no9zs Жыл бұрын
thank you so much bhaiya and lots of love to you
@anuragpandey8165
@anuragpandey8165 2 жыл бұрын
33:00 hum har jagah pohuch jate hai. Keep going brother
@PIYUSH-lz1zq
@PIYUSH-lz1zq 2 жыл бұрын
bro ...key[i] < min yeee samaj nahi aaya ...while traversing key arr elements in that are 2 3 6 how it can me smaller than min ??? please tell
@piyushsingh9320
@piyushsingh9320 2 жыл бұрын
@@PIYUSH-lz1zq see that mini is reset to INT_MAX,on every iteration of first for loop so when you come next time then mini will be reseted to INT_MAX and now we will find new mini by traversing the inner for loop...
@engg.5111
@engg.5111 2 жыл бұрын
Bhaiya back😍😍
@deepikasharma9812
@deepikasharma9812 2 жыл бұрын
Finally u are back.. 🙂
@vinaysharma6646
@vinaysharma6646 2 жыл бұрын
Bhaiya ab is course ko please pehle ki trh continue kr do ...
@tusharbhalothia7205
@tusharbhalothia7205 2 жыл бұрын
Bhaiya ab bas jaldi se graphs and dp completely complete karwa dijiye please🙏
@vishalkumarshaw9208
@vishalkumarshaw9208 2 жыл бұрын
1 no bhaia...👌👌👌
@Reehan
@Reehan 2 жыл бұрын
Aap bhagwan ka kaam kar rhe hai. Keep doing it❤️
@KapilThakur-hx2nx
@KapilThakur-hx2nx Жыл бұрын
key - distance , mst - visited
@utkarshsingh405
@utkarshsingh405 2 жыл бұрын
Keep going bhaiya.... You're doing great!.. 👍
@ayushsrivastava1586
@ayushsrivastava1586 2 жыл бұрын
Bhaiya video k liye bahut mehnat krte h sb log jldi jldi comment krdo
@shivkumar-og4ow
@shivkumar-og4ow 2 жыл бұрын
Thanks guru ji... Consistency+++
@MME__MudavathSrinu
@MME__MudavathSrinu 2 жыл бұрын
Bhaiya the way you explain the problems wow 👍👌
@PIYUSH-lz1zq
@PIYUSH-lz1zq 2 жыл бұрын
bro ...key[i] < min yeee samaj nahi aaya ...while traversing key arr elements in that are 2 3 6 how it can me smaller than min ??? please tell
@harikrushnasuhagiya3925
@harikrushnasuhagiya3925 2 жыл бұрын
Thank you Bhaiya for your consistency :)
@kshitijraj1320
@kshitijraj1320 2 жыл бұрын
Thanks a lot bhaiya ❤❤❤
@honestad3558
@honestad3558 10 ай бұрын
akhri tak bhi pooch the hai bhaiya aapko nhi pata kei last kei video dekhtey hai bhut sarey log
@awesomepatt620
@awesomepatt620 2 жыл бұрын
Thank you bhaiya for thos amazing series. I am also a student of your live Unacademy series. Bhaiya, is there any plan for a System Design course ?
@dEviL_bIsWaJiT
@dEviL_bIsWaJiT 2 жыл бұрын
Present bhaiya❤️🔥
@sciencestreamers8509
@sciencestreamers8509 2 жыл бұрын
Congratulations in advance for 150 k 🎉🎉🎉🎉🎉
@imalokpandey
@imalokpandey 2 ай бұрын
thankuuu bhaiyaa
@abhaysingh-os3qu
@abhaysingh-os3qu Жыл бұрын
just in case anyone is wondering what if the given input is directly adjacency list here goes the code it.. void spanningTree(int V, vector adj[]) { vectorkey(V,INT_MAX); vectormst(V,0); vectorparent(V,-1); key[0]=0; parent[0]=-1; for(int i=0;i
@NYSWorld
@NYSWorld 2 жыл бұрын
32:57 mai pauch gaya
@Shubham-ev1ku
@Shubham-ev1ku Жыл бұрын
Thank you sir , you really made my day.
@AnilPawar-jy9sn
@AnilPawar-jy9sn Жыл бұрын
Thankyou bhaiya for great explanation but still I feel intuition part of algo is somewhat lacking. Please try to explain the funda before going to dry run and explaining every steps.
@amarpreetkaur6056
@amarpreetkaur6056 2 жыл бұрын
Thankyou for continuing
@abhinavyadav1970
@abhinavyadav1970 11 ай бұрын
mai pahuch gya last tk😅
@oqant0424
@oqant0424 2 жыл бұрын
explained so nicely
@rohit_ojha
@rohit_ojha Жыл бұрын
thanks bhaiya.......... :)
@amanthakur7358
@amanthakur7358 2 жыл бұрын
back bro ❤️❤️🔥
@AbhishekGupta-cg2vj
@AbhishekGupta-cg2vj 2 жыл бұрын
Thanku so much bhaiya for such a great series. Consistency++
@iteself_me
@iteself_me Жыл бұрын
162 ✅completed 👍Liked 2:53
@onais__
@onais__ 2 жыл бұрын
BHAIYA LATE DALO MAGAR QUALITY AUR LENGTH AUR TOTAL TOPICS MEIN COMPRISE MAT KRNA ❤️‍🔥❤️‍🔥💫💯
@Robinhoodbhaigandhi
@Robinhoodbhaigandhi 2 жыл бұрын
Bhaiya! Nhi ho pa raha h ye. Mujhe lagta h mai coading ke liye bana hi nhi hu. Apke 10 videos dekhe par kuch samajh hi nhi aa raha .isliye dheere dheere intrest bhi kam ho raha h. Aur ab kuch samajh hi nhi aa raha ki kya karu.2021 passout hu par job bhi nhi lag rha .😟
@pragyaverma2105
@pragyaverma2105 Жыл бұрын
Thank u ji ❤
@Oroniislam-l6o
@Oroniislam-l6o 2 жыл бұрын
Thanks a lot vaia, waiting for a lot💖💖💖
@adityauniyal8632
@adityauniyal8632 Жыл бұрын
Line 31 i
@alokranjan3185
@alokranjan3185 2 жыл бұрын
thanks bhaiya
@bat_man1138
@bat_man1138 2 жыл бұрын
Error in the video ...while making dry run and explaining it...u didnt mention while checking every adjacent node first we need to check wether "mst[that_node]==0" And u included that thing directly in code. Though Nyc vid sir . For example sir at 15:20 U are checking key value for "1".but key for 1 should not be checked as mst[1] already true..so no need to look into key array.
@vortexdeo4545
@vortexdeo4545 2 жыл бұрын
Then once key key[v] for that number is updated and then it wont be updated again as its mst[v] would be marked true 🤔In Djikstra, that was not such visited/mst so dist was updated every time for a shorter value
@saadshakeel3348
@saadshakeel3348 4 ай бұрын
Can you explain why is it so, what if we get lesser weight on mst==true node than it had before
@priyanshugupta9192
@priyanshugupta9192 Жыл бұрын
Done the code by using set instead of priority queue
@amitgupta-or5nm
@amitgupta-or5nm 2 жыл бұрын
gud work ....keep it up
@roopchandjangir6862
@roopchandjangir6862 2 жыл бұрын
Love u brother 🙂🙂🙂🙂
@fazerugbrug439
@fazerugbrug439 2 жыл бұрын
excellent
@risha1907
@risha1907 2 жыл бұрын
Graph series is OP
@PIYUSH-lz1zq
@PIYUSH-lz1zq 2 жыл бұрын
bro ...key[i] < min yeee samaj nahi aaya ...while traversing key arr elements in that are 2 3 6 how it can me smaller than min ??? please tell
@risha1907
@risha1907 2 жыл бұрын
@@PIYUSH-lz1zqleast key value and uska MST False ho aise index lena hai. Toh woh least value ke liye min se compare karenge
@PIYUSH-lz1zq
@PIYUSH-lz1zq 2 жыл бұрын
@@risha1907 value of each is increasing... like oth index has 0 then first index is 2 then 3rd index is coming to 3 .... how come???
@risha1907
@risha1907 2 жыл бұрын
@@PIYUSH-lz1zq We'll be updating the values of neighbours in key arr with the given weights. Neighbours of 0 are 1 and 3.
@akankshapandey8316
@akankshapandey8316 2 жыл бұрын
Thanku so much sir 🙏
@myths8740
@myths8740 Жыл бұрын
THE MAN
@yashasvic2429
@yashasvic2429 Жыл бұрын
Thanks Bhai 👍
@swapnilsalunke5942
@swapnilsalunke5942 Жыл бұрын
Happy teachers day
@mandeepsinghsoorma3080
@mandeepsinghsoorma3080 2 жыл бұрын
don't worry bhaiya, pohoch gye last tk!!
@pranav0207
@pranav0207 2 жыл бұрын
please upload all the codes after lecture 65
@sagnikmodak4178
@sagnikmodak4178 Жыл бұрын
thanks sir ;
Lecture 95: Dijkstra's Algorithm || C++ Placement Series
35:55
CodeHelp - by Babbar
Рет қаралды 159 М.
Yay😃 Let's make a Cute Handbag for me 👜 #diycrafts #shorts
00:33
LearnToon - Learn & Play
Рет қаралды 117 МЛН
Thank you Santa
00:13
Nadir Show
Рет қаралды 36 МЛН
كم بصير عمركم عام ٢٠٢٥😍 #shorts #hasanandnour
00:27
hasan and nour shorts
Рет қаралды 11 МЛН
G-45. Prim's Algorithm - Minimum Spanning Tree - C++ and Java
19:10
take U forward
Рет қаралды 271 М.
3.5 Prims and Kruskals Algorithms - Greedy Method
20:12
Abdul Bari
Рет қаралды 2,9 МЛН
Why is Python 150X slower than C?
10:45
Mehul - Codedamn
Рет қаралды 18 М.
Prim's Algorithm
7:18
Lalitha Natraj
Рет қаралды 611 М.
L-4.9: Prim's Algorithm for Minimum Cost Spanning Tree | Prims vs Kruskal
9:55
Quiet Night: Deep Sleep Music with Black Screen - Fall Asleep with Ambient Music
3:05:46
G-47. Kruskal's Algorithm - Minimum Spanning Tree - C++ and Java
13:11
take U forward
Рет қаралды 200 М.
One Effective Trick to Learn Coding Fast (Works in 2024)
4:53
CodeWithHarry
Рет қаралды 356 М.