1. Trang chủ
  2. » Cao đẳng - Đại học

Lecture Data structures and other objects using C++ - Chapter 10b: Binary search trees - Trường Đại học Công nghiệp Thực phẩm Tp. Hồ Chí Minh

10 5 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 521,04 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Arizona Arkansas Colorado A Binary Search Tree of States The data in the  dictionary will  be stored in a  binary tree,  with each node  containing an . item  and a  key[r]

Trang 1

One of the tree applications in  Chapter 10 is binary search trees

In Chapter 10, binary search trees  are used to implement bags and  sets

This presentation illustrates how  another data type called a 

dictionary is implemented with  binary search trees

Binary Search Trees

Trang 2

of items, similar to a bag

But unlike a bag, each item 

has a string attached to it, 

called the item's key

Trang 3

A dictionary is a collection 

of items, similar to a bag

But unlike a bag, each item 

has a string attached to it, 

called the item's key

Example:

  The  items   I am

  storing are records

  containing data

  about a state.

Trang 4

of items, similar to a bag

But unlike a bag, each item 

has a string attached to it, 

called the item's key

Example:

  The  key   for each

  record is the name

Trang 5

The insertion procedure for a 

dictionary has two 

parameters

void dictionary::insert( The key for the new item, The new item );

ton

Trang 6

item, you specify the key  

Item dictionary::retrieve( "Washington" );

Trang 7

Item dictionary::retrieve( "Washington" );

The Dictionary Data Type

When you want to retrieve an 

item, you specify the 

Trang 8

tree can be used as the 

internal storage mechanism 

for the dictionary

Trang 9

Arkansas

Colorado

A Binary Search Tree of States

The data in the 

dictionary will 

be stored in a 

binary tree, 

with each node 

containing an 

Oklahoma

Flo rida

Mass.

N H

Trang 10

Arizona

Arkansas

Washington

Oklahoma Colorado

Mass.

N H

Storage rules:

Every key to the left 

of a node is 

alphabetically before 

the key of the node

Ngày đăng: 01/04/2021, 19:24

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN