1 DATA STRUCTURES. 2 LINKED LIST 3 PROS Dynamic in nature, so grow and shrink in size during execution Efficient memory utilization Insertion can be.

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

Chapter 25 Lists, Stacks, Queues, and Priority Queues
TK1924 Program Design & Problem Solving Session 2011/2012
1
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (Parallel Algorithms) Robin Pomplun.
Copyright © 2003 Pearson Education, Inc. Slide 1.
Chapter 17 Linked Data Structures. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives Nodes and Linked Lists Creating,
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
Chapter 3: Linked List Tutor: Angie Hui
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
Exit a Customer Chapter 8. Exit a Customer 8-2 Objectives Perform exit summary process consisting of the following steps: Review service records Close.
Create an Application Title 1A - Adult Chapter 3.
Custom Statutory Programs Chapter 3. Customary Statutory Programs and Titles 3-2 Objectives Add Local Statutory Programs Create Customer Application For.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Table 12.1: Cash Flows to a Cash and Carry Trading Strategy.
PP Test Review Sections 6-1 to 6-6
Chapter 17 Linked Lists.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
Linked List A linked list consists of a number of links, each of which has a reference to the next link. Adding and removing elements in the middle of.
DATA STRUCTURES AND ALGORITHMS Prepared by İnanç TAHRALI
Linked Lists.
Linked Lists Chapter 4.
Data Structures: A Pseudocode Approach with C
Data Structures ADT List
Chapter 24 Lists, Stacks, and Queues
11 Data Structures Foundations of Computer Science ã Cengage Learning.
Data Structures Using C++
Double-Linked Lists and Circular Lists
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
LINKED LIST Presented By Engr. Reema Tariq Mughal.
Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence.
CSCI2100B Linked List Jeffrey
CSE Lecture 12 – Linked Lists …
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
VOORBLAD.
Review Pseudo Code Basic elements of Pseudo code
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
Adding Up In Chunks.
Copyright © 2013 by John Wiley & Sons. All rights reserved. HOW TO CREATE LINKED LISTS FROM SCRATCH CHAPTER Slides by Rick Giles 16 Only Linked List Part.
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
Analyzing Genes and Genomes
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Pointers and Linked Lists.
Topic 16 Sorting Using ADTs to Implement Sorting Algorithms.
Energy Generation in Mitochondria and Chlorplasts
Murach’s OS/390 and z/OS JCLChapter 16, Slide 1 © 2002, Mike Murach & Associates, Inc.
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
Reference: Vinu V Das, Principles of Data Structures using C and C++
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Presentation transcript:

1 DATA STRUCTURES

2 LINKED LIST

3 PROS Dynamic in nature, so grow and shrink in size during execution Efficient memory utilization Insertion can be done at specified location Many complex applications can be carried out using Linked List CONS Occupy more memory Random access of data is some what cumbersome & Time consuming WHY & WHY NOT ?

4 A linked list is a linear collection of specially designed data elements, called NODE, linked to one another by means of Pointer. Each NODE is divided In two parts, first part contains the information and second part contains the address of the next node. Need a head to point to the first node of the list. Otherwise we wont know where the start of the list is. The next field in the last node points to nothing. We will place the memory address NULL Struct Node { }; TERMINOLOGY int DATA Struct node *Next DATANext

head head 1065 ACTUAL PICTURE IN MEMORY

6 add(9): Create a new node in memory to hold 9 Node* newNode = new Node(9); Link the new node into the list 9newNod e head current size=5 6 9 newNod e OPERATION

head SINGLY LINKED LIST 2681 head DOUBLY LINKED LIST head current CIRCULAR LINKED LIST TYPES

8 SINGLY LINKED LIST

9 headNodesize=0 List list; 2 headNode currentNode size=1 lastcurrentNode list.add(2); 26 headNode currentNode size=2 lastcurrentNode list.add(6); list.add(8); list.add(7); list.add(1); 2671 headNode currentNode size=5 lastcurrentNode 8

