Trees 11 Coding Rotations

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 16

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

    Absolutely magnificent! Very well taught. Thank you so much!

  • @daleprather3026
    @daleprather3026 3 роки тому

    Great content! You make this stuff much easier to understand.

  • @hemantparashar8781
    @hemantparashar8781 6 років тому +23

    There is a problem. In the code, parents of the nodes that are re-arranged or rotated are not updated.

  • @Play-Date-Care
    @Play-Date-Care 4 роки тому +1

    Many many thanks! You are an awesome professor!

  • @ricardoavilalegra6739
    @ricardoavilalegra6739 7 років тому +2

    Great videos, thank you very much.

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

    As ppl pointed out, node.parent is still point to node, not the tmp
    we need to make node.parent to point tmp
    but without parent pointer in Node class, it's hard (need to find node.parent starting from root)
    let's say we use parent pointer too in the Node class, then the leftRotate method can be like this, hopefully
    public Node leftRotate(Node node)
    Node tmp = node.right;
    if tmp == null // 어쩌다 오른쪽 자식이 없는데 회전을 시도하게되는 경우를 다뤄줍니다
    ---return node;
    node.right = tmp.left;
    if node.right != null // tmp에게서 null이 아닌 노드를 물려받음, 그 노드의 부모를 변경해줘야 함
    ---node.right.parent = node;
    tmp.left = node;
    tmp.parent = node.parent; // tmp의 부모를 node의 부모로 변경합니다. null이어도 괜찮습니다
    if node.parent != null // node.parent가 null이면 tmp가 root가 되므로 스킵해야합니다
    ---if node.parent.left == node // node가 부모의 왼쪽 자식인지 확인, 주소 비교로 가능
    ------node.parent.left = tmp; // node.parent가 기존의 node 대신 tmp를 가리킴
    ---else
    ------node.parent.right = tmp;
    else // node.parent 가 null 이므로 root 입니다, root를 업데이트 해줍니다
    ---root = tmp;
    node.parent = tmp; // 이제 node.parent를 tmp로 업데이트 해줘도 순서상 문제가 없습니다
    return tmp;
    comment i wrote is in korean, sorry too lazy to translate
    hopefully this is correct and helpful to others watching this amazing course

  • @皮凯鱼说的对
    @皮凯鱼说的对 7 років тому +1

    Amazing, super helpful

  • @kentkou1872
    @kentkou1872 4 роки тому

    Thank you very much.

  • @princeyadav8034
    @princeyadav8034 3 роки тому

    Great vedio

  • @huannguyentrong1249
    @huannguyentrong1249 4 роки тому

    ty

  • @aronpop1447
    @aronpop1447 5 років тому

    Set grandparents left child to temp right child..inst it set grandparent to temp right child..? I mean grandparebts left child is already having a right child which is null

  • @trerentr
    @trerentr 7 років тому

    What if grant parent is not root and we dont have parent pointer, how do we point grand parent's parent to the new head?( in this case temp )

    • @trerentr
      @trerentr 7 років тому

      just for left rotation and right rotation

    • @v3n4c0ding5
      @v3n4c0ding5 6 років тому

      I think if temp.parent is None (py) then root = return variable.

    • @_paralaks_
      @_paralaks_ 4 роки тому +1

      grandParent.parent == null means root so no problem. grandParent.parent != null means we can do: grandParent.parent.left or grandparent.parent.right = rotate(grandParent)

  • @mute0001
    @mute0001 6 років тому

    Perfect +