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 do you mean by the term “percolate up”?
How many types of linked list are there?
Give a basic algorithm for searching a binary search tree?
What is space complexity of a program?
What is the time complexity of hashmap get () and put () method?
How do you access the values within an array?
Define linked list data structure.
How does arraylist size work?
What do you mean by Runtime Error
Can we create a null as a key for a map collection?
What are the types of binary tree?
What are the drawbacks of array implementation of queue?
What are the advantages of selecetion sort?
If you have to store one lakh objects, what will be a better option- a hash map or an array list?
Write the c program to insert a node in circular singly list at the beginning.