answersLogoWhite

0

Program for linear search

Updated: 8/11/2023
User Avatar

Wiki User

14y ago

Best Answer

A simple Binary Search Algorithm is as follows:

Calculate the mid element of the collection.

Compare the key items with the mid element.

If key = middle element, then we return the mid index position for the key found.

Else If key > mid element, then the key lies in the right half of the collection. Thus repeat steps 1 to 3 on the lower (right) half of the collection.

Else key < mid element, then the key is in the upper half of the collection. Hence you need to repeat the binary search in the upper half.

for get program copy link ( babaplayer.blogspot .com/2021/07/binary-search-using-divide-and-conquer.html )

User Avatar

Baba Player

Lvl 4
2y ago
This answer is:
User Avatar
User Avatar

Rahul Ledner

Lvl 1
2y ago
great answer thxx!
More answers
User Avatar

Wiki User

14y ago

In order to perform an optimal search on a binary tree, it needs to be balanced, where the depth of all leaves is no more than one apart from each other.

Building the tree is easy. Keeping it balanced is harder. As you add and subtract nodes, you want to determine if rebalancing is needed and then do it, either on a local scale or on a global scale. This has cost, because it will slow down the process of insertion and deletion.

Various techniques have been developed to create self-balancing binary trees, such as AVL, Red-Black, AA, Splay, Scapegoat, and Treap. Some of these techniques do not actually keep the tree balanced - they keep the more often used nodes closer to the top, using statistical means - or they allow local imbalancing as a trade off between small added cost in searching vs potentially larger added cost in rebalancing.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

currentElement = dataStructure.firstElement

while dataStructure.hasMoreElements

if currentElement == targetElement

return

currentElement = dataStructure.nextElement

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

A binary search function is built into the c libraries. Look up bsearch.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Yes, please do.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Program for linear search
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Best first search program in c?

The best search programs to attempt writing in C are the following: Linear search (simplest), Binary search (faster) Hash search (fastest).


How do you run graphics program in C?

pro c language to implement linear search using pointers


Explain linear search with an example?

Sequential search of an object with in an array of objects is called as linear search.


What is linear searching?

The linear search algorithm is a special case of the brute force search.


What are advantage of linear searching?

There no advantages to linear search other than searching for the first (or last) nodes. Linear search takes linear time with an average O(n/2) for each search.


What is the running time of a linear search of an array?

Running time of a linear search is O(n)


Complexity of linear search?

the compexity of linear search in worst case is f(n) = n+1


What is search algorithm?

The linear search algorithm is a special case of the brute force search.


What are the various applications of linear search in real time?

Linear search is necessary when we must search unordered sets. Linear search times across huge sets can be improved significantly by dividing the set amongst two or more threads that can execute on independent CPU cores.


What is the simplest search technique to use to find an item in an array?

Linear search


Linear channel IPTV?

The Linear channel IPTV affects the other linear channel just as much as the program rights holders.


What are advantages and disadvantages of linear search?

1)in linear search it needs more space and time complexity. 2) in linear search if the key element is the last element and the search is from first element that is a worst case, or if the key element is the first element and the search is from last element then also is the worst case.