Part-A 1. write algorithm to delete a given node in two way link list Ans. Delete the given node: • Forward[back[loc]]= forward[loc] And back[forward[loc]]=back[loc] • Send the deleted node to the avail list

• Forward[loc]=avail and avail=loc • Exit


2. Discuss the Concept to insert an element in Link List at a given position And also implement that concept to insert ITEM=38 in the list at the location 3 where the list is as following: 46,39,48,49,58 Ans : In the one way list we simply assign the new node. And then we assign the link of new node to the next node of the location. And the link of the node of the before location to the new. Now the new node is inserted in between the two location.

• Set new=avail and avail=link[avail] • Info[new]=item=38 • If loc=NULL THEN [INSERT AS FIRST NODE]


INSERTING ON THE 3RD LOCATION 463948  38 4958 LET THE C=38

3. Discuss the Concept to insert an element in Link List where the list is sorted . And also implement that concept to insert ITEM=45where the list is as following: 33,44,55,66,88,99 Ans .. For inserting the item in the sorted link list ,we have to find the location of the item. In the given question the item is the 45. And the location is the after 44 and the before the 55. So if we want to insert the item in the link list then we have to find the location firstly. . the item will inserted between the 44 and 55. For finding the location: • If Start=null then LOC=NULL and return • If ITEM<INFO[START],then set LOC=NULL and return • Set SAVE = START and PTR=LINK[START] • Repeat step 5 and 6 while PTR!=NULL • If ITEM<INFO[PTR], then: • Set LOC:=SAVE and return • SAVE=PTR and PTR=LINK[PTR] • Set LOC=SAVE • Return

After finding the element location then we insert the item on this location.. • IF AVAIL=NULL then write OVERFLOW and EXIT • SET NEW=AVAIL and AVAIL=LINK[AVAIL] • Set INFO[NEW]= ITEM • IF LOC=NULL then • Set LINK[NEW]=START and START=NEW • ELSE set LINK[NEW]=LINK[LOC] and LINK[LOC]=NEW • EXIT Both the two algorithm is used to insert the element in the sorted list… The item will inserted like the following procedure: 33,44, 45 ,55,66,88,99 4. How queues and stacks are represented in memory? Ans. Queue can also be represented in the memory using a linear array or a linear linked list. To start with , let us consider array representation of queue. Can represent the queue two type: • Array • Link list

Array: for array queue the two varable is required front and rear that holed the index of the first and the last element of the queue..

The memory is assign as follow: #define capacity 10 Struct { Int front,rear; Int element[capacity]; }queue; Queue q; From the above coding we can assign the array memory. And we can assign memory with the link list also.. The momory is declared as follow: Struct f { Int info; Struct f *next; {node; Struct { Node *front; Node *front; }queue; Stack in the memory: Like the queue we can represent the stack usin array and link list both. It work on the concept of the first come last out.. for this we need the variable named top that hold the index of the top element of the stack and an array to hold the element of the stack.. in stack the concept will implemented as: #define max 10 Struct { int top; Int element[max]; }stack; Stack s; A stack can be represented as the linked list also.. so it is called the linked stack. The array based repesention of stack suffers from following limitation. • Size must be known 5. Write algorithm to delete last node in circular linked list? Ans.: To delete any node in a circular linked list, you need a pointer to the Prior node, the Current node, and the Next node. If the list is not doubly linked, you don't need the pointer to the Prior node. You can get Prior and Next from Current (Current.prior and or you

can walk the list looking for a node that points to Current. Then, set = Next, Next.prior = Prior, and delete Current. If you have a single pointer to one of the nodes, and that node is being deleted, you will also need to update that pointer accordingly Part-B 6. Write algorithm to convert infix expression to prefix expression? Ans. We will represent simplification as a list of the rules ,much like the rules for student and eliza. But since each simplification rule is an algebraic equation ,we will storeeach one as an exp rather than a rule. We have choice as to how general we wat our infix notation to be. Consider: (((a*(x2))+(b*x))+c) (a*x2+b*x+c) (a x 2 + b x+c) A x2 +b*x+c The first is fully parenthesized infix, the seci=on makes use of the operator precedence and the third makes use of imlicit multiplication as well as operator precedence. The fourth requires a lexical analyzer to break lisp symbol into pieces.. 7. Write advantages and disadvantages of recursion.write various application and problem solving example that require the use of recursion? Ans. Advantage of the recursion: • The code may be much easier to write. • Some situations are naturally recursive Disadvantage of recursion: • There is shallow recursion and there is deep recursion. • Shallow recursion will not overflow the stack, but it may take an excessively long time to execute. • Deep recursion is generally much faster, but it may overflow the stack. Application in the factorial: function factorial( x ) { if x equals 0 then return 1 endif

return x * factorial( x-1 ) } 8. Write procedure to delete nth element from queue ? Ans:A data structure in which objects are added to one end, called the tail, and removed from the other, called the head (- a FIFO queue). The term can also refer to a LIFO queue or stack where these ends coincide. Algorithm:This procedure deletes an element from a queue and assigns it to the variable ITEM. 1. If FRONT :=NULL,then:Write: UNDERFLOW and return. 2. Set ITEM:=QUEUE[FRONT] 3. If FRONT:=REAR,then ; Set FRONT:=NULL and REAR:=NULL Else if FRONT:=N,then; Set FRONT:=1. Else : FRONT:=FRONT+1. 4.Return.