From our textbook:
An algorithm is an explicit, precise, unambiguous, mechanically-executable sequence of elementary instructions, usually intended to accomplish a specific purpose.
From , by Cormen, et. al. [CLRS]:
An algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output.
PeasantMultiply(X, Y):
prod <- 0
x <- X
y <- Y
while x > 0
if x is odd
prod <- prod + y
x <- floor(x/2) # mediation
y <- y + y # duplation
return prod
PeasantMultiply(X, Y):
prod <- 0
x <- X
y <- Y
while x > 0
if x is odd
prod <- prod + y
x <- floor(x/2) # mediation
y <- y + y # duplation
return prod
XY == prod + xy
is an invariant for the while loop.x == 0
, so prod == XY
.X
and Y
.PeasantMultiply(X, Y):
prod <- 0
x <- X
y <- Y
while x > 0
if x is odd
prod <- prod + y
x <- floor(x/2) # mediation
y <- y + y # duplation
return prod
How many mediation and duplation operations does this algorithm require?
We use big-\(O\) to represent asymptotic upper bounds, and big-\(\Omega\) for asymptotic lower bounds.
Join the voice channel for your group. (Video on if possible.)
Table #1 | Table #2 | Table #3 | Table #4 | Table #5 | Table #6 |
---|---|---|---|---|---|
Graham | Jordan | Grace | Jack | Kevin | Claire |
Levi | Ethan | Trevor | Andrew | Drake | Nathan |
Bri | Josiah | Kristen | John | Blake | Logan |
James | Timothy | Talia | Isaac |
Complete the group exercise on the Jamboard.
For each pair of expressions \((A,B)\), indicate whether \(A\) is \(O,o,\Omega,\omega,\) and/or \(\Theta\) of \(B\). Check all boxes that apply. Put a ? where you are not sure. Here \(c>1\), \(\epsilon>0\), and \(k\geq 1\) represent constants.
\(A\) | \(B\) | \(O\) | \(o\) | \(\Omega\) | \(\omega\) | \(\Theta\) |
---|---|---|---|---|---|---|
\(100n^2 + 1000n\) | \(n^3\) | |||||
\(\log_2 n\) | \(\log_c n\) | |||||
\(n^k\) | \(c^n\) | |||||
\(\sqrt{n}\) | \(n^{\sin n}\) | |||||
\(2^n\) | \(2^{n/2}\) | |||||
\(n^{\log_2 c}\) | \(c^{\log_2 n}\) | |||||
\(\log_2(n!)\) | \(\log_2(n^n)\) | |||||
\((\log_2 n)^k\) | \(n^\epsilon\) |
.html
file to Canvas.Task | % of total |
---|---|
Daily Assignments: | 44% |
Exams: | 3 @ 14% each |
Final Exam: | 14% |
https://djhunter.github.io/algorithms/