Linked Lists CSC220 Winter 2004-5.

Slides:



Advertisements
Similar presentations
Linked Lists Geletaw S..
Advertisements

Lists CS 3358.
Singly Linked Lists What is a singly-linked list? Why linked lists?
Linked Lists.
JAVA & Linked List Implementation
DATA STRUCTURES USING C++ Chapter 5
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
CHP-5 LinkedList.
Hash Tables CSC220 Winter What is strength of b-tree? Can we make an array to be as fast search and insert as B-tree and LL?
Binary Trees CSC 220. Your Observations (so far data structures) Array –Unordered Add, delete, search –Ordered Linked List –??
Data Structures Using C++ 2E
© 2004 Goodrich, Tamassia Sequences and Iterators1.
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 Problem Solving Abstraction Oftentimes, different real-world problems can be modeled using the same underlying idea Examples: Runtime storage, Undo operation.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
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.
Chapter 8 Lists. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 8-2 Chapter Objectives Examine list processing and various ordering techniques.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
Data Structures Using C++ 2E
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha.
Chapter 5 Ordered List. Overview ● Linear collection of entries  All the entries are arranged in ascending or descending order of keys.
Chapter 8 Lists. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Examine list processing and various ordering techniques.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Data structures Abstract data types Java classes for Data structures and ADTs.
Linked Lists Tonga Institute of Higher Education.
Linked List. Background Arrays has certain disadvantages as data storage structures. ▫In an unordered array, searching is slow ▫In an ordered array, insertion.
Linked List. Iterators Operation to find a link, deleting, and inserting before or after a specified link, also involve searching through the list to.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Data Structures Types of Data Structure Data Structure Operations Examples Choosing Data Structures Data Structures in Alice.
Dynamic Array. An Array-Based Implementation - Summary Good things:  Fast, random access of elements  Very memory efficient, very little memory is required.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Linked Lists © John Urrutia 2013, All Rights Reserved1.
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
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
Introduction to Data Structures and Algorithms
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
Ordered Lists and Sorted Lists Chapter 7. Ordered Lists Array version vs. Linked-list version.
CS2006- Data Structures I Chapter 5 Linked Lists III.
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.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
Stack and Queues Part 2. Priority Queues Priority Queues (cont’) A priority queue is a more specialized data structure than a stack or a queue. However,
Linked Lists. Introduction In linked list each item is embedded in a link Each item has two parts – Data – Pointer to the next item in the list Insert,
April 27, 2017 COSC Data Structures I Review & Final Exam
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
1 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
“Sense shines with a double luster when it is set in humility. An able and yet humble man is a jewel worth a kingdom.” – William Penn Thought for the Day.
CS-2851 Dr. Mark L. Hornick 1 Linked-List collections Structure and Implementation.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture3.
UNIT-II Topics to be covered Singly linked list Circular linked list
LINKED LISTS.
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.
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.
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.
Linked List ADT used to store information in a list
C++ Programming:. Program Design Including
Top 50 Data Structures Interview Questions
CE 221 Data Structures and Algorithms
structures and their relationships." - Linus Torvalds
11-3 LINKED LISTS A linked list is a collection of data in which each element contains the location of the next element—that is, each element contains.
structures and their relationships." - Linus Torvalds
Presentation transcript:

Linked Lists CSC220 Winter 2004-5

Array vs Linked List node node Array node Linked List

What’s wrong with Array and Why lists? Disadvantages of arrays as storage data structures: slow searching in unordered array slow insertion in ordered array Fixed size Linked lists solve some of these problems Linked lists are general purpose storage data structures and are versatile.

Linked Lists Each data item is embedded in a link. Each Link object contains a reference to the next link in the list of items. In an array items have a particular position, identified by its index. In a list the only way to access an item is to traverse the list Is LL an ADT?

Operations in a simple linked list: Insertion Deletion Searching or Iterating through the list to display items.

Operations in a simple linked list: The simplest methods are insertfirst() and deletefirst(), where the first item in the linked list is accessed and deleted or a new item is inserted as the head or root of the list. To insert or delete items from any other part of the list, we need to traverse the list starting from its root and traversing till we get the item that we are looking for.

Examples ..\ReaderPrograms\ReaderFiles\Chap05\linkList\linkList.java Linklist2.java: delete (key), find(key)

Double-Ended Lists Similar to an ordinary list with the addition that a link to the last item is maintained along with that to the first. The reference to the last link permits to insert a new link directly at the end of the list as well as at the beginning. This could not be done in the ordinary linked list without traversing the whole list. This technique is useful in implementing the Queue where insertions are made at end and deletions from the front.

Double-Ended Lists ..\ReaderPrograms\ReaderFiles\Chap05\doublyLinked\doublyLinked.java First last null

Linked List Efficiency Insertion and deletion at the beginning of the list are very fast, O(1). Finding, deleting or inserting in the list requires searching through half the items in the list on an average, requiring O(n) comparisons. Although arrays require same number of comparisons, the advantage lies in the fact that no items need to be moved after insertion or deletion. As opposed to fixed size of arrays, linked lists use exactly as much memory as is needed and can expand.

Abstract Data Types Focus on what the data structure does Ignore how it does. ADT is a class considered without regard to its implementation. Examples: Stacks and Queues They can also be implemented using linked lists as opposed to array in the previous chapter.

ADT Lists Also called linear list. Group of items arranged in a linear order. Operations supported are : insertion, deletion and read an item. List is defined by its interface; the specific methods used to interact with it. This can be implemented using arrays or linked lists.

Sorted Lists (ProrityQ) As the name suggests data is stored in order. Find and delete methods are used. Advantage of sorted list over sorted array is speed of insertion and its ability to expand to fill available memory. Efficiency: -- Insertion and deletion of arbitrary items require O(n) comparisons.

Doubly Linked Lists Solves the problem of traversing backwards in an ordinary linked list. A link to the previous item as well as to the next item is maintained. The only disadvantage is that every time an item is inserted or deleted, two links have to be changed instead of one. A doubly-linked list can also be created as a double – ended list. See doublyLinked.java ..\ReaderPrograms\ReaderFiles\Chap05\doublyLinked\doublyLinked.java

Iterators (ADT) An iterator is a reference that points to a link in an associated list. In order to traverse a list, performing some operation on certain links it is efficient to go from one link to another, checking whether each meets the criteria and then performing the operation. To do this, we need a reference that can be incremented. This reference can be embedded in a class object. Objects containing references to items in data structures, used to traverse theses structures are called Iterators.

Methods in Iterator The iterator methods allow the user to move along the list and access the link currently pointed to. The following methods make the iterator more flexible: -- reset() -- nextLink() -- getCurrent() -- atEnd() -- insertAfter() -- insertBefore() -- deleteCurrent()