Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.

Slides:



Advertisements
Similar presentations
Singly linked lists Doubly linked lists
Advertisements

Lists CS 3358.
Linked Lists.
Linked Lists Linked Lists Representation Traversing a Linked List
CHP-5 LinkedList.
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
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.
Data Structures: A Pseudocode Approach with C
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Linked Lists... An introduction to creating dynamic data structures.
Linked Lists
Linked Lists in C and C++ By Ravi Prakash PGT(CS).
Data Structures & Algorithms
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 17: Linked Lists.
C++ Programming: Program Design Including Data Structures, Third 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.
©Brooks/Cole, 2003 Chapter 11 Data Structures. ©Brooks/Cole, 2003 Data Structure Data structure uses collection of related variables that can be accessed.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
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.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Summary of lectures (1 to 11)
Chapter 3: Arrays, Linked Lists, and Recursion
IntroductionIntroduction  Definition of B-trees  Properties  Specialization  Examples  2-3 trees  Insertion of B-tree  Remove items from B-tree.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Implementation of Linked List For more notes and topics visit: eITnotes.com.
Data Structures Week 5 Further Data Structures The story so far  We understand the notion of an abstract data type.  Saw some fundamental operations.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
D ATA S TRUCTURE Ali Abdul Karem Habib MSc.IT. P OINTER A pointer is a variable which represents the location of a data item. We can have a pointer to.
Data Structures and Algorithms Lecture 1 Instructor: Quratulain Date: 1 st Sep, 2009.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 17: Linked Lists.
Dynamic Array. An Array-Based Implementation - Summary Good things:  Fast, random access of elements  Very memory efficient, very little memory is required.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
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
Review 1 Polish Notation Prefix Infix Postfix Precedence of Operators Converting Infix to Postfix Evaluating Postfix.
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.
Review Sorting algorithms Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
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,
 Array is a data structure were elements are stored in consecutive memory location.in the array once the memory is allocated.it cannot be extend any more.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
CS162 - Topic #7 Lecture: Dynamic Data Structures –Review of pointers and the new operator –Introduction to Linked Lists –Begin walking thru examples of.
1 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
Linked List. LINKED LIST Link is collection of similar type of elements. There are two ways of maintaining a list in memory. The first way is store the.
Data Structure & Algorithms
Array 10 GB Hard Disk 2 GB 4 GB2 GB 3 GB DATA 4 GB Free Store data in the form of Array (Continuous memory locations) Solution-1: No Solution. Memory Insufficient.
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
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.
UNIT-II Topics to be covered Singly linked list Circular linked list
Copyright © 2012 Pearson Education, Inc. Chapter 17: 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.
Lecture 6 of Computer Science II
Unit – I Lists.
Chapter 12 – Data Structures
Review Deleting an Element from a Linked List Deletion involves:
Prepared by, Jesmin Akhter, Lecturer, IIT, JU
CSCI 3333 Data Structures Linked Lists.
Arrays and Linked Lists
Linked Lists.
Chapter 17: Linked Lists.
LINKED LIST Dr. T. Kokilavani Assistant Professor
BY PROF. IRSHAD AHMAD LONE.
Chapter 9 Linked Lists.
LINEAR DATA STRUCTURES
Presentation transcript:

Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1

More united and connected we are, more is the flexibility and scalability DeSiaMorewww.desiamore.com/ifm2

Linked Lists Is the most used data structure in the scientific computing though it is hard to be understood. They offer high flexibility and performance when used in programming. DeSiaMorewww.desiamore.com/ifm3

Linked Lists For storing similar data in memory we can use either an array or a linked list. Arrays are simple to understand and elements of arrays are easily accessible. But the following are cons of arrays: DeSiaMorewww.desiamore.com/ifm4

The cons of arrays Arrays have fixed dimension so once the size of an array is set it cannot be increased or decreased during execution. Array elements are always contiguous memory locations of which might be scarce for the big size array that we need to create Operations like insertion of new element in an array or deletion of an existing element of an array require the shifting of position left or right which make these operations tedious DeSiaMorewww.desiamore.com/ifm5

Alternative of arrays Linked list overcomes all these disadvantages by growing and shrinking in size during its lifetime. Nodes (elements) are stored at different memory locations so it happens that we fall short of memory when required. Unlike arrays shifting of nodes is not required. DeSiaMorewww.desiamore.com/ifm6

Linked Lists Linked list is a very common data structure often used to store similar data in memory. Linked list elements are not constrained to be stored in adjacent locations. The order of the elements is maintained by explicit links between them. Example the students marks can be stored in a linked list. DeSiaMorewww.desiamore.com/ifm7

Linked Lists…Diagram Linked list; N stands for Null DeSiaMorewww.desiamore.com/ifm8

Linked Lists…Definition A linked list is a collection of elements (records) called nodes or struct, each of which stores two items of information – an element of the list and link. A link is a pointer or an address that indicates explicitly the location of the node containing the successor of list element. In the figure of the above slide the arrows represent the links. DeSiaMorewww.desiamore.com/ifm9

Linked Lists The data part of each node consists of the marks obtained by a student and the link part is the pointer to the next node. The NULL in the last node indicates that this is the last node in the list DeSiaMorewww.desiamore.com/ifm10

Types of Linked Lists There are two types of linked list: Singly linked list Doubly Linked List Singly linked lists contains only one pointer to the next node as it was seen above. Doubly linked lists (Circular Linked List) have two pointers; one points to the previous node and other points to the next node. DeSiaMorewww.desiamore.com/ifm11

Linked Lists We could have record hold anything you want, however each record must be the instance of the same structure for this to work. That is we couldn’t have a node (record) point to another structure holding short, a char array, and a long. Also each structure can be located anywhere in memory, each node doesn’t have to be linear in memory. DeSiaMorewww.desiamore.com/ifm12

Linked Lists Linked list is an odd way of storing data, some people see it as useful way of storing data when developing the games software. DeSiaMorewww.desiamore.com/ifm13

Singly Linked List The singly linked list can be represented linearly as shown below: DeSiaMorewww.desiamore.com/ifm14

Linked List Operation In the singly linked list each node is dynamically allocated from the heap, so the node has a unique address. The most two operations that can be performed in the linked lists are insertion and deletion. DeSiaMorewww.desiamore.com/ifm15

Insertion/Deletion The node within the lists can be inserted or deleted. If a new node need to be allocated to the list and is to be inserted as the 3 rd node in the list DeSiaMorewww.desiamore.com/ifm16

Inserting New Node To insert new node in the list you must have a pointer to a node that will point the first node in the list. This node pointer will persistently point to the first node no matter amount of nodes get added in the list. When no node has been added in the list the pointer must be set to NULL to indicate that the list is empty. DeSiaMorewww.desiamore.com/ifm17

Deleting Node from the List There are few steps to deleting a specific element from the list: Find the node with the element (if it exists) Remove that node. Reconnect the linked list Finding the node is the matter of traversing the list and looking at each node’s element. DeSiaMorewww.desiamore.com/ifm18

Deletion Reconnecting the list once a node is to be removed involve 3 cases: Removing a node from the beginning Removing a node from the middle Removing a node from the end DeSiaMorewww.desiamore.com/ifm19