Skip to content

Commit

Permalink
Update Thu Mar 11 14:16:36 PST 2021
Browse files Browse the repository at this point in the history
  • Loading branch information
zedchance committed Mar 11, 2021
1 parent bc076a6 commit fc5d48a
Show file tree
Hide file tree
Showing 510 changed files with 12,125 additions and 41,302 deletions.
2 changes: 2 additions & 0 deletions content/CS10/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ bookCollapseSection: true
weight: 1
---

# CS10 – Intro to Computer Science

{{<section>}}

3 changes: 3 additions & 0 deletions content/CS12/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
title: "CS12"
bookCollapseSection: true
weight: 1
bookToc: false
---

# CS12 – Programming Concepts and Methods I

{{<section>}}
2 changes: 2 additions & 0 deletions content/CS13/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ bookCollapseSection: true
weight: 1
---

# CS13 – Programming Concepts and Methods II

{{<section>}}

7 changes: 4 additions & 3 deletions content/CS130/CS130-exercise-solutions-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ tags:
![72F6E1281BFBD89B0B423172C055D5B5-annotated.jpg](/notes/68152D3F4C9C983C922ABFDE4991969D.jpg)
![IMAGE](/notes/42802F0CEFC96038C9D01EB2F0FA0ECB.jpg)

For example if n = 6:
For example if {{<k>}} n = 6 {{</k>}}:

{{< katex display >}}
\begin{aligned}
t(n) &= t(n) \cdot t(n-1) \cdot t(n-2) \cdot t(n-3) \cdot t(n-4) \cdot t(n-5) \\
&= \underbrace{6 \cdot 5 \cdot 4 \cdot 3 \cdot 2 \cdot 1}_{\text{this happens} \,n\, \text{times}}
&= \underbrace{6 \cdot 5 \cdot 4 \cdot 3 \cdot 2 \cdot 1}_{\text{this happens } n \text{ times}}
\end{aligned}
{{< /katex >}}

So we have a time complexity of O(n)
So we have a time complexity of {{<k>}} O(n) {{</k>}}.

---

Expand All @@ -30,3 +30,4 @@ So we have a time complexity of O(n)


![7F7AE5D7CEDB82541183A389658C1A11-annotated.jpg](/notes/84AFC70D22F86CBB836D20380991322E.jpg)

2 changes: 1 addition & 1 deletion content/CS130/CS130-lecture-20201207.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: CS130-lecture-20201207
tags: ["shortest path tree", "dijkstra's algorithm", "bellman-ford algorithm", "turning machine"]
tags: ["shortest path tree", "dijkstra's algorithm", "bellman-ford algorithm", "turing machine"]
---

## Exercise solutions
Expand Down
5 changes: 3 additions & 2 deletions content/CS130/CS130-sorting-algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,6 @@ public class Quick

Algorithm | Running time complexity | Space complexity
--- | --- | ---
Merge | **O(nlog(n))** | **O(n)**
Quick | Best: **O(nlog(n))** Worst: **O(n^2)** | Best: **O(log(n))** Worst: **O(n)**
Merge | {{<k>}} O(nlog(n)) {{</k>}} | {{<k>}} O(n) {{</k>}}
Quick | Best: {{<k>}} O(nlog(n)) {{</k>}} Worst: {{<k>}} O(n^2) {{</k>}} | Best: {{<k>}} O(log(n)) {{</k>}} Worst: {{<k>}} O(n) {{</k>}}

2 changes: 2 additions & 0 deletions content/CS130/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ bookCollapseSection: true
weight: 1
---

# CS130 – Data Structures and Algorithms

{{<section>}}

1 change: 1 addition & 0 deletions content/CS131/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ bookCollapseSection: true
weight: 1
---

# CS131 – Software Engineering

{{<section>}}
2 changes: 1 addition & 1 deletion content/CS133/CS133-lecture-20210307.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: "CS133-lecture-20210307"
# date: 2021-03-07T10:39:46-08:00
draft: false
bookToc: true
tags: []
tags: ["clean code"]
---

## Make your code suck less
Expand Down
2 changes: 2 additions & 0 deletions content/CS133/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ bookCollapseSection: true
weight: 1
---

# CS133 – Object Oriented Computer Graphics

{{<section>}}
1 change: 0 additions & 1 deletion content/CS135/CS135-lecture-20210310.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,3 @@ Finally check if the stack is empty, step 4:

We can only get to the accept state if the stack is empty.


103 changes: 103 additions & 0 deletions content/CS135/CS135-lecture-20210311.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
title: "CS135-lecture-20210311"
# date: 2021-03-11T12:36:03-08:00
draft: false
bookToc: true
tags: ["push-down automata"]
---

## Introduction to push-down automata

A push-down automata is a finite automata with memory, more than what state its currently in.
It is a non-deterministic finite automata with a stack for memory.
Since it is drawn very similarly to drawing finite automata, we will just notate how the stack is being manipulated on the transitions.

