ALGORITHM : DDALine ( X1, Y1, XN, YN)
Here X1 and X2 denotes starting X and Y coordinates,whereas XN and YN denotes ending X and Y coordinates of the line.M is the slope of the line,DX and DY are change in X and Y coordinates respectively.

1.Set M = (YN – Y1) / (XN – X1). [Slope Of Line]
2.Set I=X1.[Initialize Counter ]
3.Repeat steps 4,5 and 6 while I <=XN.
4.If (M <= 1) Then
Set DX = 1 and Set DY = M * DX
Else
Set DY = 1 and Set DX = DY / M
[End Of If.]
5.Set X1 = X1 + DX and Set Y1 = Y1 + DY.
6.Call PutPixel(X1, Y1)
7.Set I=I+1.[Increment Counter]
[End Of Loop.]
8.Exit.


If you have any suggestions regarding this post, please comment below in the comment section.



ALGORITHM : ENQUE(VALUE,QUEUE,FRONT,REAR)
Here REAR is position for input of data into queue,FRONT is position for deletion of data and VALUE is the item to be inserted.This algorithm will insert data into QUEUE. 

1.If REAR=N-1 then : print overflow and return.
2. Set REAR=REAR+1.
3.Set QUEUE[REAR]=VALUE.
4.If FRONT=-1 then :Set FRONT=FRONT+1.
5.Exit


ALGORITHM : DEQUE(QUEUE,FRONT,REAR)
Here REAR is position for input of data into queue,FRONT is position for deletion of data .This algorithm will delete a data from QUEUE. 

1.If FRONT=-1 then : print underflow and return.
2.print QUEUE[FRONT].
3.If FRONT=REAR then :Set FRONT=REAR=-1.
    Else :Set FRONT=FRONT+1.
4.Exit.

ALGORITHM : TRAVERSAL(QUEUE,FRONT,REAR)
Here REAR is position for input of data into queue,FRONT is position for deletion of data .This algorithm will display all the data from QUEUE.

1.If FRONT=-1 then : print queue is empty and return.
2.Set I=FRONT.
3.If I<=REAR then :print QUEUE[I].
4.Set I=I+1.
5.Goto 3.
[End Of Loop.]
6.Exit.

If you have any suggestions regarding this post, please comment below in the comment section.

ALGORITHM : PUSH(STACK,TOP,VALUE,SIZE)

1.If TOP=SIZE-1, then:
     print overflow and Exit.
2.Set TOP=TOP+1.
3.STACK[TOP+1]=VALUE.
4.Exit.            
 
ALGORITHM : PUSH(STACK,TOP)

1.If TOP=-1, then:
     print underflow and Exit.
2.print STACK[TOP].
3.Set TOP=TOP-1.
4.Exit

ALGORITHM : TRAVERSAL(STACK,TOP)

1.If TOP=-1, then:
     print stack is empty and Exit.
2.[Initialize Counter]Set I=TOP.
3.Repeat steps 4 and 5 while I<=0 :
4.print STACK[I].
5.[Increase Counter]Set I=I-1.
    [End Of Loop.]
6.Exit.

If you have any suggestions regarding this post, please comment below in the comment section.



ALGORITHM :(Matrix Multiplication) MATMULTI(X,Y,Z,P,Q,R)
Here X is a matrix array of P*Q and Y is a matrix array of Q*R .This algorithm stores the product of X and Y in matrix Z of order P*R.

1.Repeat steps 2,3 and 4 for I=1 to P.
2.Repeat steps 3 and 4 for J=1 to R.
3.Set Z[I,J]=0.
4.Repeat for K=1 to Q.
          Z[I,J]=Z[I,J]+X[I,K]*Y[K,J]
          [End Of Step 4 Inner Loop.]
          [End Of Step 2  Middle Loop.]
          [End Of Step 1 Outer Loop.]
5.Exit.

If you have any suggestions regarding this post, please comment below in the comment section.




ALGORITHM :(Linear Search) LSEARCH(Arr,N,POS,ITEM)
Here Arr is a Linear array with N elements, ITEM is the element to be searched and this algorithm find the position POS of the element ITEM .

1.[Initialize Counter] Set I=0 and POS=-1.
2.Repeat steps 3 and 4 while I !=N and POS=-1.
3. If Arr[I]=ITEM,
then: [Position Found ]Set POS=I+1 and Exit.
4.[Increase Counter]Set I=I+1.
[End Of Loop]
5. If POS=-1, then:
print element not found.
Else:
print element found at POS.
6.Exit

ALGORITHM :(Binary Search) BSEARCH(Arr,N,POS,ITEM)
Here Arr is a Linear array with N elements, ITEM is the element to be searched and this algorithm find the position POS of the element ITEM .Also L is lower bound ,U is upper bound and MID is the middle term between U and L.Here POS=-1 means element not found.

1.[Initialize Variables]Set L=0, U=N-1, MID=INT((U+L)/2), POS=-1.
2.Repeat steps 3 and 4 while L<=U and Arr[MID]!=ITEM.
3. If ITEM<Arr[MID], then:
Set U=MID-1.
Else If ITEM>Arr[MID], then:
Set L=MID+1.
Else :
Set POS=MID+1 and goto step 5.
4.Set MID=(U+L)/2.
[End Of Loop]
5.Exit


If you have any suggestions regarding this post, please comment below in the comment section.


Algorithms for array traversal,insertion and deletion are shown below separately.

ALGORITHM : (Traversing of Linear Array) Here Arr is a linear array with lower bound L and upper bound U

1.[Initialize Counter] Set K=L.
2.Repeat steps 3 and 4 while K<=U
3.Print Arr[K].
4.[Increase Counter] Set K=K+1.
5.Exit

ALGORITHM :(Inserting into a Linear Array)   INSERT(Arr,N,K,ITEM)
Here Arr is a linear array with N elements ,K is positive integer such that K<=N and ITEM is the element to be inserted.

1.[Initialize Counter] Set I=N.
2.Repeat steps 3 and 4 while I>=K.
3.Set Arr[I+1]=Arr[I].
4. [Decrease Counter] Set I=I-1.
5.[Inserting ITEM] Set Arr[K]=ITEM.
6.[Reset Number Of Elements].Set N=N+1.
7.Exit

ALGORITHM :(Deleting From Linear Array)   DELETE(Arr,N,K)
Here Arr is a linear array with N elements ,K is positive integer such that K<=N and Kth element is to be deleted.

1.[Initialize Counter] Set I=K.
2.Repeat steps 3 and 4 while I=N-1.
3.Arr[I]=Arr=[I+1].
4.[Increase Counter]Set I=I+1.
5.[Reset Number Of Elements].Set N=N-1.
6.Exit.

If you have any suggestions regarding this post, please comment below in the comment section.


Followers