Understanding Bisectors

A bisector will allow us to locate where to insert an element in an array.

We'll cover the following

We are going to need to figure out where to display the tooltip. At the moment, we know where the reader is hovering their mouse. However, we do not know where to display the tooltip. We do not even know which point the reader wants to view. The only information we have at our disposal is the x and y-coordinates of the mouse.

We are going to use a bisector to help us figure out where to display the tooltip. A bisector is a function that allows us to locate where to insert an element into an array in order to maintain a sorted array. Before we discuss how a bisector will help us, let’s look at an example of how a bisector works.

Bisector example

Let’s say we had an array of five numbers. The numbers in this array range from 10 to 50.

Get hands-on with 1200+ tech skills courses.