# Linked List 3 Stack 33 Queue 40 - By Dhaval S Sheth(9033271276) 3 Linked List Singly Linked List Explain Singly Linked list: - Ans. A singly linked list is a linked list in

• Published on
27-May-2018

• View
216

1

Embed Size (px)

Transcript

• Devloped By Dhaval S Sheth(9033271276) 1

Linked List .................................................................... 3 Singly Linked List .............................................................. 3 Doubly Linked List ............................................................. 6 Explain Doubly Linked list: - ............................................... 6 Circular Singly Linked List ................................................. 10 Order Linked List: ............................................................ 15 Application of Linked list: ................................................. 16 Graphical Representation of Linked List .............................. 19 Graphical Representation of Doubly Linked List ................... 25 Graphical Representation of Circular Linked List .................. 28

Stack ......................................................................... 33 Application of the stack: ................................................... 34 Algorithm for push operation ............................................ 35 Operation: POP I from the stack. ....................................... 36 Operation: PEEP 2nd element from the stack. .................... 37

Queue ........................................................................ 40 What is queue? ............................................................... 40 Implementation of Queue: ................................................ 40 Algorithm for simple queue:- ............................................ 42 Insert function: .................................................................... 42 Delete Function .................................................................... 43 Print function ....................................................................... 44 Search Function .................................................................... 44 Update function .................................................................... 44

Circular Queue ................................................................ 45 Advantages of circular queue over simple queue ....................... 45 Disadvantages of Circular queue ............................................. 46

Algorithm for Circular Queue: - ......................................... 46 Insert function: .................................................................... 46 Delete Function: ................................................................... 47 Print Function: ...................................................................... 47

Application of Queue: ....................................................... 48 Tree .......................................................................... 49 Definition:- ..................................................................... 49 Explain Tree:- ................................................................. 49 Binary Tree:- .................................................................. 50 Representation OR Implementation of Binary Tree. .............. 51 Operation Of Binary Tree ....................................................... 53 Algorithm for preorder:- ........................................................ 54 Inorder:- ............................................................................. 54 Algorithm For Inorder Traversal of Binary Tree:- ....................... 56

• Devloped By Dhaval S Sheth(9033271276) 2

Postorder Traversal:- ............................................................ 56 Algorithm for Postorder Traversal of Binary Tree. :- .................. 57

Application of Binary Tree:- .............................................. 57 Graphs ....................................................................... 59

• Devloped By Dhaval S Sheth(9033271276) 3

Singly Linked List Explain Singly Linked list: - Ans. A singly linked list is a linked list in which each node contains only one link field pointing the next node in the list. Each node is divided in two parts.

1. Information part. 2. Contains address of next node.

NULL Head = Pointer Variable Points to first element (node) of in the list. NULL=It indicates the end of the list. 1. Algorithm for the Creation of the Simple Linked List Function CREATE(X, FIRST) [Given X, a new element, and FISRT, a pointer to the first element of a Linked linear list whose typical node contains INFO and LINK fields as in above fig, this function inserts X.]

• Devloped By Dhaval S Sheth(9033271276) 4

1. [Repeat thru step 5] Repeat while Choice! = n 2. [Allocate the New node] NEW NODE 3. [Initialize the fields of new node] INFO (NEW) = X LINK (FIRST) = NEW 4. [Want to insert another node] Read (Choice) 5. [Set the LINK field of Last inserted element] LINK (FIRST) = NULL 6. [Finished] Return Algorithm for the Inserting the element in the Simple Linked List

• Devloped By Dhaval S Sheth(9033271276) 5

Procedure PRINT (HEAD) [This Procedure print the information field of the list and HEAD is the first element of the list] 1. [Repeat step thru] Repeat while LINK (HEAD) != NULL 2. [Print the Information] Write (INFO (HEAD))

• Devloped By Dhaval S Sheth(9033271276) 6

• Devloped By Dhaval S Sheth(9033271276) 7

NULL: - It indicates the end of the list in each direction. Each node having three fields.

1. Pointer to previous node. 2. Information field. 3. Pointer to next node.

Inserting node in to or Deleting one node from the list is much easier

• Devloped By Dhaval S Sheth(9033271276) 8

Insertion in the middle of a doubly linked list

A Left-most insertion in a doubly linked list

• Devloped By Dhaval S Sheth(9033271276) 9

Algorithm for the insert an element in the doubly list

• Devloped By Dhaval S Sheth(9033271276) 10

• Devloped By Dhaval S Sheth(9033271276) 11

Explain Singly Circular Linked List: Ans. A singly circular linked list is a linked list in which the last node of the list point to the first node in the list. In Circular linked list, we can start at any node in the list & travel the whole list. For this reason we can make our external pointer to the list pointer to any node & still access all the node in the list. Representation of Circular Linked list:

Ans. 1. It is concerned with the accessibility of a node. 2. In Circular list every node is accessible from given node. i.e.: -

From this given node all nodes can be reached by many changing through the list.

3. It concerns the deletion operation. In singly linked list to delete desired node, it is necessary to give the address of first node of the list.

4. This necessity result from the fact that in order to delete desired node. The predecessor of this node has to be found.

5. To find the predecessor required that a search could be carried out by changing through node from the first node of the list such requirement doesnt exist for circular list.

• Devloped By Dhaval S Sheth(9033271276) 12

Ans. It is possible that without some care in processing, it is possible to get in to an infinite loop. Solution of Disadvantage: Ans. In processing a circular list, it is important that we are able to delete the end of list. This deletion of end is achieved by placing special node, which can be easily identified in the circular list. This special node is often called the list head of the circular list. Representation of circular list with list head is given as in following figure. Head Algorithm for the Creation of the Circular list

Procedure CREATE (TEMPHEAD) [This procedure creates the circular list and TEMPHEAD is the pointer variable which points the first element of the list] 1. [Save the address of the first element] SAVE = TEMPHEAD 2. [Repeat thru step 5] Repeat while Choice! = n 3. [Allocate the New node] NEW NODE 4. [Initialize the fields of new node] INFO (NEW) = X LINK (SAVE) = NEW SAVE = NEW 5. [Want to insert another node] Read (Choice) 6. [Set the LINK field of Last inserted element] LINK (SAVE) = TEMPHEAD

• Devloped By Dhaval S Sheth(9033271276) 13