Monday, 10 October 2016

First Come First Serve (FCFS) scheduling Algo. With C++ Program - (By-ANSHUL)

                  With this schema the process that request CPU First  is allocated the CPU first.
                The implementation of the First Come First Serve (FCFS) policy is easily managed with 
                FIFO queue.When a process enters into ready queue , its  PCB is linked onto the tail of                   the queue.When the CPU is free it is allocated to the process at the head of the queue,
                  the running process is then removed from the queue. 




The code of FCFS is simple to write and understand.FCFS is non-preemptive.


C++ Program  :-
        #include <iostream.h>
             #include <conio.h>
             void main()
     {
              int n,p[10],wt[10],t[10],i;
              clrscr();
              cout<<"Enter No. of process :"<<endl;
              cin>>n;
              cout<<"Enter Burst Time :"<<endl;
              for(i=0;i<n;i++)
              cin>>p[i];
              cout<<"Calclualting TAT & WT:"<<endl;
              t[0]=p[0];
              for(i=1;i<=n;i++)
     {    
              t[i]=t[i-1]+p[i];
              wt[i-1]=t[i-1]-p[i-1];
      }
              cout<<"Printing TAT & WT"<<endl;
              for(i=0;i<n;i++)
              cout<<"T["<<i+1<<"] ="<<t[i]<<" \t  w["<<i+1<<"] ="<<wt[i]<<endl;
               getch();
       }

Tuesday, 9 August 2016

Introduction to Java (By-Anshul)


            



JAVA is an Object oriented progarmming Language which was developed by James Gosling in SUNMICRO system in 1991.Java released its first verion in 1995 i.e. JAVA 1.0 and its latest version is JAVA ST 8.0.

Old name of Java was OAK.
In 2010.Java was acquired by Oracle Corporation.Java is very popular among all programming languages due to its special features which make it differnt from other languages:--
1. Simple and secure.
   *It is secure because it generate byte code and source code , Only byte code is transfered from system to system.And in this ,concept of pointers is not there which makes this secure.
2. Platform Independent.
   *Java is platform independent means it can run on any platform,
3. It is portable .
4.Complier and Interpreter.
  *It has complier and interpreter too.JVM(Java Virtual Machine) that takes byte code and generate Machine code which acts as interpreter.
5. Distributed.
   *It means we can  run Java program on Computer Network.
6.Multi-threaded.
    *Multithreading in Java is a  process  of executing multiple threads simultaneously.
Thread is basically a lightweight sub-process, a smallest unit of processing. Multiprocessing and multithreading, both are used to achieve multitasking.

Monday, 13 June 2016

Kruskal's Algorithm (By-Anshul)

 What is Minimum Spanning Tree ?

Given a connected and undirected graph, a spanning tree of that graph is a subgraph that is a tree and connects all the vertices together. A single graph can have many different spanning trees. A minimum spanning tree (MST) or minimum weight spanning tree for a weighted, connected and undirected graph is a spanning tree with weight less than or equal to the weight of every other spanning tree. The weight of a spanning tree is the sum of weights given to each edge of the spanning tree.
How many edges does a minimum spanning tree has?
A minimum spanning tree has (V – 1) edges where V is the number of vertices in the given graph.
What are the applications of Minimum Spanning Tree?
See this for applications of MST.
Below are the steps for finding MST using Kruskal’s algorithm
1. Sort all the edges in non-decreasing order of their weight.

2. Pick the smallest edge. Check if it forms a cycle with the spanning tree 
formed so far. If cycle is not formed, include this edge. Else, discard it.  

3. Repeat step#2 until there are (V-1) edges in the spanning tree.
The step#2 uses Union-Find algorithm to detect cycle. So we recommend to read following post as a prerequisite.
Union-Find Algorithm | Set 1 (Detect Cycle in a Graph)
Union-Find Algorithm | Set 2 (Union By Rank and Path Compression)
The algorithm is a Greedy Algorithm. The Greedy Choice is to pick the smallest weight edge that does not cause a cycle in the MST constructed so far. Let us understand it with an example: Consider the below input graph.
The graph contains 9 vertices and 14 edges. So, the minimum spanning tree formed will be having (9 – 1) = 8 edges.
After sorting:
Weight   Src    Dest
1         7      6
2         8      2
2         6      5
4         0      1
4         2      5
6         8      6
7         2      3
7         7      8
8         0      7
8         1      2
9         3      4
10        5      4
11        1      7
14        3      5
Now pick all edges one by one from sorted list of edges
1. Pick edge 7-6: No cycle is formed, include it.
2. Pick edge 8-2: No cycle is formed, include it.

3. Pick edge 6-5: No cycle is formed, include it.



4. Pick edge 0-1: No cycle is formed, include it.

5. Pick edge 2-5: No cycle is formed, include it.
6. Pick edge 8-6: Since including this edge results in cycle, discard it.
7. Pick edge 2-3: No cycle is formed, include it.


8. Pick edge 7-8: Since including this edge results in cycle, discard it.
9. Pick edge 0-7: No cycle is formed, include it.

10. Pick edge 1-2: Since including this edge results in cycle, discard it.
11. Pick edge 3-4: No cycle is formed, include it.

Since the number of edges included equals (V – 1), the algorithm stops here.

Tuesday, 7 June 2016

Thats my First post -Bubble Sort C program(With 8 inputs)


BUBBLE SORT
Program
                #include <stdio.h>
#include <conio.h>
void main()
{
int a[8],i,ptr,c;
clrscr();
                printf("Enter Eight inputs :- \n ");
for(i=0;i<8;++i)
scanf("%d",&a[i]);
printf("\n Bubble \n");
for(i=1;i<=7;++i)
{
ptr=0;
while(ptr<=(8-i))
{
if(a[ptr]>a[ptr+1])
{
c=a[ptr];
a[ptr]=a[ptr+1];
a[ptr+1]=c;
}
ptr++;
}
}
printf("After bubble sort\n");
for(i=0;i<8;++i)
printf("%d ",a[i]);
getch();
}