binary search tree
TRANSCRIPT
![Page 1: Binary search tree](https://reader036.vdocuments.us/reader036/viewer/2022082600/587cb2c81a28ab38028b5085/html5/thumbnails/1.jpg)
821 3 4 65 7 109 11 12 14130
641413 25 33 5143 53 8472 93 95 97966
Binary Search
lo
Binary search. Given value and sorted array a[], find index isuch that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo] value a[hi].
Ex. Binary search for 33.
hi
![Page 2: Binary search tree](https://reader036.vdocuments.us/reader036/viewer/2022082600/587cb2c81a28ab38028b5085/html5/thumbnails/2.jpg)
Binary Search
Binary search. Given value and sorted array a[], find index isuch that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo] value a[hi].
Ex. Binary search for 33.
821 3 4 65 7 109 11 12 14130
641413 25 33 5143 53 8472 93 95 97966
lo himid
![Page 3: Binary search tree](https://reader036.vdocuments.us/reader036/viewer/2022082600/587cb2c81a28ab38028b5085/html5/thumbnails/3.jpg)
Binary Search
Binary search. Given value and sorted array a[], find index isuch that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo] value a[hi].
Ex. Binary search for 33.
821 3 4 65 7 109 11 12 14130
641413 25 33 5143 53 8472 93 95 97966
lo hi
![Page 4: Binary search tree](https://reader036.vdocuments.us/reader036/viewer/2022082600/587cb2c81a28ab38028b5085/html5/thumbnails/4.jpg)
Binary Search
Binary search. Given value and sorted array a[], find index isuch that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo] value a[hi].
Ex. Binary search for 33.
821 3 4 65 7 109 11 12 14130
641413 25 33 5143 53 8472 93 95 97966
lo mid hi
![Page 5: Binary search tree](https://reader036.vdocuments.us/reader036/viewer/2022082600/587cb2c81a28ab38028b5085/html5/thumbnails/5.jpg)
Binary Search
Binary search. Given value and sorted array a[], find index isuch that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo] value a[hi].
Ex. Binary search for 33.
821 3 4 65 7 109 11 12 14130
641413 25 33 5143 53 8472 93 95 97966
lo hi
![Page 6: Binary search tree](https://reader036.vdocuments.us/reader036/viewer/2022082600/587cb2c81a28ab38028b5085/html5/thumbnails/6.jpg)
Binary Search
Binary search. Given value and sorted array a[], find index isuch that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo] value a[hi].
Ex. Binary search for 33.
821 3 4 65 7 109 11 12 14130
641413 25 33 5143 53 8472 93 95 97966
lo himid
![Page 7: Binary search tree](https://reader036.vdocuments.us/reader036/viewer/2022082600/587cb2c81a28ab38028b5085/html5/thumbnails/7.jpg)
Binary Search
Binary search. Given value and sorted array a[], find index isuch that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo] value a[hi].
Ex. Binary search for 33.
821 3 4 65 7 109 11 12 14130
641413 25 33 5143 53 8472 93 95 97966
lohi
![Page 8: Binary search tree](https://reader036.vdocuments.us/reader036/viewer/2022082600/587cb2c81a28ab38028b5085/html5/thumbnails/8.jpg)
Binary Search
Binary search. Given value and sorted array a[], find index isuch that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo] value a[hi].
Ex. Binary search for 33.
821 3 4 65 7 109 11 12 14130
641413 25 33 5143 53 8472 93 95 97966
lohimid
![Page 9: Binary search tree](https://reader036.vdocuments.us/reader036/viewer/2022082600/587cb2c81a28ab38028b5085/html5/thumbnails/9.jpg)
Binary Search
Binary search. Given value and sorted array a[], find index isuch that a[i] = value, or report that no such index exists.
Invariant. Algorithm maintains a[lo] value a[hi].
Ex. Binary search for 33.
821 3 4 65 7 109 11 12 14130
641413 25 33 5143 53 8472 93 95 97966
lohimid