0% found this document useful (0 votes)
17 views2 pages

(DS) 1 2

This document describes various algorithms including linear search, binary search, bubble sort, insertion sort, queue, selection sort, stack, deque, circular queue, linked list, and queue using linked list. It provides the step-by-step processes for each algorithm. The key steps include initializing any needed variables, reading input values, performing comparison or sorting operations in loops, and outputting results.

Uploaded by

Douu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

(DS) 1 2

This document describes various algorithms including linear search, binary search, bubble sort, insertion sort, queue, selection sort, stack, deque, circular queue, linked list, and queue using linked list. It provides the step-by-step processes for each algorithm. The key steps include initializing any needed variables, reading input values, performing comparison or sorting operations in loops, and outputting results.

Uploaded by

Douu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

LINEAR SEARCH BINARY SEARCH BUBBLE SORT INSERTION SORT QUEUE

ALGORITHM: ALGORITHM: ALGORITHM: ALGORITHM: ALGORITHM:


Step 1:Start Step 1:Start Step 1:Start Step 1:Start Step 1:Start
Step 2: Set count as zero, flag Step 2: Read the Array size Step 2: Read the size of arry Step 2: Read the array size Step 2: Set front and rear to -1
as zero and position as zero Step 3: Read the array Step 3: Read the elements Step 3: Read the elements Step 3: Read size of queue
Step 3: Read the limit elements Step 4: Loop(i<n) Step 4: Loop (i<n) Step 4: If (insertion)
Step 4: Read the elements Step 4: Loop(i<n) Step 4.1: Read the elements Step 4.1: Read array elements Step 4.1: If(rear=size-1)
Step 5: Loop (i<n) Step 4.1: Read the array Step 5: Loop ends Step 5: Loop ends Step 4.1.1: Print overflow
Step5.1: Read the elements elements Step 6: Loop (i<n) Step 6: Set I to 1 Step 4.2: End if
Step5.2: Incriment i Step 5: Loop ends Step 6.1: Loop(j<n-1) Step 7: Loop (i<n) Step 4.3: Else
Step 6: End of loop Step 6: Loop (i<n) Step 6.1.1: If(a[i]>a[j+1]) Step 7.1: Set temp as a[i] Step 4.3.1: Print enter the element
Step 7: Loop (i<n) Step 6.1: Loop (j<n-1) Step 6.1.2: Set temp as a[i] Step 7.2: Set j as i-1 Step 4.3.2: Read the element
Step7.1: Print the elements Step 6.2: If (a[i]>a[j+1]) Step 6.1.3: Set a[j] as a[j+1] Step 7.3: Loop (a[i]>temp & j>=0) Step 4.3.3: If (front=-1& rear=-1)
Step 8: Loop ends Step 6.2.1: Set temp as a[i] Step 6.1.4: Set a[j+1] as temp Step 7.3.1: Set a[j+1]=a[j] Step 4.3.3.1: Set front=0
Step 9: Printf enter the key Step 6.2.2: Set a[i] as a[j+1] Step 6.2: If ends Step 7.3.2: Decrement j Step 4.3.3.2: Increment rear
elements Step 6.2.3: Set a[j+1] as temp Step 6.3: Loop ends Step 7.4: End loop Step 4.3.3.3: Read element to queue [rear]
Step10: Read the element Step 6.3: Loop ends Step 7: Loop ends Step 7.5: Set a[j+1] as temp Step 4.3.3.4: Endif
Step 11: Loop (i<n) Step 7: Loop ends Step 8: Print sorted array Step8: End loop Step 4.3.4: End else
Step11.1: If (a[i]+key) Step 8: Loop (i<n) Step 9: Loop(i<n) Step9: Loop (i<n) Step 5: If (deletion)
Step11.1.1: Set flag =1 Step 8.1: Print Sorted array Step 9.1: Print array Step 9.1: Print the sorted array Step 5.1: If (front=-1)
Step11.1.2: Set position=1+1 Step 9: Loop ends Step10: Loop ends Step10: Loop ends Step 5.1.1: Print underflow
Step11.1.3: Increment count Step10: Set begin as zero Step11: Stop Step 11: Stop Step 5.2: End if
Step11.1.4: Print the key found Step11: Set end as n Step 5.3: Else
at position Step 12: Print enter the key SELECTION SORT STACK Step 5.3.1: Print deleted element is queue [front]
Step11.2: If ends Step 13: Read key ALGORITHM: ALGORITHM: Step 5.3.2: If (front=rear)
Step 12: Loop ends Step 14: Loop (begin <end) Step 1: Start Step 1:Start Step 5.3.2.1: Set front and rear as -1
Step 13: If (flag=1) Step 14.1: Set mid as Step 2: Read the size of the Step 2: Set top to -1 Step 5.3.2.2: Endif
Step 13.1: Print the key found (begin+end)/2 array Step 3: Print size of stack Step 5.3.2.3: Else
number of times Step 14.2: If (a[mid]==key) Step 3: Read the elements Step 4: If (push) Step 5.3.2.3.1: Increment front
Step 14: If ends Step 14.2.1: Print element key Step 4: Set I to 0 Step 4.1: If (top=size-1) Step 5.3.2.3.2: End Else
Step 15: Else found at position mid Step 5: Loop(i<n) Step 4.1.1: Print overflow Step 5.4: Endif
Step 15.1: Print element not Step 14.3: If ends Step 5.1: Read elements Step 4.1.2: Endif Step 6: If (display)
found Step 14.4: If (key>a[mid]) Step 5.2: Increment i Step 4.1.3: Else Step 6.1: If(front & rear are -1)
Step 16: Else end Step 14.4.1: Set begin as mid Step 6: Loop ends Step 4.1.3.1: Decrement top Step 6.1.1: Print underflow
Step 17:Stop +1 Step 7: Loop (i<n) Step 4.1.3.2: Read one element Step 6.1.2: End if
Step 14.5: Endif Step 7.1: Set j=i+1 Step 4.1.3.3: Set stack[top] to element Step 6.1.3: Else
CIRCULAR QUEUE Step 14.6: Else Step 7.2: Loop (j<n) Step 4.1.4: Else end Step 6.1.3.1: Set i as zero
ALGORITHM: Step 14.6.1: Set end as mid -1 Step 7.2.1: If(a[j]>a[i]) Step 5: If (pop) Step 6.1.3.2:Loop (i<rear)
Step 1:Start Step 14.7: Else end Step 7.2.1.1: Set temp=a[i] Step 5.1: If (top=-1) Step 6.1.3.2.1:Print queue[i]
Step 2: Set front=0&rear=0 Step 14.8: If (begin++ end) Step 7.2.1.2: Set a[i]=a[j] Step 5.1.1: Print overflow Step 6.1.3.2.2: Loop ends
Step 3: Read size of queue Step 14.8.1: Print not found Step 7.2.1.3: Set a[j]=temp Step 5.1.2: Endif Step 6.1.4:End else
Step 4: If (insertion) Step 14.9: If ends Step 7.2.2: Endif Step 5.1.3: Else Step 7: End if
Step 4.1: Read the element Step 15: Stop Step 7.2.3: Loop ends Step 5.1.3.1: Set item to stack[top] Step 8: Stop
Step 4.2: If (front and rear are Step 8: Loop ends Step 5.1.3.2: Set top to top-1
zero) DEQUEUE Step 9: Loop (i<n) Step 5.1.3.3: Else end SINGLY LINKED LIST
Step 4.2.1: Set front&rear to 1 ALGORITHM: Step 9.1: Print the sorted array Step 6: If (display) ALGORITHM:
Step 4.2.2: Read element to Step 1:Start Step 10: Loop ends Step 6.1: Set i as top Step 1:Start
queue [rear] Step 2:Read choice Step 11: Stop Step 6.2: Loop (i<top) Step 2: Read the option
Step 4.3: Endif Step 3: If (insert front) Step 6.2.1: Print stack Step 3: If (traverse)
Step 4.4: Else Step 3.1: If front =0 STACK USING LINKED Step 6.2.2: Increment i Step 3.1: Ptr=header->link
Step 4.4.1: Set next as rear Step 3.1.1: Print overflow LIST Step 6.3: Loop ends Step 3.2: While (ptr!=Null)do
mod size+1 Step 3.2: Else ALGORITHM: Step 7: Stop Step 3.2.1: Print ptr->data
Step 4.4.2: If (next=front) Step 3.2.1:Read element Step 1:Start Step 3.2.2: Ptr=ptr->link
Step 4.4.2.1: Print overflow Step 3.3: End if Step 2: Read the operation QUEUE USING LINKED LIST Step 3.3: End while
Step 4.4.2.2: End if Step 3.4: If(front= -1) Step 3: If (insertion) ALGORITHM: Step 3.4: Stop
Step 4.4.3: Else Step 3.4.1: Set front =rear=0 Step 3.1: New = Step 1:Start Step 4: Elseif (insertion at front)
Step 4.4.3.1: Set rear as next Step 3.4.2:Insert element Getnode(Node) Step 2: Read the option Step 4.1: New = getnode (Node)
Step 4.4.3.2: Read element to Step 3.5: Else if (front!=0) Step 3.1.1: If (new=null)then Step 3: If (insertion) Step 4.2: If (new=null)
queue [rear] Step 3 5.1: Set front= front-1 Step 3.1.1.1: Print insufficient Step 3.1: New = getnode (node) Step 4.2.1: Insertion not possible
Step 4.4.3.3: End else Step 3.5.2:Insert element memory” Step 3.2: Ptr=header Step 4.2.2: Exit
Step 4.4.5: End else Step 3.6: End if Step 3.1.1.2: Exit Step 3.3: While (ptr->link#Null) do Step 4.3: Else
Step 5: End if Step 4: If (insert end) Step 4: Else Step 3.3.1: Ptr=ptr->link Step 4.3.1: New->link=header->link
Step 6: If (deletion) Step 4.1:If (rear= n-1) Step 4.1:Ptr=header Step 3.4: End while Step 4.3.2: Header->link=new
Step 6.1: If (front=0) Step 4.1.1: Print ‘overflow’ Step 4.2:While(ptr->link#Null) Step 3.5: Ptr->link=new Step 4.4: Endif
Step 6.2: Print underflow Step 4.2: Else do Step 3.6: New->data=x Step 4.5: Stop
Step 6.3: Endif Step 4.2.1: Read element Step 4.2.1:Ptr=ptr->link Step 4: End if Step 5: Elseif (insertion at end)
Step 6.4: Else Step 4.2.2: If(front =-1) Step 4.2.2:End while Step 5: If (deletion) Step 5.1: New = getnode (node)
Step 6.4.1: Print deleted Step 4.2.2.1: Set front=rear=0 Step 4.2.3:Ptr->link=new Step 5.1: Ptr=header->link Step 5.2: If (new=null) then
element as queue [front] Step 4.2.3: Else Step 4.2.4:New->data=x Step 5.2: If (ptr=null) Step 5.2.1: Print insufficient memory
Step 6.4.2: If (front =rear) Step 4.2.3.1: Rear+ + Step 4.2.5:Endif Step 5.2.1: Print Empty list Step 5.2.2: Exit
Step 6.4.3: Set front and rear Step 4.2.4: End if Step 4.2.6:Endif Step 5.2.2: Exit Step 5.3: Else
as 0 Step 4.2.5:Insert element Step 5:If (Deletion) Step 5.3: Else Step 5.3.1: Ptr=header
Step 6.4.4: Endif Step 4.3: End if Step 5.1:Ptr=header Step 5.3.1:Ptr1=ptr->link Step 5.3.2: While(ptr->link#null)
Step 6.5: Else Step 5: If (delete front) Step 5.2:If(ptr->link==Null) Step 5.3.2: Header->link=ptr1 Step 5.3.2.1: Ptr=ptr->link
Step 5.1:If(f= -1) then Step 5.3.3: Return node (ptr) Step 5.3.3: End while
Step 6.5.1: Set front as front Step 5.1.1: Print overflow Step 5.2.1:Printf”empty list” Step 5.3.4: Endif Step 5.3.4: Ptr->link=new
mmode size+1 Step 5.2: Else Step 5.2.2.:Exit Step 5.3.5: Endif Step 5.3.5: New->data=x
Step 6.5.2: End else Step 5.2.1: If (f=rear) Step 5.3:Else Step 6: If (display) Step 5.3.6: New->link=null
Step 6.5.3: End else Step 5.2.2: F=rear=-1 Step 5.3.1:While(ptr- Step 6.1: Ptr=header->link Step 5.4: Endif
Step 7: End if Step 5.3: End if >link#null)do Step 6.2: While (ptr#null) do Step 5.5: Stop
Step 8: If (display) Step 6: If (insertion at end) Step 5.3.2:Ptr1=ptr Step 6.2.1: Display ptr->data Step 6: Else if (inset at any position)
Step 8.1: If (front & rear =0) Step 6.1:If(f=-1) Step 5.3.3:Ptr=ptr->link Step 6.2.2: Ptr=ptr->link Step 6.1: New = getnode (node)
Step 8.1.1: (Print under flow) Step 6.1.1: Print under flow Step 5.3.4:Endwhile Step 6.2.3: Endwhile Step 6.2: If (new==null)
Step 8.2: End if Step 6.2: Else Step 5.3.5:Ptr1->link=null Step 7: End if Step 6.2.1: Printf insufficient memory
Step 8.3: Else Step 6.2.1: If (f=rear) Step 5.3.6: Return node(ptr) Step 8: Stop Step 6.2.2: Exit
Step 8.3.1: If (front <rear) Step 6.2.1.1: F=rear=-1 Step 5.3.7:Endif Step 6.3: Else
Step 8.3.1.1: Set i as front Step 6.2.2: End if Step 6:Endif Step 7.3: End While Step 6.3.1: Ptr=header
Step 8.3.1.2: Loop (i<rear) Step 6.2.3: Rrear =rear-1 Step 7:If(display) Step 8: End if Step 6.3.2: While (ptr->data#key) and (ptr-
Step 8.3.1.2.1: Print queue[i] Step 6.3: End if Step 7.1:Ptr=header->link Step 9: Stop >link#null)
Step 8.3.1.2.2: Increment i Step 7: Stop. Step 7.2:While(ptr#Null)do Preorder() Step 6.3.2.1: Ptr=ptr->link
Step 8.3.1.3: Loop ends Step 7.3:Display(ptr->data) Step 1:Start Step 6.3.3: End while
Step 8.3.2: Endif Step 6.7: Exit Step 7.4:Ptr=ptr->link Step 2:If(p=NULL) ie start= NULL Step 6.3.4: If (ptr->link=null)
Step 8.3.3: Else Step 7: If (poly1->link!=Null) Step 7.5:Endwhile Step 2.1:Tree traversal not possible Step 6.3.4.1: Print key not available
Step 8.3.3.1: Loop (i<rear) Step 7.1: While (poly1- Step 8:Endif Step 3:Else Step 6.3.4.2: Exit
Step 8.3.3.1.1: Print queue[i] >link!=Null) Step 9: Stop Step 3.1:Print p->data Step 6.3.5: Else
Step 8.3.3.1.2: Increment i Step 7.1.1: Poly->coeff=poly1- Step 3.2:Preorder(p->left) Step 6.3.5.1: New->link=ptr->link
Step 8.3.3.2: Loop ends >coeff Step 3.3:Preorder(p->right) Step 6.3.5.2: New->data=v
Step 8.3.3.3: Set I as 1 Step 7.1.2: Poly->exp=poly1- Step 4: End if Step 6.3.5.3: Ptr->link =new
Step 8.3.3.4: Loop (i<rear) >exp Step 3.4.2.3.3: Push (ch) Step 5: Stop Step 6.3.6: Endif
Step 8.3.3.4.1: Print queue[i] Step 7.1.3: Poly1=poly1->link Step 3.4.2.4: Else Inorder() Step 6.4: Endif
Step 8.3.3.4.2: Increment i Step 7.1.4: Poly->link=getnode Step 3.4.2.4.1: Push(ch) Step 1: Start Step 6.5: Stop
Step 8.3.3.5:Loop ends (node) Step 3.4.2.5: End if Step 2:If (p=NULL) Step 7: Elseif (deletefront)
Step 8.3.4:Else end Step 7.1.5: Poly=polylink Step 3.4.3: End if Step 2.1:Tree traversal not possible Step 7.1: Ptr=header->link
Step 9:Endif Step 7.2: End while Step 3.5: If (ch is an alphabet) Step 3:Else Step 7.2: If (ptr=null) then
Stop 10: Stop Step 8: Else if Step 3.5.1: Read ch to Step 3.1:Inorder(p->left) Step 7.2.1: Print Empty list
Step 8.1: While post[j++] Step 3.2:Print p->data Step 7.2.2:Exit
POLYNOMIAL ADDITION (poly2link!=Null) Step 3.6: End if Step 3.3:Inorder(p->right) Step 7.3:Else
ALGORITHM: Step 8.1.1: Poly->coeff=poly2- Step 4: End loop Step 4: End if Step 7.3.1: Ptr1=ptr->link
Step 1:Start >coeff Step 5: While (stk[top] !=’\0’) Step 5: Stop Step 7.3.2:Header->link=ptr1
Step 2: Read coefficient Step 8.1.2: Poly->exp=poly2- Step 5.1: Read stk[top] to post Postorder() Step 7.3.3:Return node(ptr)
&exponent of 2 polynomials >exp [j++] Step 1: Start Step 7.4:Endif
Step 3: Compare the exponents Step 8.1.3: Poly2=poly2->link Step 5.2: Decrement top Step 2:If (p==NULL) Step 7.5:Stop
from 1st node Step 8.1.4: Poly->link = Step 6: End loop Step 2.1:Tree traversal not possible Step 8:Else if (delete end)
Step 4: If (poly1- getnode (node) Step7: Assign post[i] as ‘\0’ Step 3:Else Step 8.1:Ptr=header->link
>coeff>poly2->coeff) Step 8.1.5: Poly=poly->link Step 8: Print “Post fix Step 3.1:Postorder(p->left) Step 8.2:If (ptr=null)then
Step 4.1: Poly->coeff=poly1- Step 8.2: End while expression as post” Step 3.2:Postorder(p->right) Step 8.2.1:Print empty list
>coeff Step 9: End if Step9: Stop Step 3.3:Print p->data Step 8.2.2:Exit
Step 4.2: Poly->exp=poly1- Step 10: Stop Step 4: End if Step 8.3:Else
>exp Step 5: Stop Step 8.3.1:While(ptr->link#Null)
Step 4.3: Poly1=poly1->link Step 8.3.1.1:Ptr1=ptr
Step 4.4: Poly->link = getnode INFIX TO POSTFIX IMPLEMENTATION OF Eval-Postfix() Step 8.3.1.2:Ptr=ptr->link
(node) EVALUATION TREE Step 1: Start Step 8.3.2:Endwhile
Step 4.5: Poly=poly->link ALGORITHM: ALGORITHM: Step 2: Find postfix expression for Step 8.3.3:Ptr->link=null
Step 4.6: Exit Step 1: Start Step 1:Start given expression Step 8.3.4:Return node(ptr)
Step 5: Elseif (poly- Step 2:Read the expression Step 2:Ptr=new node() Step 3: For I from 0 to length of post Step 8.3.5:Endif
>exp<poly2->exp) Step 3:For I from 0 to length Step 3:Repeat the following Step 3.1: Set ch as post[i] Step 8.3.6:Stop
Step 5.1: Poly->coeff=poly2- Step 3.1: Set ch as a[i] steps until info!=0 Step 3.2: If ch is an alphabet Step 9:Elseif(delete any)
>coeff Step 3.2: If(ch=’c’) Step 4:Enter the ptr->data Step 3.2.1: Print “Enter the value for Step 9.1:Ptr1=header
Step 5.2: Poly->exp=poly2- Step 3.2.1: Push (ch) Step 5:Ptr->left=NULL and ch” Step 9.2: Ptr=ptr1->link
>exp Step 3.3: If(ch=’)’) ptr->right=NULL Step 3.2.2: Read the value to c. Step 9.3:If (ptr==null)then
Step 5.3:Poly2=poly2->link Step 3.3.1:While Step 6:If (root=NULL) Step 3.3.3: Push C to another stk. Step 9.3.1:Print Empty list
Step 5.4: Poly->link = getnode (stk[top]!=’(’) Step 6.1:Root =ptr Step 3.3: Else Step 9.3.2:Exit
(node) Step 3.3.1.1: Read Step 6.2:Start=root Step 3.3.1: Set o1 as stk[top] Step 9.4:Else
Step 5.5: Poly=poly->link stk[top]=post[j++] Step 7:Else Step 3.3.2: Decrement top Step 9.4.1:While(ptr#null) and (ptr-
Step 5.6: Exit Step 3.3.1.2: Decrement top Step 7.1:Root=start Step 3.3.3: Set o2 as stk[top] >data#key)do
Step 6: Else Step 3.3.2: End loop Step 7.2:While(root!=NULL) Step 3.3.4: Decrement top Step 9.4.1.1:Ptr1=ptr
Step 6.1: Poly->coeff=poly2- Step 3.3.3: Decrement top Step 7.2.1:If(ptr->data<root- Step 3.3.5: If(ch== +) Step 9.4.1.2:Ptr=ptr->link
>coeff+poly1->coeff Step 3.4: If (ch=’+’ or ch=’-’ >data) Step 3.3.5.1: x=o1+o2 Step 9.4.2:Endwhile
Step 6.2: Poly->exp=poly1- or ch=’*’ orch=’/’) Step 7.2.1.1:If(root- Step 3.3.6: If(ch= -) Step 9.4.3:If (ptr==null)then
>exp Step 3.4.1: If(top=-1 or >left=NULL) Step 3.3.6.1: x=o1-o2 Step 9.4.3.1:Print Key not present
Step 6.3: Poly2=poly2->link stk[top]=’(’) Step 7.2.1.1.1:Root->left=ptr Step 3.3.7: If (ch=*) Step 9.4.3.2:Exit
Step 6.4: Poly1=poly1->link Step 3.4.1.1: Push(ch) Step 7.2.1.1.2:Exit while loop Step 3.3.7.1: x=o1*o2 Step 9.4.4:Else
Step 6.5: Poly->link = getnode Step 3.4.2: Else Step 7.2.2:Root=root->left Step 3.3.8:If (ch=/) Step 9.4.4.1:Ptr1->link=ptr->link
(node) Step 3.4.2.1:x=priority (ch) Step 7.2.3:Else Step 3.3.8.1: x=o1/o2 Step 9.4.4.2:Return node(ptr)
Step 6.6: Poly=poly->link Step 3.4.2.2:y=priority Step 7.2.3.1:If(root- Step 3.3.9: End if Step 9.4.5:Endif
(stk[top]) >right==NULL) Step 3.3.10: Push (x) Step 9.4.6:Stop
Step 3.4.2.3: If(y>=x) Step 7.2.3.2:Root->right=ptr Step 3.4: End if Step 9:Endif
Step 3.4.2.3.1: Read stk[top] to Step 7.2.3.3:Exit while loop Step 4: End for Step 10:Stop
post [j++] Step 7.2.3.4: Root=root->right Step 5: Print value as stk[top]
Step 3.4.2.3.2: Decrement top Step 7.2.4: End if Step 6:Stop

You might also like