- 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 TernarySearch() function.
Below is the program to visualize the Ternary Search algorithm.
style.css: The following is the content for “style.css” used in the above file.
script.js: The following is the content for “script.js” file used in the above HTML code.