kotlin-coding-challenges

Tree traversal

Nice to solve before

Stack

Instructions

Traverse tree using Depth-First traversal.

Pre Order Depth First traversal

Algorithm:

depth_first_traversal_pre_order.svg

Result: F B A D C E G I H

Test: traverse depth first pre order

In Order Depth First traversal

Algorithm:

Result: A B C D E F G H I

Test: traverse depth first in order

depth_first_traversal_in_order.svg

Post Order Depth First traversal

Algorithm:

Result: A C E D B H I G F

Test: traverse depth first pre order reversed

depth_first_traversal_post_order.svg

Pre Order Depth First traversal reversed

Algorithm:

Result: F G I H B D E C A

Test: traverse depth first pre order reversed

In Order Depth First traversal reversed

Algorithm:

Result: I H G F E D C B A

Test: traverse depth first in order reversed

Post Order Depth First traversal reversed

Algorithm:

Result: H I G E C D A B F

Test: traverse depth first pre order reversed