Linear and Binary searching methods in Java
- Make sure JDK is installed.
- After downloading, go into the directory of the sorting program you'd like to use
- Assuming you want to use linear search, while in the directory in CLI, type:
- javac LinearSearch.java
- java LinearSearch
- Follow the instructions.
- Known as the simplest searching program and best use for smaller elements array only
- Array is traversed from first element to last element
- Current element is compared with the given element to find, returns the index of the element
- Faster than linear search
- Array list MUST be in sorted order (if you input unsorted array, the program automatically sorts the array)
- Follows the divide and conquer strategy and matches the middle element of the divided array