Explain binary searching, Fibinocci search.
Answer Posted / nipesh.....janghel....bca..2nd
Binary Search
The binary search is the standard method for searching
through a sorted array. It is
much more efficient than a linear search, where we pass
through the array elements in
turn until the target is found. It does require that the
elements be in order.
The binary search repeatedly divides the array in two, each
time restricting the search to
the half that should contain the target element.
In this example, we search for the integer 5 in the 10-
element array below:
2 : 5 : 6 : 8 : 10 : 12 : 15 : 18 : 20 : 21
Loop 1 - Look at whole array
Low index = 0, high index = 9
Choose element with index (0+9)/2 = 4
Compare value (10) to target
10 is greater than 5, so the target must be in the lower
half of the array
Set high index = (4-1) = 3
Loop 2
Low index = 0, high index = 3
Choose element with index (0+3)/2 = 1
Compare value (5) to target
5 is equal to target
Target was found, index = 1
| Is This Answer Correct ? | 23 Yes | 4 No |
Post New Answer View All Answers
What is dynamic array how it is created?
How would you reverse the characters of an array?
What do you mean by rehashing?
What is a concurrenthashmap?
Which is better arraylist or linkedlist?
Draw the B-tree of order 3 created by inserting the following data arriving in sequence – 92 24 6 7 11 8 22 4 5 16 19 20 78
What are the complexity of binary search?
What is difference between list and linked list?
What does adt stands for?
On clicking a node in a tree, all the adjacent edges are turned on. Calculate min of clicks such that all the edges are turned on.
Can binary tree have 1 child?
How do you do a mergesort?
How does the bubble sort work?
What is data type with example?
What is unhashable type list?