UNIT-II Topics to be covered Singly linked list Circular linked list

Slides:



Advertisements
Similar presentations
Linked Lists Geletaw S..
Advertisements

Stacks, Queues, and Linked Lists
Linked Lists.
DATA STRUCTURES USING C++ Chapter 5
Linked Lists Linked Lists Representation Traversing a Linked List
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.
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
Foundation of Computing Systems Lecture 2 Linked Lists.
1 CSC 211 Data Structures Lecture 22 Dr. Iftikhar Azim Niaz 1.
Data Structures: A Pseudocode Approach with C
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.
COMP103 - Linked Lists (Part A)1 Chapter 17 Truly dynamic memory management.
Summary of lectures (1 to 11)
INTRODUCTION TO DATA STRUCTURE. Topics To Be Discussed………………………. Meaning of Data Structure Classification of Data Structure Data Structure Operations.
Chapter 3: Arrays, Linked Lists, and Recursion
UNIT-2. Singly Linked List Doubly Linked List Circular Linked List Representing Stack with Linked List. Representing Queue with Linked List.
Implementation of Linked List For more notes and topics visit: eITnotes.com.
SAK 3117 Data Structures Chapter 6: LINKED LISTS.
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
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.
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.
1 Chapter 16 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion and.
1 Chapter 16 Linked Structures Dale/Weems/Headington.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
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.
Kovács Zita 2014/2015. II. félév DATA STRUCTURES AND ALGORITHMS 26 February 2015, Linked list.
Linked Structures, LinkedStack
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Linked Lists Linked Lists Dale.
 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.
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.
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.
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.
CHAPTER 51 LINKED LISTS. Introduction link list is a linear array collection of data elements called nodes, where the linear order is given by means of.
Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.
LINKED LISTS.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
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.
Chapter 16: Linked Lists.
Linked List :: Basic Concepts
Lectures linked lists Chapter 6 of textbook
Program based on queue & their operations for an application
Data Structure Interview Question and Answers
Review Deleting an Element from a Linked List Deletion involves:
Data Structure and Algorithms
Prepared by, Jesmin Akhter, Lecturer, IIT, JU
Lecture - 6 On Data Structures
UNIT-3 LINKED LIST.
Data Structures Interview / VIVA Questions and Answers
Linked List Sudeshna Sarkar.
LINKED LISTS CSCD Linked Lists.
Arrays and Linked Lists
Linked Lists.
LINKED LIST.
Chapter 16 Linked Structures
LINKED LIST Dr. T. Kokilavani Assistant Professor
BY PROF. IRSHAD AHMAD LONE.
LINEAR DATA STRUCTURES
Linked Lists.
CMPT 225 Lecture 5 – linked list.
Presentation transcript:

UNIT-II Topics to be covered Singly linked list Circular linked list Doubly linked list Representing Stack with linked list Representing Queues with linked list

In array elements are stored in consecutive memory locations In array elements are stored in consecutive memory locations. To occupy the adjacent space, block of memory that is required for the array should be allocated before hand. Once memory allocated it cannot be extended any more. So that array is called the static data structure. Wastage of memory is more in arrays.

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 list is able to grow in size as needed Array has a fixed size Data must be shifted during insertions and deletions Linked list is able to grow in size as needed Does not require the shifting of items during insertions and deletions.

Linked Lists

Linked list\singly linked list It is a dynamic data structure where amount of memory required can be varied during its use. A linked list consists of a collection of elements called nodes linked together by pointers. In linked list, adjacency between the elements are maintained by means of links or pointers.

Linked List Collection of links with reference to the first. Each link (node) has Data Part: part to store data Link Part :link that refers to the next node in the list. Data part of the node can be an integer, a character, a String or an object of any kind.

Node Head Node

Classification of linked list Depending on the requirements the pointers are maintained, and accordingly linked list can be classified into three groups. Single linked list Circular linked list Double linked list\doubly linked list.

Singly Linked Lists A linked list is an ordered collection of homogeneous data elements called nodes where linear order is maintained by means of links and pointers. Each node stores Element\data(may be integer, char or string) link to the next node next node elem Start Null A B C D

single linked list First link has dummy value for data reference to next link refers to the first link that hold information Last link does not refer to the next one. Reference to the next link is null

Operations on singly linked list Insertion Deletion Traverse Search

Insertion in linked list There are various positions where node can be inserted. Insert at front ( as a first element) Insert at end ( as a last node) Insert at middle ( any position)

Insert new node at front in linked list Algorithm step1- create a new node Step2- new->link=header->link Step3- new->data=item Step4- header->link=new. Step5-stop

header Null 10 20 30 2 2 1 1 5 Newnode

Insert new node at end of the linked list Algorithm Step1- create a new node Step2- ptr=header Step3- while(ptr->link!=null) 3.1. ptr=ptr->link Step4- ptr->link=new Step5- new->data=item Step6- new->link=null Step7-stop

header ptr Null 10 20 30 1 40 Newnode

Insert new node at any position in linked list Algorithm 1.Create new node 2. ptr=header 3. while((ptr->data!=key)&&(ptr->link!=null) 3.1 ptr=ptr->link 4. if(ptr->link=null 4.1.print key is not found in the list 5. Else 5.1 new->link=ptr->link 5.2 new->data=item 5.3. ptr->link= new 6. End if 7. stop.

ptr header Null 10 20 30 2 1 5 Newnode

Deletion of a node from ll Like insertion, there are also various cases of deletion: Deletion at the front Deletion at the end Deletion at any position in the list

1.Deletion at the front Algorithm ptr=header->link If( ptr==NULL) 2.1 print “the list is empty” 3. else 3.1 ptr1=ptr->link 3.2 header->link=ptr1 3.3 return ptr 4. End if 5. stop

header Null KEY 20 30 ptr ptr1

2. Deletion at the end Algorithm 1.ptr=header 2. if(ptr->link==NULL) 2.1 print “ the list is empty” 3. Else 3.1 while(ptr->link!=NULL) 3.2 ptr1=ptr 3.3 ptr=ptr->link; 3.4 end while 4 ptr1->link=NULL 4.1 return ptr 4. End if 5. stop

ptr header ptr1 Null KEY 20 30

3. Deletion at any position Algorithm ptr1=header ptr=ptr1->link While(ptr!=NULL) 3.1 if(ptr->data!=key) 3.2 ptr1=ptr 3.3 ptr=ptr->link 4. Else 4.1 ptr1->link=ptr->link 4.2 return ptr 5. End while 6. If (ptr==NULL) 6.1 print “key does not exist” 7. stop

ptr1 header ptr Null 10 KEY 30