Тёмный

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

take U forward
Подписаться 632 тыс.
Просмотров 300 тыс.
0% 0

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
---------------------------------------------------------------------------------------------------------------------------

Опубликовано:

 

26 сен 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 278   
@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 Год назад
Why dont you use visited array?
@priyanshkumar_iitd
@priyanshkumar_iitd 2 месяца назад
understood
@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
@awesome_latest_virals6098
@awesome_latest_virals6098 Год назад
<a href="#" class="seekto" data-time="926">15:26</a> instead of assigning value using loop , we can just write vector dist ( V , INT_MAX);
@Cools74
@Cools74 3 месяца назад
Both are same time complexity:)
@priyanshkumar_iitd
@priyanshkumar_iitd 2 месяца назад
yes, for more compactness of code, we can write :)
@princenagar1686
@princenagar1686 21 день назад
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! 😀
@shivyanshgarg2641
@shivyanshgarg2641 6 месяцев назад
i like how i can write the code myself after being 5 - 6 mins in the video.
@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.
@therangeplus
@therangeplus 4 дня назад
thank you for explaining the stuff so well. Every other youtuber I have watched didnt help much but u explain the concept so well and you do the code,
@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
@venkat.sairam
@venkat.sairam 8 месяцев назад
🎯 Key Takeaways for quick navigation: <a href="#" class="seekto" data-time="2">00:02</a> 📚 *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. <a href="#" class="seekto" data-time="155">02:35</a> 📖 *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. <a href="#" class="seekto" data-time="236">03:56</a> 🚀 *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. <a href="#" class="seekto" data-time="249">04:09</a> 📊 *Representing the Graph* - Explains how to represent a graph using an adjacency list with pairs (node, weight). - Provides an example of storing adjacency information. <a href="#" class="seekto" data-time="364">06:04</a> 🌐 *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. <a href="#" class="seekto" data-time="379">06:19</a> ⏩ *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. <a href="#" class="seekto" data-time="677">11:17</a> 🧐 *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. <a href="#" class="seekto" data-time="1083">18:03</a> ❌ *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. <a href="#" class="seekto" data-time="1262">21:02</a> ⏰ *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
@sambhavagarwal5871
@sambhavagarwal5871 Год назад
understand Thanks a lot for your immense efforts Striver.
@Moch117
@Moch117 11 месяцев назад
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)
@dinushachathuranga7657
@dinushachathuranga7657 Год назад
excellent explanation. Lucky to find your channel.❤
@CodeMode9313
@CodeMode9313 Год назад
Habibi ye bhi kamal video banti ... bahut accha bahut accha
@TrendyGamer007
@TrendyGamer007 Год назад
loving this playlist 3000❣
@raghavmanish24
@raghavmanish24 3 месяца назад
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
@vakhariyajay2224
@vakhariyajay2224 Год назад
Thank you very much. You are a genius.
@rahulprasad3575
@rahulprasad3575 Год назад
bro this is the exact thing i was searching today
@cinime
@cinime Год назад
Understood! Super fantastic explanation as always, thank you very much!!
@unfamousgaayak4838
@unfamousgaayak4838 Месяц назад
U r doing a great job man . Salute to you ..
@1qwertyuiop1000
@1qwertyuiop1000 11 месяцев назад
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.. 👍
@jambajuice07
@jambajuice07 Год назад
half way done ! wont stop
@rishabhgupta9846
@rishabhgupta9846 Год назад
understood,great explanation
@hashcodez757
@hashcodez757 9 месяцев назад
Undestood BHAIYA!! thanks alot
@SonuKumar-ed2bo
@SonuKumar-ed2bo Год назад
<a href="#" class="seekto" data-time="1040">17:20</a> We need to put the node in queue for same distanse too. So we need to put a equality sign over there
@rishabhagarwal8049
@rishabhagarwal8049 Год назад
Understood Sir, Thank you very much
@giit85
@giit85 Год назад
Great continue this series
@A52VarshaSanga-pr7km
@A52VarshaSanga-pr7km Месяц назад
Thank you so much ..your videos give me hope that I can do better !!
@AYUSHKUMAR-xj4wc
@AYUSHKUMAR-xj4wc Год назад
Awesome 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.
@sanketmudholkar2889
@sanketmudholkar2889 Год назад
This series is far better than any of the netflix original ones
@ruchitjoshi6889
@ruchitjoshi6889 Год назад
Why the priority queue has been initialized with pair? we can simply take 2-d vector in the pq
@dhanashreegodase4445
@dhanashreegodase4445 10 месяцев назад
You are a Masterpeice!!
@harleenkaur7751
@harleenkaur7751 Год назад
Amazing explanation. Thanks Bhaiya
@harshnaruto3122
@harshnaruto3122 Год назад
You are hero for us
@supratimnayek2776
@supratimnayek2776 Год назад
Amazing explanation
@DevashishJose
@DevashishJose 5 месяцев назад
understood, thank you so much.
@sagarvk18
@sagarvk18 9 месяцев назад
Love and Respect!
@ananttyagi7372
@ananttyagi7372 Год назад
understood very well
@maniknr2293
@maniknr2293 Год назад
Loved it❤
@banothutharun2743
@banothutharun2743 17 дней назад
understood brother.❤
@amitp277
@amitp277 Год назад
great work 👏
@_hulk748
@_hulk748 Год назад
Thankyou sir understood🙇‍♂️🙏❤
@ashutoshpatel2048
@ashutoshpatel2048 11 дней назад
this stuff is really code . i solved qustn on leetcode based is topic all by myself in 40 min.
@mriduljain6809
@mriduljain6809 Год назад
Understood Bhaiya😍😍
@rahuljain224
@rahuljain224 6 месяцев назад
Superb explanation
@coder6109
@coder6109 3 месяца назад
IMP: when to apply -> when we have weighted undirected graph , TC -> ElogV as at max our heap has V elements
@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
@deepakgoyal1643
@deepakgoyal1643 Год назад
what is the need of taking priority queue as in pair , i think there is no need of pair , we can simply take int
@sharusharath1058
@sharusharath1058 Месяц назад
nice explaination
@gautamsaxena4647
@gautamsaxena4647 2 месяца назад
understood bhaiya
@deepalirathod4929
@deepalirathod4929 4 дня назад
You are legend !
@hrushi_borhade
@hrushi_borhade Год назад
understood striver!!!
@sallaklamhayyen9876
@sallaklamhayyen9876 2 месяца назад
thank you so much 🥰🥰🥰
@user-tk2vg5jt3l
@user-tk2vg5jt3l 2 месяца назад
Thank you bhaiya
@gauravrai2979
@gauravrai2979 Год назад
can someone explain the priority queue declaration part in java I don't understand the ((x,y) -> x.distance - y.distance ).
@sanyam9712
@sanyam9712 Год назад
understood. Please make playlist on bit masking and bit manipulation
@flip4661
@flip4661 Год назад
Amazing 👏
@suhaasmohandos5869
@suhaasmohandos5869 3 месяца назад
@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?
@haha44261
@haha44261 Месяц назад
striver bhai...dadhi thodi gahri(deep) katt gayi hai side se...😅...this video is greattt.
@maximelebreux2914
@maximelebreux2914 4 месяца назад
Good teaching
@UECAshutoshKumar
@UECAshutoshKumar 9 месяцев назад
Thank you sir 😊
@abhinavhadole6516
@abhinavhadole6516 Год назад
Jai Dijkstra's Algorithm 🙇🏼🙏🏻
@namamiNarayana
@namamiNarayana Год назад
Understood! :) Thank you for your invaluable efforts striver! _/\_ ^^
@user-kl3qv1sc8k
@user-kl3qv1sc8k 2 месяца назад
amazing🤩🤩
@deepakjain4481
@deepakjain4481 4 месяца назад
well you are great simple as that
@Shivanai_h
@Shivanai_h Год назад
Understood 👌👌
@user-zn3be9ik1x
@user-zn3be9ik1x Год назад
I am so so happy finally i understood this algorithm thankyou ☺
@alokamgnaneswarasai5158
@alokamgnaneswarasai5158 25 дней назад
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??????
@TarunKumar-cn6in
@TarunKumar-cn6in Год назад
Understood 🙏
@eshaanpandey7353
@eshaanpandey7353 Год назад
Understood 👍
@shashankrustagi3725
@shashankrustagi3725 Год назад
hi striver, what is shortest path faster algorithm? SPFA? is it similar to dijkstra?
@LBK3
@LBK3 Год назад
understood ❤
@The_Shubham_Soni
@The_Shubham_Soni 11 месяцев назад
UNDERSTOOD.
@suhaanbhandary4009
@suhaanbhandary4009 Год назад
understood!!
@p38_amankuldeep75
@p38_amankuldeep75 Год назад
understood💙💙💙
@gunjjoshi5687
@gunjjoshi5687 Год назад
Thank You
@Bhoomika_Dev
@Bhoomika_Dev Год назад
Understood 😊
@DINGFULU
@DINGFULU 23 дня назад
pretty good video
@devanshgoel3433
@devanshgoel3433 Год назад
thank u bro!
@deepanshuchawla6493
@deepanshuchawla6493 Год назад
Is there any difference if we use queue at place of priority_queue
@suryakiran2970
@suryakiran2970 Год назад
Understood❤
@SohelRana-tp8ww
@SohelRana-tp8ww 9 месяцев назад
Can't thank you enough.
@medhanshmathur8108
@medhanshmathur8108 3 месяца назад
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?
@abhinandanvyas4087
@abhinandanvyas4087 Год назад
can you tell me whats the diffrence between this and video 29 is it the same?
@gouravkushwaha3001
@gouravkushwaha3001 8 месяцев назад
Is bellman ford applicable to negative weight graph?
@user-un2fh9rz7p
@user-un2fh9rz7p 3 месяца назад
This Dijkstra's algorithm is similar to Shortest Path in Undirected Graph with Unit Weights(previous video), only difference is that we don't keep track of the distance in the queue, rather we take it from distance array.I wonder if this makes a difference in the algorithm
@googleit2490
@googleit2490 Год назад
Understood !!
@letstrycoding6389
@letstrycoding6389 Год назад
Can someone explain ..initialization of priority queue ...first line in the code...why use greater...??
@takeUforward
@takeUforward Год назад
PQ by default works as max heap, with that initialisation it works as min heap
@KS0607
@KS0607 Год назад
understood
@pranavindore2410
@pranavindore2410 4 месяца назад
understood😃
@soni.himansh
@soni.himansh Год назад
Understood.
@priyanshvatsal9791
@priyanshvatsal9791 Год назад
Understood 😊😇
@23cash86
@23cash86 Год назад
<a href="#" class="seekto" data-time="711">11:51</a> 10,5 will also be in min-heap of d,n
@b_01_aditidonode43
@b_01_aditidonode43 10 месяцев назад
understood sir :)
@Sara-ed3jq
@Sara-ed3jq Год назад
Understoood
@shubhamkshirsagar4511
@shubhamkshirsagar4511 Год назад
Understood!!!
Далее
G-33. Dijkstra's Algorithm - Using Set - Part 2
12:29
Просмотров 131 тыс.
God-Tier Developer Roadmap
16:42
Просмотров 7 млн
Schoolboy - Часть 2
00:12
Просмотров 7 млн
Мой инстаграм: v1.ann
00:13
Просмотров 105 тыс.
Пиратские котики
00:50
Просмотров 144 тыс.
How Dijkstra's Algorithm Works
8:31
Просмотров 1,3 млн
How Zig Improved C! (Updated)
12:28
Просмотров 3 тыс.
C++ vs Rust: which is faster?
21:15
Просмотров 386 тыс.
G-41. Bellman Ford Algorithm
27:43
Просмотров 190 тыс.
This Algorithm is 1,606,240% FASTER
13:31
Просмотров 784 тыс.
Why Do Bubbles Form In Glasses Of Water?
12:33
Просмотров 104 тыс.
Dijkstra's Algorithm - Computerphile
10:43
Просмотров 1,3 млн
8 patterns to solve 80% Leetcode problems
7:30
Просмотров 290 тыс.
Schoolboy - Часть 2
00:12
Просмотров 7 млн