Monday, December 16, 2013

Queue (First In First Out)

First In First Out
Queue : : Rear & Fornt
Applications: Job Scheduling
First in First Out
Queue ADT
objects: a finite ordered list with zero or more elements.
methods:
     for all queue Î Queue, item Î element,
             
max_ queue_ size Î positive integer
    
Queue createQ(max_queue_size) ::=
              create an empty queue whose maximum size is
             
max_queue_size
    
Boolean isFullQ(queue, max_queue_size) ::=   
  
           if(number of elements in queue == max_queue_size)
  
           return TRUE
             
else return FALSE
    
Queue Enqueue(queue, item) ::=
              if
(IsFullQ(queue)) queue_full
             else insert item at rear of queue and return queue    
Queue ADT (cont’d)
Boolean isEmptyQ(queue) ::=
            
 if (queue ==CreateQ(max_queue_size))
             
return TRUE
              else return FALSE
     Element
dequeue(queue) ::=
             
if (IsEmptyQ(queue)) return
              else
remove and return the item
at front of queue.

What is Queue ? Examples of Queue ?

  1. Stores a set of elements in a particular order
  2. Stack principle: FIRST  IN  FIRST  OUT
  3. = FIFO
  4. It means: the first element inserted is the first one to be removed
  5. Example
The first one in line is the first one to be served

Real life examples
  1. Waiting in line
  2. Waiting on hold for tech support
Applications related to Computer Science
  1. Threads
  2. Job scheduling (e.g. Round-Robin algorithm for CPU allocation)

Tuesday, July 16, 2013

Number Pattern-01

C programming Pattern-01
Pattern-01 source code in C Programming


#include<stdio.h>
int main()
{
  int i,j,k=1;
  for(i=1;i<=5;i+=2)
  {
    for(j=5;j>=1;j--)
    {
      if(j>i)
        printf(" ");
      else
        printf("%d ",k++);
    }
    printf("\n");
  }
}

Monday, July 8, 2013

Linear Search

Linear Search
Linear Search in C
C Programming "Linear Search"
#include<stdio.h>
int main()
{
 int arr[10],i,value,index;
 printf("Please enter 10 values:\n");
 for(i=0;i<10;i++)
  scanf("%d",&arr[i]);
  
 printf("\nEnter a value to be searched: ");
 scanf("%d",&value);
 
 index = -1;
 for(i=0;i<10;i++)
 {
  if(arr[i]==value)
  {
   index=i;
   break;
  }
 }
 
 if(index>=0)
  printf("Value found in Array at %d location",index);
 else
  printf("Value not found in Array");
 return 0;
}

LiBinary Search
Binary Search in C
C Programming "Binary Search" - See more at: http://www.programming-and-it-research-center.blogspot.com/#sthash.b5niQNhp.dpuf
bBinary Search
Binary Search in C
C Programming "Binary Search" - See more at: http://www.programming-and-it-research-center.blogspot.com/#sthash.b5niQNhp.dpuf