Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Presentation: BY D Group

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

Dgroup@mca.

com ************

Presentation
ON

BY
D Group
Member of D group
Privanka Dabhai
Insert at first in single linked list

Praful Aparnathi
Insert at Last in single linked list

Arpan Shah
Insert at Order in single linked list

Narendra Chauhan
Delete in single linked list

Ram Sanjay
Copy in single linked list

Rushabh Bhavsar
MCQ

Bhavisha Purohit
Index Of Linear Linked List

INDEX
1.Introduction
2.Algorithms
3.MCQ
Introduction Of Linked List

Introduction Of Linked List

This subsection describes in detail the


representation of linear lists using linked
allocation. Algorithms such as the insertion of
nodes and the deletion of nodes from a linked
linear list are given.

The programming aspects of linked allocation


are discussed both from the simulation point of
view, using arrays, and from the programmer
defined data type facility available in pascal.
Introduction Of Linked List

Introduction Of Linked List

The first approach is the one which is usually taken in


programming linked represented structures in languages
that do not have pointer or link facilities, such as
FORTRAN,ALGOL 60 and BASIC, while the second
approach is used in languages that do have pointer
facilities, such as Pascal, PL/ISNOBOL,ALGOL 68 and
ALGOL W.
Introduction Of Linked List

Introduction Of Linked List

info Link
Introduction Of Linked List

Introduction Of Linked List


The pointer variable AVAIL contains the address of the top
node in the stack. The address of the next available node
is to be stored in the variable NEW.

If a node is available then the new top most element of the


stack is denoted by LINK(AVAIL). The fields of the node
corresponding to the pointer value of NEW can now be
filled in and the field LINK(NEW) is set to a value which
designates the successor node of this new node.
Introduction Of Linked List
A similar procedure can be formulated for the
return of a discarded node to the availability
stack. If the address of this discarded node is
given by the variable FREE, then the link field
of this node is set to the present value of
AVAIL and the value of FREE becomes the
new value of AVAIL.

We can now formulate an algorithm which


inserts a node into a linked linear list in a
stack like manner.
Algorithms of Linked List

Algorithms
→ Insert at first in single linked list
→ Insert at Last in single linked list
→ Insert at Order in single linked list
→ Delete in single linked list
→ Copy in single linked list
Insert at first in single linked

Insert at first in single linked list

INSERT(X,FIRST)

Where X is a new element and FIRST, a pointer to the first element


of a linked linear list whose typical node contains INFO and LINK fields
as previously described, this function insert X. AVAIL is a pointer to the
top element of the availability stack; NEW is a temporary pointer
variable. It is required that X precede the node whose address is given
to the FIRST.
INSERT(X,FIRST) linked list

Insert at first in single linked list


Step 1: [Underflow?]
if AVAIL= NULL
Then write (“Availability stack underflow”)
return (FIRST)

Step 2: [Obtain address of next free node]


NEW ←AVAIL
Step 3: [Remove free node from availability
node]
AVAIL ← Step
LINK(AVAIL)
4: [Initialize fields node from availability
stack]
INFO(NEW) ← X
LINK(NEW) ← FIRST
Step 5: [Return address of new node]
Return(NEW)
INSERT_LAST(X,FIRST)

Insert at Last in single linked list

INSERT_LAST(X,FIRST)

Where X is a new element and FIRST, a pointer to the first


element of a linked linear list whose typical node contains INFO and
LINK fields as previously described, this function insert X. AVAIL is a
pointer to the top element of the availability stack; NEW & SAVE are
temporary pointer variable. It is required that X be inserted at the end of
the list.
INSERT_LAST(X,FIRST)

Insert at Last in single linked list


Step 1: [Underflow?]
if AVAIL= NULL
then write (“Availability stack underflow”)
return (FIRST)

Step 2: [Obtain address of next free node]


NEW ← AVAIL

Step 3: [Remove free node from availability node]


AVAIL ← LINK(AVAIL)

Step 4: [Initialize fields node from availability stack]


INFO(NEW) ← X
LINK(NEW) ← NULL
INSERT_LAST(X,FIRST)

Insert at Last in single linked list


Step 5: [Is the list EMPTY?]
if FIRST= NULL
then Return(NEW)

Step 6: [Initiate search for the last node]


SAVE ← FIRST

Step 7 : [Search for end of list]


Repeat while LINK(SAVE) ≠ NULL
SAVE ← LINK(SAVE)

Step 8 : [Set LINK Field of last node to NEW]


LINK(SAVE) ← NEW

Step 9: [Return first node]


Return(FIRST)
INSERT_ORD(X,FIRST)

Insert at Order in single linked list

INSERT_ORD(X,FIRST)

Where X is a new element and FIRST, a pointer to the first


element of a linked linear list whose typical node contains INFO and
LINK fields as previously described, AVAIL is a pointer to the top
element of the availability stack; NEW & SAVE are temporary pointer
variable. It is required that X be inserted so that it preserves the ordering
of the terms in increasing order of their INFO fields.
INSERT_ORD(X,FIRST)

Insert at Order in single linked list


Step 1: [Underflow?]
if AVAIL= NULL
then write (“Availability stack underflow”)
return (FIRST)

Step 2: [Obtain address of next free node]


NEW ← AVAIL

Step 3: [Remove free node from availability node]