### Drawing transitions for PDAs

Each arrow has a triple: `a,b,c`, where
- `a` is the char to consume from input (or {{<k>}} \lambda {{</k>}})
- `b` is the char to pop from the top of the stack, `b` is always popped when following this transition
- `c` is a string to push onto the stack (from right to left)

An arrow can be followed if and only if:
- `a` matches next input char (or {{<k>}} \lambda {{</k>}}), and
- `b` matches top of the stack

Following the arrow: consumes `a`, pops `b`, pushes `c`

Convention: when drawing the PDAs, {{<k>}} \emptyset {{</k>}} signifies the bottom of the stack at start.

### Steps to follow when creating a PDA

1. Think of a stack-based algorithm
2. Try to implement the algorithm with a PDA

### Example 1

The language {{<k>}} L = \{a^n b^n: n \geq 0\} {{</k>}} represents the strings {{<k>}} \{\lambda, ab, aabb, aaabbb, \ldots\} {{</k>}}.

We saw earlier that we cannot represent this language using finite automata, proving it wasn't a regular language.
Let's think of an algorithm to accomplish this language:

1. Consume an {{<k>}} a {{</k>}} and push it onto the stack
2. When we start to see {{<k>}} b {{</k>}}'s we pop an {{<k>}} a {{</k>}}

We can start with the first {{<k>}} a {{</k>}} seen:

![image_2021-03-11-13-26-12](/notes/image_2021-03-11-13-26-12.png)

Then we can self loop for the next {{<k>}} a {{</k>}} when there is already one on the stack:

![image_2021-03-11-13-27-04](/notes/image_2021-03-11-13-27-04.png)

We can think of the first state as "pushing {{<k>}} a {{</k>}}'s onto the stack."
After this phase we will move onto "matching {{<k>}} b {{</k>}}'s", this will be our second state.

The first self loop consumes the {{<k>}} b {{</k>}}, and pops the {{<k>}} a {{</k>}}, and pushes the empty string back to the stack ({{<k>}} \lambda {{</k>}}).

![image_2021-03-11-13-30-19](/notes/image_2021-03-11-13-30-19.png)

The arrow transitioning from the first to the second state will be {{<k>}} b,a,\lambda {{</k>}}:

![image_2021-03-11-13-32-50](/notes/image_2021-03-11-13-32-50.png)

{{< hint info >}}
Note: This arrow could also be labeled \\( \lambda,a,a \\)
{{< /hint >}}

At this point the PDA will work with all of the good strings in the language.
To decide where the accept state is we need to think of what the stack should look like once the string is consumed.
When we no input and the bottom of the stack, we can accept, {{<k>}} \lambda, \emptyset, \emptyset {{</k>}}:

![image_2021-03-11-13-36-47](/notes/image_2021-03-11-13-36-47.png)

String is accepted if and only if {{<k>}} a^n b^n {{</k>}} seen and all input is consumed.
The last thing to take care of is accepting the empty string {{<k>}} \lambda {{</k>}}.
To do this, we can add {{<k>}} \lambda, \emptyset, \emptyset {{</k>}} on the middle arrow:

![image_2021-03-11-13-41-01](/notes/image_2021-03-11-13-41-01.png)

### Example 2

Consider the language {{<k>}} L= \{w \mid w \in \{a,b\} \text{ and } w \text{ has equal number of } a \text{'s and } b \text{'s} \} {{</k>}}.

To accomplish:
- Use the stack to keep match of excess

![image_2021-03-11-13-50-26](/notes/image_2021-03-11-13-50-26.png)

Input is accepted if and only if all input is consumed with an equal amount of {{<k>}} a {{</k>}}'s and {{<k>}} b {{</k>}}'s (stack is empty).

## Relative power of PDA

Recall, we showed that any NFA can be expressed as a DFA, therefore they have the same expressive power.
Every NFA can be turned into an equivalent PDA.

Any arrow labeled {{<k>}} x {{</k>}} in a NFA can be expressed as an arrow triple {{<k>}} x, \emptyset, \emptyset {{</k>}} in a PDA.

Therefore, the power a PDA has is greater than or equal to an NFA's power.

PDA's can recognize {{<k>}} a^nb^n {{</k>}}, and no NFA can recognize this language.

So a PDA is not equal in power to a NFA, so therefore it must mean that a PDA is greater than a NFA in expressive ability.

2 changes: 2 additions & 0 deletions content/CS135/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ bookCollapseSection: true
weight: 1
---

# CS135 – Computer Theory and Programming Languages

{{<section>}}
2 changes: 2 additions & 0 deletions content/CS137/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ bookCollapseSection: true
weight: 1
---

# CS137 – Computer Organization

{{<section>}}
90 changes: 90 additions & 0 deletions content/CS138/CS138-lecture-20210311.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: "CS138-lecture-20210311"
# date: 2021-03-11T08:53:51-08:00
draft: false
bookToc: true
tags: ["UDP"]
---

