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.

Slides:



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

Inserting a Node into a Specified Position of a Linked List To create a node for the new item newNode = new Node(item); To insert a node between two nodes.
Lists CS 3358.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
Linked Lists.
Linear Lists – Linked List Representation
Linked Lists Contents 1.LinkedList implements the Interface List 2.Doubly Linked List implementation of common methods a.boolean add( Object x) -- append.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
Review Learn about linked lists
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Contd... Objectives Explain the design, use, and operation of a linear list Implement a linear.
Linked List Improvements & Memory. BigO's What is BigO for our basic linked list operations? InsertStart Insert at middle InsertEnd Retrieve First Value.
© 2006 Pearson Addison-Wesley. All rights reserved5 A-1 Chapter 5 Linked Lists CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
Lists and the Collections Framework
1 Chapter 3 Arrays, Linked Lists, and Recursion. 2 Static vs. Dynamic Structures A static data structure has a fixed size This meaning is different than.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 17: 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.
© 2006 Pearson Addison-Wesley. All rights reserved5 A-1 Chapter 5 Linked Lists.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 17 Linked.
Linked Lists part II. Linked Lists A linked list is a dynamic data structure consisting of nodes and links: 627 start 8 This symbol indicates a null reference.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
Summary of lectures (1 to 11)
Linking Objects Together References are particularly important in computer science because they make it possible to represent the relationship among objects.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
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.
2 Preliminaries Options for implementing an ADT List Array has a fixed size Data must be shifted during insertions and deletions Linked list is able to.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 17: Linked Lists.
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.
Linked List Chapter Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the.
Linked List by Chapter 5 Linked List by
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
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.
Linked Lists Chapter 4. Linked Structures: Motivations Arrays have fixed size –Problematic for data structures of arbitrary size Arrays order items physically.
Chapter 5 Linked Lists. © 2004 Pearson Addison-Wesley. All rights reserved 5 A-2 Preliminaries Options for implementing an ADT –Array Has a fixed size.
COMPSCI 105 SS 2015 Principles of Computer Science
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
Linear Data Structures
Lab - 11 Keerthi Nelaturu. Ordered Structure Using Doubly linked list All elements in the list are arranged in an order Implement the Ordered Structure.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
CSC 205 Programming II Lecture 15 Linked List – Other Variations.
Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley CHAPTER 4 Linked.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
1 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
CC 215 DATA STRUCTURES LINKED LISTS Dr. Manal Helal - Fall 2014 Lecture 3 AASTMT Engineering and Technology College 1.
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.
Advanced Programming 7/10/20161 Ananda Gunawardena.
1 Linked List. List vs Arrays Two built-in data structures that can be used to organize data, or to create other data structures: Lists Arrays.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Chapter 3: Fundamental Data Structures: The Array and Linked Structures Data Structures in Java: From Abstract Data Types to the Java Collections Framework.
Unit – I Lists.
Chapter 5 Linked Lists © 2006 Pearson Addison-Wesley. All rights reserved.
Linked Lists Chapter 5 (continued)
CMSC202 Computer Science II for Majors Lecture 12 – Linked Lists
Chapter 5 Linked Lists © 2011 Pearson Addison-Wesley. All rights reserved.
Chapter 4 Linked Lists.
Chapter 4 Linked Lists
Dummy Nodes, Doubly Linked Lists and Circular Linked Lists
Chapter 4 Linked Lists.
Chapter 5 Linked Lists © 2006 Pearson Addison-Wesley. All rights reserved.
Doubly Linked Lists Lecture 21 Tue, Mar 21, 2006.
Chapter 4 Linked Lists.
Figure 4.1 a) A linked list of integers; b) insertion; c) deletion.
Linked Lists Chapter 5 (continued)
Chapter 5 Linked Lists © 2006 Pearson Addison-Wesley. All rights reserved.
Linked List Improvements
Linked Lists Chapter 5 (continued)
Linked Lists Chapter 5 (continued)
Presentation transcript:

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 (due to need of copying data and resizing array) Reference based (LL) Keeps place for exactly N elements Each element takes 2 memory places Slow accession time Slow removals and insertion (due to accession)

Passing a Linked List to a Method A method with access to a linked list’s head reference has access to the entire list When head is an actual argument to a method, its value is copied into the corresponding formal parameter Figure 5-19 A head reference as an argument

Examples Merge() method, takes 2 sorted lists and returns one sorted list containing all elements (the original lists can be destroyed) Fast insertions and deletions at the beginning of the list using array-based implementation Fast insertion at the end and fast deletion at the beginning using linked-list (alternatively, array-based) implementation [tail reference]

Variations of the Linked List: Tail References tail references Remembers where the end of the linked list is To add a node to the end of a linked list tail.setNext(new Node(request, null)); Figure 5-22 A linked list with head and tail references

Doubly Linked List Each node references both its predecessor and its successor Dummy head nodes are useful in doubly linked lists Figure 5-26 A doubly linked list

Doubly Linked List To delete the node that curr references curr.getPrecede().setNext(curr.getNext()); curr.getNext().setPrecede(curr.getPrecede()); Figure 5-28 Reference changes for deletion

Doubly Linked List To insert a new node that newNode references before the node referenced by curr newNode.setNext(curr); newNode.setPrecede(curr.getPrecede()); curr.setPrecede(newNode); newNode.getPrecede().setNext(newNode); Figure 5-29 Reference changes for insertion

Eliminating special cases in Doubly Linked List Figure 5-27 a) A circular doubly linked list with a dummy head node; b) an empty list with a dummy head node

Doubly Linked List Circular doubly linked list precede reference of the dummy head node references the last node next reference of the last node references the dummy head node Eliminates special cases for insertions and deletions

Doubly Linked List - benefits Fast insertions and deletions at both ends of the list To perform deletion and insertion, we need reference to the current node (to node after place where we are inserting). (Usual implementation of LinkedLists)