CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Linked Lists Course Lecture Slides 23 July 2010 A list is only as strong.

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

Singly linked lists Doubly linked lists
Lists CS 3358.
Stacks, Queues, and Linked Lists
Review Generics and the ArrayList Class
Linear Lists – Linked List Representation
Data Structures ADT List
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
ITEC200 Week04 Lists and the Collection Interface.
John Hurley Cal State LA
David Weinberg presents Linked Lists: The Background  Linked Lists are similar to ArrayLists in their appearance and method of manipulation  They do.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
Data Structures Simple data type –int, char, long Reference data type –Integer, String, Composite data type == Data Structure –Collection of elements.
Data Structures: A Pseudocode Approach with C
Lecture - 1 on Data Structures. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Data Type and Data Structure Data type Set of possible values for variables.
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.
CS 206 Introduction to Computer Science II 09 / 17 / 2008 Instructor: Michael Eckmann.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Main Index Contents 11 Main Index Contents Abstract Model of a List Obj. Abstract Model of a List Obj. Insertion into a List Insertion into a List Linked.
Chapter 4 Linked Structures. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 4-2 Chapter Objectives Describe the use of references to create.
Queues Chapter 6. Chapter 6: Queues2 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in the Queue interface.
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.
CS 206 Introduction to Computer Science II 09 / 19 / 2008 Instructor: Michael Eckmann.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Lists Based on content from: Java Foundations, 3rd Edition.
Arrays and Linked Lists "All the kids who did great in high school writing pong games in BASIC for their Apple II would get to college, take CompSci 101,
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
CS 46B: Introduction to Data Structures July 9 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
1/ 124 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 18 Programming Fundamentals using Java 1.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
CS 307 Fundamentals of Computer ScienceLinked Lists 1 Topic 14 Linked Lists "All the kids who did great in high school writing pong games in BASIC for.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Generics and Collections Course Lecture Slides 19 th July 2010 “Never.
Kovács Zita 2014/2015. II. félév DATA STRUCTURES AND ALGORITHMS 26 February 2015, Linked list.
Linked List by Chapter 5 Linked List by
© 2014 Goodrich, Tamassia, Goldwasser Singly Linked Lists1 Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
Subject Name : Data Structure Using C Title : Linked Lists
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
M180: Data Structures & Algorithms in Java Linked Lists Arab Open University 1.
1 Data Organization Example 1: Heap storage management –Keep track of free chunks of memory Example 2: A simple text editor –Maintain a sequence of lines.
List Interface and Linked List Mrs. Furman March 25, 2010.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
 2015, Marcus Biel, Linked List Data Structure Marcus Biel, Software Craftsman
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
Given a node v of a doubly linked list, we can easily insert a new node z immediately after v. Specifically, let w the be node following v. We execute.
Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Templates Linked Lists.
1 Data Organization Example 1: Heap storage management Maintain a sequence of free chunks of memory Find an appropriate chunk when allocation is requested.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Chapter 3: Fundamental Data Structures: The Array and Linked Structures Data Structures in Java: From Abstract Data Types to the Java Collections Framework.
Lecture 6 of Computer Science II
Data Structure By Amee Trivedi.
CSCI-255 LinkedList.
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,
CMSC202 Computer Science II for Majors Lecture 12 – Linked Lists
Dummy Nodes, Doubly Linked Lists and Circular Linked Lists
Arrays and Linked Lists
CS212D: Data Structures Week 5-6 Linked List.
CS2013 Lecture 4 John Hurley Cal State LA.
Problem Understanding
Linked List and Selection Sort
Chapter 17: Linked Lists.
Problem Understanding
Presentation transcript:

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Linked Lists Course Lecture Slides 23 July 2010 A list is only as strong as its weakest link. --Donald Knuth

[News] Tropical storm Bonnie hit Biscayne Bay, FL this morning! Credits: NOAA

Data structure A way of structuring, storing and organizing data in computers that facilitates efficient operations on the data. Data structures help to devise algorithms for solving complex operations on the data in an efficient manner.

Data structures Array Stack List Linked List Queue Graph Tree And many more!

ArrayList To insert (remove) an element in (from) the interior of an ArrayList requires shifting of data and is a linear-time O(n) operation!

Linked List Is a collection of linked nodes (think of a chain!) Memory allocation for nodes is non-contiguous Sports constant time O(1) insertion and updates

Linked List Variations Singly-Linked Lists Doubly-Linked Lists Multi-Linked Lists Circular Linked Lists Unrolled Linked Lists (multiple elements in each node) Lists with only head pointer nodes With head and tail nodes With head, tail and cursor (currently requested) nodes And many more!

Singly Linked List A set of nodes, each containing some data and a link to the next node. Dynamic data-structure.

Singly Linked List A set of nodes, each containing some data and a link to the next node. Dynamic data-structure. Advantages: Simple implementation, Efficient, constant time O(1) insertion and removal operation.

Singly Linked List Node : self-referencing structure Link : reference to a node Linked list: List of nodes Has dedicated head and tail indicators

Operations on Singly Linked List Create list Add node Add node at head Add node at tail Add node at index i Remove node Remove node at head Remove node at tail Remove node at index i Iterate (traverse) the list Find node at index Find previous node to the one at index i Set node at index i to new node Size of list Clear list

Create (Node) public class Node { // data held by the node public T nodeValue; // next node in the list public Node next; // default constructor with no initial value public Node() { nodeValue = null; next = null; }... }

Empty List If list is empty (head == null) Set both head and tail to point to new node Singly Linked List: Add node

Add node to head Insert new node before current head node Two-step process Singly Linked List: Add node

Add node to head 1. Update the next link of a new node, to point to the current head node. Singly Linked List: Add node 2. Update head link to point to the new node.

Add node to tail Insert new node after current tail node Two-step process Singly Linked List: Add node

Add node to head 1. Update the next link of the current tail node, to point to the new node. Singly Linked List: Add node 2. Update tail link to point to the new node.

Add node at index i If node at index i represents head or tail node, Refer previous pseudo-code for add node at head/ tail Else Two-step process Singly Linked List: Add node

Add node at index i 1. Update link of the new node, to point to the "next" node. Singly Linked List: Add node 2. Update link of the "previous" node, to point to the new node.

Remove node from list with only one node Both head and tail point to the (same node) only existing node. Remove link to the node from both the head and tail, by setting both to null. Dispose off the node (set to null) Singly Linked List: Remove node

Remove node from head Remove the node pointed to by head. Two-step process Singly Linked List: Remove node

Remove node from head Singly Linked List: Remove node 1. Update head link to point to the node, next to the head. 2. Dispose removed node.

Remove node from tail Remove the node pointed to by tail. Need access to the previous node of current tail. Three-step process Singly Linked List: Remove node

Remove node from tail Singly Linked List: Remove node 1. Update tail link to point to the node, before the tail. In order to find it, list should be traversed first, beginning from the head. 2. Set next link of the new tail to NULL. 3. Dispose removed node.

Remove node at index i If index i is not 0 or n-1, this operation removes the node between two nodes. Two-step process Singly Linked List: Remove node

Remove node at index i Singly Linked List: Remove node 1. Update next link of the previous node, to point to the next node, relative to the removed node. 2. Dispose removed node.

Doubly Linked List Has links to both previous and next nodes Advantage: faster (bi-directional) traversal But, more control data (links) stored

Get more info! Java docs: Linked List (doubly linked list) Java docs: Using and programming generics in J2SE 5.0 Java docs: Collections framework tutorial java/util/LinkedList.html lections/index.html