Skip to content

Commit 87c3adf

Browse files
committed
Initial commit.
0 parents  commit 87c3adf

File tree

246 files changed

+3884
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+3884
-0
lines changed

.github/workflows/deploy-website.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: deploy website
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
deploy-website:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- uses: cachix/install-nix-action@v27
14+
with:
15+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
16+
17+
- run: nix develop --command make
18+
19+
- name: Deploy
20+
uses: peaceiris/actions-gh-pages@v4
21+
with:
22+
github_token: ${{ secrets.GITHUB_TOKEN }}
23+
publish_dir: ./_build

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_build
2+
.DS_Store

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.PHONY: html
2+
html:
3+
practicebank build problems _build --template template.html
4+
cp style.css _build/style.css

flake.lock

+95
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-23.05;
3+
4+
inputs.practicebank.url = github:eldridgejm/practicebank/0.1.5;
5+
inputs.practicebank.inputs.nixpkgs.follows = "nixpkgs";
6+
7+
outputs = {
8+
self,
9+
nixpkgs,
10+
practicebank,
11+
}: let
12+
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-darwin"];
13+
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
14+
in {
15+
devShell = forAllSystems (
16+
system: let
17+
pkgs = nixpkgs.legacyPackages.${system};
18+
in
19+
pkgs.mkShell {
20+
buildInputs = [
21+
# python environment
22+
(
23+
pkgs.python3.withPackages (p: [
24+
practicebank.defaultPackage.${system}
25+
])
26+
)
27+
];
28+
}
29+
);
30+
};
31+
}

problems/001/code.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def foo(n):
2+
i = 0
3+
while i < n**2:
4+
i = i + 2
5+
j = 0
6+
while j < n:
7+
for k in range(n):
8+
print(i + j + k)
9+
j = j + 10

problems/001/problem.tex

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
%% source: 2022-fa-redemption_midterm_01
2+
%% tags: [time complexity]
3+
\begin{prob}
4+
What is the time complexity of the following function in terms of $n$?
5+
State your answer using asymptotic notation (e.g., $\Theta(n)$).
6+
7+
\inputminted{python}{./code.py}
8+
9+
\begin{soln}
10+
$\Theta(n^4)$
11+
\end{soln}
12+
13+
\end{prob}

problems/002/code.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def foo(n):
2+
for i in range(n**2):
3+
4+
for j in range(i):
5+
print(i+j)
6+
7+
for k in range(n):
8+
print(i+k)
9+
10+
for x in range(n - i):
11+
print(x)

problems/002/problem.tex

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
%% source: 2022-fa-redemption_midterm_01
2+
%% tags: [time complexity]
3+
\begin{prob}
4+
What is the time complexity of the following function in terms of $n$?
5+
6+
\inputminted{python}{./code.py}
7+
8+
\begin{soln}
9+
$\Theta(n^4)$
10+
\end{soln}
11+
12+
\end{prob}

problems/003/code.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from math import sqrt, log, ceil
2+
3+
def foo(n):
4+
for i in range(ceil(n**3 - 10*n + sqrt(n))):
5+
for j in range(ceil(log(n**2))):
6+
print(i, j)

problems/003/problem.tex

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
%% source: 2022-fa-redemption_midterm_01
2+
%% tags: [time complexity]
3+
\begin{prob}
4+
What is the time complexity of the following function in terms of $n$?
5+
6+
\inputminted{python}{./code.py}
7+
8+
\begin{soln}
9+
$\Theta(n^3 \log n)$
10+
\end{soln}
11+
12+
\end{prob}

problems/004/code.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def foo(arr):
2+
"""`arr` is a list containing n numbers."""
3+
for x in arr:
4+
if x > max(arr) / 2:
5+
print('large!')
6+
elif x < min(arr) * 2:
7+
print('small!')
8+
else:
9+
print('neither!')

problems/004/problem.tex

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
%% source: 2022-fa-redemption_midterm_01
2+
%% tags: [time complexity]
3+
\begin{prob}
4+
What is the time complexity of the following function in terms of $n$?
5+
6+
\inputminted{python}{./code.py}
7+
8+
\begin{soln}
9+
$\Theta(n^2)$
10+
\end{soln}
11+
12+
\end{prob}

