c++ - Red Black Tree ~ 1 Child Deletes -


is ever possible red parent node have 1 black child node? have been playing around red/black tree simulator online , can't manage case of happen.

the reason behind asking believe have unnecessary if in code...

if (temp_node->color == black && node->color == red) {     node->color = black;     global_violation = false; } 

thanks feedback!!

no, isn't possible.

remember, in red/black tree, paths root of tree off of tree must pass through same number of black nodes (that's 1 of red/black tree invariants).

if have red node x 1 black child y, cannot have red child (since breaks red/black invariant red nodes can't have red children).

this means path through x missing child pass through @ least 1 fewer black node path through x, y, , off tree there, breaking red/black tree invariants.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -