Thursday, 27 July 2017

DAA PRACTICAL MANUAL: PRACTICAL 2

                                                                                                      Date:27-07-2017
Experiment No: 02

1. Experiment vision: Write a program to study and implement Binary search.
2. OBJECTIVE: Program to implement an array of object in C and to find the specific 
                              element using divide method.  
3. THEORY:  In computer science, a binary search or half-interval search algorithm finds the position of a specified input value (the search "key") within an array sorted by key value. In each step, the algorithm compares the search key value with the key value of the middle element of the array. If the keys match, then a matching element has been found and its index, or position, is returned. Otherwise, if the search key is less than the middle element's key, then the algorithm repeats its action on the sub-array to the left of the middle element or, if the search key is greater, on the sub-array to the right. If the remaining array to be searched is empty, then the key cannot be found in the array and a special "not found" indication is returned. A binary search halves the number of items to check with each iteration, so locating an item (or determining its absence) takes logarithmic time.
4.  PROGRAM:
#include<stdio.h>
void main()
{
int c,first,last,middle,n,search,array[10];
printf("enter no of element");
scanf("%d",&n);
printf("enter %d integer\n",n);
for(c=0;c<n;c++)
scanf("%d",&array[c]);
printf("enter a no to be search");
scanf("%d",&search);
first=0;
last=n-1;
middle=(first+last)/2;
while(first<=last)
{
if(array[middle] < search)
first=middle+1;
else if(array[middle]==search)
{
printf("%d found at location %d\n",search,middle+1);
break;
}
else
last=middle-1;
middle=(first+last)/2;
}
if(first>last)
printf("not found");
}

5. OUTPUT:
------------------------------------------
------------------------------------------

6. conclusion:
Thus C programs for binary search implement and executed successfully.
7.  REMARK:
Array of element is the concepts are used for printing the values of number element and to find the element using implementing binary search method.
In that we work on divide and conquer method.  
8. Discussion Questions:
1) what is binary search?
_________________________________________________________________________________________________________________________________________________________
2) How is binary search working explain with example? (diagrammatically)
___________________________________________________________________________________________________________________________________________________________
3) What is the complexity of binary search method?
__________________________________________________________________________________________________________________________________________________________________

                                    

Wednesday, 26 July 2017

DAA PRACTICAL MANUAL: PRACTICAL 1

Department of Computer Science & Engineering, DES’s COET Dhamangaon Rly. 
PRACTICAL NO.1:  Write a program to implement Linear Search

Date: 20/07/2017
EXPERIMENT NO: 01
1. EXPERIMENT VISION: Write a program to implement Linear Search.

2. OBJECTIVE: Program to implement an array of object in C and to find the specific
element.

3. THEORY:Linear search is usually very simple to implement, and is practical when the list
has only a few elements, or when performing a single search in an unordered list. many values
have to be searched in the same list, it often pays to pre-process the list in order to use a faster
method. For example, one may sort the list and use binary search, or build any efficient search
data structure from it. Should the content of the list change frequently, repeated re-organization
may be more trouble than it is worth. As a result, even though in theory other search algorithms
may be faster than linear search (for instance binary search), in practice even on medium sized
arrays (around 100 items or less) it might be infeasible to use anything else. On larger arrays, it
only makes sense to use other, faster search methods if the data is large enough, because the
initial time to prepare (sort) the data is comparable to many linear searches. Linear search in c
programming: The following code implements linear search (Searching algorithm) which is used
to find whether a given number is present in an array and if it is present then at what location it
occurs. It is also known as sequential search. It is very simple and works as follows: We keep on
comparing each element with the element to search until the desired element is found or list
ends. Linear search in c language for multiple occurrences and using function.

4.Algorithm:
Step-1: Start
Step-2: Accept no. of the values
Step-3: Accept the values and store it in an array
Step-4: Accept the no. to be searched as ‘num’
Step-5: If a value is found equal to ‘num’, output, ‘Element found’.
Step-6: If the value is not found, output, ‘Element not found’.
Step-7: Stop
5.Flowchart:

6. PROGRAM:
#include<stdio.h>
void main()
{
int arr[100],search,n,i;
printf("enter the no. element to be enter in array");
scanf("%d",&n);
printf("enter the array element");
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
printf("enter the element to be search");
scanf("%d",&search);
for(i=0;i<n;i++)
{
if(arr[i]==search)
{
printf("element %d search at the position %d",search,i+1);
break;
}
}
if(arr[i]!=search)
printf("search %d element is not found",search);
}

7. OUTPUT:
------------------------------------------
------------------------------------------

8. CONCLUSION:
Thus a we have studied C program for linear search and executed successfully.

9. REMARK:
Array of element is the concepts are used for printing the values of number
element and to find the element using implementing linear search method.

10. DISCUSSION QUESTIONS:
1)What is array? How are they created?
______________________________________________________________________________
___________________________________________________________________________
2) What are the different types of array?
______________________________________________________________________________
__________________________________________________________________________
3) What is the mean complexity? What are the types of complexity?
______________________________________________________________________________
______________________________________________________________________________
4) What is the complexity of linear search method?
______________________________________________________________________________
______________________________________________________________________________

About Me

Hi, I am Prof. Amol Zade, working in the field of teaching and research from last more than 10 years. My area of interests are Artificial Intelligence, Wireless Networking, Algorithms. I have 16 International paper publications along with 4 International Conference; also 3 Books published. published on Object Oriented Programming with open source approach.