Lab 4 Notes

Next Prev Binary Tree

nextAncestor()

  • returns the first ancestor that is next with respect to an inorder traversal or null if there is none
    • hint: use parent to go up in the binary tree

[Example 1]

  • Consider node g in the following binary tree:
d, b, f, e, g, a, c
   ?     ?  ^  -

bt1.png

  • What about node c?

next()

  • returns the next node according to an inorder traversal

[Example 2]

  • Consider node b in the following binary tree:
d, b, f, e, a, c
   ^  -

bt2.png

  • What about e?
d, b, f, e, a, c
         ^  -

Date: 2023-09-22 Fri 00:00

Author: Tianyu Chen

Created: 2023-09-22 Fri 09:34