Chapter 8: Data Abstractions

Similar documents
Chapter 8: Data Abstractions

Data Abstractions. National Chiao Tung University Chun-Jen Tsai 05/23/2012

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Queues. ADT description Implementations. October 03, 2017 Cinda Heeren / Geoffrey Tien 1

Data Structure. IBPS SO (IT- Officer) Exam 2017

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

CS301 - Data Structures Glossary By

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

Stacks, Queues and Hierarchical Collections

3. Fundamental Data Structures

Data Structures Question Bank Multiple Choice

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

Algorithms and Data Structures

Binary Trees

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

References and Homework ABSTRACT DATA TYPES; LISTS & TREES. Abstract Data Type (ADT) 9/24/14. ADT example: Set (bunch of different values)

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

CMSC Introduction to Algorithms Spring 2012 Lecture 7

CSE 530A. B+ Trees. Washington University Fall 2013

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

[ DATA STRUCTURES] to Data Structures

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

Programming II (CS300)

Data Structures and Algorithms

Programming and Data Structure Solved. MCQs- Part 2

Trees. (Trees) Data Structures and Programming Spring / 28

The questions will be short answer, similar to the problems you have done on the homework

Second-generation: Assembly language. Figure 6.1 Generations of programming languages. Assembly Language Characteristics.

CSCE 110 PROGRAMMING FUNDAMENTALS. Prof. Amr Goneid AUC

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8)

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this

Properties of red-black trees

LECTURE 11 TREE TRAVERSALS

Chapter 6: Programming Languages

CSE 12 Week Eight, Lecture One

Lecture 32. No computer use today. Reminders: Homework 11 is due today. Project 6 is due next Friday. Questions?

Chapter 20: Binary Trees

Trees. CSE 373 Data Structures

BBM 201 Data structures

Why Do We Need Trees?

Binary Trees, Binary Search Trees

Course Review for Finals. Cpt S 223 Fall 2008

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

[ DATA STRUCTURES ] Fig. (1) : A Tree

TREES cs2420 Introduction to Algorithms and Data Structures Spring 2015

DATA STRUCTURES AND ALGORITHMS

Topic 14. The BinaryTree ADT

Course Review. Cpt S 223 Fall 2009

CSCI212 Computer Science. Binary Trees/Heaps/Binary Search Trees

Basic Data Structures (Version 7) Name:

Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

Unit 10: Data Structures CS 101, Fall 2018

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

TREES Lecture 10 CS2110 Spring2014

DATA STRUCTURE AND ALGORITHM USING PYTHON

EE 368. Weeks 5 (Notes)

Recursive Data Structures and Grammars

Department of Computer Science and Technology

12 Abstract Data Types

ITEC2620 Introduction to Data Structures

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

13.4 Deletion in red-black trees

Fundamentals of Data Structure

MAHARAJA KRISHNAKUMARSINHJI BHAVNAGAR UNIVERSITY NAAC Accreditation Grade B (With effect from Academic Year: )

CS61BL. Lecture 3: Asymptotic Analysis Trees & Tree Traversals Stacks and Queues Binary Search Trees (and other trees)

Garbage Collection: recycling unused memory

CMSC 341 Priority Queues & Heaps. Based on slides from previous iterations of this course

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

and 6.855J February 6, Data Structures

CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial

4.1 COMPUTATIONAL THINKING AND PROBLEM-SOLVING

Trees. Introduction & Terminology. February 05, 2018 Cinda Heeren / Geoffrey Tien 1

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

The tree data structure. Trees COL 106. Amit Kumar Shweta Agrawal. Acknowledgement :Many slides are courtesy Douglas Harder, UWaterloo

Data and File Structures Laboratory

Chapter 9 Abstract Data Types and Algorithms

( ) n 3. n 2 ( ) D. Ο

CS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux

Building Java Programs

Trees. Truong Tuan Anh CSE-HCMUT

Binary Trees Due Sunday March 16, 2014

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

Data Structure. Recitation III

CSCI-1200 Data Structures Fall 2018 Lecture 23 Priority Queues II

DATA STRUCTURES AND ALGORITHMS. Hierarchical data structures: AVL tree, Bayer tree, Heap

tree nonlinear Examples

15.082J/6.855J/ESD.78J September 14, Data Structures

