Binary Search Flashcards
Hints of BS:
Sorted and target makes it directly Binary Search
What is the raw binary search algorithm?
What is binary search called?
half-interval search
What is binary search?
It is an algorithm used to find the position of a value in a sorted array.
How does BS work?
the list is split in half and then searched in each half. The list must be sorted before running the algorithm.
What loop is must in binary search?
While loop
Binary search while loop format
while left<=right; return the formula
then make the if statements
What is inorder traversal?
- Traverse the left subtree
- Visit the root.
- Traverse the right subtree
Does traversing by inorder traversal, and the elements being in the true order means the tree is actually in order?
IDK yet
What happens if the binary search tree has duplicate elements?
It must be on the left side if it is allowed
flip the logic of BST
Validate the left tree node’s value to make sure that it is less than the current root value(the roots change every node)
BST recursive function with (min,max) range
initially, the range is infinite. At left side, the min is negative infinity and the max is root.value. The recursive function needs to be implemented and properly adjusted the ranges as traversed through the tree