# 4.2: Some Algorithms


An algorithm is, informally, an explicit set of rules to follow to solve a problem.

Exercise $$\PageIndex{1}$$

Suppose we have a finite list of integers. Describe a method we could use to always find the greatest one.

Below, we give an algorithm in pseudocode to do just this.

algorithm for determining the greatest integer in a finite list

• Input: list of integers, $$\{a_1,a_2,\ldots,a_n\}$$
• Let $$\max := a_1$$
• For $$i$$ from $$2$$ to $$n$$
• if $$\max<a_i$$ then $$\max := a_i$$
• Return $$\max$$

Definition

The time complexity of an algorithm is the time required to run an algorithm. It is usually measured in terms of the number of operations used by an algorithm and expressed in big-O notation.

How many operations does the previous algorithm require?

Exercise $$\PageIndex{2}$$

Determine an algorithm (written in pseudocode) and the time complexity of that algorithm for:

1. computing the dot product of two vectors
2. computing the product of two square matrices
3. sorting a list of integers (so that it is arranged from least to greatest).

4.2: Some Algorithms is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by LibreTexts.