Skip to main content Accessibility help
×
Home
  • This chapter is unavailable for purchase
  • Print publication year: 2007
  • Online publication date: June 2012

Chapter 12 - Binary Trees and Binary Search Trees

Summary

Trees are a very common data structure in computer science. A tree is a nonlinear data structure that is used to store data in a hierarchical manner. We examine one primary tree structure in this chapter, the binary tree, along with one implementation of the binary tree, the binary search tree. Binary trees are often chosen over more fundamental structures, such as arrays and linked lists, because you can search a binary tree quickly (as opposed to a linked list) and you can quickly insert data and delete data from a binary tree (as opposed to an array).

THE DEFINITION OF A TREE

Before we examine the structure and behavior of the binary tree, we need to define what we mean by a tree. A tree is a set of nodes connected by edges. An example of a tree is a company's organization chart (see Figure 12.1).

The purpose of an organization chart is to communicate to the viewer the structure of the organization. In Figure 12.1, each box is a node and the lines connecting the boxes are the edges. The nodes, obviously, represent the entities (people) that make up an organization. The edges represent the relationship between the entities. For example, the Chief Information Officer (CIO), reports directly to the CEO, so there is an edge between these two nodes. The IT manager reports to the CIO so there is an edge connecting them.

Related content

Powered by UNSILO