28
BY D Group Presentation ON ************ [email protected]

linked list

Embed Size (px)

DESCRIPTION

leniar linklist ppt with facebook theme

Citation preview

Page 1: linked list

BYD Group

PresentationON

************[email protected]

Page 2: linked list

Privanka DabhaiInsert at first in single linked list

Praful AparnathiInsert at Last in single linked list

Narendra ChauhanDelete in single linked list

Ram SanjayCopy in single linked list

Bhavisha Purohit

Rushabh BhavsarMCQ

Arpan ShahInsert at Order in single linked list

Member of D group

Page 3: linked list

Index Of Linear Linked List

1.Introduction2.Algorithms3.MCQ

INDEX

Page 4: 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

Page 5: linked list

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.

Page 6: linked list

Introduction Of Linked List

Introduction Of Linked List

info Link

Page 7: linked list

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.

Page 8: 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.

Introduction Of Linked List

Page 9: linked list

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

Page 10: 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 at first in single linked

Insert at first in single linked list

Page 11: linked list

Step 3: [Remove free node from availability node]

AVAIL ← LINK(AVAIL)

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

return (FIRST)

INSERT(X,FIRST) linked list

Insert at first in single linked list

Step 2: [Obtain address of next free node] NEW ←AVAIL

Step 4: [Initialize fields node from availability stack]

INFO(NEW) ← X LINK(NEW) ← FIRST

Step 5: [Return address of new node] Return(NEW)

Page 12: 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

Page 13: linked 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

Page 14: linked list

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)

Page 15: 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

Page 16: 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

Page 17: 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)

INSERT_ORD(X,FIRST)

Insert at Order in single linked list

Page 18: 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

Page 19: 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

Page 20: 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

DELETE(X,FIRST)

Delete in single linked list

Page 21: 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

Page 22: 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

Page 23: 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

Page 24: linked list

COPY(FIRST)

Copy in single linked list

Step 7 : [Set Link of last node and return] PTR(NEW) ← NULL Return NULL return

Page 25: linked list

Linear Linked List Linear Linked List MCQ PPT

Page 26: linked list

Linear Linked List 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_________ (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(a) Linked list (b) stack (c) queue (d) frontal List

3)To Access an item in a singly linked list you must usa a _______ algorithm.(a) 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.

(a) 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

Page 27: linked list

Linear Linked List 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

Page 28: linked list

THANKYOU

THANKYOU