Sequences 8/1/2018 4:38 AM Linked Lists Linked Lists.

Slides:



Advertisements
Similar presentations
Singly linked lists Doubly linked lists
Advertisements

© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Arrays: pluses and minuses + Fast element access. -- Impossible to resize.
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
Queue & List Data Structures & Algorithm Abstract Data Types (ADTs) ADT is a mathematically specified entity that defines a set of its instances,
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.
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
Linked Lists1 Part-B3 Linked Lists. Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data structure consisting of a sequence.
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
Stacks and Linked Lists. Abstract Data Types (ADTs) An ADT is an abstraction of a data structure that specifies – Data stored – Operations on the data.
Mohammad Amin Kuhail M.Sc. (York, UK) University of Palestine Faculty of Engineering and Urban planning Software Engineering Department Computer Science.
Lecture 3 Queues Queues1. queue: – Retrieves elements in the order they were added. – First-In, First-Out ("FIFO") – Elements are stored in order of insertion.
© 2014 Goodrich, Tamassia, Goldwasser Singly Linked Lists1 Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
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.
© 2004 Goodrich, Tamassia Queues. © 2004 Goodrich, Tamassia Stacks2 The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow.
Queues1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich,
Linked List, Stacks Queues
Lecture 6 of Computer Science II
Elementary Data Structures
Review Array Array Elements Accessing array elements
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Queues 5/11/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
Data Structure By Amee Trivedi.
Vectors 5/31/2018 9:25 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Program based on queue & their operations for an application
Sequences 6/3/2018 9:11 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Chapter 15 Lists Objectives
Data Structure Dr. Mohamed Khafagy.
Linked Lists Linked Lists 1 Sequences Sequences 07/25/16 10:31
Sequences 8/2/ :13 AM Linked Lists Linked Lists.
Sequences 8/2/ :16 AM Linked Lists Linked Lists.
EEL 4854 IT Data Structures Linked Lists
Stacks and Queues.
Queues Queues Queues.
Data Structures Linked list.
LINKED LISTS CSCD Linked Lists.
CMSC 341 Lecture 5 Stacks, Queues
Queues 11/9/2018 6:32 PM Queues.
Stacks, Queues, and Deques
Queues.
Arrays and Linked Lists
Queue.
Sequences 11/22/2018 3:25 AM Doubly-Linked Lists Doubly-Linked Lists.
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
Stacks, Queues, and Deques
Sequences 11/27/2018 1:37 AM Singly Linked Lists Singly Linked Lists.
Queue and Priority Queue Implementations
Queues 12/3/2018 Queues © 2014 Goodrich, Tamassia, Goldwasser Queues.
Linked Lists.
Sequences 12/8/2018 3:02 AM Linked Lists Linked Lists.
CS212D: Data Structures Week 5-6 Linked List.
Queues 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
CS2013 Lecture 4 John Hurley Cal State LA.
Stacks and Queues CSE 373 Data Structures.
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Recall What is a Data Structure Very Fundamental Data Structures
Problem Understanding
Recall What is a Data Structure Very Fundamental Data Structures
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Lecture 16 Section 6.2 Thu, Mar 1, 2007
Copyright © Aiman Hanna All rights reserved
Linked Lists & Iterators
Using a Queue Chapter 8 introduces the queue data type.
Computing Spans Given an an array X, the span S[i] of X[i] is
Using a Queue Chapter 8 introduces the queue data type.
CS210- Lecture 6 Jun 13, 2005 Announcements
Stacks, Queues, and Deques
Stacks and Linked Lists
Problem Understanding
Presentation transcript:

Sequences 8/1/2018 4:38 AM Linked Lists Linked Lists

Recap: Array-based Stack in Python

Recap: Queue in Python (1/2)

Recap: Queue in Python (2/2)

Assignment #5: Stacks and Queues R-6.5 Implement a function that reverses a list of elements by pushing them onto a stack in one order, and writing them back to the list in reversed order. R-6.13 Suppose you have a deque D containing the numbers (1,2,3,4,5,6,7,8), in this order. Suppose further that you have an initially empty queue Q. Give a code fragment that uses only D and Q (and no other variables) and results in D storing the elements in the order (1,2,3,5,4,6,7,8). R-6.14 Repeat the previous problem using the deque D and an initially empty stack S. Find spans in an array. Given an array arr[], the SPAN s[i] of arr[i] is the maximum number of consecutive elements arr[j] immediately before arr[i] such that arr[j] <= arr[i]. (C++ codes: spans1.cpp, spans2.cpp ). Implement both the spans1 which runs in O(n2) time and the spans2 which runs in O(n) time in Python.

R6.5 reverses a list of elements by pushing them onto a stack in one order, and writing them back to the list in reversed order.

R-6.13 Suppose you have a deque D containing the numbers (1,2,3,4,5,6,7,8), in this order. Suppose further that you have an initially empty queue Q. Give a code fragment that uses only D and Q (and no other variables) and results in D storing the elements in the order (1,2,3,5,4,6,7,8).

R-6.14 Repeat the previous problem using the deque D and an initially empty stack S.

Find spans in an array Sequences 8/1/2018 4:38 AM https://docs.python.org/3/library/stdtypes.html?highlight=join#str.join

Find spans in an array Sequences 8/1/2018 4:38 AM https://docs.python.org/3/library/stdtypes.html?highlight=join#str.join

Singly Linked List A singly linked list is a concrete data structure consisting of a sequence of nodes, starting from a head pointer Each node stores element link to the next node next node elem head  A B C D Linked Lists

The Node Class for List Nodes Sequences 8/1/2018 4:38 AM The Node Class for List Nodes By default, Python represents each namespace with an instance of the built-in dict class (see Section 1.2.3) that maps identifying names in that scope to the associated objects. provide a class-level member named slots that is assigned to a fixed sequence of strings that serve as names for instance variables. By default, Python represents each namespace with an instance of the built-in dict class (see Section 1.2.3) that maps identifying names in that scope to the associated objects. provide a class-level member named slots that is assigned to a fixed sequence of strings that serve as names for instance variables. Linked Lists

Inserting at the Head Allocate a new node Insert new element Have new node point to old head Update head to point to new node Linked Lists

Removing at the Head Update head to point to next node in the list Allow garbage collector to reclaim the former first node Linked Lists

Inserting at the Tail Allocate a new node Insert new element Have new node point to null Have old last node point to new node Update tail to point to new node Linked Lists

Removing at the Tail Removing at the tail of a singly linked list is not efficient! There is no constant-time way to update the tail to point to the previous node Linked Lists

Stack as a Linked List We can implement a stack with a singly linked list The top element is stored at the first node of the list The space used is O(n) and each operation of the Stack ADT takes O(1) time nodes t  elements Linked Lists

Linked-List Stack in Python

Queue as a Linked List We can implement a queue with a singly linked list The front element is stored at the first node The rear element is stored at the last node The space used is O(n) and each operation of the Queue ADT takes O(1) time r nodes f  elements Linked Lists

Linked-List Queue in Python supporting worst-case O(1)-time for all operations Linked Lists

Application: Round Robin Schedulers We can implement a round robin scheduler using a queue Q by repeatedly performing the following steps: e = Q.dequeue() Service element e Q.enqueue(e) Queue Dequeue Enqueue Shared Service © 2013 Goodrich, Tamassia, Goldwasser Queues

Queue with a Circularly Linked List in Python