when it comes to finding... «Грокаем структуры данных»

  • Аватар пользователя
    fru-n-quiz
    22 марта 2026
    when it comes to finding the predecessor of a node N in the whole tree, <…>:
    •If N has a left subtree, then yes, its predecessor is the maximum of that subtree.
    •If N does not have a left subtree and it’s a right child, then its parent is also its predecessor.
    •If N does not have a left subtree and it’s a left child, we have to climb up the tree until we find node M that is a right child—its parent is the predecessor of N.
    •If we reach the root before finding such a node, then it means that N is the minimum of the tree, and it has no predecessor.
    like1 понравилось
    4