G-32. Dijkstra's Algorithm - Using Priority Queue - C++ and Java - Part 1

  Рет қаралды 288,031

take U forward

take U forward

Жыл бұрын

GfG-Problem Link: bit.ly/3KeZZ7j
C++/Java/Codes and Notes Link: takeuforward.org/data-structu...
DP Series: • Striver's Dynamic Prog...
SDE Sheet: takeuforward.org/interviews/s...
Check out our Website for curated resources:
Our Second Channel: / @striver_79
In case you are thinking to buy courses, please check below:
Code "takeuforward" for 15% off at GFG: practice.geeksforgeeks.org/co...
Code "takeuforward" for 20% off on sys-design: get.interviewready.io?_aff=takeuforward
Crypto, I use the Wazirx app: wazirx.com/invite/xexnpc4u
Take 750 rs free Amazon Stock from me: indmoney.onelink.me/RmHC/idje...
Earn 100 rs by making a Grow Account for investing: app.groww.in/v3cO/8hu879t0
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
---------------------------------------------------------------------------------------------------------------------------

Пікірлер: 269
@takeUforward
@takeUforward Жыл бұрын
Let's continue the habit of commenting “understood” if you got the entire video. Please give it a like too, you don't 😞 Do follow me on Instagram: striver_79
@sdexstarlord
@sdexstarlord Жыл бұрын
can you tell me what is the use of this priority_queuepq ?? and why did you used this vector ??
@TrndxAtomic
@TrndxAtomic Жыл бұрын
@@sdexstarlord in C++ the default priority queue is max heap...the syntax used above is for creating min-heap.
@sukhjattana5887
@sukhjattana5887 Жыл бұрын
understood (Y) (Y) ....u forgot to pin this :p
@namratam1522
@namratam1522 11 ай бұрын
Why dont you use visited array?
@priyanshkumariitd
@priyanshkumariitd Ай бұрын
understood
@awesome_latest_virals6098
@awesome_latest_virals6098 Жыл бұрын
15:26 instead of assigning value using loop , we can just write vector dist ( V , INT_MAX);
@Cools74
@Cools74 3 ай бұрын
Both are same time complexity:)
@priyanshkumariitd
@priyanshkumariitd Ай бұрын
yes, for more compactness of code, we can write :)
@princenagar1686
@princenagar1686 7 күн бұрын
There is a problem in that is when whe check ( currentNodeDistance + distance_till_now < current NodeDistance then Assignment new shortest distance) in this line if we sum in INT_MAX with some positive value then it will become NEGATIVE and thus evaluates as Small instead of Big.
@visase2036
@visase2036 Жыл бұрын
Ahh Finally! Here it goes ... Happy to see you back after many days ,was waiting for the new video graph playlist. Thanks a lot for your immense efforts Striver. Good to see you in a new look! Virat Kohli of DSA! 😀
@ideepakpandey
@ideepakpandey Жыл бұрын
Wow, 3 videos on Dijkstra. We will not find such detailed videos even in expensive premium courses.
@takeUforward
@takeUforward Жыл бұрын
It will be more than 3, around 10. Including problems 🫡 Give me a day or two. All will be out.
@ideepakpandey
@ideepakpandey Жыл бұрын
@@takeUforward great🔥🙌. You are literally god for those students like me who cannot afford premium courses.
@sharathkumar8338
@sharathkumar8338 Жыл бұрын
@@ideepakpandey even premium courses are not this worth. personal experience.
@codingvibesofficial
@codingvibesofficial Жыл бұрын
@take u forward That's our striver bhaiya
@suheabkhan2546
@suheabkhan2546 Жыл бұрын
Learning Dijkshtra algo for the first time... And understand it in the one watch was like unbelievable.. #striver op
@user-ye5zq6hr7r
@user-ye5zq6hr7r 5 ай бұрын
Striver bhaiya cant thank you enough...heard the concept and coded it on one go all credits to you🙏
@nikhilraj9900
@nikhilraj9900 Жыл бұрын
I have already solved more than 15 problems on Dijextra but i can't resist myself to watch whole video.
@amanasrani6405
@amanasrani6405 Ай бұрын
understood, we are so lucky to have u striver
@johnj171
@johnj171 Ай бұрын
love you man I will watch every second!!! love you for the dedication and series you have contributed for the community
@shivyanshgarg2641
@shivyanshgarg2641 6 ай бұрын
i like how i can write the code myself after being 5 - 6 mins in the video.
@CodeMode9313
@CodeMode9313 11 ай бұрын
Habibi ye bhi kamal video banti ... bahut accha bahut accha
@sambhavagarwal5871
@sambhavagarwal5871 Жыл бұрын
understand Thanks a lot for your immense efforts Striver.
@dinushachathuranga7657
@dinushachathuranga7657 Жыл бұрын
excellent explanation. Lucky to find your channel.❤
@TrendyGamer007
@TrendyGamer007 Жыл бұрын
loving this playlist 3000❣
@Moch117
@Moch117 10 ай бұрын
Thank you! I implemented it on my own and it worked without storing the distance on the priority queue. I only stored the nodes themselves. I also used a Pair class to store (dest,weight)
@cinime
@cinime Жыл бұрын
Understood! Super fantastic explanation as always, thank you very much!!
@rahulprasad3575
@rahulprasad3575 Жыл бұрын
bro this is the exact thing i was searching today
@hashcodez757
@hashcodez757 8 ай бұрын
Undestood BHAIYA!! thanks alot
@vakhariyajay2224
@vakhariyajay2224 Жыл бұрын
Thank you very much. You are a genius.
@raghavmanish24
@raghavmanish24 2 ай бұрын
thanku striver .....again i have started this series from where i have stoped due to some reasons ,,,,,i'm sure this time i will complete this
@SonuKumar-ed2bo
@SonuKumar-ed2bo Жыл бұрын
17:20 We need to put the node in queue for same distanse too. So we need to put a equality sign over there
@jambajuice07
@jambajuice07 Жыл бұрын
half way done ! wont stop
@unfamousgaayak4838
@unfamousgaayak4838 Ай бұрын
U r doing a great job man . Salute to you ..
@rishabhagarwal8049
@rishabhagarwal8049 Жыл бұрын
Understood Sir, Thank you very much
@AYUSHKUMAR-xj4wc
@AYUSHKUMAR-xj4wc Жыл бұрын
Awesome Explanation 👍👌
@dhanashreegodase4445
@dhanashreegodase4445 10 ай бұрын
You are a Masterpeice!!
@rishabhgupta9846
@rishabhgupta9846 Жыл бұрын
understood,great explanation
@chiragsawarn9548
@chiragsawarn9548 11 ай бұрын
In this implementation it was extremely difficult to figure out the complexity. When we use a visited array, it become clear that a node may be queued multiple times but its neighbors will only be processed once. Because the first occurrence of duplicate node in the queue will have the lightest path and mark the node as visited. Eliminating the need for redundancies to be processed.
@giit85
@giit85 Жыл бұрын
Great continue this series
@harshnaruto3122
@harshnaruto3122 Жыл бұрын
You are hero for us
@harleenkaur7751
@harleenkaur7751 Жыл бұрын
Amazing explanation. Thanks Bhaiya
@1qwertyuiop1000
@1qwertyuiop1000 10 ай бұрын
One suggestion in java code.. Instead of doing 2 operations I.E. peek() and remove() at line number 81,82& 83, we can do one operation pop().. Just an FYI for other java codes... Happy coding.. 👍
@A52VarshaSanga-pr7km
@A52VarshaSanga-pr7km Ай бұрын
Thank you so much ..your videos give me hope that I can do better !!
@namamiNarayana
@namamiNarayana Жыл бұрын
Understood! :) Thank you for your invaluable efforts striver! _/\_ ^^
@mriduljain6809
@mriduljain6809 Жыл бұрын
Understood Bhaiya😍😍
@sagarvk18
@sagarvk18 9 ай бұрын
Love and Respect!
@maniknr2293
@maniknr2293 Жыл бұрын
Loved it❤
@supratimnayek2776
@supratimnayek2776 Жыл бұрын
Amazing explanation
@sanketmudholkar2889
@sanketmudholkar2889 Жыл бұрын
This series is far better than any of the netflix original ones
@abhinavhadole6516
@abhinavhadole6516 Жыл бұрын
Jai Dijkstra's Algorithm 🙇🏼🙏🏻
@amitp277
@amitp277 Жыл бұрын
great work 👏
@gauravrai2979
@gauravrai2979 Жыл бұрын
can someone explain the priority queue declaration part in java I don't understand the ((x,y) -> x.distance - y.distance ).
@_hulk748
@_hulk748 Жыл бұрын
Thankyou sir understood🙇‍♂️🙏❤
@ananttyagi7372
@ananttyagi7372 Жыл бұрын
understood very well
@banothutharun2743
@banothutharun2743 4 күн бұрын
understood brother.❤
@flip4661
@flip4661 Жыл бұрын
Amazing 👏
@DevashishJose
@DevashishJose 5 ай бұрын
understood, thank you so much.
@hrushi_borhade
@hrushi_borhade Жыл бұрын
understood striver!!!
@ruchitjoshi6889
@ruchitjoshi6889 Жыл бұрын
Why the priority queue has been initialized with pair? we can simply take 2-d vector in the pq
@rahuljain224
@rahuljain224 5 ай бұрын
Superb explanation
@Shivanai_h
@Shivanai_h Жыл бұрын
Understood 👌👌
@SWEcodes
@SWEcodes Жыл бұрын
I guess if you will not check that the if dis != dist[node] we do not have to process this node as it is already processed. Because there can be same nodes with different distance in priority queue. The answer is still corrects, but i guess with your code it might lee to a worst of V.E
@shashankrustagi3725
@shashankrustagi3725 Жыл бұрын
hi striver, what is shortest path faster algorithm? SPFA? is it similar to dijkstra?
@user-kl3qv1sc8k
@user-kl3qv1sc8k Ай бұрын
amazing🤩🤩
@gautamsaxena4647
@gautamsaxena4647 2 ай бұрын
understood bhaiya
@sanyam9712
@sanyam9712 Жыл бұрын
understood. Please make playlist on bit masking and bit manipulation
@eshaanpandey7353
@eshaanpandey7353 Жыл бұрын
Understood 👍
@sallaklamhayyen9876
@sallaklamhayyen9876 Ай бұрын
thank you so much 🥰🥰🥰
@sharusharath1058
@sharusharath1058 28 күн бұрын
nice explaination
@user-tk2vg5jt3l
@user-tk2vg5jt3l 2 ай бұрын
Thank you bhaiya
@venkat.sairam
@venkat.sairam 8 ай бұрын
🎯 Key Takeaways for quick navigation: 00:02 📚 *Introduction to Dijkstra's Algorithm* - Dijkstra's Algorithm is crucial for solving shortest path problems. - It starts from a source node and finds the shortest distances to all other nodes. 02:35 📖 *Implementation Methods* - Dijkstra's Algorithm can be implemented using Priority Queue, Set, or Queue data structures. - Priority Queue and Set are more efficient, with Set being the fastest. 03:56 🚀 *Importance of Watching All Videos* - Emphasizes the importance of watching all videos to grasp the concept thoroughly. - Mentions that problem-solving will follow once the concept is clear. 04:09 📊 *Representing the Graph* - Explains how to represent a graph using an adjacency list with pairs (node, weight). - Provides an example of storing adjacency information. 06:04 🌐 *Initial Configuration* - Describes the initial setup, including the minimum heap data structure and a distance array. - Initializes the source node with a distance of 0. 06:19 ⏩ *Iteration Process* - Explains the iteration process, similar to BFS, where nodes are processed in order of minimum distance. - Highlights the importance of discovering shorter distances during the iteration. 11:17 🧐 *Handling Adjacent Nodes* - Details how to handle adjacent nodes and update their distances. - Demonstrates the process of selecting the best path to each adjacent node. 18:03 ❌ *Limitation: Negative Weight Cycles* - Discusses the limitation of Dijkstra's Algorithm when dealing with negative weight edges or cycles. - Explains why negative weights can lead to an infinite loop. 21:02 ⏰ *Time Complexity* - Mentions the time complexity of Dijkstra's Algorithm as O(E log V), where E is the number of edges and V is the number of nodes. - Teases upcoming explanations about priority queues and set data structures. Made with HARPA AI
@alokamgnaneswarasai5158
@alokamgnaneswarasai5158 12 күн бұрын
Understood!
@TarunKumar-cn6in
@TarunKumar-cn6in Жыл бұрын
Understood 🙏
@UECAshutoshKumar
@UECAshutoshKumar 9 ай бұрын
Thank you sir 😊
@Bhoomika_Dev
@Bhoomika_Dev Жыл бұрын
Understood 😊
@deepanshuchawla6493
@deepanshuchawla6493 Жыл бұрын
Is there any difference if we use queue at place of priority_queue
@suryakiran2970
@suryakiran2970 Жыл бұрын
Understood❤
@The_Shubham_Soni
@The_Shubham_Soni 10 ай бұрын
UNDERSTOOD.
@Sara-ed3jq
@Sara-ed3jq 11 ай бұрын
Understoood
@devanshgoel3433
@devanshgoel3433 Жыл бұрын
thank u bro!
@p38_amankuldeep75
@p38_amankuldeep75 Жыл бұрын
understood💙💙💙
@ranjithr6046
@ranjithr6046 Жыл бұрын
can anyone say what is the need for this algorithm because we already found the shortest path in previous lectures of striver??????
@suhaasmohandos5869
@suhaasmohandos5869 2 ай бұрын
@takeUforward Do we need a visited array for Dijikstras algo? On what basis is it be decided if we need a visited array for any type of traversal including BFS/DFS?
@DINGFULU
@DINGFULU 10 күн бұрын
pretty good video
@SohelRana-tp8ww
@SohelRana-tp8ww 9 ай бұрын
Can't thank you enough.
@LBK3
@LBK3 Жыл бұрын
understood ❤
@suhaanbhandary4009
@suhaanbhandary4009 Жыл бұрын
understood!!
@maximelebreux2914
@maximelebreux2914 4 ай бұрын
Good teaching
@user-zn3be9ik1x
@user-zn3be9ik1x Жыл бұрын
I am so so happy finally i understood this algorithm thankyou ☺
@abhinandanvyas4087
@abhinandanvyas4087 Жыл бұрын
can you tell me whats the diffrence between this and video 29 is it the same?
@priyanshvatsal9791
@priyanshvatsal9791 Жыл бұрын
Understood 😊😇
@googleit2490
@googleit2490 Жыл бұрын
Understood !!
@pranavindore2410
@pranavindore2410 4 ай бұрын
understood😃
@b_01_aditidonode43
@b_01_aditidonode43 9 ай бұрын
understood sir :)
@dreamyme543
@dreamyme543 Жыл бұрын
Understood:)
@varunaggarwal7126
@varunaggarwal7126 Жыл бұрын
1 silly question, if you have observed striver has put distance first in priority_queue due to ease of sorting as the values are sorted based on first value, but I put distance second, and wrote a comparison function from there I observed that if i return bool operator()(pii a, pii b) { return a.second < b.second; } its giving me TLE, isn't the first value should be smaller that second when implementing min_heap, if i return opposite, its running fine, anyone has idea about it?
@chiragbirla5606
@chiragbirla5606 Жыл бұрын
put less than or equal to
@gouravkushwaha3001
@gouravkushwaha3001 8 ай бұрын
Is bellman ford applicable to negative weight graph?
@shubhamkshirsagar4511
@shubhamkshirsagar4511 Жыл бұрын
Understood!!!
@subhadeepghosh2813
@subhadeepghosh2813 Жыл бұрын
maza aa gya
@soni.himansh
@soni.himansh Жыл бұрын
Understood.
@deepakjain4481
@deepakjain4481 3 ай бұрын
well you are great simple as that
@gunjjoshi5687
@gunjjoshi5687 Жыл бұрын
Thank You
@kaushalshinde3920
@kaushalshinde3920 Жыл бұрын
understood
@user-zr3jr7pm1c
@user-zr3jr7pm1c 10 ай бұрын
Nice Video
@medhanshmathur8108
@medhanshmathur8108 2 ай бұрын
what is the need of taking heap ,cant we just go to neighbour node everytime using adjancency list and check for the distance condition whether it is greater or lower it would then automatically cover all the nodes?
@gametech7046
@gametech7046 Жыл бұрын
will there be videos on union find???? Pls reply...
@Raj-yr3vz
@Raj-yr3vz Жыл бұрын
is it applicable for directed graph?
@kushagramishra3026
@kushagramishra3026 Жыл бұрын
"Understood'👍
@adarshkumarrao3478
@adarshkumarrao3478 Жыл бұрын
UNDERSTOOD
@only_for_fun1234r
@only_for_fun1234r Жыл бұрын
In vid 28 you solved using bfs using queue is it related to dijkstra algo.???
G-33. Dijkstra's Algorithm - Using Set - Part 2
12:29
take U forward
Рет қаралды 126 М.
Despicable Me Fart Blaster
00:51
_vector_
Рет қаралды 25 МЛН
Sigma Kid Hair #funny #sigma #comedy
00:33
CRAZY GREAPA
Рет қаралды 33 МЛН
Became invisible for one day!  #funny #wednesday #memes
00:25
Watch Me
Рет қаралды 60 МЛН
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
ThePrimeTime
Рет қаралды 584 М.
How Dijkstra's Algorithm Works
8:31
Spanning Tree
Рет қаралды 1,3 МЛН
G-41. Bellman Ford Algorithm
27:43
take U forward
Рет қаралды 183 М.
Economist fact-checks Scott Galloway’s Anti-Boomer TED Talk
26:05
Money & Macro
Рет қаралды 3,3 М.
Dijkstra's Algorithm - Computerphile
10:43
Computerphile
Рет қаралды 1,3 МЛН
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 625 М.
2.6.3 Heap - Heap Sort - Heapify - Priority Queues
51:08
Abdul Bari
Рет қаралды 2 МЛН
Despicable Me Fart Blaster
00:51
_vector_
Рет қаралды 25 МЛН