Homework No:3: CAP205: Data Structure
Homework No:3: CAP205: Data Structure
Homework No:3: CAP205: Data Structure
• 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
THE PROCES IS THE FOLLOWING:
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.
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…
Struct f
{
Int info;
Struct f *next;
{node;
Struct
{
Node *front;
Node *front;
}queue;
A stack can be represented as the linked list also.. so it is called the linked stack. The array based
representation of stack suffers from following limitation.
• Size must be known
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
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.
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.