@@ -86,3 +86,68 @@ export const linearSearchMetaData: Algorithms = {
8686}
8787
8888// ----------------------------------- End ----------------------------------------------//
89+
90+ // ---------------------------------- Binary Search ---------------------------------------//
91+
92+ const binarySearchData = {
93+ defination :`Binary Search is a searching algorithm used in a sorted array by repeatedly dividing the search interval in half.
94+ The idea of binary search is to use the information that the array is sorted and reduce the time complexity to O(Log n)` ,
95+ flowChart : 'assets/ds-image/DSA-404.webp' ,
96+ explainImage : 'assets/ds-image/DSA-404.webp' ,
97+ properties : [
98+ `The pre-condition for the binary search is that the elements must be arranged in a sorted order` ,
99+ `The implementation of binary search is limited as it can be implemented only on those data structures
100+ that have two-way traversal` ,
101+ `It is based on the divide and conquer approach` ,
102+ `It is preferrable for the large-size data sets` ,
103+ `It can be implemented only on a singledimensional array`
104+ ] ,
105+ workingProcedure :[
106+ `Compare 'x' with the middle element` ,
107+ `If 'x' matches with the middle element, we return the mid index` ,
108+ `Else If 'x' is greater than the mid element, then 'x' can only lie in the right half subarray after the mid element.
109+ So we recur for the right half` ,
110+ `Else ('x' is smaller) recur for the left half`
111+ ] ,
112+ advantage : [
113+ `It is better than a linear search algorithm since its run time complexity is O(Log n)` ,
114+ `At each iteration, the binary search algorithm eliminates half of the list and significantly reduces the search space` ,
115+ `The binary search algorithm works even when the array is rotated by some position and finds the target element`
116+ ] ,
117+ disadvantage : [
118+ `The recursive method uses stack space` ,
119+ `Programming binary search algorithm is error prone and difficult` ,
120+ `The interaction of binary search with memory hierarchy i.e. caching is poor.
121+ (because of its random access nature)`
122+ ] ,
123+ applications : [
124+ `Find an element in a sorted array` ,
125+ `Find the first value greater than or equal to x in a given array of sorted integers` ,
126+ `Find the frequency of a given target value in an array of integers` ,
127+ `Dictionary: In the dictionary, all the words are arranged in lexicographical order, therefore,
128+ to find a particular word, we can simply binary search to find the alphabets without having to go through each word` ,
129+ `Find if a number is a square of any integer: To check if a number is a square of any integer, run a binary search from 1
130+ to num and check if the square of mid is equal to num.`
131+ ] ,
132+ performance : [
133+ `Best Case Time Complexity of Binary Search: O(1)` ,
134+ `Average Case Time Complexity of Binary Search: O(logN)` ,
135+ `Worst Case Time Complexity of Binary Search: O(logN)` ,
136+ `Space Complexity of Binary Search: O(1) for iterative, O(logN) for recursive`
137+ ] ,
138+
139+ } ;
140+
141+ export const binarySearchMetaData : Algorithms = {
142+ defination : Helper . setHeader ( binarySearchData . defination ) ,
143+ properties : Helper . setListwithTitleHtml ( 'Properties of Binary Search' , binarySearchData . properties ) ,
144+ explainImage : Helper . setExampleImage ( 'Binary Search Image' , binarySearchData . explainImage ) ,
145+ flowChart : Helper . setExampleImage ( 'Flowchart of Binary Search' , binarySearchData . flowChart ) ,
146+ advantage : Helper . setListwithTitleHtml ( 'Advantages of Binary Search' , binarySearchData . advantage ) ,
147+ disadvantage : Helper . setListwithTitleHtml ( 'Disadvantages of Binary Search' , binarySearchData . disadvantage ) ,
148+ applications : Helper . setListwithTitleHtml ( 'Applications of Binary Search' , binarySearchData . applications ) ,
149+ other : Helper . setListwithTitleHtml ( 'Performance of Binary Search' , binarySearchData . performance ) ,
150+ workingProcedure : Helper . setListwithTitleHtml ( 'Follow the below steps to solve the problem' , binarySearchData . workingProcedure ) ,
151+ }
152+
153+ // ----------------------------------- End ----------------------------------------------//
0 commit comments