Program for linear search, Data Structure & Algorithms

Assignment Help:

Program for Linear Search.

Program: Linear Search

/*Program for Linear Search*/

/*Header Files*/

#include

#include

/*Global Variables*/

int search;

int flag;

/*Function Declarations*/

int input (int *, int, int);

void linear_search (int *, int, int);

void display (int *, int);

/*Functions */

void linear_search(int m[ ], int n, int el)

{

int k;

flag = 1;

for(k=0; k

{

if(m[k]==el

{

printf("\n Searching is Success\n");

printf("\n Element : %i Found at location : %i", element, k+1);

flag = 0;

}

}

if(flag==1)

printf("\n Searching is unsuccessful");

}

void display(int m[ ], int n)

{

int i;

for(i=0; i< 20; i++)

{

printf("%d", m[i];

}

}

int input(int m[ ], int n, int el)

{

int i;

n = 20;

el = 30;

printf("Number of elements in the list : %d", n);

for(i=0;i<20;i++)

{

m[i]=rand( )%100;

}

printf("\n Element to be searched :%d", el);

search = el;

return n;

}

/* Main Function*/

void main( )

{

int n, el, m[200];

number = input(m, n,el);

el = search;

printf("\n Entered list: \n");

display(m, n);

linear_search(m, n, el);

printf("\n In the following list\n");

display(m, n);

}

Program 1 examines each key value in the array 'm', one by one and stops while a match occurs or the entire array is searched.


Related Discussions:- Program for linear search

Define dynamic programming, Define Dynamic Programming  Dynamic  progra...

Define Dynamic Programming  Dynamic  programming  is  a  method  for  solving  problems  with  overlapping  problems.  Typically, these sub problems arise from a recurrence rel

Sparse matrix, Q. Define a sparse matrix. Explain different types of sparse...

Q. Define a sparse matrix. Explain different types of sparse matrices? Show how a triangular array is stored in memory. Evaluate the method to calculate address of any element ajk

Heap sort, We will start by defining a new structure called Heap. Figure 3 ...

We will start by defining a new structure called Heap. Figure 3 illustrates a Binary tree. Figure: A Binary Tree A complete binary tree is said to assure the 'heap con

Threaded binary tree, i need the full concept of it... please can anyone pr...

i need the full concept of it... please can anyone provide

Illustrate an example of algorithm, Illustrate an example of algorithm ...

Illustrate an example of algorithm Consider that an algorithm is a sequence of steps, not a program. You might use the same algorithm in different programs, or express same alg

Terminology used for files structures, Given are the definitions of some im...

Given are the definitions of some important terms: 1) Field: This is an elementary data item characterized by its size, length and type. For instance, Name

Deletion of an element from the linear array, Program will demonstrate dele...

Program will demonstrate deletion of an element from the linear array /* declaration of delete_list function */ voiddelete_list(list *, int); /* definition of delete_list

Worst case and average case, Worst Case: For running time, Worst case runn...

Worst Case: For running time, Worst case running time is an upper bound with any input. This guarantees that, irrespective of the type of input, the algorithm will not take any lo

What is binary search, What is binary search?   Binary search is most ...

What is binary search?   Binary search is most useful when list is sorted. In binary search, element present in middle of the list is determined. If key (the number to search)

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd