Trees

Trees

A tree is a nonlinear data structure, compared to arrays, linked lists, stacks and queues which are linear data structures. A tree can be empty with no nodes or a tree is a structure consisting of one node called the root and zero or one or more subtrees.

Challenge 15

Challenge 16

Write the following method for the Binary Tree class

Find the maximum value stored in the tree. You can assume that the values stored in the Binary Tree will be numeric.

Challenge 17

Write a function called breadth first

Challenge 18

Write a function called fizz buzz tree

If the value is divisible by 3, replace the value with “Fizz”
If the value is divisible by 5, replace the value with “Buzz”
If the value is divisible by 3 and 5, replace the value with “FizzBuzz”
If the value is not divisible by 3 or 5, simply turn the number into a String.

Approach & Efficiency

Depth First

Big O in Trees

Binary Search Trees

A Binary Search Tree (BST) is a type of tree that does have some structure attached to it. In a BST, nodes are organized in a manner where all values that are smaller than the root are placed to the left, and all values that are larger than the root are placed to the right.

API

Whiteboard Process

Find maximum value
find maximum value

Tree breadth first Tree breadth first

Tree FizzBuzz Tree FizzBuzz