Difference between revisions of "Algorithm"

esse quam videri
Jump to: navigation, search
 
(5 intermediate revisions by 2 users not shown)
Line 2: Line 2:
 
=Definition=
 
=Definition=
 
A set of rules, or instructions, to perform a calculation or other problem-solving operations.
 
A set of rules, or instructions, to perform a calculation or other problem-solving operations.
 +
 +
Algorithms can be all sorts of things!
 +
[[file:AlgorithmVisual.jpg | 1024 px]]
  
 
=Relevance=
 
=Relevance=
Line 7: Line 10:
  
 
=Explanation=
 
=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.
+
An algorithm is a set of instructions used to perform a task. These tasks can be a multitude of things, such as sorting a list, finding an element in a list, squaring a number, etc.
  
 
=Example=
 
=Example=
Line 22: Line 25:
 
return true;
 
return true;
 
}
 
}
}
+
    }
// result not found after the loop
+
    // result not found after the loop
return false;
+
    return false;
 
}
 
}
  
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
=Resources=
 
 
== See also ==
 
== See also ==
 
* [[Function]]
 
* [[Function]]
Line 43: Line 44:
 
* [[Graph]]
 
* [[Graph]]
  
==Notes==
 
  
  
==External Links==
 
  
  

Latest revision as of 15:10, 8 August 2019

Definition

A set of rules, or instructions, to perform a calculation or other problem-solving operations.

Algorithms can be all sorts of things! AlgorithmVisual.jpg

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. These tasks can be a multitude of things, 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;
}

See also