Difference between revisions of "Algorithm"
esse quam videri
(→Example) |
(→Example) |
||
Line 22: | Line 22: | ||
return true; | return true; | ||
} | } | ||
− | + | } | |
− | + | // result not found after the loop | |
− | + | return false; | |
} | } | ||
Revision as of 21:18, 20 June 2019
Contents
Definition
A set of rules, or instructions, to perform a calculation or other problem-solving operations.
Relevance
Often, you'll need the same operation performed with different data, writing algorithms that can do this will let you reuse more code!
Explanation
An algorithm is a set of instructions used to perform a task such as sorting a list, finding an element in a list, squaring a number, etc.
Example
// An example of a simple algorithm to search for an element in a list may look like the following
bool Search(string name, List<string> contacts)
{
for(int i = 0; i < contacts.Count; i++)
{
if(contacts[i] == name)
{
// result found!
return true;
}
}
// result not found after the loop
return false;
}
Resources
See also
- Function
- Heapsort
- Quicksort
- Hash Table
- Recursion
- Binary Search Tree
- Greedy Algorithm
- Binomial Heap
- NP-Completeness
- Graph