Linked lists Singly linked lists Doubly linked lists Circular lists Self-organizing lists LinkedList and ArrayList Data Structures and Algorithms in Java,

Slides:



Advertisements
Similar presentations
Linked Lists Geletaw S..
Advertisements

Queues and Linked Lists
Data Structures ADT List
Linked Lists Ping Zhang 2010/09/29. 2 Anatomy of a linked list A linked list consists of: –A sequence of nodes abcd Each node contains a value and a link.
Linked Lists.
Data Structure Lecture-5
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
Review Learn about linked lists
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
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.
Linked Lists [AJ 15] 1. 2 Anatomy of a Linked List  a linked list consists of:  a sequence of nodes abcd each node contains a value and a link (pointer.
4 Linked-List Data Structures  Linked-lists: singly-linked-lists, doubly-linked-lists  Insertion  Deletion  Searching © 2008 David A Watt, University.
Linked list More terminology Singly-linked lists Doubly-linked lists DLLs compared to SLLs Circular Lists.
Comparison summary Array based (dynamic) Keeps place for up to 4N elements Each element takes 1 memory places Fast accession time Slow removals and insertion.
Linked Lists. 2 Anatomy of a linked list A linked list consists of: –A sequence of nodes abcd Each node contains a value and a link (pointer or reference)
CS 206 Introduction to Computer Science II 09 / 17 / 2008 Instructor: Michael Eckmann.
Linked Lists. Anatomy of a linked list A linked list consists of: –A sequence of nodes abcd Each node contains a value and a link (pointer or reference)
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
Doubly Linked Lists1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
Chapter 3: Arrays, Linked Lists, and Recursion
Week 3 - Wednesday.  What did we talk about last time?  Started linked lists.
Doubly Linked Lists Deleting from the end of the list – Have to traverse the entire list to stop right in front of tail to delete it, so O(n) – With head.
Chapter 17 Linked List.
Lists Based on content from: Java Foundations, 3rd Edition.
CSE 131 Computer Science 1 Module 9: Linked Lists Using references to link objects Basic operations on linked lists Implementing a linked list of integers.
More on Linked List Algorithms. Linked List and Template Remember the implementation of a double linked list we learned before. Some of methods are shown.
Chapter 9: Linked Lists Learn about linked lists. Learn about doubly linked lists. Get used to thinking about more than one possible implementation of.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
Binary trees Binary search trees Expression trees Heaps Data Structures and Algorithms in Java, Third EditionCh06 – 1.
Linked List Chapter Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the.
Lecture5: Linked Lists Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
© 2014 Goodrich, Tamassia, Goldwasser Singly Linked Lists1 Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
Winter 2006CISC121 - Prof. McLeod1 Stuff Deadline for assn 3 extended to Monday, the 13 th. Please note that the testing class for assn 3 has changed.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
CS2006- Data Structures I Chapter 5 Linked Lists III.
4-1 4 Linked List Data Structures Linked lists: singly-linked and doubly-linked. Insertion. Deletion. Searching. © 2001, D.A. Watt and D.F. Brown.
Copyright © 0 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by Tony.
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,
Chapter 3 The easy stuff. Lists If you only need to store a few things, the simplest and easiest approach might be to put them in a list Only if you need.
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
Introduction Dynamic Data Structures Grow and shrink at execution time Linked lists are dynamic structures where data items are “linked up in a chain”
Lists (2). Circular Doubly-Linked Lists with Sentry Node Head.
Week 4 - Wednesday.  What did we talk about last time?  Started linked lists.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Data Structures and Algorithm Analysis Dr. Ken Cosh Linked Lists.
One implementation of the LIST ADT Insert new node before current and new node becomes current (assume new node created) node newNode = new node; head.
Linked List, Stacks Queues
Unit 3 Linked Lists King Fahd University of Petroleum & Minerals
Introduction What Is Linked List? (2002 , 2007,2011)
Linked Lists.
Program based on queue & their operations for an application
Doubly Linked Lists 6/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Linked List Stacks, Linked List Queues, Dequeues
Doubly Linked List Review - We are writing this code
COP3530- Data Structures Advanced Lists
Algorithm for deleting a node from a singly linked list
Java collections library
Linked Lists.
Dummy Nodes, Doubly Linked Lists and Circular Linked Lists
Circularly Linked Lists
Doubly Linked Lists Lecture 21 Tue, Mar 21, 2006.
LINKED LISTS.
Figure 4.1 a) A linked list of integers; b) insertion; c) deletion.
Linked Lists.
Linked Lists.
Jyh-Shing Roger Jang (張智星) CSIE Dept, National Taiwan University
Presentation transcript:

