Friday, 13 April 2012

What is Queue ? Algorithms to insert and delete in queue.

22 comments

What is Queue ?

Queue is ordered collection of homogeneous data elements in which insertion and deletion operation take place at two end . insertion allowed from starting of queue called FRONT point and deletion allowed from REAR end only
  • insertion operation is called ENQUEUE
  • deletion operation is called DEQUEUE 

Block Diagram of Queue

Conditions in Queue

  • FRONT < 0 ( Queue is Empty )
  • REAR = Size of Queue ( Queue is Full )
  • FRONT < REAR ( Queue contains at least one element )
  • No of elements in queue is : ( REAR - FRONT ) + 1

Restriction in Queue

we can not insert element directly at middle index (position) in Queue and vice verse for deletion. insertion operation possible at REAR end only and deletion operation at FRONT end, to insert we increment REAR and to delete we increment FRONT.

Algorithm for ENQUEUE (insert element in Queue)

Input : An element say ITEM that has to be inserted.
Output : ITEM is at the REAR of the Queue.
Data structure : Que is an array representation of queue structure with two pointer FRONT and REAR.

Steps:

1.  If ( REAR = size ) then //Queue is full
2.        print "Queue is full"
3.        Exit
4.  Else
5.        If ( FRONT = 0 ) and ( REAR = 0 ) then //Queue is empty
6.               FRONT = 1
7.        End if
8.        REAR = REAR + 1 // increment REAR
9.        Que[ REAR ] = ITEM
10. End if
11. Stop

Algorithm for DEQUEUE (delete element from Queue)

Input : A que with elements. FRONT and REAR are two pointer of queue .
Output : The deleted element is stored in ITEM.
Data structure : Que is an array representation of queue structure..

Steps:

1.  If ( FRONT = 0 ) then
2.        print "Queue is empty"
3.        Exit
4.  Else
5.        ITEM = Que [ FRONT ]
6.        If  ( FRONT  =  REAR )
7.               REAR = 0
8.               FRONT = 0
9.        Else
10.             FRONT  =  FRONT + 1
11.      End if
12. End if 
13. Stop 

What Next !!

Implement program using this Algorithms, if any query or suggestion then comment it.

Monday, 2 April 2012

Visual Demonstration of Bubble Sort Algorithm

0 comments
Bubble sort is easiest sorting in Data Structure ( from programming point of View ),

Why this sorting called Bubble sorting ?
In this sorting method, Greatest element is comes at last index of List and all least elements comes up in each pass Like BUBBLE. bubble comes up from bottom and heavy weight goes down.

in below Video Tutorial Following topics are explained :

  • Algorithm of Bubble sort
  • Visual Demonstration of Bubble sort
  • Time complexity of this sorting 



Source :  http://www.youtube.com/watch?v=P00xJgWzz2c
 

Recent Post

Recent Comments

© 2010 IamLearningHere Template by MBT