Chapter 8 Data Abstractions. © 2005 Pearson Addison-Wesley. All rights reserved 8-2 Chapter 8: Data Abstractions 8.1 Data Structure Fundamentals 8.2 Implementing.

Slides:



Advertisements
Similar presentations
COSC2007 Data Structures II Chapter 10 Trees I. 2 Topics Terminology.
Advertisements

Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Connecting with Computer Science, 2e
Data Structures: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Summary of lectures (1 to 11)
Chapter 12 Trees. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Define trees as data structures Define the terms.
Chapter 12 Collections. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Collections A collection is an object that helps us organize and manage.
Marc Smith and Jim Ten Eyck
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Important Problem Types and Fundamental Data Structures
Binary Trees Chapter 6.
COSC2007 Data Structures II
Data Structures Winter What is a Data Structure? A data structure is a method of organizing data. The study of data structures is particularly important.
Grade 12 Computer Studies HG
Chapter 8 Data Abstractions. 2 Chapter 8: Data Abstractions 8.1 Data Structure Fundamentals 8.2 Implementing Data Structures 8.3 A Short Case Study 8.4.
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Introduction to Data Structures. Definition Data structure is representation of the logical relationship existing between individual elements of data.
1 Data Abstractions Shyh-Kang Jeng Department of Electrical Engineering/ Graduate Institute of Communication Engineering National Taiwan University.
Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Connecting with Computer Science 2 Objectives Learn what a data structure is and how it is used Learn about single and multidimensional arrays and how.
Lists ADT (brief intro):  Abstract Data Type  A DESCRIPTION of a data type  The data type can be anything: lists, sets, trees, stacks, etc.  What.
Data Structures Week 5 Further Data Structures The story so far  We understand the notion of an abstract data type.  Saw some fundamental operations.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
Chapter 8: Data Abstractions Senem Kumova Metin. 8-2 Chapter 8: Data Abstractions 8.1 Basic Data Structures – Arrays – Lists, Stacks, Queues – Trees 8.2.
Connecting with Computer Science, 2e Chapter 8 Data Structures.
ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 10: Trees Data Abstraction & Problem Solving with C++
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
Chapter 9 (modified) Abstract Data Types and Algorithms Nell Dale John Lewis.
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
9-1 Abstract Data Types Abstract data type A data type whose properties (data and operations) are specified independently of any particular implementation.
P p Chapter 10 has several programming projects, including a project that uses heaps. p p This presentation shows you what a heap is, and demonstrates.
Overview of Course Java Review 1. This Course Covers, using Java Abstract data types Design, what you want them to do (OOD) Techniques, used in implementation.
Trees CS 105. L9: Trees Slide 2 Definition The Tree Data Structure stores objects (nodes) hierarchically nodes have parent-child relationships operations.
Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
12/8/2015CS Introduction to Information Engineering1 Data Structure 12/8/2015 Che-Rung Lee.
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
Chapter 16 – Data Structures and Recursion. Data Structures u Built-in –Array –struct u User developed –linked list –stack –queue –tree Lesson 16.1.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
Data Structure and Algorithms
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary Trees.
Chapter 11 Indexing And Hashing (1) Yonsei University 1 st Semester, 2016 Sanghyun Park.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
Class Review.
Data Structure Interview Question and Answers
Chapter 8: Data Abstractions
i206: Lecture 13: Recursion, continued Trees
Chapter 8: Data Abstractions
Introduction to Data Structures
Chapter 11 Indexing And Hashing (1)
Important Problem Types and Fundamental Data Structures
Chapter 8: Data Abstractions
Presentation transcript:

Chapter 8 Data Abstractions

© 2005 Pearson Addison-Wesley. All rights reserved 8-2 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

© 2005 Pearson Addison-Wesley. All rights reserved 8-3 Basic data structures Homogeneous array List –Stack –Queue Tree

© 2005 Pearson Addison-Wesley. All rights reserved 8-4 Terminology for lists List = collection of data whose entries are arranged sequentially Head = beginning Tail = end

© 2005 Pearson Addison-Wesley. All rights reserved 8-5 Terminology for stacks Stack = a list in which entries are removed and inserted only at the head LIFO = last-in-first-out Top = head of list Bottom or base = tail of list Pop = remove entry from the top Push = insert entry at the top

© 2005 Pearson Addison-Wesley. All rights reserved 8-6 Terminology for queues Queue = a list in which entries are removed at the head and are inserted at the tail FIFO = first-in-first-out

© 2005 Pearson Addison-Wesley. All rights reserved 8-7 Terminology for a tree Tree = a collection of data whose entries have a hierarchical organization Node = an entry in a tree Binary tree = tree in which every node has at most two children Depth = number of nodes in longest path from root to leaf

© 2005 Pearson Addison-Wesley. All rights reserved 8-8 Terminology for a tree (continued) Root node = the node at the top Terminal or leaf node = a node at the bottom Parent of a node = the node immediately above the specified node Child of a node = a node immediately below the specified node Ancestor = parent, parent of parent, etc. Descendent = child, child of child, etc. Siblings = nodes sharing a common parent

© 2005 Pearson Addison-Wesley. All rights reserved 8-9 Figure 8.1 An example of an organization chart

