35
Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Embed Size (px)

Citation preview

Page 1: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Chapter 8Data Abstractions

Introduction to CS

1st Semester, 2015 Sanghyun Park

Page 2: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Outline Data Structure Basics Arrays Lists Stacks Queues Trees

Page 3: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Data Structure Basics The topic of data structures explores ways in which users

can be ________ from the details of actual data storage(__________)

The shape or size of data structures may or may not change over time (dynamic vs. static structures);____ structures are easier to manage than dynamic ones

A ______ is a memory cell that contains the address of another memory cell; the value in the pointer tells us where to find the data

Page 4: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Single Dimensional Arrays

If the first reading is at address x,the ith reading is located at address ________

Page 5: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Two Dimensional Arrays

Row major order vs. column major order If we let c represent the number of columns in an array,

then the address of the entry in the ith row and jth column will be ________________

x

Page 6: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Contiguous Lists List is a collection of entries that appear in a _____ order Lists appear in both static and dynamic forms Let us consider techniques for storing a list of names

in a machine’s main memory The simplest structure is a ___________ list

Page 7: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Linked Lists A contiguous list suffers disadvantages

when implementing ________ lists The problem encountered can be simplified

if we use _______ lists

Page 8: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Deleting an Entry From Linked List

Page 9: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Inserting an Entry Into Linked List

Page 10: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Supporting The Conceptual List To support the ________ to the list structure,

the programmer should write a collection of __________ for performing such activities as inserting a new entry and searching for an entry

The users do not concern whether the list structure is implemented as a contiguous structure or a linked one;the users only call the procedure like PrintList(CSI2106)

Page 11: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Stacks A _____ is a list in which all insertions and deletions are

performed at the _____ end of the structure

The last entry entered will always be the first entry removed – last-in, first-out (______) structure

The end of a stack at which entries are inserted and deleted are called the ____ of the stack

The process of inserting an entry on the stack is called a ____ operation, and the process of deleting an entry is called a ____ operation

Page 12: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Backtracking A classic application of a stack occurs when a program

unit requests the execution of a ________ As each procedure is called, a ______ to the return

location is pushed on a stack; as each procedure is completed, the top entry from the stack is extracted

Page 13: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Printing a Linked Listin Reverse Order (1/3)

Page 14: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Printing a Linked Listin Reverse Order (2/3)

Page 15: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Printing a Linked Listin Reverse Order (3/3)

Page 16: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Stack Implementation

Push operation needs a test if stack is ____ Pop operation needs a test if stack is _____

Page 17: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Queues A _____ is a list in which all insertions are performed at

____ end while all deletions are made at the ____ end

The concept of a queue is inherent in any system in which objects are served in the same order in whichthey arrive - first-in, first-out (_____) structure

The end at which entries are removed is called the ____

The end at which new entries are added is called the ___

Page 18: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Queue Implementation

Page 19: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Queue “Crawling” Through Memory

Page 20: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Circular Queue

Page 21: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

An Example of an Organization Chart

Page 22: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Representation of a Tree

Page 23: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Tree Terminology

Page 24: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Binary Trees Binary trees are trees in which each node has at most

___ children

Such trees normally are stored in memory using a ______ structure similar to that of linked lists

Page 25: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Examples of Binary Trees

Page 26: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

A Binary Tree Usinga Linked Storage System

Page 27: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

A Binary Tree Stored Without Pointers

Page 28: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

A Sparse Binary TreeStored Without Pointers

Page 29: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Binary Search Using Binary Trees

Page 30: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Binary Search Example

Page 31: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Depth-First Traversal

Page 32: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Preorder Traversal

Page 33: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Inorder Traversal

Page 34: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Postorder Traversal

Page 35: Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park

Breadth-First Traversal