Linked lists Singly linked lists Doubly linked lists Circular lists Self-organizing lists LinkedList and ArrayList Data Structures and Algorithms in Java, Third EditionCh03 – 1

Singly linked list node public class SLLNode { public T info; public SLLNode next; public SLLNode() { next = null; } public SLLNode(T el) { info = el; next = null; } public SLLNode(T el, SLLNode p) { info = el; next = p; } el abbreviated as: el Data Structures and Algorithms in Java, Third EditionCh03 – 2

Singly linked list SLLNode p; p = new SLLNode (2); p.next = new SLLNode (8); p.next.next = new SLLNode (3); 2 \ p 8 \ 2 p 82 p 3 \ \ \ Data Structures and Algorithms in Java, Third EditionCh03 – 3

Singly linked list public class SLL { protected SLLNode head, tail; // methods: } head tail // methods: 2 83 \ Data Structures and Algorithms in Java, Third EditionCh03 – 4

Singly linked list: insertion at the head 2 83 \ tail 5 head tail null special case: 5 \ head Data Structures and Algorithms in Java, Third EditionCh03 – 5

Singly linked list: insertion at the tail 2 83 head tail 5 \ head tail null special case: 5 \ \ Data Structures and Algorithms in Java, Third EditionCh03 – 6

Singly linked list: deletion from the head 83 \ tail head tail null special case: \ head 2 3 Data Structures and Algorithms in Java, Third EditionCh03 – 7

Singly linked list: deletion from the tail 2 8 \ tail head tail null special case: \ head 3 \ 3 Data Structures and Algorithms in Java, Third EditionCh03 – 8

Doubly linked list public class DLL { protected DLLNode head, tail; // methods: } head tail // methods: 2 \ 83 \ public class DLLNode { public T info; public DLLNode next, prev; // constructors: } Data Structures and Algorithms in Java, Third EditionCh03 – 9

Doubly linked list: insertion at the head 2 83 \ tail 5 \ head tail null special case: 5 \ \ head \ Data Structures and Algorithms in Java, Third EditionCh03 – 10

Doubly linked list: deletion from the tail 2 \ 8 \ tail head tail null special case: \ \ head 3 \ 3 Data Structures and Algorithms in Java, Third EditionCh03 – 11

Self-organizing lists Move‑to‑front method: after the desired element is located, put it at the beginning of the list. A BCDC CABD Transpose method: after the desired element is located, swap it with its predecessor. ABCDC ACBD Data Structures and Algorithms in Java, Third EditionCh03 – 12

A 4 B 2 C 2 D 1 C Ordering method: order the list using a criterion natural for information under scrutiny. ABCDC ABCD Count method: order the list by the number of times elements are being accessed. A 4 C 3 B 2 D 1 Self-organizing lists (cont’d) C 2 Data Structures and Algorithms in Java, Third EditionCh03 – 13

Self-organizing lists: accessing elements for the first time move-to-front, transpose, and count methods: A BXYP ABXYP ordering method: ABXYP ABPXY Data Structures and Algorithms in Java, Third EditionCh03 – 14

Self-organizing lists: example element D A C C B A A plain D DA DAC DACB move-to- front D DA DAC CDA CDAB ACDB trans- pose D DA DAC DCA DCAB DACB ADCB count D1D1 D1A1D1A1 D1A1C1D1A1C1 C2D1A1C2D1A1 C2D1A1B1C2D1A1B1 C2A2D1B1C2A2D1B1 A3C2D1B1A3C2D1B1 ordering D AD ACD ABCD A BC ABC represents the list

Priority queue: linked list implementation number of operationsenqueuedequeue unordered list ordered list const n ≤ n const Data Structures and Algorithms in Java, Third EditionCh03 – 16