© 2005 Pearson Addison-Wesley. All rights reserved 8-10 Figure 8.2 Tree terminology

© 2005 Pearson Addison-Wesley. All rights reserved 8-11 Nature of data structures Static: size of data structure does not change Dynamic: size of data structure can change

© 2005 Pearson Addison-Wesley. All rights reserved 8-12 Storing homogeneous arrays Requires enough contiguous memory to hold all data Two dimensional arrays –Row-major order: each row is stored together Address polynomial: A[r,c] = (r-1)(# columns) + (c-1) –Column-major order: each column is stored together

© 2005 Pearson Addison-Wesley. All rights reserved 8-13 Storing lists Contiguous list = list stored in a homogeneous array Linked list = list in which each node points to the next one –Head pointer = pointer to first entry in list –NIL pointer = non-pointer value used to indicate end of list

© 2005 Pearson Addison-Wesley. All rights reserved 8-14 Figure 8.3 Novels arranged by title but linked according to authorship

© 2005 Pearson Addison-Wesley. All rights reserved 8-15 Figure 8.4 The array of temperature readings stored in memory starting at address x

© 2005 Pearson Addison-Wesley. All rights reserved 8-16 Figure 8.5 A two-dimensional array with four rows and five columns stored in row major order

© 2005 Pearson Addison-Wesley. All rights reserved 8-17 Figure 8.6 Names stored in memory as a contiguous list

© 2005 Pearson Addison-Wesley. All rights reserved 8-18 Figure 8.7 The structure of a linked list

© 2005 Pearson Addison-Wesley. All rights reserved 8-19 Figure 8.8 Deleting an entry from a linked list

© 2005 Pearson Addison-Wesley. All rights reserved 8-20 Figure 8.9 Inserting an entry into a linked list

© 2005 Pearson Addison-Wesley. All rights reserved 8-21 Storing stacks and queues Can use same mechanisms as for lists Circular queue = homogeneous array where the first array entry is treated as immediately following the last array entry –Prevents a queue from crawling out of its allotted storage space

© 2005 Pearson Addison-Wesley. All rights reserved 8-22 Figure 8.10 A stack in memory

© 2005 Pearson Addison-Wesley. All rights reserved 8-23 Figure 8.11 A queue implementation with head and tail pointers. Note how the queue crawls through memory as entries are inserted and removed.

© 2005 Pearson Addison-Wesley. All rights reserved 8-24 Storing a binary tree Linked structure –Each node = data cell + two child pointers –Accessed through a pointer to root node Mapped to a contiguous array –A[1] = root node –A[2],A[3] = children of A[1] –A[4],A[5],A[6],A[7] = children of A[2] and A[3] –…

© 2005 Pearson Addison-Wesley. All rights reserved 8-25 Figure 8.12 The structure of a node in a binary tree

© 2005 Pearson Addison-Wesley. All rights reserved 8-26 Figure 8.13 The conceptual and actual organization of a binary tree using a linked storage system

© 2005 Pearson Addison-Wesley. All rights reserved 8-27 Figure 8.14 A tree stored without pointers

© 2005 Pearson Addison-Wesley. All rights reserved 8-28 Figure 8.15 A sparse, unbalanced tree shown in its conceptual form and as it would be stored without pointers

© 2005 Pearson Addison-Wesley. All rights reserved 8-29 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.

© 2005 Pearson Addison-Wesley. All rights reserved 8-30 Figure 8.16 A procedure for printing a linked list

© 2005 Pearson Addison-Wesley. All rights reserved 8-31 Figure 8.17 The letters A through M arranged in an ordered tree

© 2005 Pearson Addison-Wesley. All rights reserved 8-32 Figure 8.18 The binary search as it would appear if the list were implemented as a linked binary tree

© 2005 Pearson Addison-Wesley. All rights reserved 8-33 Figure 8.19 The successively smaller trees considered by the procedure in Figure 8.18 when searching for the letter J

© 2005 Pearson Addison-Wesley. All rights reserved 8-34 Figure 8.20 Printing a search tree in alphabetical order

© 2005 Pearson Addison-Wesley. All rights reserved 8-35 Figure 8.21 A procedure for printing the data in a binary tree

© 2005 Pearson Addison-Wesley. All rights reserved 8-36 Figure 8.22 Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree

© 2005 Pearson Addison-Wesley. All rights reserved 8-37 Figure 8.23 A procedure for inserting a new entry in a list stored as a binary tree

© 2005 Pearson Addison-Wesley. All rights reserved 8-38 Figure 8.24 A stack of integers implemented in Java and C#

© 2005 Pearson Addison-Wesley. All rights reserved 8-39 Customized data types User-defined data type = template for a heterogeneous structure Abstract data type = user-defined data type with methods for access and manipulation Class = abstract data type with extra features –Characteristics can be inherited –Contents can be encapsulated –Constructor methods to initialize new objects

© 2005 Pearson Addison-Wesley. All rights reserved 8-40 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

© 2005 Pearson Addison-Wesley. All rights reserved 8-41 Figure 8.25 Our first attempt at expanding the machine language in Appendix C to take advantage of pointers

© 2005 Pearson Addison-Wesley. All rights reserved 8-42 Figure 8.26 Loading a register from a memory cell that is located by means of a pointer stored in a register