Chapter 3: Abstract Data Types Lists, Stacks Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.

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
Stacks using Linked Lists. Stack Data Structure As we already know, stacks are linear data structures. This means that their contexts are stored in what.
Linear Lists – Linked List Representation
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
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.
M180: Data Structures & Algorithms in Java
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
CHAPTER 7 Queues.
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
Data Structures: A Pseudocode Approach with C
CS Data Structures II Review COSC 2006 April 14, 2017
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Chapter 3 Stacks.
Data Structures & Algorithms
Stacks. What is a stack? Last-in first-out data structure (LIFO) New objects are placed on top Removal restricted to top object Examples?
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Chapter 3: Abstract Data Types Queues Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
CHAPTER 8 Lists. 2 A list is a linear collection Adding and removing elements in lists are not restricted by the collection structure We will examine.
Stacks.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
CHAPTER 6 Stacks Array Implementation. 2 Stacks A stack is a linear collection whose elements are added and removed from one end The last element to be.
CHAPTER 6 Stacks. 2 A stack is a linear collection whose elements are added and removed from one end The last element to be put on the stack is the first.
Summary of lectures (1 to 11)
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.
CHAPTER 3 : STACKS 3.1 Understand Stacks 3.2 Implement the operation of stack By : Suzila Yusof.
Chapter 7 Stacks II CS Data Structures I COSC 2006
Comp 245 Data Structures Stacks. What is a Stack? A LIFO (last in, first out) structure Access (storage or retrieval) may only take place at the TOP NO.
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
Chapter 4 Stacks Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving. Its called.
ISOM MIS 215 Module 3 – Stacks and Queues. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
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.
Information and Computer Sciences University of Hawaii, Manoa
COP3530 Data Structures600 Stack Stack is one the most useful ADTs. Like list, it is a collection of data items. Supports “LIFO” (Last In First Out) discipline.
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.
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’
Stacks And Queues Chapter 18.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
The List ADT A sequence of zero or more elements A 1, A 2, A 3, … A N-1 N: length of the list A 1 : first element A N-1 : last element A i : position i.
Introduction to Data Structures and Algorithms
CS 201 Data Structures and Algorithms Chapter 3: Lists, Stacks, and Queues - I Text: Read Weiss, §3.1 – 3.5 1Izmir University of Economics.
Linear Data Structures
Computer Engineering Rabie A. Ramadan Lecture 6.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Stack Data Structure By Marwa M. A. Elfattah. Stack - What A stack is one of the most important non- primitive linear data structure in computer science.
Lecture 21 Data Structures, Algorithms and Complexity Stacks and Queues GRIFFITH COLLEGE DUBLIN.
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Objectives Upon completion you will be able to: Explain the design, use, and operation of a linear.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Stacks and Queues Chapter 4.
CE 221 Data Structures and Algorithms
Stacks.
Stacks and Queues.
Queues Queues Queues.
Stack and Queue APURBO DATTA.
Queues 11/9/2018 6:28 PM Queues 11/9/2018 6:28 PM Queues.
Queues 11/16/2018 4:19 AM Queues 11/16/2018 4:19 AM Queues.
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
Queue and Priority Queue Implementations
Queues 12/3/2018 Queues © 2014 Goodrich, Tamassia, Goldwasser Queues.
Queues 12/30/2018 9:24 PM Queues 12/30/2018 9:24 PM Queues.
Figure 7.1 Some queue operations. Figure 7.1 Some queue operations.
Stacks, Queues, and Deques
CS210- Lecture 3 Jun 6, 2005 Announcements
Abstract Data Types Stacks CSCI 240
Stack Implementations
Presentation transcript:

Chapter 3: Abstract Data Types Lists, Stacks Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

2 An ADT a set of objects a set of operations Same set of objects, different sets of operations => different ADTs ADTs are implemented using classes, hiding implementation details: encapsulation

3 LIST ABSTRACTION Definition: A linear configuration of elements, called nodes.

4 Characteristics Insert and delete nodes in any order The nodes are connected Each node has two components Information (data) Link to the next node The nodes are accessed through the links between them

5 Head Predecessor of X Node X Success- or of X tail For each node the node that is in front of it is called predecessor. The node that is after it is called successor.

6 Terminology Head (front, first node): The node without predecessor, the node that starts the lists. Tail (end, last node): The node that has no successor, the last node in the list. Current node: The node being processed. From the current node we can access the next node. Empty list: No nodes exist

7 Basic operations To create/destroy a list To expand/shrink the list Read/Write operations Changing the current node (moving along the list) To report current position in the list To report status of the list

8 ADT List Notation L - list e - item of the same type as the information part of an element (a node) in the list b - boolean value

9 Operations in ADT Notation Insert(L,e) Inserts a node with information e before the current position Delete(L) Deletes the current node in L, the current position indicates the next node. RetrieveInfo(L)  e Returns the information in the current node.

10 Insertion and Deletion A. Insertion To insert a node X between the nodes A and B:.Create a link from X to B..Create a link from A to X,

11 Insertion X A B

12 Insertion and Deletion B. Deletion To delete a node X between A and B: Create a link from A to B, Remove node X

13 Deletion A X B

14 Node Linking 1.Single linked lists : Each node contains two links - to the previous and to the next node 2.Double linked lists : Each node contains a link only to the next node 3.Circular lists: The tail is linked to the head.

15 List Implementation Static – using an array Dynamic – using linear nodes

16 Array Implementation Two parallel arrays are used:  Index array - the number stored in the i-th element shows the index of the "next" node, i.e. node that follows the i-th node  Data array - used to store the informational part of the nodes.

17

18 STACKS Definition: The last stored element is the first to be accessed (LIFO: last in - first out)

19 Basic operations Push: store a data item at the top of the stack Pop: retrieve a data item from the top of the stack

20 ADT Definition of STACK Notation: Sstack eitem of same type as the elements of S bboolean value

21 Operations Init_Stack(S) Procedure to initialize S to an empty stack Destroy_Stack(S) Procedure to delete all elements in S

22 Operations Stack_Empty(S)  b Boolean function that returns TRUE if S is empty. Stack_Full(S)  b Boolean function that returns TRUE if S is full.

23 Operations Push(S,e) Procedure to place an item e into S (if there is room, i.e. S is not full) Pop(S)  e Procedure to take the last item stored in S (this item is called also - top element) if S is not empty

24 Example A procedure to replace the elements of a nonempty stack, assuming they are of type integers, with their sum Pre: A nonempty stack with elements of type integers. Post: S contains only one element – the sum of previously stored elements.

25 Algorithm 1.e1  Pop(S) 2.while stack is not empty repeat 2.1. e2  pop(S) 2.2. push(S, e1+e2) 2.3. e1  pop (S) 3.push(S,e1)