Chapter 8: Data Abstractions

Slides:



Advertisements
Similar presentations
Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence.
Advertisements

Binary Trees CSC 220. Your Observations (so far data structures) Array –Unordered Add, delete, search –Ordered Linked List –??
Connecting with Computer Science, 2e
Data Structures: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
Data Structures Data Structures Topic #8. Today’s Agenda Continue Discussing Table Abstractions But, this time, let’s talk about them in terms of new.
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.
Chapter 12 Trees. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Define trees as data structures Define the terms.
CHAPTER 12 Trees. 2 Tree Definition A tree is a non-linear structure, consisting of nodes and links Links: The links are represented by ordered pairs.
Marc Smith and Jim Ten Eyck
Binary Trees Chapter 6.
Trees & Graphs Nell Dale & John Lewis (adaptation by Michael Goldwasser and Erin Chambers)
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Chapter 9 Abstract Data Types and Algorithms. 2 Abstract Data Types Abstract data type A data type whose properties (data and operations) are specified.
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.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
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.
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.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 5 Prepared by İnanç TAHRALI.
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.
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.
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 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.
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 © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
1 Trees What is a Tree? Tree terminology Why trees? What is a general tree? Implementing trees Binary trees Binary tree implementation Application of Binary.
Search: Binary Search Trees Dr. Yingwu Zhu. Review: Linear Search Collection of data items to be searched is organized in a list x 1, x 2, … x n – Assume.
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.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
ADT description Implementations
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
Class Review.
Data Structure Interview Question and Answers
12 C Data Structures.
Stacks and Queues.
Chapter 8: Data Abstractions
i206: Lecture 13: Recursion, continued Trees
Chapter 20: Binary Trees.
Chapter 21: Binary Trees.
Trees and Binary Trees.
Further Data Structures
Trees CMSC 202, Version 5/02.
Trees.
Pointers & Dynamic Data Structures
Tree.
CS210- Lecture 9 June 20, 2005 Announcements
Chapter 20: Binary Trees.
Important Problem Types and Fundamental Data Structures
(1 - 2) Introduction to C Data Structures & Abstract Data Types
Data Structures Using C++ 2E
Chapter 8: Data Abstractions
Presentation transcript:

Chapter 8: Data Abstractions

Chapter 8: Data Abstractions 8.1 Basic Data Structures 8.2 Related Concepts 8.3 Implementing Data Structures 8.4 A Short Case Study 8.5 Customized Data Types 8.6 Classes and Objects 8.7 Pointers in Machine Language

Basic Data Structures Arrays Aggregates List Stack Queue Tree

Figure 8.1 Lists, stacks, and queues

Terminology for Arrays Array: A block of data whose entries are of same type A two dimensional array consists for rows and columns Indices are used to identify positions

Terminology for Aggregates Aggregate: A block of data items that might be of different type or sizes Each data item is called a field Fields are usually accessed by name

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

Terminology for Stacks Stack: A list in which entries are removed and inserted only at the 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

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

Figure 8.2 An example of an organization chart

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

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

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

Figure 8.3 Tree terminology

Related Concepts Abstraction Static vs. Dynamic Structure Pointer Shield users (application software) from details of actual data storage Static vs. Dynamic Structure Does the shape and size change over time? Pointer A storage area that encodes an address where data is stored Later used to access the data

Figure 8.4 Novels arranged by title but linked according to authorship

Storing Arrays Memory address of a particular cell can be computed Row-major order versus column major order Address polynomial

Figure 8.5 The array of temperature readings stored in memory starting at address x

Figure 8.6 A two-dimensional array with four rows and five columns stored in row major order

Storing Aggregates Fields can be stored one after the other in a contiguous block: Memory cell address of each field can be computed Fields can be stored in separate locations identified by pointers

Figure 8.7 Storing the aggregate type Employee

Storing Lists Contiguous list: List in which entries are stored in an array Linked list: List in which entries are linked by pointers Head pointer: Pointer to first entry in list null: A “non-pointer” value used to indicate end of list