AVAIL ← LINK(AVAIL)

Step 4: [Copy information contents into new node]


INFO(NEW) ← X

Step 5: [Is the list EMPTY?]


if FIRST= NULL
then Return(NEW)
INSERT_ORD(X,FIRST)

Insert at Order in single linked list


Step 6: [Does the new node precede all others in the list?]
if INFO(NEW) ≤ INFO(FIRST)
then LINK(NEW) ← FIRST
Return(NEW)

Step 7 : [Initialize temporary pointer]


SAVE ← FIRST

Step 8 : [Search for predecessor of new node]


Repeat while LINK(SAVE) ≠ NULL and INFO(LINK(SAVE)) ≤ INFO (NEW)
SAVE ← LINK(SAVE)

Step 9 : [Set LINK Field of new node and its predecessor]


LINK(NEW) ← LINK(SAVE)
LINK(SAVE) ← NEW

Step 10: [Return first node]


Return(FIRST)
DELETE(X,FIRST)

Delete in single linked list

Where X and FIRST, pointer Variable


whose values denote the address of a node
in linked list and the address of the first
node in the linked list, respectively, this
procedure deletes the node whose address
is given by X. TEMP is used to find the
desired node, and PRED keeps track of the
predecessor of TEMP. note that FIRST is
changed only when X is the first elements
of the list.
DELETE(X,FIRST)

Delete in single linked list


Step 1: [EMPTY LIST?]
if FIRST= NULL
then write (“Underflow”)
return

Step 2: [Initialize search for X]


TEMP ← FIRST

Step 3: [Find X]
Repeat thru Step 5 while TEMP ≠ x and
LINK(TEMP) ≠ NULL

Step 4: [Update Predecessor Marker ]


PRED ← TEMP

Step 5: [Move to next node]


TEMP ← LINK(TEMP)
DELETE(X,FIRST)

Delete in single linked list


Step 6: [End of the list?]
if TEMP ≠ X
then write(„NODE NOT FOUND”)
return

Step 7: [Delete X]
if X = FIRST (is X the First NODE?)
then FIRST ← LINK(FIRST)
else LINK(PRED) ← LINK(X)

Step 8 : [Return node to availability area]


LINK(X) ← AVAIL
AVAIL ← X
return
COPY(FIRST)

Copy in single linked list

Given FIRST, a pointer to the first


node in the linked list, this function makes a
copy of this list. A typical node in the given
list consists of INFO and LINK fields. The new
list is to contain nodes whose information
and pointer fields are denoted by FIELD and
PTR, respectively. The address of the first
node in the newly created list is to be placed
in BEGIN. NEW,SAVE and PRED are pointer
variable.
COPY(FIRST)

Copy in single linked list


Step 1: [EMPTY LIST?]
if FIRST= NULL
then write (“Underflow”)
return

Step 2: [Copy first node]


if AVAIL = NULL
then write(„Availability Stack UNDERFLOW‟)
return(0)
else NEW ← AVAIL
AVAIL ← LINK(AVAIL)
FIELD(NEW) ← INFO(FIRST)
BEGIN ← NEW

Step 3: [Initialize traversal]


SAVE ← FIRST
COPY(FIRST)

Copy in single linked list


Step 4: [Move to next node if not at the end of list]
Repeat through step 6 while LINK(SAVE) ≠ NULL

Step 5: [Update Predecessor and save pointers ]


PRED ← NEW
SAVE ← LINK(SAVE)

Step 6: [Copy Node]


if AVAIL = NULL
then write(„Availability Stack UNDERFLOW‟)
return(0)
else NEW ← AVAIL
AVAIL ← LINK(AVAIL)
FIELD(NEW) ← INFO(SAVE)
PTR(PRED) ← NEW
COPY(FIRST)

Copy in single linked list


Step 7 : [Set Link of last node and return]
PTR(NEW) ← NULL
Return NULL
return
Linear Linked List MCQ PPT
Linear Linked List MCQ PPT

1)A linear Structure in which the individual elements are joined together by
references to other elements in the structure is known as a_________
•Tree (b) Vector (c) Linked list (d) Table

2)A list that restricts insertions and removals to the front ( or top ) is known as a
(b) Linked list (b) stack (c) queue (d) frontal List

3)To Access an item in a singly linked list you must usa a _______ algorithm.
(b) Traversal (b) access (c) removal (d) insertion

4)Linked lists are collections of data items “lined up in row”-insertions and deletion can be made
only at the front and the back of a linked list.
(b) TRUE (b) FALSE

5)Self-referential objects can be linked together to from useful data structures such as
lists,queues,stacks and tree
(a) TRUE (b) FALSE
Linear Linked List MCQ PPT

6)The situation when in a linked list START=NULL is


(a) Underflow (b) overflow (c) housefull (d) saturated

7)The link field in the last node of the linked list contains
(a) NULL (b) link to the first node (c) pointer to the next element (d) Zero value
8)To delete a node at the beginning of the list, the location of the list is modified as the
address of the.
(a) Second element in the list (b)First element in the list (c) Last element in the list.

9) In the linked list representation of the stacks, the top of the stack is represented by
(a)The last node (b) Any of the nodes (c) First node

10) A linked list in which the last node points to the first is called a
(a) Doubly linked list (b) Circular list (c) Generalized list
THANK
YOU

You might also like