Skip to content

minor style updates #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 13 additions & 13 deletions modules/CS260/Joes_Notes/Greedy_Algorithms_Scheduling.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Given a set of jobs with a start and end time. Find the largest set of jobs such
* Sort the jobs by end time in ascending order
* Create an empty set of selected jobs
* Iterate though the set of jobs
* * If a job is compatible with the current selected jobs then add it
* If a job is compatible with the current selected jobs then add it

##### Checking For compatibility

Expand All @@ -38,9 +38,9 @@ jobs <- The available jobs with .start and .end

jobs = jobs.sort(job.end) // Sort the job by end time in increasing order O(nlogn)
selected = [] // empty set
for( job : jobs ){
for ( job : jobs ) {
// the first job is added by default
if (selected.length ==0 || last.finish <= job.start){
if (selected.length == 0 || last.finish <= job.start){
selected.add(job)
last=job
}
Expand All @@ -58,7 +58,7 @@ proof by contradiction
* The most efficient set ($$j_1,j_2,j_3...j_m$$) also exists such that the largest $$r$$ can be found
* Select an $$r$$ such that $$\forall v < r : i_v = j_v \land i_r \neq j_r$$ (r is the largest value such that all pairs before r are equal)

As $i_r$ is selected by the finish first algorithm; no job exists that is compatible with $$\{ i_1...i_{r-1} \}$$ and finishes before $$i_r$$ so $$j_r$$ finishes after or with $$i_r$$
As $$i_r$$ is selected by the finish first algorithm; no job exists that is compatible with $$\{ i_1...i_{r-1} \}$$ and finishes before $$i_r$$ so $$j_r$$ finishes after or with $$i_r$$

This implies that $$i_r$$ can replace $$j_r$$ this is contradictory as it goes against the maximality of $$r$$

Expand All @@ -78,7 +78,7 @@ Given a set of jobs (intervals) schedule the jobs into the least number of rooms
* Going through each job in turn
* * check if the new schedule and add the job

#### **Checking For compatibility
#### Checking For compatibility
* Store the schedules in a priority queue
* use the end time of the last job added as the key
* Check compatibility with queue.Find_Min
Expand All @@ -90,18 +90,18 @@ Given a set of jobs (intervals) schedule the jobs into the least number of rooms
```java
rooms= new PriorityQueue
jobs = jobs.sort(job.start)
for (job in jobs){
for (job : jobs) {
// the first job is added by default
if (rooms.length>0 && rooms.find_Min_Key <= job.start){
if (rooms.length > 0 && rooms.find_Min_Key <= job.start) {
room=rooms.pop_Min()
room.add(job)
rooms.add(room,job.end)
}else{
room=[job]
rooms.add(room,job.end)
rooms.add(room, job.end)
} else {
room = [job]
rooms.add(room, job.end)
}
}
return rooms.values();
return rooms.values()
```
<div id="screen1"></div>

Expand Down Expand Up @@ -219,4 +219,4 @@ Show that at every stage of the the greedy algorithm produces a solution that is
Discover structural bounds asserting that every solution must have a set value. Then show your algorithm achieves this bound.

#### Exchange
Gradually transform any optimal solution to the one found by the greedy algorithm without hurting the solution quality.
Gradually transform any optimal solution to the one found by the greedy algorithm without hurting the solution quality.
10 changes: 6 additions & 4 deletions modules/CS260/Joes_Notes/Greedy_Algorithms_Shortest_Path.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ part: true

### Single-Pair Shortest path problem
**Input**:

* A weighted graph/digraph
* A source node(start)
* A destination node(end)

**Output**:
* A shortest path through the graph from the source to the destination

### Single-Source shortest path problem
**Input**:

* A weighted graph/digraph
* A source node(start)

**Output**:
* A set of shortest paths through the graph from the source to every node in the graph
* Can be represented as a tree with the source as the node
Expand All @@ -36,10 +41,7 @@ initialize $$S \leftarrow \{s\}$$ , $$d[u] \leftarrow 0$$
repeatedly:
* choose unexplored node $$v\notin S$$ that minimises $$\pi(v)$$ where:

$$
\pi(v) = \min_{e = (u,v):u \in S}

$$
$$\pi(v) = \min_{e = (u,v):u \in S}$$

* add $$v$$ to $$S$$ , $$d[v]\leftarrow \pi(v)$$
* prev[v] $$\leftarrow e$$
Expand Down