Figure 8.8 Names stored in memory as a contiguous list

Figure 8.9 The structure of a linked list

Figure 8.10 Deleting an entry from a linked list

Figure 8.11 Inserting an entry into a linked list

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

Figure 8.12 A stack in memory

Figure 8.13 A queue implementation with head and tail pointers

Figure 8.14 A circular queue containing the letters P through V

Storing Binary Trees Linked structure Contiguous array 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] = children of A[1] A[4],A[5],A[6],A[7] = children of A[2] and A[3]

Figure 8.15 The structure of a node in a binary tree

Figure 8.16 The conceptual and actual organization of a binary tree using a linked storage system

Figure 8.17 A tree stored without pointers

Figure 8.18 A sparse, unbalanced tree shown in its conceptual form and as it would be stored without pointers

Manipulating Data Structures Ideally, a data structure should be manipulated solely by pre-defined functions Example: A list typically has a function insert for inserting new entries The data structure along with these functions constitutes a complete abstract tool

Figure 8.19 A function for printing a linked list def PrintList (List): CurrentPointer = List.Head while (CurrentPointer is not None): print(CurrentPointer.Value) CurrentPointer = CurrentPointer.Next

Case Study Problem: Construct an abstract tool consisting of a list of names in alphabetical order along with the operations: search, print, and insert.

Figure 8.20 The letters A through M arranged in an ordered tree

Figure 8.21 The binary search as it would appear if the list were implemented as a linked binary tree def Search (Tree, TargetValue): if (Tree is None): return None # Search failed elif (TargetValue == Tree.Value): return Tree # Search succeeded elif (TargetValue < Tree.Value): # Continue search in left subtree return Search(Tree.Left, TargetValue) elif (TargetValue > Tree.Value): # Continue search in right subtree return Search(Tree.Right, TargetValue)

Figure 8.22 The successively smaller trees considered by the function in Figure 8.21 when searching for the letter J

Figure 8.23 Printing a search tree in alphabetical order

Figure 8.24 A function for printing the data in a binary tree def PrintTree (Tree): if (Tree is not None): PrintTree(Tree.Left) print(Tree.Value) PrintTree(Tree.Right)

Figure 8.25 Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree

Figure 8.26 A function for inserting a new entry in a list stored as a binary tree def Insert(Tree, NewValue): if (Tree is None): # Create a new leaf with NewValue Tree = TreeNode() Tree.Value = NewValue elif (NewValue < Tree.Value): # Insert NewValue into the left subtree Tree.Left = Insert(Tree.Left, NewValue) elif (NewValue > Tree.Value): # Insert NewValue into the right subtree Tree.Right = Insert(Tree.Right, NewValue) else: # Make no change return Tree

User-defined Data Type Use an aggregate structure to define new type, in C: struct EmployeeType { char Name[25]; int Age; real SkillRating; } Use the new type to define variables: struct EmployeeType DistManager, SalesRep1;

Abstract Data Type A user-defined data type that can include both data (representation) and functions (behavior) Example: interface StackType { public int pop(); public int push(int item); public boolean isEmpty(); public boolean isFull(); }

Class An abstract data type with extra features Properties can be inherited Constructor methods to initialize new objects Contents can be encapsulated

Figure 8.27 A stack of integers implemented in Java and C# class StackOfIntegers implements StackType { private int[] StackEntries = new int[20]; private int StackPointer = 0;  public void push(int NewEntry) { if (StackPointer < 20) StackEntries[StackPointer++] = NewEntry; }  public int pop() { if (StackPointer > 0) return StackEntries[--StackPointer]; else return 0; } public boolean isEmpty() { return (StackPointer == 0); public boolean isFull() { return (StackPointer >= MAX);  

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

Figure 8.28 Our first attempt at expanding the machine language in Appendix C to take advantage of pointers

Figure 8.29 Loading a register from a memory cell that is located by means of a pointer stored in a register

End of Chapter