- First, we will generate a random array using Math.random() function and then sort it using sort() function.
- Different color is used to indicate which element is being traversed at current time.
- Since the algorithm performs the operation very fast, the setTimeout() function has been used to slow down the process.
- New array can be generated by pressing the “Ctrl+R” key.
- The searching is performed using BinarySearch() function.
Below is the program to visualize the Binary Search algorithm.