Monday, 2 February 2015

Binary Search program in C

Friends,

Below are the binary search programs written in C. One is recursive version and the other is iterative version. I'll keep updating all algorithms as C codes.


Programs are simple and self explanatory.


ITERATIVE BINARY SEARCH



#include<stdio.h>

int BinSrch(int arr[],int low_index, int up_index, int key)
{
int mid;
while(low_index <= up_index)
{
mid = (low_index + up_index)/2;
if(key < arr[mid])
{
up_index = mid-1;
}

else if(key > arr[mid])
{
low_index = mid + 1;
}
else
return mid;
}
return -1;
}

int main()
{
printf("\nEnter no of elements: ");
int n;
scanf("%d",&n);
int arr[n],i;

printf("\nEnter elements: ");
for(i=0;i {
scanf("%d",&arr[i]);
}

printf("\nEnter search element: ");
int key;
scanf("%d",&key);

int position = BinSrch(arr,0,n-1,key);
if(position == -1)
printf("\nElement not found!");
else
printf("\nElement found at position: %d",position);
return 0;
}







RECURSIVE BINARY SEARCH

#include<stdio.h>

int BinSearch(int arr[], int low_index, int up_index, int key)
{
if(low_index <= up_index)
{
int mid = (low_index + up_index)/2;

if(key < arr[mid])
return BinSearch(arr,low_index,mid-1,key);

else if(key > arr[mid])
return BinSearch(arr,mid+1,up_index,key);

else
{
return mid;
}
}

else
{
return -1;
}
}//BinSrch()


int main()
{
int n,i;
printf("\nEnter no of elements: ");
scanf("%d",&n);
int arr[n];
printf("\nEnter elements: ");
for(i=0;i scanf("%d", &arr[i]);
printf("\nEnter search element: ");
int key;
scanf("%d", &key);
int position = BinSearch(arr,0,n-1,key);
if(position == -1)
printf("\nSearch element not found!!");
else
printf("\nSearch element found at position %d",position);
return 0;
}




Wednesday, 24 September 2014

RefCommunicator

Hi,

I've created a simple, easy to use Java chat application. Its not a great visually appealing, high end application but can suffice the purpose of communication in a LAN. We can even use this in our labs to communicate with our friends. Give it a try and report if there are any errors.


You can set any username. The IPAddress field always takes the destination computer IP Address. If you are using Group Chat, enter a Multicast IP Address.



More info:

I've implemented this using only UDP (no Sockets or ServerSockets). Hence, no need of centralized server to listen for requests and establishing connections. It is completely a peer to peer app and it just sends the message to the target machine (doesn't matter the receiver is online or not) and doesn't report any errors (acknowledgements) if the receiver doesn't receive it successfully.  

This app can work in two modes :- Single (One-to-One chat) or Group chat. With 'Group Chat' option selected, one need to enter a Multicast IP Address which other people in the group are using and every one in the group should stick to the same port.

The Attach Files feature is not yet implemented in this version (due to some bugs), you can expect this in the next update. Any bugs, please comment.

Don't forget to minimize the app when faculty is near by :)

Friday, 14 March 2014

Operating system lab programs [update]

Operating system lab programs

SCHEDULING ALGORITHMS :


1.  First Come First Serve (FCFS)    


2. Shortest Remaining Time First (SJF with preemption ,SRTF)  


3. Priority Scheduling (Preemptive)  


4. Round Robin (RR)      


Note:
 
For the above programs, input should be given in increasing order of arrival time (applicable for SRTF and Priority). Inorder to reduce the complexity of the code, the flexibility of giving random order of arrival times is not included in the program. You can also apply any sorting technique to this code to add that feature. 

These programs are working perfectly for almost all cases, if any bugs are there please comment below.

Tuesday, 4 February 2014

Operating System lab programs

Operating system lab programs forwarded by our OS sir

1. First Come First Serve Scheduling Algorithm (FCFS)   

2. Shortest Job First Scheduling Algorithm (SJF)   

3. Priority Based Scheduling Algorithm  

4. Round Robin Scheduling Algorithm (RR)   

5. Banker's Algorithm  

6. Deadlock Detection   

7. MVT   

8. MFT  

9. First In First Out (FIFO)   

10. Paging   

11. Optimal 








Tuesday, 24 December 2013

Tuesday, 17 December 2013

Operating systems concepts with java 6th edition e-book

Name : Operating systems concepts with Java

Edition : 6th

Author : Silberschatz





This is 6th edition our sir suggested us to follow this edition (not 8th)

 

Saturday, 14 December 2013

Textbook of environmental studies for Undergraduates by Erach Bharucha

Name : Textbook of environmental studies for Undergraduates

Author : Erach Bharucha

(Ripped Version)




This edition is older than our prescribed book but most of the content is same.



Friday, 13 December 2013

Software Engineering, A practitioner's approach 7th ed e-book

Name  : Software Engineering, A practitioner's approach

Author : Roger S Pressman

Edition : 7th




This book is 7th edition but our prescribed book is 6th edition

Wednesday, 11 December 2013