Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in.

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Stacks, Queues, and Linked Lists
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
A queue is a linear, homogeneous, container that stores and dispenses its content in a FIFO manner. FIFO - First In First Out The first (most distant)
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Queues1 Part-B2 Queues. Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions follow the first-in first-out scheme.
ADVANCED DATA STRUCTURES AND ALGORITHM ANALYSIS Chapter 3 Lists, Stacks, and Queues.
1 Stack and Queue. 2 Stack In Out ABCCB Data structure with Last-In First-Out (LIFO) behavior.
Stacks  a data structure which stores data in a Last-in First-out manner (LIFO)  has a pointer called TOP  can be implemented by either Array or Linked.
What is a Queue? n Logical (or ADT) level: A queue is an ordered group of homogeneous items (elements), in which new elements are added at one end (the.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
1 A full binary tree A full binary tree is a binary tree in which all the leaves are on the same level and every non leaf node has two children. SHAPE.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Data Structure Dr. Mohamed Khafagy.
CS Data Structures II Review COSC 2006 April 14, 2017
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Stacks. What is a stack? Last-in first-out data structure (LIFO) New objects are placed on top Removal restricted to top object Examples?
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
Stacks.
Queues.
1 Lecture 24 Abstract Data Types (ADT) –I Overview  What is an Abstract Data type?  What is Stack ADT?  Stack ADT Specifications  Array Implementation.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
1 Lecture 26 Abstract Data Types – IV Overview  The List ADT  Implementing Stacks as Linked List  Linked List Implementation of Queues .  Preview:
© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
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.
Lists CSE1303 Part A Data Structures and Algorithms.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
EXPANDING STACKS AND QUEUES CS16: Introduction to Data Structures & Algorithms 1 Tuesday, February 10, 2015.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
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.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues (slightly modified by Dan Fleck)
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
1 CSE 1342 Programming Concepts Lists. 2 Basic Terminology A list is a finite sequence of zero or more elements. –For example, (1,3,5,7) is a list of.
C++ STL CSCI 3110.
CPSC 252 Concrete Data Types Page 1 Overview of Concrete Data Types There are two kinds of data types: Simple (or atomic) – represents a single data item.
CMSC 202 Stacks and Queues. What’s a Queue? A queue is a linear collection of homogeneous data in which items added to the queue must be placed at the.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
A data structure is a type of data storage ….similar to an array. There are many data structures in Java (Stacks, Queues, LinkedList, Sets, Maps, HashTables,
Stacks And Queues Chapter 18.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
The Abstract Data Type Queue A queue New items enter at the back, or rear, of the queue Items leave from the front of the queue First-in, first-out (FIFO)
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.
UNIT II Queue. Syllabus Contents Concept of queue as ADT Implementation using linked and sequential organization. – linear – circular queue Concept –
1 Data Structures and Algorithms Stacks and Queues.
© 2011 Pearson Addison-Wesley. All rights reserved 8 B-1 Chapter 8 (continued) Queues.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Linear Data Structures
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
STACK Data Structure
Lecture 21 Data Structures, Algorithms and Complexity Stacks and Queues GRIFFITH COLLEGE DUBLIN.
Lecture 10 b Stacks b Queues. 2 Stacks b A stack ADT is linear b Items are added and removed from only one end of a stack b It is therefore LIFO: Last-In,
114 3/30/98 CSE 143 Collection ADTs [Chapter 4] /30/98 Collection ADTs  Many standard ADTs are for collections  Data structures that manage groups.
Queue ADT for lining up politely. COSC 2006 queue2 Queue – simple collection class  first-in first-out (FIFO) structure insert new elements at one end.
Chapter 15 Lists Objectives
Queue data structure.
Stacks and Queues.
Queues Queues Queues.
Stack and Queue APURBO DATTA.
Stack and Queue.
Introduction to Data Structure
CMSC 341 Lecture 5 Stacks, Queues
Queues.
CSC 143 Queues [Chapter 7].
Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.
Data Structures & Programming
Presentation transcript:

cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in ADT - Abstract Data Type

cosc237/data structures2 Data Types Simple data type, atomic data type –cannot be broken down –int, float, char structured data type –components can be atomic or structured –rules that define how the components relate to each other –Arrays, structs

cosc237/data structures3 C++ Array Domain:Each C++ array consists of 1. A collection of a fixed number of component values each of the same type 2. A set of index values that are nonnegative integers Structure: There is a one-to-one relationship between each index and an array element Operations: Retrieve the value of the array eleemnt asociated with index I Store a value into the array element associated with index i

cosc237/data structures4 Data Structures Linear (ordered) –Direct Access Homogeneous components – Array Heterogeneous components – Record –Sequential Access General – List Last-in, first-out – Stack First-in, first-out – Queue Nonlinear (unordered) - Set

cosc237/data structures5 Array Components –array elements Access individual elements by – index or subscript Direct access to a component through index Homogeneous components

cosc237/data structures6 Array as ADT Domain:Each array consists of 1. A collection of a fixed number of component values each of the same type 2. A set of index values that are nonnegative integers Structure: linear, direct access structure with one- to-one relationship between each index and an array element Operations: ValueAt(i) – retrieve value of array element associated with index i Store(i,v) - Store value v into the array element associated with index i

cosc237/data structures7 Record Components – fields Access individual elements by –field name or field identifier Direct access to a component via field name Heterogeneous components

cosc237/data structures8 Record as ADT Domain:Each record consists of 1. A collection of a fixed number of component values which may be of different types 2. A set of identifiers (field names) for selecting each component Structure: linear, direct access structure with one- to-one relationship between each field name and a field of the record Operations: ValueAt(fname) – retrieve value of field whose name is fname Store(i,v) - Store value v into the field whose name is fname

cosc237/data structures9 List Components –list items or list elements Access individual elements –Sequentially Head or front – first item in the list Tail, back, end – last item in the list Varying length sequential access to a component through implicit list cursor Homogeneous components

cosc237/data structures10 List as ADT Domain:Each list consists of 1. A collection of component values each of the same type 2. An implicit list cursor in the range 1 through n + 1, where n is the length of the list Structure: linear, sequential access structure of varying length

cosc237/data structures11 List cont'd Operations: Create(); // empty list created Boolean IsEmpty(); Boolean IsFull(); void Reset(); // cursor set to front of list Boolean EndOfList(); void Advance(); // advance cursor to next item ItemType CurrentItem(); //return item at list cursor void InsertBefore(); void InsertAfter(); void Delete();// delete item at list cursor

cosc237/data structures12 Lists vs Arrays Advantages of lists –easier to perform insertions & deletions Disadvantage of lists –No direct access

cosc237/data structures13 Stacks Restricted list where insertions or deletions occur at one end LIFO – Last-In, First-Out Top – end where insertions or deletion take place Push, Pop, Top Run-time stack

cosc237/data structures14 Stack as ADT Domain:Each stack is a collection of component values each of the same type Structure: list maintained in LIFO order so only most recently inserted item is accessible

cosc237/data structures15 Stack cont'd Operations: Create(); // empty stack created Boolean IsEmpty(); Boolean IsFull(); void Push(/* in */ ItemType newItem); // newItem is at top of stack ItemType Top(); //return item at top of stack void Pop(); // Top item removed from stack

cosc237/data structures16 Queues Restricted list –Insertions occur at the tail of the list - tail –deletions occur at the head - front FIFO – First-In, First-Out Enqueue – appends item to rear of queue Dequeue – removes item from front of queue Front – inspects first item Top – end where insertions or deletion take place Buffered input, printer queue

cosc237/data structures17 Queue as ADT Domain:Each queue is a collection of component values each of the same type Structure: list maintained in FIFO order so insertions take place at the rear and deletions take place at the front

cosc237/data structures18 Queue cont'd Operations: Create(); // empty queue created Boolean IsEmpty(); Boolean IsFull(); void Enqueue(/* in */ ItemType newItem); // newItem is at rear of queue ItemType Front(); //return item at front of queue void Dequeue(); // front item removed from queue