Linear Data Structures

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Data Structure HKOI training /4/2010 So Pak Yeung.
Stack & Queues COP 3502.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
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.
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.
 A queue is a waiting line…….  It’s in daily life:-  A line of persons waiting to check out at a supermarket.  A line of persons waiting.
Elementary Data Structures CS 110: Data Structures and Algorithms First Semester,
Data Structure Dr. Mohamed Khafagy.
 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
Queue RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
CS Data Structures II Review COSC 2006 April 14, 2017
Chapter 3: Abstract Data Types Lists, Stacks Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
COMP 110 Introduction to Programming Mr. Joshua Stough.
Chapter 7 Queues. © 2005 Pearson Addison-Wesley. All rights reserved7-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
Summary of lectures (1 to 11)
Stacks, Queues, and Deques
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.
Stacks, Queues, and Deques. 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.
Stacks, Queues, and Deques
© 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 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)
© 2006 Pearson Education Chapter 12: Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
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.
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R1. Elementary Data Structures.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues.
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.
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
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’
1 Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
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,
1 Data Structures - Part II CS215 Lecture #8. Stacks  Last-In-First-Out (LIFO)  Stacks are often used in programming when data will need to be used.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
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.
Implementation of QUEUE For more notes and topics visit: eITnotes.com.
1. Circular Linked List In a circular linked list, the last node contains a pointer to the first node of the list. In a circular linked list,
1 Algorithms Queues, Stacks and Records stored in Linked Lists or Arrays.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
CSCI 62 Data Structures Dr. Joshua Stough October 7, 2008.
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.
CH 5 : STACKS, QUEUES, AND DEQUES ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
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,
CS6045: Advanced Algorithms Data Structures. Dynamic Sets Next few lectures will focus on data structures rather than straight algorithms In particular,
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
STACKS & QUEUES for CLASS XII ( C++).
Review Array Array Elements Accessing array elements
Queues.
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Data Structure By Amee Trivedi.
COSC160: Data Structures: Lists and Queues
Chapter 15 Lists Objectives
Queues Queues Queues.
Stack and Queue APURBO DATTA.
Stacks, Queues, and Deques
Stacks, Queues, and Deques
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.
Stacks, Queues, and Deques
Presentation transcript:

Linear Data Structures Department of CE/IT, M.S.P.V.L. Polytechnic College, Pavoorchatram.

Linear Data Structures Lists Linked list Doubly linked list Circular list Stack Queue Circular queue

Linked List Properties State of List Elements in linked list are ordered Element has successor State of List Head Tail Cursor (current position) Cursor Head Tail

Reference-based Implementation Nodes contain references to other nodes Example Issues Easy to find succeeding elements Start from head of list for preceding elements

Array vs. Reference-based Linked List Insertion / deletion = O(1) Indexing = O(n) Easy to dynamically increase size of list Array Insertion / deletion = O(n) Indexing = O(1) Compact, uses less space Easy to copy, merge Better cache locality

Linked List – Insert (After Cursor) Original list & new element temp Modify temp.next  cursor.next

Linked List – Insert (After Cursor) Modify cursor.next  temp Modify cursor  temp

Linked List – Delete (Cursor) Find before such that before.next = cursor Modify before.next  cursor.next

Linked List – Delete (Cursor) Modify cursor  before.next

Doubly Linked List Properties State of List Elements in linked list are ordered Element has predecessor & successor State of List Head Tail Cursor (current position) Cursor Head Tail

Doubly Linked List Example Issues Easy to find preceding / succeeding elements Extra work to maintain links (for insert / delete) More storage per node

Node Structures for Linked Lists Class Node { Object data; Node next; } Doubly linked list Node previous;

Doubly Linked List – Insertion Example Must update references in both predecessor and successor nodes

Circular Linked Lists Last element links to first element Properties Can reach entire list from any node Need special test for end of list Represent Buffers Naturally circular data Head Tail

Circular Linked Lists – Examples Circular doubly linked list

Stack Properties Stack operations Elements removed in opposite order of insertion Last-in, First-out (LIFO) Must track position of Top (last element added) Stack operations Push = add element (to top) Pop = remove element (from top)

Stack Implementations Linked list Add / remove from head of list Array Increment / decrement Top pointer after push / pop Top X Y Z …

Stack Applications Run-time procedure information Arithmetic computations Postfix notation Simplified instruction set Java bytecode

Queue Properties Queue operations Elements removed in order of insertion First-in, First-out (FIFO) Must track Front (first in) and Back (last in) Queue operations Enqueue = add element (to back) Dequeue = remove element (from front)

Queue Implementations Linked list Add to tail (Back) of list Remove from head (Front) of list Array Circular array

Queue – Array Store queue as elements in array Problem Queue contents move (“inchworm effect”) As result, can not add to back of queue, even though queue is not full

Queue – Circular Array Circular array (ring) Problem q[ 0 ] follows q[ MAX – 1 ] Index using q[ i % MAX ] Problem Detecting difference between empty and nonempty queue

Queue – Circular Array Approach 1 Problem Keep Front at first in Keep Back at last in Problem Empty queue identical to queue with 1 element

Queue – Circular Array Approach 2 Problem Keep Front at first in Keep Back at last in – 1 Problem Empty queue identical to full queue

Queue – Circular Array Inherent problem for queue of size N Solutions Only N possible (Front – Back) pointer locations N+1 possible queue configurations Queue with 0, 1, … N elements Solutions Maintain additional state information Use state to recognize empty / full queue Examples Record Size Record QueueEmpty flag Leave empty element in queue Store marker in queue