## UDP cont.

![image_2021-03-11-09-01-20](/notes/image_2021-03-11-09-01-20.png)
![image_2021-03-11-09-01-54](/notes/image_2021-03-11-09-01-54.png)
![image_2021-03-11-09-02-50](/notes/image_2021-03-11-09-02-50.png)
![image_2021-03-11-09-03-06](/notes/image_2021-03-11-09-03-06.png)
![image_2021-03-11-09-07-34](/notes/image_2021-03-11-09-07-34.png)

## Principles of reliable data transfer

![image_2021-03-11-09-11-07](/notes/image_2021-03-11-09-11-07.png)
![image_2021-03-11-09-12-50](/notes/image_2021-03-11-09-12-50.png)
![image_2021-03-11-09-15-32](/notes/image_2021-03-11-09-15-32.png)
![image_2021-03-11-09-17-24](/notes/image_2021-03-11-09-17-24.png)
![image_2021-03-11-09-17-28](/notes/image_2021-03-11-09-17-28.png)

{{< columns >}}
Expected features
- No bit errors
- No loss of data

<--->

Problems
- Bit error
- Data loss

<--->

Solutions
1. Error detection (checksum)
2. Data recovery
{{< /columns >}}

![image_2021-03-11-09-21-00](/notes/image_2021-03-11-09-21-00.png)
![image_2021-03-11-09-24-20](/notes/image_2021-03-11-09-24-20.png)

So how do we do recovery?
We learn from human to human conversation, *"pardon?"* to recover data loss in the conversation.

Feedback: ACK for positive, NAK for negative.

So the receiver will send an ACK if the packet was received without loss, otherwise it'll send NAK.
Then, from the sender's perspective it will move on to the next data transmission if ACK is received from receiver.
Otherwise, (NAK from receiver) it will retransmit the last data until an ACK is received.

![image_2021-03-11-09-37-13](/notes/image_2021-03-11-09-37-13.png)

So we have a new problem, what if ACK/NAK is corrupted on the way back?

The sender has no way to find out whether the current packet was successful or not.
We can allow the sender to retransmit the data, but it can cause duplicates on the receiver's side.
To avoid and handle duplicates, the sender adds a sequence number to each packet, this way the receiver can discard duplicates.

![image_2021-03-11-09-41-53](/notes/image_2021-03-11-09-41-53.png)

We have to stop and wait, each time we only transmit one single packet.
If we're only sending 1 packet at a time, when we wait until its successful each time we give it a sequence number, so we actually only need 2 different sequence numbers.

pkt 0... pkt 1... pkt 0... pkt 1... etc

![image_2021-03-11-09-48-26](/notes/image_2021-03-11-09-48-26.png)

What if the ACK response is corrupted?

![image_2021-03-11-09-50-06](/notes/image_2021-03-11-09-50-06.png)
![image_2021-03-11-09-50-45](/notes/image_2021-03-11-09-50-45.png)
![image_2021-03-11-09-51-34](/notes/image_2021-03-11-09-51-34.png)
![image_2021-03-11-09-55-53](/notes/image_2021-03-11-09-55-53.png)

If the sender receives the same ACK for the same packet, then that must mean that the last packet was corrupted during transmission.
Instead of sending NAK for the current packet, it is equivalent of sending the ACK for the last packet.
This tells the sender that the current packet wasn't successful, and the sender should retransmit.

![image_2021-03-11-10-00-24](/notes/image_2021-03-11-10-00-24.png)

NAK 1 -> ACK 0;

NAK 0 -> ACK 1;

If the first packet has a problem, then simply no response shows that it had a problem.

2 changes: 2 additions & 0 deletions content/CS138/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ bookCollapseSection: true
weight: 1
---

# CS138 – Computer Networking and Internet

{{<section>}}
2 changes: 2 additions & 0 deletions content/CS26/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ bookCollapseSection: true
weight: 1
---

# CS26 – Discrete Structures

{{<section>}}
2 changes: 2 additions & 0 deletions content/CS39/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ bookCollapseSection: true
weight: 1
---

# CS39 – Intro to Computer Architecture

{{<section>}}
2 changes: 2 additions & 0 deletions content/CS46/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ bookCollapseSection: true
weight: 1
---

# CS46 – System Programming with C

{{<section>}}
30 changes: 0 additions & 30 deletions content/ENGL1B/ENGL1B-assignment-8.md

This file was deleted.

7 changes: 0 additions & 7 deletions content/ENGL1B/_index.md

This file was deleted.

2 changes: 2 additions & 0 deletions content/MATH100/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ bookCollapseSection: true
weight: 1
---

# MATH100 – Applied Linear Algebra

{{<section>}}
2 changes: 2 additions & 0 deletions content/MATH31/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ bookCollapseSection: true
weight: 1
---

# MATH31 – Calculus II

{{<section>}}

0 comments on commit fc5d48a

Please sign in to comment.