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.

Slides:



Advertisements
Similar presentations
Lists CS 3358.
Advertisements

DATA STRUCTURES AND ALGORITHMS Prepared by İnanç TAHRALI
Linear Lists – Linked List Representation
Linked Lists Linked Lists Representation Traversing a Linked List
CHP-5 LinkedList.
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
Data Structures: A Pseudocode Approach with C
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
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.
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.
Chapter 3: Arrays, Linked Lists, and Recursion
Chapter 17 Linked List.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
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.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Subject Name : Data Structure Using C Title : Linked Lists
Data Structures Using C++1 Chapter 5 Linked Lists.
M180: Data Structures & Algorithms in Java Linked Lists Arab Open University 1.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
CS 201 Data Structures and Algorithms Chapter 3: Lists, Stacks, and Queues - I Text: Read Weiss, §3.1 – 3.5 1Izmir University of Economics.
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Linked list: a list of items (nodes), in which the order of the nodes is determined by the address, called the link, stored in each node C++ Programming:
IKI 10100I: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Data.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture1.
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
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.
UNIT-V ABSTRACT DATA TYPE 1.LIST 2.STACK 3.QUEUE EC6301-II-ECE-C.
CPSC 252 Linked Lists III Page 1 Variations on Singly Linked Lists Inserting or deleting at the front of a list is different from at any other point in.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Chapter 16: Linked Lists.
Linked List ADT used to store information in a list
Lecture 6 of Computer Science II
Unit – I Lists.
C++ Programming:. Program Design Including
Cpt S 122 – Data Structures Abstract Data Types
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists (cont) [Chapter 4; Chapter 6, pp ]
Data Structure By Amee Trivedi.
CSCI-255 LinkedList.
Program based on queue & their operations for an application
UNIT – I Linked Lists.
CMSC202 Computer Science II for Majors Lecture 12 – Linked Lists
Review Deleting an Element from a Linked List Deletion involves:
CE 221 Data Structures and Algorithms
Lists CS 3358.
Data Structure Dr. Mohamed Khafagy.
Linked Lists Linked Lists 1 Sequences Sequences 07/25/16 10:31
UNIT-3 LINKED LIST.
EEL 4854 IT Data Structures Linked Lists
Linked list insertion Head. Linked list insertion Head.
LINKED LISTS CSCD Linked Lists.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Chapter 15 Lists Objectives
Arrays and Linked Lists
Sequences 11/27/2018 1:37 AM Singly Linked Lists Singly Linked Lists.
Linked Lists.
Doubly Linked Lists or Two-way Linked Lists
CS212D: Data Structures Week 5-6 Linked List.
Chapter 11 Data Structures.
Problem Understanding
Chapter 17: Linked Lists.
LINKED LISTS.
Figure 4.1 a) A linked list of integers; b) insertion; c) deletion.
17CS1102 DATA STRUCTURES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED.
More on Linked List Yumei Huo Department of Computer Science
Chapter 9 Linked Lists.
Problem Understanding
Presentation transcript:

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 two parts: data and link. The name of the list is the same as the name of this pointer variable. Figure 11.9 shows a linked list called scores that contains four elements. We define an empty linked list to be only a null pointer: Figure 11.9 also shows an example of an empty linked list.

Figure 11.9 Linked lists

Abstract Data Types (ADT) Definition : Is a set of operation Mathematical abstraction No implementation detail Example : Lists, sets, graphs, stacks are examples of ADT along with their operations

THE LIST ADT Ordered sequence of data items called elements A1, A2, A3, …,AN is a list of size N size of an empty list is 0 Ai+1 succeeds Ai Ai-1 preceeds Ai position of Ai is i first element is A1 called “head” last element is AN called “tail” Operations ?

Outline Linked list nodes Linked list operations Insertion Append Deletion Linked list representation & implementation Other types of linked lists Sorted Doubly-linked Circular 1st March 2007

Array vs Linked List node node Array node Linked List

Linked List Implementation of Lists Series of nodes not adjacent in memory contain the element and a pointer to a node containing its succesor Avoids the linear cost of insertion and deletion !

Linked List Implementation of Lists Series of nodes not adjacent in memory contain the element and a pointer to a node containing its succesor Avoids the linear cost of insertion and deletion !

Linked List Implementation of Lists Linked List Array PrintList O(N) (traverse the list) O(N) Find FindKth (L,i) O(i) O(1) Delete O(1) O(N) Insert

Doubly Linked List Traversing list backwards not easy with regular lists Insertion and deletion more pointer fixing Deletion is easier Previous node is easy to find

Circulary Linked List Last node points the first

Cursor Implementation of Linked List If L = 5, then L represents list (A, B, E) If M = 3, then M represents list (C, D, F)

Linked List: Insertion a b c d current Insert X immediately after current position a b c d x current 1st March 2007

Inserting a Node When inserting a node in the middle of a linked list, we must first find the spot to insert it Let current refer to the node before the spot where the new node will be inserted

Implementing Insertion: Step By Step Insertion immediately after current position // create a new node tmp = new ListNode<DataType>(); // place x in the element field tmp.data = x; a b x current tmp 1st March 2007

Implementing Insertion: Step By Step Insertion immediately after current position // create a new node tmp = new ListNode<DataType>(); // place x in the element field tmp.data = x; // x’s next node is b tmp.next = current.next; a b x current tmp 1st March 2007

Implementing Insertion: Step By Step Insertion immediately after current position // create a new node tmp = new ListNode<DataType>(); // place x in the element field tmp.data = x; // x’s next node is b tmp.next = current.next; // a’s next node is x current.next = tmp; a b x current tmp 1st March 2007

Implementing Insertion: Shortest Version An even shorter version: // create a new node current.next = new ListNode<DataType>(x,current.next); a b x current 1st March 2007

Inserting a Node A method called insert could be defined to add a node anywhere in the list, to keep it sorted, for example Inserting at the front of a linked list is a special case

Implementing Basic Deletion Delete an item immediately after current position Basic deletion is a bypass in the linked list. a x b current a b current 1st March 2007

Other Linked Lists Doubly-linked lists: Each list node stores both the previous and next nodes in the list. Useful for traversing linked lists in both directions. Circular-linked lists: Last node's next references the first node. Works with or without headers. A head tail prev next prev A B C next first 1st March 2007