Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

AVAIL CONCEPT IN DSA, Schemes and Mind Maps of Data Structures and Algorithms

AVAIL CONCEPT IN DSA ALONG WITH ALL TOPICS COVERED

Typology: Schemes and Mind Maps

2021/2022

Uploaded on 10/12/2022

pranjali-pandey-1
pranjali-pandey-1 🇮🇳

5

(3)

5 documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Data Structures
Lecture 6: Linked List Operations
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download AVAIL CONCEPT IN DSA and more Schemes and Mind Maps Data Structures and Algorithms in PDF only on Docsity!

Data Structures

Lecture 6: Linked List Operations

Outlines

  • (^) Introduction
  • (^) Traversing a Linked List
  • (^) Searching a Linked List
  • (^) Memory Allocation & Garbage Collection
  • (^) Overflow and Underflow
  • (^) Review Questions

Traversing a Linked List

  • (^) PTR is a pointer variable which points to the node currently being processed.
  • (^) LINK [PTR] points to the next node to be processed.

 Algorithm (Traversing a linked list)

  1. Set PTR = START. [Initialize pointer PTR]
  2. Repeat step 3 and 4 while PTR ≠ NULL.
  3. Apply PROCESS to INFO[PTR].
  4. Set PTR = LINK [PTR]. [PTR points to next node] [End of Step 2 Loop.]
  5. EXIT

Problems

  • (^) Write an algorithm to modify each element of an integer linked list such that (a) each element is double of its original value. (b) each element is sum of its original value and its previous element.
  • (^) Write an algorithm to find out the maximum and minimum data element from an integer linked list.

Searching a Linked List (1)

 List is Unsorted

SEARCH (INFO, LINK, START, ITEM, LOC)

  1. Set PTR = START.
  2. Repeat Step 3 While PTR ≠ NULL.
  3. If ITEM = INFO [PTR], then: Set LOC = PTR, and EXIT. Else: Set PTR = LINK [PTR]. [PTR points to next node] [End of if Structure.] [End of step 2 Loop.]
  4. Set LOC = NULL. [Search is Unsuccessful.]
  5. Exit. [Return LOC and Exit.]

Searching a Linked List (2)

 List is Sorted

SEARCH (INFO, LINK, START, ITEM, LOC)

  1. Set PTR = START.
  2. Repeat Step 3 While PTR ≠ NULL.
  3. If ITEM > INFO [PTR], then: PTR = LINK [PTR]. [PTR points to next node] Else if ITEM = INFO [PTR], then: Set LOC = PTR, and EXIT. [Search is successful.] Else: Set LOC = NULL, and EXIT. [ITEM exceeds INFO[PTR]…] [End of if Structure.] [End of step 2 Loop.]
  4. Return LOC.
  5. Exit.

Free Pool

  • (^) Linked list with free pool or list of Available space. INFO LINK START 1 2 3 AVAIL 4 5 6 7 8 9 10 A E C B D F 0 6 9 7 8 4 3 1 0 5 2 10

Garbage Collection

  • (^) Garbage collection is a technique of collecting all the deleted spaces or unused spaces in memory.
  • (^) The OS of a computer may periodically collect all the deleted space onto the free-storage list.
  • (^) Garbage collection may take place when there is only some minimum amount of space or no space is left in free storage list.
  • (^) Garbage collection is invisible to the programmer.

Overflow and Underflow

Overflow: When a new data are to be inserted into a data

structure but there is no available space i.e. the free storage list is empty.

  • (^) Overflow occurs when AVAIL = NULL , and we want insert an element.
  • (^) Overflow can be handled by printing the ‘OVERFLOW’ message and/or by adding space to the underlying data structure.

Overflow and Underflow

Underflow: When a data item is to be deleted from an

empty data structure.

  • (^) Underflow occurs when START = NULL , and we want to delete an element.
  • (^) Underflow can be handled by printing the ‘UNDERFLOW’ message.

Review Questions

  • (^) Write an algorithm to find out the maximum and minimum data element from an integer linked list.
  • (^) What is the condition of Overflow and underflow?
  • (^) What are the steps followed during garbage collection?