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.

Slides:



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

Linked Lists.
Linked Lists Linked Lists Representation Traversing a Linked List
CHP-5 LinkedList.
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
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 Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Linked Lists. Array Limitations Arrays have a fixed size that cannot be changed at run time What if your program had an array to store info regarding.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
CS Data Structures Chapter 4 Lists.
Introduction to C Programming CE Lecture 19 Linear Linked Lists.
Searching Searching: –Mainly used for: Fetching / Retrieving the Information such as, –Select query on a database. –Important thing is: Retrieval of Information.
UNIT-2. Singly Linked List Doubly Linked List Circular Linked List Representing Stack with Linked List. Representing Queue with Linked List.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
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.
17. ADVANCED USES OF POINTERS. Dynamic Storage Allocation Many programs require dynamic storage allocation: the ability to allocate storage as needed.
Lists. Container Classes Many applications in Computer Science require the storage of information for collections of entities e.g. a student registration.
Lists 1. Introduction Data: A finite sequence of data items. Operations: Construction: Create an empty list Empty: Check if list is empty Insert: Add.
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.
CSC 211 Data Structures Lecture 13
C++ Data Types Structured array struct union class Address pointer reference Simple IntegralFloating char short int long enum float double long double.
Lists II. List ADT When using an array-based implementation of the List ADT we encounter two problems; 1. Overflow 2. Wasted Space These limitations are.
A first look an ADTs Solving a problem involves processing data, and an important part of the solution is the careful organization of the data In order.
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.
Stack Any Other Data Structure Array Linked List
Dynamic Array. An Array-Based Implementation - Summary Good things:  Fast, random access of elements  Very memory efficient, very little memory is required.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Queue Queue: –Like any other data structure (apart from Array and Linked List), Queue also can be implemented, –Either as an Array or, –As a Linked List.
COSC 1P03 Data Structures and Abstraction 5.1 Linear Linked Structures A bank is a place where they lend you an umbrella in fair weather and ask for it.
Review Sorting algorithms Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Linked Lists. Array List Issues Painful insert/remove at start/middle.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Linked Lists Linked Lists Dale.
Linked List X Header X 4000 ptr Question: Search a value 40 in the linked list. Steps: ptr = Header->Link While(ptr.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 CSC 211 Data Structures Lecture 11 Dr. Iftikhar Azim Niaz 1.
Data Structure & Algorithms
1 Linked List. 2 List A list refers to a sequence of data items  Example: An array The array index is used for accessing and manipulation of array elements.
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.
UNIT-II Topics to be covered Singly linked list Circular linked list
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.
DYNAMIC MEMORY ALLOCATION. Disadvantages of ARRAYS MEMORY ALLOCATION OF ARRAY IS STATIC: Less resource utilization. For example: If the maximum elements.
C++ Programming:. Program Design Including
Linked List :: Basic Concepts
Lectures linked lists Chapter 6 of textbook
Linked Lists Chapter 6 Section 6.4 – 6.6
Review Deleting an Element from a Linked List Deletion involves:
Prepared by, Jesmin Akhter, Lecturer, IIT, JU
Lists.
Programmazione I a.a. 2017/2018.
Lists.
Arrays and Linked Lists
Linked List.
Chapter 16 Linked Structures
Data Structures & Algorithms
LINKED LIST Dr. T. Kokilavani Assistant Professor
Presentation transcript:

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 Solution-2: Shifting of the occupied space to make space. Not a feasible solution.

Linked List 10 GB Hard Disk 2 GB 4 GB2 GB 3 GB DATA 4 GB Free Store data in the form of Linked List (Discontinuous memory locations) Solution: How will the data be read / accessed? Start / Header Basic Structure of Linked List: Header

Linked List Header Element DATA LINK Link / Pointer to the next node. OR Address of the next node. NODE

Linked List Representation Question: Create a linked list containing data 10, 15. Get a node. Avail / Header NULL Header NULL Add ’10’ Add ’15’ Delete ’15’. Return the node. Memory Bank Memory Pool Getting a node. Memory Allocation.Memory Manager Returning a node.Memory De-Allocation.Garbage Collector Process:Called as:Done by: new

Linked List Representation Header NULL Linked List Header NULL Header Linked List NULL Same / Similar

Linked List in Algo v/s Program Algorithm Program Creation of a node. DATA LINK NODE struct node { int data; struct node * link; } Get a new node. (Memory Manager) new = GetNode(NODE) struct node * header; header = (struct node *) malloc(sizeof(struct node)); Return/Delete a node. (Garbage Collector) Return(ptr) Return(header) ptr, header are the references of the nodes to be deleted. free(ptr) free(header) Process Assume that it exists. float, char etc. Pointer to a structure temp = GetNode(NODE) Access parts of node. new->DATA, new->LINK temp->DATA, temp->LINK header->DATA, header->LINK temp->DATA, temp->LINK

Array v/s Linked List Array Linked List Uses the concept of Dynamic Memory Allocation. All the required memory needs to be allocated in advance. Memory can be allocated on demand and not in advance. Has a fixed dimension. So cannot grow or shrink at run time. Can always grow or shrink at run time. Elements are always stored at continuous / contiguous memory locations. Elements might be stored at discontinuous memory locations. Operations like Insertion and Deletion are time-consuming. They might require major shifting of elements. Operations like Insertion and Deletion are simple and less time-consuming. Shifting of elements is not required. Only adjustment of links are required. Uses the concept of Static Memory Allocation. No need to store the address of the next element. Need to store the address of the next element along with the value.

Linked List NULL Header NULL 2000 Question: Increment all the values of the linked list by needs to be 11, 15 to 16 and 20 to 21. In short, some processing needs to be done on each and every node of the linked list. Algorithm: TraverseLinkedList At the start of the algorithm, we only have a reference to the starting node of the linked list, i.e. Header. Before we can do some process on any node, we need to have a reference to that node.

Linked List NULL Header NULL 2000 Algorithm: TraverseLinkedList Question: Increment all the values of the linked list by 1. Steps: ptr =Header->Link ptr ptr->Data = ptr->Data + 1 ptr =ptr->Link ptr->Data = ptr->Data + 1 ptr = ptr->Link ptr->Data = ptr->Data + 1 ptr = ptr->Link Steps: ptr = Header->Link While(ptr != NULL) EndWhile ptr->Data = ptr->Data + 1 ptr = ptr->Link ptr NULL

Linked List NULL Header NULL 2000 Algorithm: TraverseLinkedList Question: Increment all the values of the linked list by 1. ptr Steps: ptr = Header->Link While(ptr != NULL) EndWhile ptr->Data = ptr->Data + 1 ptr = ptr->Link ptr NULL 6000 Header Steps: ptr = Header While(ptr->Link != NULL) EndWhile ptr->Data = ptr->Data + 1 ptr = ptr->Link ptr NULL

Linked List NULL Header 10 NULL 1000 NULL NULL 1000 Algorithm: TraverseLinkedList Question: Increment all the values of the linked list by 1. ptr Steps: ptr = Header->Link While(ptr != NULL) EndWhile ptr->Data = ptr->Data + 1 ptr = ptr->Link Header ptr Steps: ptr = Header While(ptr->Link != NULL) EndWhile ptr = ptr->Link ptr->Data = ptr->Data + 1 ptr NULL 11 ptr Process(ptr->Data)

Linked List Algorithm: TraverseLinkedList NULL Header NULL 2000 ptr In which direction was the traversal possible? In a single direction from left to right. ptr Linked List / Header Linked ListSingle Linked List / Singly Linked List Algorithm: Traverse_SL

Linked List Algorithm: –Traverse_SL. Input: –Header: Pointer to the starting node of the linked list. Output: –According to Process(). Data Structure: –Single Linked List whose address of starting node is known from Header.

Algorithm: Traverse_SL Steps: ptr = Header While(ptr->Link != NULL), do ptr = ptr->Link Process(ptr->Data) EndWhile

Algorithm: InsertFront_SL Question: Insert a node in the linked list. NULL Header NULL At the beginning of the linked list.Value = new Steps: new = GetNode(NODE) ptr = Header->Link new->Data = 10 new->Link = ptr Header->Link = new 10 new->Link = Header->Link = new Header->Link new->Data = Steps: new = GetNode(NODE) ptr Sequence Important ? Yes Sequence Important ? No

Algorithm: InsertFront_SL Question: Insert a node in the linked list.At the beginning of the linked list.Value = 10 ptr = Header->Link new->Data = 10 new->Link = ptr Header->Link = new Steps: new = GetNode(NODE) NULL Header 1000 NULL 10 new 2000 NULL ptr NULL 2000 What if a node is not available? X new->Data = X

Linked List Algorithm: –InsertFront_SL. Input: –Header: Pointer to the starting node of the linked list. –X: Data of the node to be inserted. Output: –Single Linked List with a newly inserted node at the front. Data Structure: –Single Linked List whose address of starting node is known from Header.

Algorithm: InsertFront_SL Steps: new = GetNode(NODE) //Get a memory block of type NODE and stores its pointer in new. If(new == NULL), then print “Memory is Insufficient” Else ptr = Header->Link new->Data = X new->Link = ptr Header->Link = new EndIf Stop

Algorithm: InsertEnd_SL Question: Insert a node in the linked list. NULL Header NULL At the end of the linked list.Value = new NULL Steps: new = GetNode(NODE) 4000 ptr If(new == NULL), then print “Memory Insufficient” Else ptr = Header While(ptr->Link != NULL) ptr = ptr->Link Process(ptr->Data) EndWhile Steps (cntd): new->Data = 10 new->Link = NULL //new->Link = ptr->Link ptr->Link = new EndIf Stop

Algorithm: InsertEnd_SL Question: Insert a node in the linked list. NULL Header At the end of the linked list.Value = NULL Steps: new = GetNode(NODE) ptr If(new == NULL), then print “Memory Insufficient” Else ptr = Header While(ptr->Link != NULL) ptr = ptr->Link EndWhile new->Data = 10 new->Link = NULL //new->Link = ptr->Link ptr->Link = new EndIf Stop Traverse to the end of Single Linked List. 10 new 2000 NULL 2000 new->Data = X

Linked List Algorithm: –InsertEnd_SL Input: –Header: Pointer to the starting node of the linked list. –X: Data of the node to be inserted. Output: –Single Linked List with a newly inserted node at the end. Data Structure: –Single Linked List whose address of starting node is known from Header.

Algorithm: InsertEnd_SL Steps: new = GetNode(NODE) //Get a memory block of type NODE and stores its pointer in new. If(new == NULL), then print “Memory is Insufficient” Else ptr = Header While(ptr->Link != NULL) ptr = ptr->Link EndWhile new->Data = X new->Link = NULL // new->Link = ptr->Link ptr->Link = new EndIf Stop

Algorithm: DeleteFront_SL Question: Delete a node from the linked list. NULL Header At the front of the linked list NULL ptr ptr1 Steps: ptr = Header->Link ptr1 = ptr->Link Header->Link = ptr1 ReturnNode(ptr) Header->Link = ptr->Link Steps: ptr = Header->Link ReturnNode(ptr) Sequence does not matter. Sequence matters.

Algorithm: DeleteFront_SL Question: Delete a node from the linked list. NULL Header At the front of the linked list NULL Steps: ptr = Header->Link ptr1 = ptr->Link Header->Link = ptr1 ReturnNode(ptr) ptr NULL Steps: ptr = Header->Link If(Header->Link == NULL) Else print “List is empty. Deletion not possible” ptr1 = ptr->Link Header->Link = ptr1 ReturnNode(ptr) EndIf

Linked List Algorithm: –DeleteFront_SL Input: –Header: Pointer to the starting node of the linked list. Output: –Single Linked List after eliminating/deleting node from the front of the list in case the list is not empty. Data Structure: –Single Linked List whose address of starting node is known from Header.

Algorithm: DeleteFront_SL Steps: If(Header->Link == NULL), then print “List is Empty. Deletion not possible.” Else ptr = Header->Link ptr1 = ptr->Link Header->Link = ptr1 ReturnNode(ptr) //Return the memory block referenced by ptr to memory bank. EndIf Stop

Algorithm: DeleteEnd_SL Question: Delete a node from the linked list. NULL Header From the end of the linked list NULL 4000 Steps: NULL ptr ptr1 ptr = Header While(ptr->Link != NULL), do EndWhile ptr = ptr->Link ptr1 = ptr Steps: ptr1->Link = NULL ReturnNode(ptr) //ptr1->Link = ptr->Link EndIf If(Header->Link == NULL), then print “List is empty. Deletion not possible” Else (cntd)

Algorithm : DeleteEnd_SL Question: Delete a node from the linked list. NULL Header 20 From the end of the linked list NULL Steps: ptr ptr1 ptr = Header While(ptr->Link != NULL), do EndWhile ptr = ptr->Link ptr1 = ptr ptr1->Link = NULL ReturnNode(ptr) //ptr1->Link = ptr->Link EndIf If(Header->Link == NULL), then print “List is empty. Deletion not possible” Else NULL Stop

Linked List Algorithm: –DeleteEnd_SL Input: –Header: Pointer to the starting node of the linked list. Output: –Single Linked List after eliminating/deleting node from the end of the list in case the list is not empty. Data Structure: –Single Linked List whose address of starting node is known from Header.

Algorithm: DeleteEnd_SL Steps: If(Header->Link == NULL), then print “List is Empty. Deletion not possible.” Else ptr = Header While(ptr->Link != NULL), do ptr1 = ptr ptr = ptr->Link EndWhile ptr1->Link = NULL //ptr1->Link = ptr->Link ReturnNode(ptr) //Return the memory block referenced by ptr to memory bank. EndIf Stop

Algorithm: Search_SL Question: Search for a particular node in the linked list. NULL Header Value = NULL 4000 NULL Header NULL 4000 ptr Search is successful.Address of the element is 3000 (ptr). Output: Search is unsuccessful.Address is NULL. Output:

Algorithm: Search_SL Question: Search for a particular node in the linked list.Value = 15 Steps: ptr = Header While(ptr->Link != NULL) EndWhile ptr = ptr->Link Process(ptr->Data) If(ptr->Data == 15) found = 1 location = ptr, found = 0, location = NULL If(found == 0), then Else print “Search unsuccessful.” print “Search successful.” EndIf Return(location) AND (found == 0), do Conditions

Algorithm: Search_SL Question: Search for a particular node in the linked list. NULL Header Value = NULL 4000 NULL Header NULL 4000 ptr NULL Header NULL 4000 ptr While(ptr->Link != NULL) AND (ptr->Data != 15) Condition:

Algorithm: Search_SL Question: Search for a particular node in the linked list.Value = 15 Steps: ptr = Header While(ptr->Link != NULL) AND (ptr->Data != 15) EndWhile ptr = ptr->Link If(ptr->Data == 15) Else EndIf Return(location) print “Search successful.” print “Search unsuccessful.” location = ptr location = NULL Stop

Algorithm: Search_SL Question: Search for a particular node in the linked list.Value = 15 Steps: ptr = Header While(ptr->Link != NULL) AND (ptr->Data != 15) EndWhile ptr = ptr->Link If(ptr->Data == 15) Else EndIf Return(location) print “Search successful.” print “Search unsuccessful.” location = ptr location = NULL Steps: ptr = Header, found = 0, location = NULL While(ptr->Link != NULL) AND (found == 0) EndWhile ptr = ptr->Link If(ptr->Data == 15) found = 1 location = ptr If(found == 0), then Else print “Search unsuccessful.” print “Search successful.” EndIf Return(location) KEY

Linked List Algorithm: –Search_SL Input: –Header: Pointer to the starting node of the linked list. –KEY: Data to be searched. Output: –Location: Pointer to a node where the KEY belongs or an error message. Data Structure: –Single Linked List whose address of starting node is known from Header.

Algorithm: Search_SL Steps: ptr = Header, found = 0, location = NULL While(ptr->Link != NULL) AND (found == 0) ptr = ptr->Link If(ptr->Data == KEY) found = 1 location = ptr EndIf EndWhile If(found == 0), then print “Search unsuccessful.” Else print “Search successful.” EndIf Return(location) Stop

Algorithm: InsertAny_SL Question: Insert a node in the linked list. NULL Header After node with value = 25.Value = new ptr ptr1 NULL Header NULL 4000 ptr NULL

Algorithm: InsertAny_SL Question: Insert a node in the linked list.After node with value = 25.Value = 15 Steps: ptr = Header While(ptr->Link != NULL) AND (ptr->Data != 25) EndWhile ptr = ptr->Link new = GetNode(NODE) If(new == NULL), then print “Memory Insufficient.” Else If(ptr->Data != 25), then print “25 not found in the linked list.” Else ptr1 = ptr->Link new->Data = 15 new->Link = ptr1 ptr->Link = new EndIf KEY X

Trace Algorithm: InsertAny_SL NULL Header NULL NULL 5000 new 5000 ptr1 NULL ptr = Header While(ptr->Link != NULL) AND (ptr->Data != KEY) EndWhile ptr = ptr->Link new = GetNode(NODE) If(new == NULL), then print “Memory Insufficient.” Else If(ptr->Data != KEY), then print “KEY not found in the linked list.” Else ptr1 = ptr->Link new->Data = X new->Link = ptr1 ptr->Link = new EndIf Steps: Steps: (cntd) ptr KEY = 25X = 15

Linked List Algorithm: –InsertAny_SL Input: –Header: Pointer to the starting node of the linked list. –KEY: Data of the node after which a new node is to be inserted. –X: Data of the node to be inserted. Output: –Node with data X inserted after node with data KEY in a Single Linked List. Data Structure: –Single Linked List whose address of starting node is known from Header.

Algorithm: InsertAny_SL Steps: new = GetNode(NODE) If(new == NULL), then print “Memory Insufficient.” Else ptr = Header While(ptr->Link != NULL) AND (ptr->Data != KEY), do ptr = ptr->Link EndWhile If(ptr->Data != KEY), then print “KEY not found in the linked list.” Else ptr1 = ptr->Link new->Data = X new->Link = ptr1 ptr->Link = new EndIf

Algorithm: DeleteAny_SL Question: Delete a node from the linked list. X Node with value = ptr ptr ptr ptr ptr ptr ptr X 5000 ptr2 X Header X 4000 ptr Header ptr1

Algorithm: DeleteAny_SL Question: Delete a node from the linked list.Node with value = 45 Steps: ptr = Header While(ptr->Link != NULL) AND (ptr->Data != 45), do ptr1 = ptr ptr = ptr->Link EndWhile If(ptr->Data == 45), then ptr2 = ptr->Link ptr1->Link = ptr2 ReturnNode(ptr) Else print “45 not found. Deletion not possible.” EndIf Stop KEY

Trace Algorithm: DeleteAny_SL KEY = 55 X Header X 4000 ptr ptr1 ptr2 NULL Steps: ptr = Header While(ptr->Link != NULL) AND (ptr->Data != KEY), do ptr1 = ptr ptr = ptr->Link EndWhile If(ptr->Data == KEY), then ptr2 = ptr->Link ptr1->Link = ptr2 ReturnNode(ptr) Else print “KEY not found. Deletion not possible.” EndIf Stop Steps: (cntd) X

Linked List Algorithm: –DeleteAny_SL Input: –Header: Pointer to the starting node of the linked list. –KEY: Data of the node to be deleted. Output: –Node with data KEY deleted from the linked list or message on failure. Data Structure: –Single Linked List whose address of starting node is known from Header.

Algorithm: DeleteAny_SL Steps: ptr = Header While(ptr->Link != NULL) AND (ptr->Data != KEY), do ptr1 = ptr ptr = ptr->Link EndWhile If(ptr->Data == KEY), then ptr2 = ptr->Link ptr1->Link = ptr2 ReturnNode(ptr) Else print “KEY not found. Deletion not possible.” EndIf Stop

Algorithm: Merge_SL Question: Join/Merge 2 linked lists into 1 single linked list. X Header X 4000 ptr X Header X 5000 ptr Steps: ptr = Header1 While(ptr->Link != NULL), do EndWhile ptr = ptr->Link ptr1 = Header2->Link Steps: (cntd) ptr->Link = ptr1 Header = Header1 Stop Header ReturnNode(Header2)

Linked List Algorithm: –Merge_SL Input: –Header1: Pointer to the starting node of the 1 st linked list. –Header2: Pointer to the starting node of the 2 nd linked list. Output: –Header: Pointer to the starting node of the merged/joined/combined linked list. Data Structure: –Single Linked List whose address of starting node is known from Header.

Algorithm: Merge_SL Steps: ptr = Header1 While(ptr->Link != NULL), do ptr = ptr->Link EndWhile ptr1 = Header2->Link ptr->Link = ptr1 ReturnNode(Header2) Header = Header1 Stop

Algorithm: Split_SL Question: Split the linked list into 2 linked lists. X From node with value = ptr ptr ptr ptr X X ptr1 X Header X 4000 ptr Header X 7000 Header1 5000

Algorithm: Split_SL Question: Split the linked list into 2 linked lists. X From node with value = ptr ptr ptr ptr X X ptr1 Header X 7000 Header Steps: ptr = Header While(ptr->Link != NULL) AND (ptr->Data != 45), EndWhile ptr = ptr->Link Steps: (cntd) If(ptr->Data == 45) Header1 = GetNode(NODE) ptr1 = ptr->Link Header1->Data = NULL Header1->Link = ptr1 ptr->Link = NULL Else print “45 not found. Split not possible.” KEY

Linked List Algorithm: –Split_SL Input: –Header: Pointer to the starting node of the linked list. –KEY: Data of the node after which the list is supposed to be split. Output: –Header1: Pointer to the starting node of the 2 nd linked list if split is successful or message otherwise. Data Structure: –Single Linked List whose address of starting node is known from Header.

Algorithm: Split_SL Steps: ptr = Header While(ptr->Link != NULL) AND (ptr->Data != KEY), do ptr = ptr->Link EndWhile If(ptr->Data == KEY), then Header1 = GetNode(NODE) ptr1 = ptr->Link Header1->Data = NULL Header1->Link = ptr1 ptr->Link = NULL Else print “KEY not found. Split not possible.” EndIf Stop