Academia.eduAcademia.edu

Binary Trees

Abstract

This article introduces the basic concepts of binary trees, and then works through a series of practice problems with solution code in C/C++ and Java. Binary trees have an elegant recursive pointer structure, so they are a good way to learn recursive pointer algorithms.

Key takeaways

  • /* Given a binary tree, return true if a node with the target data is found in the tree.
  • struct node* build123() { This problem demonstrates simple binary tree traversal.
  • For each node in a binary search tree, create a new duplicate node, and insert the duplicate as the left child of the original node.
  • Suppose you are building an N node binary search tree with the values 1..N. How many structurally different binary search trees are there that store those values?
  • To be a binary search tree, for every node, all of the nodes in its left tree must be <= the node, and all of the nodes in its right subtree must be > the node.