Binary Search
Problem:
How to find an element in a sorted array using Binary Search.
Solution:
1: Take start = 0, end = length of array - 1.
2: Repeat following steps till start is less than or equal to end:
(a) Set mid = (start + end)/2.
(b) Check if array[mid] == num, then return mid.
(c) If num is less than array[mid], set end = mid-1, to look for num in first half of the array.
(d) Else set start = mid+1, to look for num in second half of the array.
3: Return -1.
Code and Algorithm Visualization: http://www.ideserve.co.in/learn/binary-search-in-a-sorted-array
Binary Search Playlist: https://www.youtube.com/playlist?list=PLamzFoFxwoNhR2uFoqm6nr8VgsERgTmYy
Website: http://www.ideserve.co.in
Facebook: https://www.facebook.com/IDeserve.co.in
Видео Binary Search канала IDeserve
How to find an element in a sorted array using Binary Search.
Solution:
1: Take start = 0, end = length of array - 1.
2: Repeat following steps till start is less than or equal to end:
(a) Set mid = (start + end)/2.
(b) Check if array[mid] == num, then return mid.
(c) If num is less than array[mid], set end = mid-1, to look for num in first half of the array.
(d) Else set start = mid+1, to look for num in second half of the array.
3: Return -1.
Code and Algorithm Visualization: http://www.ideserve.co.in/learn/binary-search-in-a-sorted-array
Binary Search Playlist: https://www.youtube.com/playlist?list=PLamzFoFxwoNhR2uFoqm6nr8VgsERgTmYy
Website: http://www.ideserve.co.in
Facebook: https://www.facebook.com/IDeserve.co.in
Видео Binary Search канала IDeserve
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
Programming Interview Question: How to print all diagonal's sums for a given binary tree?Level Order TraversalReverse a Linked List - IterativeProgramming Interview Question: Searching a 2D Sorted MatrixImplement a fair coin given an unfair coinBuying and selling stocksMinimum length subarray of an unsorted array sorting which results in complete sorted arrayFind an element in a sorted rotated array without finding pivot (minimum element)Maximum size square sub-matrix with all 1sBuilding Bridges Dynamic ProgrammingLeaders in an arrayFind intersection of two Linked Lists - O(A + B) Time Complexity and O(1) Space ComplexityCreate a balanced Binary Search Tree (BST) from a sorted arrayNext greater element in an arraySpiral level order traversal of a binary treeProgramming Interview Question: Recover Binary Search TreeDetect a loop in a linked listProgramming Interview Question: Find intersection of two Linked ListsFind an element in a sorted rotated arrayDemo of IDeserve web platform www.ideserve.co.in