Tree — Part2

1- Pre-Order Traversal

Pre-Order
Traversal: FBADCEGIH

2- Post-Order Traversal

Post-Order
Traversal: ACEDBHIGF

3- In-Order Traversal

In-Order
Traversal: ABCDEFGHI

Insertion

Case 1:

Case 2:

For Implementing :

  • Right child red, left child black: Call Rotate Left Method
    (left rotation: Orient a right-leaning red link to lean left)
  • Left child and left-left grandchild red: Call Rotate Right Method
    (right rotation: Orient a left-leaning red link to lean right)
  • Both children Red: call FlipColor Method
    (recolor to split a 4-node)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ahmad Berahman

Ahmad Berahman

I have a dream to have a spectacular garden