10 30 START Create Node With DATA (30) 30 START Create Node With DATA (40) at END START Create Node With DATA (10) at BEGINING START Create Node With DATA (20) at SECOND Position START Create Node With DATA (20) at LAST Position

11 Insert node at BEGINING 1.Input DATA to be inserted 2.Create a NewNode 3.NewNode -> DATA = DATA 4.If (START == NULL) NewNode -> Next = NULL else NewNode -> Next = START 5.START = NewNode 6.Exit ALGORITHM

12 1.Input DATA to be inserted 2.Create a NewNode 3.NewNode - > DATA = DATA 4.NewNode -> Next = NULL 4.If (START == NULL) START = NewNode else TEMP = START while (TEMP -> NEXT != NULL) TEMP = TEMP -> NEXT 5.TEMP -> NEXT = NewNode 6.Exit ALGORITHM Insert node at END

13 1.Input DATA & POS to be inserted 2.Initialize TEMP = START & K =0 3.Repeat step 3 while K < POS (a) TEMP = TEMP -> NEXT (b) if (TEMP == NULL) Node Is Not In The List Exit (c) K = K Create a New Node 5.NewNode -> DATA = DATA 6.NewNode -> Next = TEMP -> NEXT 7.TEMP -> Next = NewNode 8.EXIT. ALGORITHM Insert node at SPECIFIED LOCATION

14 1.Input DATA to be deleted 2.If (START-> DATA = = DATA) (a) TEMP = START (b) START = START -> Next (c) free (TEMP) (d) Exit 3. HOLD = START 4. While (HOLD -> Next -> Next != NULL) (a) if (HOLD -> Next ->DATA == DATA) (i) TEMP = HOLD -> Next (ii) HOLD -> Next = TEMP -> Next (iii) free (TEMP) (iv) Exit. (b) HOLD = HOLD -> Next 5. if (HOLD -> Next -> DATA == DATA ) (a) TEMP = HOLD -> Next (b) free (TEMP) (c) HOLD -> Next = NULL (d) Exit. 6. DATA not Found 7. Exit. 1 st Location Ith Location Last Location ALGORITHM DELETE NODE

15 1.Input DATA to be searched 2.Initialize TEMP = START & POS = 1 3.Repeat Steps 4, 5 & 6 until TEMP = NULL 4.If (TEMP -> DATA == DATA) (a) DATA found at POS (b) Exit. 5. TEMP = TEMP -> Next 6. POS = POS If (TEMP = NULL) DATA Not Found in LIST 8. Exit. ALGORITHM SEARCHING NODE

16 1.If (START == NULL) (a) LIST is Empty (b) Exit. 2.Initialize TEMP =START 3.Repeat Step 4 and 5 Until TEMP = NULL 4.Display TEMP -> DATA 5.TEMP = TEMP -> Next 6.Exit. ALGORITHM DISPLAY NODES

17 10NULL Push (10) TOP 20 Push (20) 10NULL TOP 30 Push (30) 20 TOP 10NULL 20 Pop() 10NULL TOP 40 Push (40) 20 TOP 10NULL STACK – Using LINKED LIST

18 PUSH 1.Input DATA to be pushed 2.Create a New Node 3.NewNode -> DATA = DATA 4.NewNode -> Next = TOP 5.TOP = NewNode 6.Exit. ALGORITHM

19 ALGORITHM POP 1.If ( TOP == NULL ) STACK Is Empty 2.Else (a). TEMP = TOP (b). Poped Data : TOP -> DATA (c). TOP = TOP -> Next (d). TEMP -> Next = NULL (e). Free (TEMP) 3.Exit.

20 10NULL Push (10) Front 10 Push (20) 20NULL 10 Push (30) 2030NULL 20 Pop() 30NULL 20 Push (40) 3040NULL Rear Front Rear Front Rear NULL QUEUE – Using LINKED LIST

21 PUSH 1.Input DATA to be pushed 2.Create a New Node 3.NewNode -> DATA = DATA 4.NewNode -> Next = NULL 5.If ( REAR != NULL ) REAR -> Next = NewNode 5.REAR = NewNode 6.Exit. ALGORITHM

