Search⌘ K
AI Features

Searching Algorithms

Explore searching algorithms including linear search and binary search in this lesson. Understand their working principles, step-by-step implementations, and how they differ in terms of efficiency. Gain the knowledge needed to apply these algorithms effectively in coding interviews using Java.

Brute force: Linear search

This is the most simple searching algorithm, and it is in O(n)O(n) time. In fact, give it a shot. You’ll probably be able to come up with it yourself!

Java
class Search {
public static int linearSearch(int s, int[] arr, int arrSize) {
// Write your code here
return Integer.MAX_VALUE;
}
}

How linear search works

Go through each element one by one. When ...