Find Critical and Pseudo Critical Edges in Minimum Spanning Tree - Leetcode 1489 - Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ต.ค. 2024

ความคิดเห็น • 21

  • @NeetCodeIO
    @NeetCodeIO  ปีที่แล้ว +4

    Forgot to mention, time complexity is O(E^2), where E is number of edges since we have nested loops iterating over the edges.
    The union find operations are practically O(1).

    • @dk4882
      @dk4882 ปีที่แล้ว +1

      Thank you so much sir for adding this problem in NeetCode All List 🙏
      Sir could you please also add last 5 daily problems solved on this channel to the NeetCode All List
      Rest of all problems are in the List .

  • @dk4882
    @dk4882 ปีที่แล้ว +4

    Sir please also add these problems in NeetCode All List

  • @laumatthew71
    @laumatthew71 ปีที่แล้ว

    This problem is a really tough one... Great explanation from you sir, thank you very much !

  • @nhienle5137
    @nhienle5137 ปีที่แล้ว +1

    You are awesome, this question broke my streak ...

  • @swanv951
    @swanv951 ปีที่แล้ว +2

    In the path compression for the iterative version of find() (of UnionFind), you set parent of each node to be its grand parent as you move up. The recursive version would have set this to the actual root (during unwinding), making it better, right?

  • @jaysabva3618
    @jaysabva3618 ปีที่แล้ว +3

    NeetCode === NeatCode 👍😀

  • @kirillzlobin7135
    @kirillzlobin7135 3 หลายเดือนก่อน

    If from our initial MST we remove anu edge and put another - it will anyways be worse than original one, because we already in the very beggining used all minimal weights. No? Could not understand it

  • @thekindspill
    @thekindspill ปีที่แล้ว +6

    I think the implementation is very complex just like the one in Leetcode official Solution.
    It could be simplified to a great extent. Below can help :
    class UnionFind {
    public:
    vector parent;
    UnionFind(int n){
    parent.resize(n);
    for(int i=0;i

    • @smitrajrana4016
      @smitrajrana4016 ปีที่แล้ว

      Hey! I did similar implementation as you except I used a[2]

  • @uptwist2260
    @uptwist2260 ปีที่แล้ว +1

    Thanks for the daily

  • @indrajitpal63
    @indrajitpal63 ปีที่แล้ว

    This is a great explanation. Thanks NeetCode ! 🌟

  • @MP-ny3ep
    @MP-ny3ep ปีที่แล้ว

    Great explanation as always. Thank you

  • @sanchitmishra1895
    @sanchitmishra1895 ปีที่แล้ว +1

    @NeetCodeIO can you tell if there is inplace solution for lastIdx 2161? maybe some variation of dutch flag algo?

  • @saagerbabung5652
    @saagerbabung5652 ปีที่แล้ว +1

    Time complexity ?

  • @gokulgokul8054
    @gokulgokul8054 ปีที่แล้ว

    Why we need to mention self in line 13. In that line he write self.find() in the class

    • @abhimanyuambastha2595
      @abhimanyuambastha2595 7 หลายเดือนก่อน

      that is how python classes are used. self says that your accessing the function inside the class. Much like "this" in java

  • @SanjayKumar-iu7rq
    @SanjayKumar-iu7rq ปีที่แล้ว +7

    Bro you should have taken a proper graph to explain,
    Using 3 nodes not able to identify what is happening in explanation

  • @princeanthony8525
    @princeanthony8525 10 หลายเดือนก่อน

    I still don’t understand what pseudo critical means. You rushed it a bit.

    • @DJSTEVE42
      @DJSTEVE42 10 หลายเดือนก่อน +1

      From what I understood a critical edge is one that is vital to obtain the most minimum cost spanning tree. If the edge that is going to be removed causes the cost of the spanning tree to increase then it is a critical edge. So considering the word Critical we can say that this edge is vital to achieve the most minimum cost spanning tree. Whereas when we talk about Pseudo Critical , pseudo means false i.e we are looking for false critical edges meaning we are looking for edges that aren't going cause the cost of the spanning tree to dip, meaning whether or not that edge is there isn't going to affect the cost of the spanning tree. We will always get the minimum cost of the spanning tree if pseudo edges are removed because they are the edges that do not affect the spanning tree from achieving the most minimum possible cost.

    • @dipsrips
      @dipsrips 4 หลายเดือนก่อน

      @@DJSTEVE42 very nice explanation I was about to most the explanation. In simple terms critical edge removal will result in weight increase larger than minimum spanning tree cost. Whereas removal of pseudo critical node will not cause the weight to increase or dip for mst.