22 ALGORITHM POP 1.If ( FRONT == NULL || FRONT > REAR ) QUEUE Is Empty 2.Else (a). Popped Data : FRONT -> DATA (b). If (FRONT != REAR ) FRONT = FRONT -> Next Else FRONT = NULL 3.Exit.

23 DOUBLY LINKED LIST

24 Moving forward in a singly-linked list is easy; moving backwards is not so easy. To move back one node, we have to start at the head of the singly- linked list and move forward until the node before the current. To avoid this we can use two pointers in a node: one to point to next node and another to point to the previous node Struct node { } TERMINOLOGY int DATA; Struct node *next; Struct node *prev; DATAnext prev

25 Need to be more careful when adding or removing a node. Need to be more careful when adding or removing a node. size= head current Insert Node

26 1.NewNode->Next = current->Next size= head current 1 9 newNode 1 Insert Node

27 size= head current 1 9 newNode NewNode->prev = current Insert Node

28 size= head current 1 9 newNode current->next->prev = NewNode Insert Node

29 size= head current 1 9 newNode current->next = NewNode Insert Node

30 Size= head current 1 9 newNode current = NewNode Insert Node

31 1.Input DATA & POS 2.Initialize TEMP = START & i=1 3.while ( i < POS ) & (TEMP != NULL) TEMP = TEMP -> Next 4.If (TEMP != NULL) & I = POS a). Create a NewNode b). NewNode -> DATA = DATA c). NewNode -> next = TEMP -> next d). NewNode -> prev = TEMP e). TEMP -> next - > prev = NewNode f). TEMP - > next = NewNode 5.Else Position Not Found 6.Exit INSERT NODE

32 1.Input DATA to be deleted 2.Initialize TEMP = START 3.while (TEMP -> next -> DATA != DATA) TEMP = TEMP -> next 5.HEAD = TEMP TEMP = TEMP -> next 6.HEAD -> next = TEMP -> next 7.TEMP -> next -> prev = HEAD 8.Exit. DELETE NODE

33 CIRCULAR LINKED LIST

34 The next field in the last node in a singly-linked list is set to NULL. Doubly-linked lists have two NULL pointers: prev in the first node and next in the last node. A way around this potential hazard is to link the last node with the first node in the list to create a circularly-linked list. TERMINOLOGY

head current size= head current size=5 6 View of CIRCULAR QUEUE

start size=5 Traversing a CIRCULAR QUEUE Display(Start) 1.If Start = NULL Print List is empty!! End If 2.Set TEMP = Start 3.Do Print TEMP -> DATA Set TEMP = TEMP -> next While TEMP != Start 4. Exit.

start Insertion in the Begining Insert_beg(Start) 1.If Start = NULL Set Start=nptr Set Start -> next = Start Else Set TEMP = Start While TEMP ->next !=Start Set TEMP = TEMP -> next End While Set nptr -> next = Start Set Start = nptr Set TEMP -> next = Start End If 2.Exit. nptr 4 4 start (a) (b)

start Insertion at the End Insert_beg(Start) 1.If Start = NULL Set Start=nptr Set Start -> next = Start Else Set TEMP = Start While TEMP ->next !=Start Set TEMP = TEMP -> next End While Set TEMP -> next = nptr Set nptr -> next = Start End If 2.Exit. nptr (b) 4 temp

start Deletion from Begining delete_beg(Start) 1. If Start = NULL Print Underflow: List is empty! End If 2.Set TEMP = Start 3.Set ptr = TEMP 4.While ptr ->next !=Start Set ptr = ptr -> next End While 5.Set Start = Start -> next 6.Set ptr -> next = Start 7.Deallocate TEMP 8.Exit. (b) ptrtemp

start Deletion from the End delete_end(Start) 1. If Start = NULL Print Underflow: List is empty! End If 2.Set TEMP = Start 3.If temp -> next = start Set Start = NULL Else While TEMP ->next !=Start Set save = TEMP Set TEMP = TEMP -> next End While Set save -> next = Start End If 4.Deallocate TEMP 5.Exit. (b) tempsave