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.

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.
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.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
COMP 110 Introduction to Programming Mr. Joshua Stough.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
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.
Chapter 18 - basic definitions - binary trees - tree traversals Intro. to Trees 1CSCI 3333 Data Structures.
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.
COSC2007 Data Structures II
Review C++ exception handling mechanism Try-throw-catch block How does it work What is exception specification? What if a exception is not caught?
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.
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.
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.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
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.
1 Chapter 17 Object-Oriented Data Structures. 2 Objectives F To describe what a data structure is (§17.1). F To explain the limitations of arrays (§17.1).
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.
Trees CS 105. L9: Trees Slide 2 Definition The Tree Data Structure stores objects (nodes) hierarchically nodes have parent-child relationships operations.
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.
CMSC 202, Version 5/02 1 Trees. CMSC 202, Version 5/02 2 Tree Basics 1.A tree is a set of nodes. 2.A tree may be empty (i.e., contain no nodes). 3.If.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Data Structure and Algorithms
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
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.
Chapter 8: Data Abstractions
Tree data structure.
i206: Lecture 13: Recursion, continued Trees
Trees and Binary Trees.
Tree data structure.
Chapter 8: Data Abstractions
Trees.
Important Problem Types and Fundamental Data Structures
Chapter 8: Data Abstractions
Presentation transcript:

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 Related Concepts – Static versus dynamic structures – Pointers 8.3 Implementing Data Structures

8-3 Data Structures A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently Basic Data Structures – Homogeneous array – Heterogeneous array – List Linked list Stack Queue – Tree

8-4 Basic Data Structures : Arrays Homogeneous array: The block of data items whose entries are of the same type – int array1[6]; // includes 6 integers – float * array2 =new float [6]; // includes 6 floating-point numbers Heterogeneous array: The block of data items that might be of different types. (The items within block are usually called components) – class Employee { public : int ID; string name;}; Employee array[8];

Basic Data Structures : Lists List : A collection whose entries are arranged sequentially. – The beginning of the list is head. – The other end of the list is tail. 8-5 datanextdatanextdatanext NULL head class Linked_list { int data; Linked_list*next; }; Linked_list * head; tail

Basic Data Structures : Stacks Stack : A list in which entries are inserted or removed only from head. – The head of the stack is called top of the stack – Bottom or base: The tail of list (stack) – Inserting a new entry is called pushing. – Deleting an entry is called popping – Last in first out (LIFO) : The last entry placed on a stack will always be the first entry to be removed 8-6 top

Basic Data Structures : Queue Queue : A list in which entries are inserted only at the tail and removed only from head. – First in first out (FIFO) : The first entry placed on a queue will always be the first entry to be removed 8-7

8-8 Figure 8.1 Lists, stacks, and queues

8-9 Figure 8.2 An example of an organization chart

8-10 Basic Data Structures : 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 Root Leaf nodes

8-11 Basic Data Structures : Tree (cont.) – Parent: The node immediately above a specified node ( 3 is the parent of 1 and 6 ) – Child: A node immediately below a specified node ( 14 is a child of 10) – Ancestor: Parent, parent of parent, etc. (10 is ancestor of 14 and 13) – Descendent: Child, child of child, etc. (13 is a decendent of 14,10 and 7) – Siblings: Nodes sharing a common parent (4 and 7 are siblings)

8-12 Basic Data Structures : Tree (cont.) Binary tree: A tree in which every node has at most two children Depth (The depth of tree): The number of nodes in longest path from root to leaf Subtree:The node (except root node) with the nodes below it A subtree

Basic Data Structures : Tree (cont.) The size of a binary tree is the number of nodes in it –This tree has size 9 The depth of a node is its distance from the root –a is at depth zero –e is at depth 2 The depth of a binary tree is the depth of its deepest node –This tree has depth 3 a b c de f g hı

8-14 Figure 8.3 Tree terminology

8-15 Related Concepts Static Data Structures: Size and shape of data structure does not change (compile time) Dynamic Data Structures: Size and shape of data structure can change (run time) Pointers: Used to locate data

8-16 Storing Arrays Homogeneous arrays – Row-major order versus 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

8-17 Figure 8.5 The array of temperature readings stored in memory starting at address x (Homogenous Array)

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

19 Storage mapping function : ROW MAJOR ORDER the mapping b/w pointer values and array indices EXAMPLE: int d [3]; d[i]  *(&d[0]+i)  *(d+i) EXAMPLE: int a [3] [4]; a[i][j]  *(&a[0][0]+4*i+j)  *(a+4*i+j) // address polynomial If indexing starts from 1 then  x+ c*(i-1)+(j-1)

8-20 Figure 8.7 Storing the heterogeneous array Employee

8-21 Storing Lists Contiguous list: List stored in a homogeneous array (Example: int a [10]) 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

8-22 Figure 8.8 Names stored in memory as a contiguous list

8-23 Figure 8.9 The structure of a linked list

8-24 Figure 8.10 Deleting an entry from a linked list

8-25 Figure 8.11 Inserting an entry into a linked list

8-26 Figure 8.19 A procedure for printing a linked list

8-27 Exercise : Question 8 (pg.428) Linked list The table represents a position in memory. Each entry in the list consists of two cells: The first contains a letter of alphabet; the second contains a pointer to the next list entry. Alter the pointers so that the letter N is no longer in the list then replace the letter N with the letter G and alter the pointers so that the new letter appears int he list in its proper place in alphabetical order

8-28 Storing Stacks and Queues Stacks usually stored as contiguous lists (arrays) but also may be implemented using linked 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

8-29 Figure 8.12 A stack in memory

Exercise :STACKS x= pop(&n); push(11,&n); x= pop(&n); push(3,&n); push(2,&n); x= pop(&n);} main() { stack n; int x; reset(&n); push(4,&n); push(5,&n); push(3,&n); push(2,&n); push(1,&n);

8-31 Figure 8.13 A queue implementation with head and tail pointers // insert from tail //remove from head enqueue(A) enqueue(B) enqueue(C) X= dequeue() enqueue(D) Y= dequeue() enqueue(E)

8-32 Figure 8.14 A circular queue containing the letters P through V

8-33 Storing Binary Trees Linked structure – Each node = data cells + two child pointers – Accessed via a pointer to root node struct node { int data; struct node * left; struct node * right;}; Contiguous array structure (without pointers) – 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]

8-34 Figure 8.15 The structure of a node in a binary tree

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

8-36 Figure 8.17 A tree stored without pointers

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

8-38 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. A queue typically needs at least enqueue and dequeue procedures. – The data structure along with these procedures constitutes a complete abstract tool.