• No results found

Objectives. Upon completion you will be able to:

N/A
N/A
Protected

Academic year: 2021

Share "Objectives. Upon completion you will be able to:"

Copied!
80
0
0

Loading.... (view fulltext now)

Full text

(1)

Ch

t

7

Ch

t

7

Chapter 7

Chapter 7

Bi

S

h T

Bi

S

h T

Binary Search Trees

Binary Search Trees

Objectives

Upon completion you will be able to:

• Create and implement binary search trees

• Create and implement binary search trees

• Understand the operation of the binary search tree ADT

• Write application programs using the binary search tree ADT

pp

p

g

g

y

• Design and implement a list using a BST

• Design and implement threaded trees

(2)

7-1 Basic Concepts

p

Binary search trees provide an excellent structure for searching

Binary search trees provide an excellent structure for searching

a list and at the same time for inserting and deleting data into the

a list and at the same time for inserting and deleting data into the

list

list

list.

list.

(3)
(4)
(5)
(6)

7-2 BST Operations

p

We discuss four basic BST operations: traversal, search, insert,

We discuss four basic BST operations: traversal, search, insert,

and delete; and develop algorithms for searches, insertion, and

and delete; and develop algorithms for searches, insertion, and

deletion

deletion

deletion.

deletion.

T

l

• Traversals

• Searches

I

ti

• Insertion

• Deletion

(7)
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15)
(16)
(17)
(18)

(continued)

(19)
(20)

7-3 Binary Search Tree ADT

y

We begin this section with a discussion of the BST data structure

We begin this section with a discussion of the BST data structure

and write the header file for the ADT. We then develop 14

and write the header file for the ADT. We then develop 14

programs that we include in the ADT

programs that we include in the ADT

programs that we include in the ADT.

programs that we include in the ADT.

D t St

t

• Data Structure

• Algorithms

(21)
(22)
(23)
(24)
(25)
(26)
(27)
(28)
(29)
(30)
(31)
(32)
(33)
(34)
(35)
(36)
(37)
(38)
(39)
(40)
(41)
(42)
(43)
(44)
(45)
(46)
(47)
(48)

7-4 BST Applications

pp

This section develops two applications that use the BST ADT. We

This section develops two applications that use the BST ADT. We

begin the discussion of BST Applications with a simple

begin the discussion of BST Applications with a simple

application that manipulates integers The second application

application that manipulates integers The second application

application that manipulates integers. The second application,

application that manipulates integers. The second application,

student list, requires a structure to hold the student's data.

student list, requires a structure to hold the student's data.

• Integer Application

• Student List Application

• Student List Application

(49)
(50)
(51)
(52)
(53)
(54)
(55)
(56)
(57)
(58)
(59)
(60)
(61)
(62)
(63)
(64)
(65)
(66)
(67)
(68)
(69)
(70)
(71)

7-5 Threaded Trees

This section develops two applications that use the BST ADT. We

This section develops two applications that use the BST ADT. We

begin the discussion of BST Applications with a simple

begin the discussion of BST Applications with a simple

application that manipulates integers The second application

application that manipulates integers The second application

application that manipulates integers. The second application,

application that manipulates integers. The second application,

student list, requires a structure to hold the student's data.

student list, requires a structure to hold the student's data.

(72)
(73)
(74)
(75)
(76)
(77)
(78)
(79)
(80)

References

Related documents

 We are HALVING the search space …O(log n) time.. If the value we are searching for is in the root, return true... 3) If not, if the value is less than that stored in the root

(Convince yourself that a left subtree with a balance factor equal to 0 at its root cannot occur in this case.) The necessary rebalancing operations

• All BST nodes can be accessed through root reference by recursively accessing left or right child nodes... Operations

Trees Trees.. Binary trees that represent algebraic expressions.. A binary search tree of names.. Binary trees with the same nodes but different heights.. Level-by-level numbering of

• In order to insert a new node in a binary tree, we have to be at a node with a vacant left or right child. • This is performed in the same way

• For each node, all simple paths from the node to descendant leaves contain the same number of black nodes. Example of a

• In order to insert a new node in a binary tree, we have to be at a node with a vacant left or right child. • This is performed in the same way

This paper concerns partially persistent trees, with the added operation of rollback, which can promote an arbitrary earlier version of the tree to live ver- sion, allowing it to