Searching Algorithms
Let's study some famous and important searching algorithms including binary search!
We'll cover the following...
Brute Force: Linear Search
This is the most simple searching algorithm and it is in time. In fact, give it a shot. You’ll probably be able to come up with it yourself!
Press + to interact
main.cpp
AuxiliaryFunctions.cpp
AuxiliaryFunctions.h
#include "AuxiliaryFunctions.h"int linearSearch(int s, int* arr, int arrSize) {return -1;// Write your code here}
How Linear Search works #
Go through each element one by one. When the element that you are searching for is found, return its index. Here are some slides to make things clearer:
Implementation #
Press + to interact
main.cpp
AuxiliaryFunctions.h
AuxiliaryFunctions.cpp
#include <iostream>using namespace std;void printArray(int* arr, int arrSize);int findMin(int* arr, int start, int end);int findMax(int* arr, int start, int end);
Binary Search #
You must have already encountered ...