Skip to content
Merged

V4 #1

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ tsconfig.tsbuildinfo
private/
.replit
replit.nix
content/SEM_6/.obsidian
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
# Quartz v4

> “[One] who works with the door open gets all kinds of interruptions, but [they] also occasionally gets clues as to what the world is and what might be important.” — Richard Hamming

Quartz is a set of tools that helps you publish your [digital garden](https://jzhao.xyz/posts/networked-thought) and notes as a website for free.

🔗 Read the documentation and get started: https://quartz.jzhao.xyz/

[Join the Discord Community](https://discord.gg/cRFFHYye7t)

## Sponsors

<p align="center">
<a href="https://github.com/sponsors/jackyzha0">
<img src="https://cdn.jsdelivr.net/gh/jackyzha0/jackyzha0/sponsorkit/sponsors.svg" />
</a>
</p>
notes
1 change: 0 additions & 1 deletion content/Measure-Theory-Notes/Measure_Theory/Info.md

This file was deleted.

62 changes: 62 additions & 0 deletions content/SEM_6/DSA/Lecture 01 - Jan 5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## Basic Algorithms

### Sum of Two Numbers

**Pseudo Code:**
1. Read $a, b$
2. $S = a + b$
3. Print $S$

**Implementation (C):**
```c
#include <stdio.h>

int main() {
int a, b, sum;

printf("Enter two numbers: ");
scanf("%d %d", &a, &b);

sum = a + b;

printf("Sum = %d\n", sum);

return 0;
}
```

### Sum of m Numbers

**Algorithm:**
1. Read $m$ numbers
2. Initialize $S = 0$
3. For $i = 0$ to $m - 1$:
- $S = S + A[i]$
4. Print $S$

### Matrix Sum - 2D Array

**Algorithm:**
1. Read $m, n$ (dimensions of matrix)
2. Initialize $S = 0$
3. For $i = 0$ to $n - 1$:
- For $j = 0$ to $m - 1$:
- Read $A[i][j]$
- $S = S + A[i][j]$
4. Print $S$

### Recursion: Factorial

**Recurrence Relation:**
$$\text{Fact}(n) = \begin{cases} 1 & \text{if } n = 0 \\ n \times \text{Fact}(n-1) & \text{else} \end{cases}$$

### Algorithm Properties

- **Input:** Zero or more inputs
- **Output:** At least 1 output
- **Efficiency:** Minimal time and space complexity

### Topics to Cover

- Prime Checkers
- Fibonacci Number
79 changes: 79 additions & 0 deletions content/SEM_6/DSA/Lecture 02 - Jan 6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
## Algorithm Properties

1. Input $\geq 0$ (zero or more)
2. Output $\geq 1$ (at least one)
3. Correct
4. Language Independent
5. Unambiguous
6. Efficiency
- **Time Complexity:** Amount of time taken
- **Space Complexity:** Amount of memory used
---
## Time Complexity Analysis

### Example 1: Sum of Two Numbers

```
(1) Read a, b → Assignment Statement (2 time units)
(2) S = a + b → Constant time 'c' (2 time units)
Logic Operation
(3) Print S → Print operation (1 time unit)
```

**Total Time:** $$T(n) = 2 + 2 + 1 = 5 \rightarrow O(1)$$

### Example 2: Sum of n Numbers

```
S = 0 → 1 time unit
for i = 0 to n → 2n time units
S = S + A[i] → 2n time units
```

**Analysis:**
- $n$ numbers input operations
- Loop executes $n$ times
- Each iteration: constant time operations

$$T(n) = O(n)$$

### Example 3: Matrix Addition - 2D Array

```
for i = 0 to n → Outer loop runs n times
for j = 0 to m → Inner loop runs m times
C[i,j] = A[i,j] + B[i,j] → Executed n × m times
```

**Time Complexity:** $$T(n,m) = O(n \times m)$$

**Note:** For square matrices where $n = m$, complexity is $O(n^2)$

---
## Fibonacci Algorithm

**Iterative Algorithm:** Time Complexity $O(n)$

```
Fib(n)
f1 = 0
f2 = 1

for i = 2 to n
temp = f1 + f2
f1 = f2
f2 = temp

return f2
```

**Recursive Definition:**

$$
\text{Fib}(n) =
\begin{cases}
0 & \text{if } n = 0 \\
1 & \text{if } n = 1 \\
\text{Fib}(n-1) + \text{Fib}(n-2) & \text{otherwise}
\end{cases}
$$
91 changes: 91 additions & 0 deletions content/SEM_6/DSA/Lecture 03 - Jan 8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
## Fibonacci Time Complexity (Continued)

**Recurrence Relation:**
$$f(n) = f(n-1) + f(n-2)$$

**Time Complexity:**
$$T(n) = T(n-1) + T(n-2) + c$$

$$T(n) = a^n$$

where:
$$a^2 = a^1 + a^0$$
$$a^2 - a - 1 = 0$$
$$a = \frac{1 \pm \sqrt{5}}{2}$$

Therefore:
$$T(n) = \left(\frac{1+\sqrt{5}}{2}\right)^n \text{ or } \left(\frac{1-\sqrt{5}}{2}\right)^n = O(\phi^n)$$

where $\phi \approx 1.618$ (golden ratio)

*We take the larger value for upper bound*

---
## Array Search Problems

**Example Array:** $[1, 100, 20, 35, 45] = A[5]$

**Task:** Check if $60$ is present

### Linear Search Algorithm

**Given:** Array $A$ with $n$ elements, search for value $X$

```
for i = 0 to n-1:
if A[i] == X:
return i // Found at index i
return -1 // Not found
```

**Time Complexity:** $T(n) = O(n)$

---
## Binary Search

**Example:** If Array sorted: $[1, 20, 35, 45, 100]$

**Finding 20:**
- Check mid of array $\rightarrow 35$
- Since $20 < 35$: Check left half

### Binary Search Algorithm

```
low = 0
high = n - 1
while (low ≤ high):
mid = (low + high) / 2
if A[mid] == X:
return mid // Found
else if A[mid] > X:
high = mid - 1 // Search left half
else:
low = mid + 1 // Search right half
return -1 // Not found
```

**Time Complexity Analysis:**
$$T(n) = c + T(n/2)$$

where $c$ is constant time for comparison and mid calculation.

**Solving the Recurrence:**

Base case: $T(1) = 1$

$$T(n) = c + T(n/2)$$
$$T(n) = c + c + T(n/4)$$
$$T(n) = c + c + c + ... + T(n/2^i)$$

When $n/2^i = 1$:
$$n = 2^i$$
$$\log_2 n = i$$

Therefore:
$$T(n) = c \cdot i + 1 = c \log n + 1$$

**Final Complexity:**
$$\boxed{T(n) = O(\log n)}$$

> **Note:** Efficient but array must be sorted!
55 changes: 55 additions & 0 deletions content/SEM_6/DSA/Lecture 04 - Jan 12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## Introduction to Algorithms

**ADT (Abstract Data Type):**
- Specifies what data values it can hold
- Specifies what operations can be performed on it

**Data Structure:** How we organize data in memory

**Array Operations:** Inserting, deleting, searching, traversing

### Basic Operations

**Unified Computational Model:** Each basic operation takes constant time (1 unit)

### Linear Search

Given an array of $n$ elements, check if $x$ is present by examining each element.

**Best Case:** $O(1)$ (element found at first position)

**Worst Case:** $O(n)$ (element at end or not present)

**Average Case:** $O(n)$

---
## Asymptotic Analysis of Algorithms

Asymptotic analysis describes how an algorithm behaves as input size increases.

---
## Time Complexity Notations

$$O \qquad \Omega \qquad \Theta$$
$$(\text{Upper Bound}) \quad (\text{Lower Bound}) \quad (\text{Tight Bound})$$

**Example:**
$$T(n) = 100n + 5$$

## Big-O Notation

**Definition:** $f(n) = O(g(n))$ if there exist positive constants $C$ and $n_0$ such that:

$$f(n) \leq C \cdot g(n) \quad \text{for all } n \geq n_0$$

**Example:**

Given $T(n) = 100n + 5$, we want to show $T(n) = O(n)$

$$100n + 5 \leq C \cdot n$$

Choosing $C = 101$ and $n_0 = 5$:

$$100n + 5 \leq 101n \quad \text{for all } n \geq 5$$

Therefore, $100n + 5 = O(n)$
Loading