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

Поділитися
Вставка
  • Опубліковано 8 січ 2025

КОМЕНТАРІ • 322

  • @takeUforward
    @takeUforward  2 роки тому +113

    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

    • @TrndxAtomic
      @TrndxAtomic 2 роки тому

      @Abhay Bisht in C++ the default priority queue is max heap...the syntax used above is for creating min-heap.

    • @sukhjattana5887
      @sukhjattana5887 2 роки тому

      understood (Y) (Y)
      ....u forgot to pin this :p

    • @namratam1522
      @namratam1522 Рік тому

      Why dont you use visited array?

    • @imPriyansh77
      @imPriyansh77 7 місяців тому

      understood

    • @KiranKumar-sb3ti
      @KiranKumar-sb3ti 7 місяців тому

      understood

  • @awesome_latest_virals6098
    @awesome_latest_virals6098 Рік тому +87

    15:26 instead of assigning value using loop , we can just write vector dist ( V , INT_MAX);

    • @Cools74
      @Cools74 8 місяців тому +10

      Both are same time complexity:)

    • @imPriyansh77
      @imPriyansh77 7 місяців тому +8

      yes, for more compactness of code, we can write :)

    • @princenagar1686
      @princenagar1686 5 місяців тому +6

      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.

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

  • @ideepakpandey
    @ideepakpandey 2 роки тому +131

    Wow, 3 videos on Dijkstra. We will not find such detailed videos even in expensive premium courses.

    • @takeUforward
      @takeUforward  2 роки тому +138

      It will be more than 3, around 10. Including problems 🫡 Give me a day or two. All will be out.

    • @ideepakpandey
      @ideepakpandey 2 роки тому +21

      @@takeUforward great🔥🙌. You are literally god for those students like me who cannot afford premium courses.

    • @sharathkumar8338
      @sharathkumar8338 2 роки тому +17

      @@ideepakpandey even premium courses are not this worth. personal experience.

    • @codingvibesofficial
      @codingvibesofficial 2 роки тому +2

      @take u forward That's our striver bhaiya

  • @visase2036
    @visase2036 2 роки тому +80

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

  • @suheabkhan2546
    @suheabkhan2546 2 роки тому +13

    Learning Dijkshtra algo for the first time... And understand it in the one watch was like unbelievable.. #striver op

  • @CodeMode9313
    @CodeMode9313 Рік тому +4

    Habibi ye bhi kamal video banti ... bahut accha bahut accha

  • @nikhilraj9900
    @nikhilraj9900 2 роки тому +3

    I have already solved more than 15 problems on Dijextra but i can't resist myself to watch whole video.

  • @Moch117
    @Moch117 Рік тому +6

    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)

  • @shivyanshgarg2641
    @shivyanshgarg2641 11 місяців тому +21

    i like how i can write the code myself after being 5 - 6 mins in the video.

  • @abhinavhadole6516
    @abhinavhadole6516 2 роки тому +8

    Jai Dijkstra's Algorithm 🙇🏼🙏🏻

  • @priyanshugupta4875
    @priyanshugupta4875 2 місяці тому +7

    if someone is having difficulty in getting the intuition, watch abdul sari sir once then come here for implementation.

    • @Tbm4545
      @Tbm4545 4 години тому

      Abdul bari*

  • @ShahNawaz-cx3pi
    @ShahNawaz-cx3pi Місяць тому +1

    ** We can use simple priority_queue i.e. there is no need to have pair inside PQ , we can take distance from distance array itself.
    After all there are various ways to implement so , we can do both:
    my code is here
    vector dijkstra(vector &adj, int src) {
    int n = adj.size();
    vectordist(n,1e9);
    priority_queue pq;
    pq.push(src);
    dist[src]=0;
    while(!pq.empty()){
    int node = pq.top();
    pq.pop();
    for(auto it:adj[node]){
    int adjNode = it.first;
    int weight = it.second;
    if(dist[adjNode]>dist[node]+weight){
    dist[adjNode]=dist[node]+weight;
    pq.push(adjNode);
    }
    }
    }
    return dist;


    }

  • @harikareddy-o4f
    @harikareddy-o4f 10 місяців тому

    Striver bhaiya cant thank you enough...heard the concept and coded it on one go all credits to you🙏

  • @muskanagrawal7428
    @muskanagrawal7428 5 місяців тому +2

    16:30 sir, in vectoradj[ ] given in ques, inner vector should store int, not pair how does it work for it[0] or it[1] in code, as it should have been vector

  • @therangeplus
    @therangeplus 5 місяців тому

    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,

  • @sanketmudholkar2889
    @sanketmudholkar2889 2 роки тому +2

    This series is far better than any of the netflix original ones

  • @TrendyGamer007
    @TrendyGamer007 2 роки тому +4

    loving this playlist 3000❣

  • @johnj171
    @johnj171 6 місяців тому

    love you man I will watch every second!!! love you for the dedication and series you have contributed for the community

  • @amanasrani6405
    @amanasrani6405 6 місяців тому

    understood, we are so lucky to have u striver

  • @rahulprasad3575
    @rahulprasad3575 2 роки тому +1

    bro this is the exact thing i was searching today

  • @1qwertyuiop1000
    @1qwertyuiop1000 Рік тому +3

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

  • @harshps1317
    @harshps1317 Місяць тому +1

    Actually, you can make it as optimal as using a set; just change one, like after pq. pop(), check if dis > dist[node], and then continue (which means skip it). This skip checking {10,5} and save time .

  • @raghavmanish24
    @raghavmanish24 8 місяців тому

    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 2 роки тому +1

    17:20 We need to put the node in queue for same distanse too. So we need to put a equality sign over there

  • @chiragsawarn9548
    @chiragsawarn9548 Рік тому +4

    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.

  • @hashcodez757
    @hashcodez757 Рік тому

    Undestood BHAIYA!!
    thanks alot

  • @ashutoshpatel2048
    @ashutoshpatel2048 5 місяців тому

    this stuff is really code . i solved qustn on leetcode based is topic all by myself in 40 min.

  • @coder6109
    @coder6109 8 місяців тому +1

    IMP: when to apply -> when we have weighted undirected graph , TC -> ElogV as at max our heap has V elements

  • @SWEcodes
    @SWEcodes 2 роки тому +4

    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

  • @cinime
    @cinime 2 роки тому +1

    Understood! Super fantastic explanation as always, thank you very much!!

  • @sambhavagarwal5871
    @sambhavagarwal5871 2 роки тому

    understand Thanks a lot for your immense efforts Striver.

  • @dinushachathuranga7657
    @dinushachathuranga7657 Рік тому

    excellent explanation. Lucky to find your channel.❤

  • @unfamousgaayak4838
    @unfamousgaayak4838 6 місяців тому

    U r doing a great job man . Salute to you ..

  • @23cash86
    @23cash86 Рік тому

    11:51 10,5 will also be in min-heap of d,n

  • @apmotivationakashparmar722
    @apmotivationakashparmar722 Місяць тому

    Thank you so much Striver !❤

  • @haha44261
    @haha44261 6 місяців тому +1

    striver bhai...dadhi thodi gahri(deep) katt gayi hai side se...😅...this video is greattt.

  • @A52VarshaSanga-pr7km
    @A52VarshaSanga-pr7km 6 місяців тому

    Thank you so much ..your videos give me hope that I can do better !!

  • @jambajuice07
    @jambajuice07 Рік тому

    half way done !
    wont stop

  • @psionl0
    @psionl0 Рік тому

    Understood. In fact, I was able to solve leetCode 1514. Path with Maximum Probability without assistance after seeing this video.

    • @TheRandomPerson49
      @TheRandomPerson49 6 місяців тому

      Thanks bro for telling, I also tried and solution accepted. 👍🏻

  • @vakhariyajay2224
    @vakhariyajay2224 2 роки тому +1

    Thank you very much. You are a genius.

  • @dhanashreegodase4445
    @dhanashreegodase4445 Рік тому +1

    You are a Masterpeice!!

  • @Tbm4545
    @Tbm4545 Годину тому

    If u r coming from 28 video Shortest lath UG , u can easily get this only difference is we have used Prique insted of normal queue

  • @shaddyrogue9430
    @shaddyrogue9430 2 роки тому +12

    Understood.
    JAVA Code with Pair Class :
    class Pair{
    int distance;
    int node;
    Pair(int distance,int node){
    this.distance=distance;
    this.node=node;
    }
    }
    class Solution
    {
    //Function to find the shortest distance of all the vertices
    //from the source vertex S.
    static int[] dijkstra(int V, ArrayList adj, int S)
    {
    // Write your code here
    PriorityQueue pq=new PriorityQueue((x,y)->x.distance-y.distance);
    int dist[]=new int[V];
    for(int i=0;i

    • @Abhay-vk9uq
      @Abhay-vk9uq Рік тому

      Do you know what "(x,y)->x.distance-y.distance" in the line " PriorityQueue pq=new PriorityQueue((x,y)->x.distance-y.distance);" is doing???????

    • @pulkitchausali1354
      @pulkitchausali1354 Рік тому

      @@Abhay-vk9uq We are overriding the comparator for PriorityQueue so that it will always keep Pair with the shortest distance at the top
      you have to know the lambda function and how to write own comparator for our use

    • @Moch117
      @Moch117 Рік тому

      No need for pair in the priority queue. Just add the node itself. We can retrieve the distance from the distance array

  • @mriduljain6809
    @mriduljain6809 Рік тому

    Understood Bhaiya😍😍

  • @harshnaruto3122
    @harshnaruto3122 2 роки тому +1

    You are hero for us

  • @letstrycoding6389
    @letstrycoding6389 2 роки тому +2

    Can someone explain ..initialization of priority queue ...first line in the code...why use greater...??

    • @takeUforward
      @takeUforward  2 роки тому +7

      PQ by default works as max heap, with that initialisation it works as min heap

  • @SushmithaSathyanarayanan-u4l
    @SushmithaSathyanarayanan-u4l 8 місяців тому

    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

  • @rishabhagarwal8049
    @rishabhagarwal8049 2 роки тому

    Understood Sir, Thank you very much

  • @ruchitjoshi6889
    @ruchitjoshi6889 Рік тому

    Why the priority queue has been initialized with pair? we can simply take 2-d vector in the pq

  • @AYUSHKUMAR-xj4wc
    @AYUSHKUMAR-xj4wc Рік тому

    Awesome Explanation 👍👌

  • @GopiPusuluri-t4b
    @GopiPusuluri-t4b 6 місяців тому

    it is better to insert in distance array when we pop out from queue, because queue already stored minimum distance with node in front

  • @user-zn3be9ik1x
    @user-zn3be9ik1x Рік тому +1

    I am so so happy finally i understood this algorithm thankyou ☺

  • @princenagar1686
    @princenagar1686 5 місяців тому

    For those who don't understand that why he take 1e9 instead of INT_MAX is because when you add something in INT_MAX then it become negative. So in line 29 of this c++ code , this will give you incorrect results.

  • @PriyaJain-yd7ni
    @PriyaJain-yd7ni 8 місяців тому

    Dijkstra's works on negative weighs. It only has problem with negative weight cycles.

  • @scaffgaming
    @scaffgaming 8 місяців тому +1

    There is a video number 28 we do the same algorithm I don't know why time complexity is better here because in that video 28 we did the shortest path from SRC with unit weight but weight is not matter here we are just adding the weight so what's the difference between exactly this algorithm or number 28 video alogrithm we exactly doing the same think

  • @rahuljain224
    @rahuljain224 11 місяців тому

    Superb explanation

  • @Xp-Sam
    @Xp-Sam 11 місяців тому +2

    Please answer my question
    I have read at many places that, dijkstra cannot work for negative edge weights
    but I tested this algorithm for many negative edge directed graphs, and it is working fine
    Still I am not able to find any example of directed graph with negative edge weight where this will fail
    vector dijkstra(int V, vector adj[], int S)
    {
    vector distance(V, 1e9);
    distance[S] = 0;
    priority_queue pq;
    pq.push({0, S});
    while(!pq.empty()){
    auto p = pq.top();pq.pop();
    int node = p.second;
    int dist = p.first;
    for(auto &x : adj[node]){
    int newDist = dist + x[1];
    if(newDist < distance[x[0]]){
    pq.push({newDist, x[0]});
    distance[x[0]] = newDist;
    }
    }
    }
    return distance;
    }
    , so why its written everywhere that it wont work for negative edge weight graph
    Either the above is not the actual dijkstra code, or they are wrong

    • @mewerchewer7503
      @mewerchewer7503 7 місяців тому +1

      There are many variants of Dijkstra. This variant allows for re-entrance of a node which allows for possibilities of further relaxation which is what happens in the case of negative edge weights but has TC of exponential (Goes from being a greedy approach to almost search the entire edge space multiple times), which often leads to TLE in contests or some harder problems. Besides, if a problem allows for negative edge weights, then there could be a possibility of a negative cycle in one of the test cases, where Dijkstra will simply fail. That is why, nobody uses Dijkstra if the question mentions the negative edge weights (unless the constraints of the graph are extremely small) and thus, most codes have implementation allowing for processing of node at maximum of one time (then it would be marked as processed or visited)

    • @Learner_45
      @Learner_45 5 місяців тому

      @@mewerchewer7503 does that(the variant which fails for negative edges) use visited array or something like that?

  • @_hulk748
    @_hulk748 Рік тому

    Thankyou sir understood🙇‍♂️🙏❤

  • @suhaasmohandos5869
    @suhaasmohandos5869 8 місяців тому

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

  • @sanyam9712
    @sanyam9712 2 роки тому +1

    understood. Please make playlist on bit masking and bit manipulation

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

  • @giit85
    @giit85 2 роки тому

    Great continue this series

  • @AmanKumar-xw5bs
    @AmanKumar-xw5bs 7 місяців тому +2

    Good explanation BUT Dijkstras algo is somewhat similar to this but little different, In this video you are visiting already visited vertices again which is just unncessary(as there are no negative edge cycles). Instead you can just make a visited array and don't visited vertices those are marked visited. Thats how the actual Dijkstras algorithm works.

    • @divyachauhan363
      @divyachauhan363 2 місяці тому

      exactly

    • @tejasparse9053
      @tejasparse9053 2 місяці тому

      Exactly. The algo he coded is working for negative weights (not cycles) because we are visiting multiple times. Took me an hour to realize this is not the correct dijkstra.

  • @kaichang8186
    @kaichang8186 4 місяці тому

    understood, thanks for the great video

  • @anupamroy9533
    @anupamroy9533 Рік тому +1

    by dijkstra can directed graph with negative edge be solved .? in this video undirected graph is used. please anyone answer

  • @medhanshmathur8108
    @medhanshmathur8108 8 місяців тому

    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?

  • @rishabhgupta9846
    @rishabhgupta9846 2 роки тому

    understood,great explanation

  • @robertnant1264
    @robertnant1264 6 місяців тому

    So Dijkstra is basically doing level order traversal. But this time the level is represented by the distance to start node? Hence the use of a priority queue?

  • @ujjwalrawat2361
    @ujjwalrawat2361 2 роки тому +1

    I have seen some people are also using a processed array to track which nodes are processed why you are not doing so...?

    • @takeUforward
      @takeUforward  2 роки тому

      the logic still is the same, let me know if you find some better complexity, thanks.

  • @gauravrai2979
    @gauravrai2979 Рік тому +1

    can someone explain the priority queue declaration part in java I don't understand the ((x,y) -> x.distance - y.distance ).

  • @supratimnayek2776
    @supratimnayek2776 2 роки тому

    Amazing explanation

  • @TarunKumar-nc8dh
    @TarunKumar-nc8dh 4 місяці тому

    since we are not using visited array will this work on graph with -ve edge weights but no -ve cycle?

  • @shubhambhatt2704
    @shubhambhatt2704 Рік тому

    16:40 can anyone explain?
    Shouldn't it be edgeweight=it[0] and node=it[1] ?
    I'm a bit confused over here

    • @autobotin
      @autobotin Рік тому

      he explained by taking the elements as {dist, node}..but in the GFG question it is given as {node, dist}. That's why edgeweight = it[1] and node = it[0].

    • @dhanushdm5761
      @dhanushdm5761 Рік тому

      @@autobotin does that mean it[1] points for first element and it[0] points for second element in { dist (1st) , node(2nd) } pqueue

    • @autobotin
      @autobotin Рік тому

      @@dhanushdm5761 it[0] point to the first element i.e. node and it[1] points to the secong element i.e. distance.

    • @dhanushdm5761
      @dhanushdm5761 Рік тому

      @@autobotin ok ok according to gfg problem.. ->o for node and 1 for distance

  • @aryashjain7893
    @aryashjain7893 2 роки тому +2

    if i store the pq as ({node , wieght}) would there be any issue , it works fine on gfg , rest understood

    • @takeUforward
      @takeUforward  2 роки тому +4

      watch the third video of dijksta, you will know why it worked

    • @aryashjain7893
      @aryashjain7893 2 роки тому

      @@takeUforward han bhaiya dekhaa 😂 🤣 u r a truee mentor... 36th se jo questions hai usme aur clear ho gaya

  • @ranjithr6046
    @ranjithr6046 Рік тому +1

    can anyone say what is the need for this algorithm because we already found the shortest path in previous lectures of striver??????

  • @tusharvlogs6333
    @tusharvlogs6333 Рік тому

    i think we do not need the weights in the pair as they can be accessed from the dist[node] directly. we can just put the node is the pq whenever we get a dist[node] < previous value of dist[node] and its so obvious that the new node that has been inserted into the priority queue is because of the change in the distance will be due to that node only

    • @sravanik1368
      @sravanik1368 Рік тому

      I also got the same doubt and I implemented Dijktra's algo using Queue which stores only adjacent nodes. It worked fine. No need to use priority queue also.
      The reason behind using priority queue is that, we want to order the nodes based on distance.. but here not storing distance and whenever you encounter a particular node we are getting distance from distance array. So I feel an algorithm using Queue works. I am not getting why we need 3 algorithms?

    • @sravanik1368
      @sravanik1368 Рік тому +4

      And I think the reason behind storing the distances is that to avoid traversing the multiple paths. If you store the distance in the priority queue always we get the shortest distance first and then we traverse in that path. Otherwise we could have gone in the longest path and after that we have to update each and every node to get the shortest path. If you get the shortest path first we can avoid at most longest paths.

    • @Moch117
      @Moch117 Рік тому

      Yes I did the same and it worked out. I think hes doing it just for clarity. You just need to store nodes only; you can get distance in the distance array since it will always be updated before we add the node to the queue

  • @cursed_nerd
    @cursed_nerd Рік тому

    New beard looking good

  • @banothutharun2743
    @banothutharun2743 5 місяців тому

    understood brother.❤

  • @sagarvk18
    @sagarvk18 Рік тому

    Love and Respect!

  • @rookiedrummer6838
    @rookiedrummer6838 3 місяці тому

    Thanks the tutorial is awesome.
    Line number 18 should be pq.push({s,0}) ??

  • @afridihaque5700
    @afridihaque5700 2 роки тому

    Striver bhaiya OP

  • @amitp277
    @amitp277 Рік тому

    great work 👏

  • @Nikhil-Tomar
    @Nikhil-Tomar 4 місяці тому

    I think some explanations should be required in this video, First is in normal algorithm we had to keep marked nodes,

  • @KunalRajput-r2q5m
    @KunalRajput-r2q5m 3 місяці тому

    Why we are using PriorityQueue of , if we can find shortest path using PriorityQueue of only ??

    • @joshua_dlima
      @joshua_dlima 3 місяці тому

      distance is what helps us pick the next optimal node to be explored

  • @namamiNarayana
    @namamiNarayana Рік тому

    Understood! :)
    Thank you for your invaluable efforts striver! _/\_ ^^

  • @gouravkushwaha68
    @gouravkushwaha68 Рік тому

    Is bellman ford applicable to negative weight graph?

  • @UECAshutoshKumar
    @UECAshutoshKumar Рік тому +1

    Thank you sir 😊

  • @only_for_fun1234r
    @only_for_fun1234r Рік тому

    In vid 28 you solved using bfs using queue is it related to dijkstra algo.???

  • @maximelebreux2914
    @maximelebreux2914 9 місяців тому

    Good teaching

  • @maniknr2293
    @maniknr2293 2 роки тому

    Loved it❤

  • @karthik-varma-1579
    @karthik-varma-1579 Місяць тому

    done and dusted striver
    telugu people attendance (from vizag)

  • @deepalirathod4929
    @deepalirathod4929 5 місяців тому

    You are legend !

  • @varunaggarwal7126
    @varunaggarwal7126 Рік тому +1

    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?

  • @kushagramishra3026
    @kushagramishra3026 2 роки тому

    "Understood'👍

  • @DevashishJose
    @DevashishJose 10 місяців тому

    understood, thank you so much.

  • @sallaklamhayyen9876
    @sallaklamhayyen9876 7 місяців тому

    thank you so much 🥰🥰🥰

  • @harshdasila6680
    @harshdasila6680 2 роки тому +2

    Can you please tell how much videos are left for this series?

    • @takeUforward
      @takeUforward  2 роки тому

      You can check A2Z sheet, we will cover all of them in the graphs section

    • @harshdasila6680
      @harshdasila6680 2 роки тому

      @@takeUforward time? Tb tk pura upload ho jaayaga

    • @takeUforward
      @takeUforward  2 роки тому +4

      @@harshdasila6680 Trying bro asap, kyu ki office rehta hai na.

    • @harshdasila6680
      @harshdasila6680 2 роки тому

      @@takeUforward yes bro i understand ❤️

  • @hrushi_borhade
    @hrushi_borhade Рік тому

    understood striver!!!

  • @shashankrustagi3725
    @shashankrustagi3725 Рік тому

    hi striver, what is shortest path faster algorithm? SPFA? is it similar to dijkstra?