# Algorithms and Data Structures

Algorithm -- briefly, is a step-by-step instruction that as a whole complete a process. Usually this process solves problems such as sorting , finding data, and many other problems. It can be thought of as a recipe, with each ingredient contributing to the whole food, thus solving your problem of hunger :)

## Examples of Algorithms

Linear searching algorithm : A linear searching has O(n) time complexity. Lets step through a process of creating an algorithm for this problem.

Steps:

1. We need a way to check through every element in the data. This can be done through a loop. A loop (ex, for loop , while loop) enables the programmer to run a block of code multiple times
2. Each iteration we need to check if the value that we are searching for matches. If so then return that index.
3. handle error, like what happens if the value we are searching for is not there ?

Since we have the step-by-step process written. We are able to effectively write an algorithm that follows the process above.

This function is written in C++.

int searchLinearly( int * Array, int MaxSize, int searchValue)
{
//Step # 1 - loop through every element if needed
for(int i = 0; i < MaxSize; i++)
{
if( Array[i] == searchValue ) // Step # 2 -- search value
return i;
}

return -1; //Step # 3 -- handle error if value not found
}

So as you can see there is a step-by-step process in creating an algorithm. The above code could be written in template version but I chose not to for simplicity sake.

## See also

 Wikibooks has a book on the topic of Algorithms.

Coming soon.