answersLogoWhite

0


Best Answer

#include <iostream>

#include <conio.h>

int linearSearch( const int array[], int length, int value);

int main()

{

const int arraySize = 100;

int a[arraySize];

int element;

for( int i = 0; i < arraySize; i++)

{

a[i] = 2 * i;

}

element = linearSearch( a, arraySize, 10);

if( element != -1 )

cout << "Found value in element " << element << endl;

else

cout << "Value not found." << endl;

getch();

return 0;

}

int linearSearch( const int array[], int length, int value)

{

if(length==0) return -1;

else if (array[length-1]==value) return length-1;

else return urch( array, length-1, value);

}

it is in c++ language ,u can change it to c by including stdio.h ,printf & scanf.....i think it wud be beneficial

have a look their too. similar program like that and easy understanding

http://fahad-cprogramming.blogspot.com/2014/02/linear-search-program-in-c-using.html

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

6y ago

Iteration is more efficient.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Binary search iterative method over recurssive method?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the advantage of the binary search method?

It gets you to the answer with fewer steps.


How do you get principal varivation from iterative deepening search?

You will get principal variation from iterative deepening search using sequential moves within the framework. It is important to note that this may slow down the search due to space requirements.&Ecirc;


What assumption about the list is made when binary search is conducted?

Binary search requires that the list be in search key order.


Write an iterative function to search an element in a binary search tree?

_node* search (_node* head, _key key) { _node* node; for (node=head; node != NULL;;) { if (key == node-&gt;key) return node; else if (key &lt; node.&gt;key) node = node-&gt;left; else node = node-&gt;right; } return node; }


What is the use of binary?

Binary trees are commonly used to implement binary search tree and binary heaps.


A binary search of an orderd set of elements in an array or a sequential search of the elements.Which one is faster?

A binary search is much faster.


What is the binary number for decimal 191?

It is 10111111 in binary. Try a search for '191 to binary'.


Items that are not suitable for a binary search?

The only items suitable for a binary search are those which are in a sorted order.


Does binary tree and binary search tree same?

no they are not same


What are the drawbacks of the binary search?

The only drawback I know of is that binary search requires that the list already be sorted. So if you have a really large unsorted list than binary search would not be the best option.


How do you convert 43 into binary?

There is a good method outlined is this answer: http://wiki.answers.com/Q/How_do_you_convert_57_into_binary A quick way is to use Google calculator: Enter "43 in binary" into Google's search field (without the quotes) It returns 43 = 0b101011


How do you print all data in a Binary Search Tree?

By using Depth First Search or Breadth First search Tree traversal algorithm we can print data in Binary search tree.