Thus, it is reasonable to compare binary search trees and binary heaps as is shown in Table 1.

CSI33 Data Structures

Data Structures, Algorithms & Data Science Platforms

Fundamental Algorithms

A set of nodes (or vertices) with a single starting point

CMSC 341 Lecture 14: Priority Queues, Heaps

Transcription:

Chapter 8: Data Abstractions Computer Science: An Overview Eleventh Edition by J. Glenn Brookshear Copyright 2012 Pearson Education, Inc. Chapter 8: Data Abstractions 8.1 Data Structure Fundamentals 8.2 Implementing Data Structures 8.3 A Short Case Study 8.4 Customized Data Types 8.5 Classes and Objects 8.6 Pointers in Machine Language Copyright 2012 Pearson Education, Inc. 0-2 1

Basic Data Structures Homogeneous array Heterogeneous array List Stack Queue Tree Copyright 2012 Pearson Education, Inc. 0-3 Figure 8.1 Lists, stacks, and queues Copyright 2012 Pearson Education, Inc. 0-4 2

Terminology for Lists List: A collection of data whose entries are arranged sequentially Head: The beginning of the list Tail: The end of the list Copyright 2012 Pearson Education, Inc. 0-5 Terminology for Stacks Stack: A list in which entries are removed and dinserted only at tthe head LIFO: Last-in-first-out Top: The head of list (stack) Bottom or base: The tail of list (stack) Pop: To remove the entry at the top Push: To insert an entry at the top Copyright 2012 Pearson Education, Inc. 0-6 3

Terminology for Queues Queue: A list in which entries are removed at tthe head and are inserted at tthe tail FIFO: First-in-first-out Copyright 2012 Pearson Education, Inc. 0-7 Figure 8.2 An example of an organization chart Copyright 2012 Pearson Education, Inc. 0-8 4

Terminology for a Tree Tree: A collection of data whose entries have a hierarchical organization Node: An entry in a tree Root node: The node at the top Terminal or leaf node: A node at the bottom Copyright 2012 Pearson Education, Inc. 0-9 Terminology for a Tree (continued) Parent: The node immediately above a specified node Child: A node immediately below a specified node Ancestor: Parent, parent of parent, etc. Descendent: Child, child of child, etc. Siblings: Nodes sharing a common parent Copyright 2012 Pearson Education, Inc. 0-10 5

Terminology for a Tree (continued) Binary tree: A tree in which every node has at most two children Depth: The number of nodes in longest path from root to leaf Copyright 2012 Pearson Education, Inc. 0-11 Figure 8.3 Tree terminology Copyright 2012 Pearson Education, Inc. 0-12 6

Additional Concepts Static Data Structures: Size and shape of data structure t does not change Dynamic Data Structures: Size and shape of data structure can change Pointers: Used to locate data Copyright 2012 Pearson Education, Inc. 0-13 Figure 8.4 Novels arranged by title but linked according to authorship Copyright 2012 Pearson Education, Inc. 0-14 7

Storing Arrays Homogeneous arrays Row-major order versus s column major order Address polynomial Heterogeneous arrays Components can be stored one after the other in a contiguous block Components can be stored in separate locations identified by pointers Copyright 2012 Pearson Education, Inc. 0-15 Figure 8.5 The array of temperature readings stored in memory starting at address x Copyright 2012 Pearson Education, Inc. 0-16 8

Figure 8.6 A two-dimensional array with four rows and five columns stored in row major order Copyright 2012 Pearson Education, Inc. 0-17 Figure 8.7 Storing the heterogeneous array Employee Copyright 2012 Pearson Education, Inc. 0-18 9

Storing Lists Contiguous list: List stored in a homogeneous array Linked list: List in which each entries are linked by pointers Head pointer: Pointer to first entry in list NIL pointer: A non-pointer value used to indicate end of list Copyright 2012 Pearson Education, Inc. 0-19 Figure 8.8 Names stored in memory as a contiguous list Copyright 2012 Pearson Education, Inc. 0-20 10

Figure 8.9 The structure of a linked list Copyright 2012 Pearson Education, Inc. 0-21 Figure 8.10 Deleting an entry from a linked list Copyright 2012 Pearson Education, Inc. 0-22 11

Figure 8.11 Inserting an entry into a linked list Copyright 2012 Pearson Education, Inc. 0-23 Storing Stacks and Queues Stacks usually stored as contiguous lists Queues usually stored as Circular Queues Stored in a contiguous block in which the first entry is considered to follow the last entry Prevents a queue from crawling out of its allotted storage space Copyright 2012 Pearson Education, Inc. 0-24 12

Figure 8.12 A stack in memory Copyright 2012 Pearson Education, Inc. 0-25 Figure 8.13 A queue implementation with head and tail pointers Copyright 2012 Pearson Education, Inc. 0-26 13

Storing Binary Trees Linked structure Each node = data cells + two child pointers Accessed via a pointer to root node Contiguous array structure A[1] = root node A[2],A[3] A[3] = children of A[1] A[4],A[5],A[6],A[7] = children of A[2] and A[3] Copyright 2012 Pearson Education, Inc. 0-27 Figure 8.14 A circular queue containing the letters P through V Copyright 2012 Pearson Education, Inc. 0-28 14

Figure 8.15 The structure of a node in a binary tree Copyright 2012 Pearson Education, Inc. 0-29 Figure 8.16 The conceptual and actual organization of a binary tree using a linked storage system Copyright 2012 Pearson Education, Inc. 0-30 15

Figure 8.17 A tree stored without pointers Copyright 2012 Pearson Education, Inc. 0-31 Figure 8.18 A sparse, unbalanced tree shown in its conceptual form and as it would be stored without pointers Copyright 2012 Pearson Education, Inc. 0-32 16

Manipulating Data Structures Ideally, a data structure should be manipulated solely by pre-defined procedures. Example: A stack typically needs at least push and pop procedures. The data structure along with these procedures constitutes a complete abstract tool. Copyright 2012 Pearson Education, Inc. 0-33 Figure 8.19 A procedure for printing a linked list Copyright 2012 Pearson Education, Inc. 0-34 17

Case Study Problem: Construct an abstract tool consisting of a list of names in alphabetical l order along with the operations search, print, and insert. Copyright 2012 Pearson Education, Inc. 0-35 Figure 8.20 The letters A through M arranged in an ordered tree Copyright 2012 Pearson Education, Inc. 0-36 18

Figure 8.21 The binary search as it would appear if the list were implemented as a linked binary tree Copyright 2012 Pearson Education, Inc. 0-37 Figure 8.22 The successively smaller trees considered by the procedure in Figure 8.18 when searching for the letter J Copyright 2012 Pearson Education, Inc. 0-38 19

Figure 8.23 Printing a search tree in alphabetical order Copyright 2012 Pearson Education, Inc. 0-39 Figure 8.24 A procedure for printing the data in a binary tree Copyright 2012 Pearson Education, Inc. 0-40 20

Figure 8.25 Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree Copyright 2012 Pearson Education, Inc. 0-41 Figure 8.26 A procedure for inserting a new entry in a list stored as a binary tree Copyright 2012 Pearson Education, Inc. 0-42 21

User-defined Data Type A template for a heterogeneous structure Example: define type EmployeeType to be {char Name[25]; int Age; real SkillRating; } Copyright 2012 Pearson Education, Inc. 0-43 Abstract Data Type A user-defined data type with procedures for access and manipulation Example: define type StackType to be {int StackEntries[20]; int StackPointer = 0; procedure push(value) {StackEntries[StackPointer] value; StackPointer StackPointer + 1; } procedure pop... } Copyright 2012 Pearson Education, Inc. 0-44 22

Class An abstract data type with extra features Characteristics can be inherited Contents can be encapsulated Constructor methods to initialize new objects Copyright 2012 Pearson Education, Inc. 0-45 Figure 8.27 A stack of integers implemented in Java and C# Copyright 2012 Pearson Education, Inc. 0-46 23

Pointers in Machine Language Immediate addressing: Instruction contains the data to be accessed Direct addressing: Instruction contains the address of the data to be accessed Indirect addressing: Instruction contains the location of the address of the data to be accessed Copyright 2012 Pearson Education, Inc. 0-47 Figure 8.28 Our first attempt at expanding the machine language in Appendix C to take advantage of pointers Copyright 2012 Pearson Education, Inc. 0-48 24

Figure 8.29 Loading a register from a memory cell that is located by means of a pointer stored in a register Copyright 2012 Pearson Education, Inc. 0-49 25