problems/005/code.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def foo(arr):
2+
"""`arr` is a list containing n numbers."""
3+
previous = None
4+
n = len(arr)
5+
for x in arr:
6+
if x == previous:
7+
for i in range(n**2):
8+
print('Equal!')
9+
return
10+
previous = x

problems/005/problem.tex

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
%% source: 2022-fa-redemption_midterm_01
2+
%% tags: [best and worst case]
3+
\begin{prob}
4+
What is the \textbf{best case} time complexity of the following function in
5+
terms of $n$?
6+
7+
\inputminted{python}{./code.py}
8+
9+
\begin{soln}
10+
$\Theta(n)$
11+
\end{soln}
12+
13+
\end{prob}

problems/006/problem.tex

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
%% source: 2022-fa-redemption_midterm_01
2+
%% tags: [best and worst case]
3+
\begin{prob}
4+
What is the \textbf{worst case} time complexity of the function in the previous problem?
5+
6+
\begin{soln}
7+
$\Theta(n^2)$
8+
\end{soln}
9+
10+
\end{prob}

problems/007/problem.tex

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
%% source: 2022-fa-redemption_midterm_01
2+
%% tags: [theoretical lower bounds]
3+
\begin{prob}
4+
Suppose you are given a (possibly unsorted) array containing $n$ elements.
5+
Each element is either zero or one. You are tasked with determining if
6+
the majority (at least half) of the array's elements are one.
7+
8+
What is the \textbf{tight} theoretical lower bound for the worst case time
9+
complexity of this problem?
10+
11+
\begin{soln}
12+
$\Theta(n)$
13+
\end{soln}
14+
15+
\end{prob}

problems/008/problem.tex

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
%% source: 2022-fa-redemption_midterm_01
2+
%% tags: [theoretical lower bounds, sorted structure]
3+
\begin{prob}
4+
5+
Consider the same problem as above, except now you may assume that the array
6+
is \textbf{sorted}. What is the \textbf{tight} theoretical lower bound for the worst
7+
case time complexity of any algorithm which solves this problem?
8+
9+
\begin{soln}
10+
$\Theta(1)$
11+
\end{soln}
12+
13+
\end{prob}

problems/009/code.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import random
2+
3+
def foo(n):
4+
# draw a random number uniformly from 0, 1, 2, ..., 99
5+
# in constant time
6+
x = random.randrange(100)
7+
for i in range(x):
8+
for j in range(n):
9+
print("Here!")

problems/009/problem.tex

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
%% source: 2022-fa-redemption_midterm_01
2+
%% tags: [expected time]
3+
\begin{prob}
4+
What is the \textbf{expected} time complexity of the function below?
5+
6+
\inputminted{python}{./code.py}
7+
8+
\begin{soln}
9+
$\Theta(n)$
10+
\end{soln}
11+
12+
\end{prob}

problems/010/code.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import random
2+
3+
def foo(n):
4+
# draw a number uniformly at random from 0, 1, 2, ..., n-1
5+
# in constant time
6+
x = random.randrange(n)
7+
if x < 100:
8+
for j in range(n**2):
9+
print(j)

problems/010/problem.tex

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
%% source: 2022-fa-redemption_midterm_01
2+
%% tags: [expected time]
3+
\begin{prob}
4+
What is the \textbf{expected} time complexity of the function below?
5+
6+
\inputminted{python}{./code.py}
7+
8+
\begin{soln}
9+
$\Theta(n)$
10+
\end{soln}
11+
12+
\end{prob}

problems/011/code.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def foo(arr, stop=None):
2+
if stop is None:
3+
stop = len(arr) - 1
4+
5+
if stop < 0:
6+
return 1
7+
8+
last = arr[stop]
9+
return last * foo(arr, stop - 1)

problems/011/problem.tex

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
%% source: 2022-fa-redemption_midterm_01
2+
%% tags: [recurrence relations]
3+
\begin{prob}
4+
State (but do not solve) the recurrence describing the run time of the following code,
5+
assuming that the input, \mintinline{python}{arr}, is a list of size $n$.
6+
7+
\inputminted{python}{./code.py}
8+
9+
\begin{soln}
10+
$T(n) = T(n-1) + \Theta(1)$
11+
\end{soln}
12+
13+
\end{prob}

0 commit comments

Comments
 (0)