Anki Deck Changes

Commit: 62665c5d - new AD cards

Author: obrhubr <obrhubr@gmail.com>

Date: 2025-12-23T15:39:42+01:00

Changes: 56 note(s) changed (55 added, 1 modified, 0 deleted)

ℹ️ Cosmetic Changes Hidden: 1 note(s) had formatting-only changes and are not shown below

Note 1: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: J5>uyKCn19
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary
The ADT Dictionary implements the following methods:
  • search(x, W) returns the position of the key x in memory
  • insert(x, W) Insert the key x into W, as long as it’s not saved there yet
  • delete(x, W) find and delete the key x from W

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary
The ADT Dictionary implements the following methods:
  • search(x, W) returns the position of the key x in memory
  • insert(x, W) Insert the key x into W, as long as it’s not saved there yet
  • delete(x, W) find and delete the key x from W
Field-by-field Comparison
Field Before After
Text The ADT Dictionary implements the following methods:<br><ul><li>{{c1::<b>search(x, W)</b> returns the position of the key x in memory}}</li><li>{{c2::<b>insert(x, W)</b> Insert the key <b>x</b> into <b>W</b>, as long as it’s not saved there yet}}<br></li><li>{{c3::<b>delete(x, W)</b> find and delete the key <b>x</b> from <b>W</b>}}<br></li></ul>
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary

Note 2: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: M11/nZaHIu
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary
search insert delete
unsorted Array \(O(n)\) \(O(1)\) \(O(n)\)
sorted Array \(O(\log n)\) \(O(n)\) \(O(n)\)
DLL \(O(n)\) (no bin. search possible) \(O(1)\) \(O(n)\)

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary
search insert delete
unsorted Array \(O(n)\) \(O(1)\) \(O(n)\)
sorted Array \(O(\log n)\) \(O(n)\) \(O(n)\)
DLL \(O(n)\) (no bin. search possible) \(O(1)\) \(O(n)\)
Field-by-field Comparison
Field Before After
Text <b></b><b></b><b></b><b></b><table> <tbody><tr> <td></td> <td><b>search</b></td> <td><b>insert</b></td> <td><b>delete</b></td> </tr> <tr> <td>unsorted Array</td> <td>{{c1::\(O(n)\)}}</td> <td>{{c2::\(O(1)\)}}</td> <td>{{c3::\(O(n)\)}}</td> </tr> <tr> <td>sorted Array</td> <td>{{c4::\(O(\log n)\)}}</td> <td>{{c5::\(O(n)\)}}</td> <td>{{c6::\(O(n)\)}}</td> </tr> <tr> <td>DLL</td> <td>{{c7::\(O(n)\) (no bin. search possible)}}</td> <td>{{c8::\(O(1)\)}}</td> <td>{{c9::\(O(n)\)}}</td> </tr> </tbody></table>
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary

Note 3: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: n/PBpw~:i9
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::1._Binary_Search_Trees
We can use a binary search tree to implement the dictionary. The tree-condition is for every node, all keys in the left child are smaller than those in the right child.

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::1._Binary_Search_Trees
We can use a binary search tree to implement the dictionary. The tree-condition is for every node, all keys in the left child are smaller than those in the right child.
Field-by-field Comparison
Field Before After
Text We can use a binary search tree to implement the dictionary. The tree-condition is {{c1::for every node, all keys in the left child are smaller than those in the right child}}.
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::1._Binary_Search_Trees

Note 4: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: kR-q@1!eo3
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::1._Binary_Search_Trees
Runtime: search in binary tree: \(O(h)\) where \(h\) is the height.

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::1._Binary_Search_Trees
Runtime: search in binary tree: \(O(h)\) where \(h\) is the height.
Field-by-field Comparison
Field Before After
Text Runtime:&nbsp;<b>search</b>&nbsp;in binary tree: {{c1::\(O(h)\)&nbsp;where&nbsp;\(h\)&nbsp;is the height}}.
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::1._Binary_Search_Trees

Note 5: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: tH)JXa7KfA
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::1._Binary_Search_Trees
Worst case for search in a binary tree?

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::1._Binary_Search_Trees
Worst case for search in a binary tree?

Binary trees are not balanced possible that \(h >> \log_2 n\)
Worst case example if inserted in ascending order:
Field-by-field Comparison
Field Before After
Front <b>Worst case</b> for <b>search</b> in a <b>binary tree</b>?
Back Binary trees are not&nbsp;<b>balanced</b>&nbsp;possible that&nbsp;\(h &gt;&gt; \log_2 n\)<br>Worst case example if inserted in ascending order:<br><b></b><img src="paste-201c49e27928e7a814e89e8de667e07e5c7789ce.jpg">
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::1._Binary_Search_Trees

Note 6: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: uHC]1fZd$=
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
Tree Condition: for 2-3 Trees implementing dictionary.

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
Tree Condition: for 2-3 Trees implementing dictionary.

Each node has 2 or 3 children but that all leafs are on the same level
Field-by-field Comparison
Field Before After
Front <b>Tree Condition</b>: for&nbsp;<b>2-3 Trees</b>&nbsp;implementing dictionary.
Back Each node has <b>2 or 3 children</b> but that all leafs are <b>on the same level</b>
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees

Note 7: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: H0^#YREe-o
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
2-3 Tree is an external search-tree.

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
2-3 Tree is an external search-tree.

This means that the values are stored in the leaves only. The nodes are for "navigation".
Field-by-field Comparison
Field Before After
Text A&nbsp;<b>2-3 Tree</b>&nbsp;is an {{c1:: external}} search-tree.
Extra This means that the values are stored in the leaves only. The nodes are for "navigation".
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees

Note 8: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: FYr.:eNxT,
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
Types of 2-3 Tree nodes:

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
Types of 2-3 Tree nodes:

keys in left (middle, right) sub-tree \(l\) (\(m, r\) respect.ively):
  1. 2 children: 1 separator \(s\) s.t. for  \(l \leq s < r\).
  2. 3 children: 2 separators \(s_1, s_2\) s.t. \(l \leq s_1 < m \leq s_2 < r\)

Field-by-field Comparison
Field Before After
Front Types of&nbsp;<b>2-3 Tree</b>&nbsp;nodes:
Back keys in left (middle, right) sub-tree&nbsp;\(l\)&nbsp;(\(m, r\)&nbsp;respect.ively):<br><ol><li>2 children: 1 separator&nbsp;\(s\)&nbsp;s.t. for &nbsp;\(l \leq s &lt; r\).</li><li>3 children: 2 separators&nbsp;\(s_1, s_2\)&nbsp;s.t.&nbsp;\(l \leq s_1 &lt; m \leq s_2 &lt; r\)</li></ol><img src="paste-099f4518906c93c69e397c80221d3fd5535c17e2.jpg"><br>
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees

Note 9: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: wbdb9#fK:J
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
Height of a 2-3 Tree for \(n\) keys is \(\leq \log_2(n)\) thus \(h=\)\(O(\log(n)\) (O-notation).

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
Height of a 2-3 Tree for \(n\) keys is \(\leq \log_2(n)\) thus \(h=\)\(O(\log(n)\) (O-notation).

Note that for the case \(n = 1\) the root has one leaf with the key.
Field-by-field Comparison
Field Before After
Text Height of a <b>2-3 Tree</b>&nbsp;for&nbsp;\(n\)&nbsp;keys is {{c1::\(\leq \log_2(n)\)}} thus&nbsp;\(h=\){{c2::\(O(\log(n)\)}} (O-notation).
Extra Note that for the case&nbsp;\(n = 1\)&nbsp;the root has one leaf with the key.
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees

Note 10: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: Br&58pkCU{
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
We start counting the height of a tree at \(0\).

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
We start counting the height of a tree at \(0\).
Field-by-field Comparison
Field Before After
Text We start counting the height of a tree at {{c1::\(0\)}}.
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees

Note 11: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: Bz)mOB:[n-
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
2-3 Tree: Runtime of: Search, Inserting, Deleting:  \(O(\log n)\) 

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
2-3 Tree: Runtime of: Search, Inserting, Deleting:  \(O(\log n)\) 

This is because the tree is now forced to be balanced and \(h \leq \log_2 n\).
Field-by-field Comparison
Field Before After
Text <b>2-3 Tree</b>: Runtime of: Search, Inserting, Deleting: {{c1::&nbsp;\(O(\log n)\)}}&nbsp;
Extra This is because the tree is now forced to be balanced and&nbsp;\(h \leq \log_2 n\).
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees

Note 12: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: H?Cs9sT6&{
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
2-3 Tree: Inserting Steps:
  1. Search for the correct node under which the key is inserted: \(O(\log_2 n)\)
  2. Insert the new key value as a separator
  3. Rebalance (if necessary, i.e. more than 3 keys)
  • split node into two nodes (each gets 2 children and 1 seps)
  • the middle sep is pushed to the parent level (and propagate)

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
2-3 Tree: Inserting Steps:
  1. Search for the correct node under which the key is inserted: \(O(\log_2 n)\)
  2. Insert the new key value as a separator
  3. Rebalance (if necessary, i.e. more than 3 keys)
  • split node into two nodes (each gets 2 children and 1 seps)
  • the middle sep is pushed to the parent level (and propagate)

The rebalancing being recursively pushed to the parent limits the operations at the height \(h\) thus we get \(O(\log n)\).
Field-by-field Comparison
Field Before After
Text <b>2-3 Tree</b>: Inserting Steps:<br><ol><li>{{c1::Search for the correct node under which the key is inserted:&nbsp;\(O(\log_2 n)\)}}</li><li>{{c2::Insert the new key value as a&nbsp;<b>separator</b>}}</li><li>{{c3::<b>Rebalance</b>&nbsp;(if necessary, i.e. more than 3 keys)<br></li></ol><ul><li>split node into two nodes (each gets 2 children and 1 seps)</li><li>the middle sep is pushed to the parent level (and propagate)}}</li></ul>
Extra The rebalancing being recursively pushed to the parent limits the operations at the height&nbsp;\(h\)&nbsp;thus we get&nbsp;\(O(\log n)\).
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees

Note 13: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: OY@2Ay+>4p
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
2-3 Tree: Deleting Steps:
  1. Search for the correct node under which the key is inserted: \(O(\log_2 n)\)
  2. Remove the leaf with the value and one separator
  3. Rebalance (if necessary, i.e. now 1 key)

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
2-3 Tree: Deleting Steps:
  1. Search for the correct node under which the key is inserted: \(O(\log_2 n)\)
  2. Remove the leaf with the value and one separator
  3. Rebalance (if necessary, i.e. now 1 key)

Field-by-field Comparison
Field Before After
Text <b>2-3 Tree</b>: Deleting Steps:<br><ol><li>{{c1::Search for the correct node under which the key is inserted:&nbsp;\(O(\log_2 n)\)}}</li><li>{{c2::Remove the leaf with the value and one separator}}</li><li>{{c3::<b>Rebalance</b>&nbsp;(if necessary, i.e. now 1 key)}}</li></ol>
Extra <img src="paste-7d452d931b0485669156a2669de65234617e5eb6.jpg">
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees

Note 14: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: m3`Qbb~x?c
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
2-3 Tree: Deleting Steps if neighbour has 3 keys:

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
2-3 Tree: Deleting Steps if neighbour has 3 keys:

Our current node adopts one of the children. The separators have to be updated (one is given with the adopted child)
Field-by-field Comparison
Field Before After
Front <b>2-3 Tree</b>: Deleting Steps if neighbour has 3 keys:
Back Our current node adopts one of the children. The separators have to be updated (one is given with the adopted child)<br><img src="paste-bd8f4c10d3d0aaa08619b4e358673f9ff6b134a0.jpg">
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees

Note 15: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: Q}a3<1,J]C
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
2-3 Tree: Deleting Steps if neighbour has 2 keys:

Back

ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees
2-3 Tree: Deleting Steps if neighbour has 2 keys:

  1. the nodes \(u\) and \(v\) are merged to form one new node with 3 children.
  2. The separator from the parent node is pulled down to be the new \(s_2\).
Parent may lose child -> rebalance there (can go up to the root).
If root has 1 child -> root replaced by child.
Field-by-field Comparison
Field Before After
Front 2-3 Tree: Deleting Steps if neighbour has 2 keys:
Back <ol><li>the nodes&nbsp;\(u\)&nbsp;and&nbsp;\(v\)&nbsp;are <b>merged</b> to form one new node with <b>3 children</b>.</li><li>The separator from the parent node is pulled down to be the new&nbsp;\(s_2\).</li></ol>Parent may lose child -&gt; rebalance there (can go up to the root).<br>If root has 1 child -&gt; root replaced by child.<br><img src="paste-fcffee6f619138677fc86eb74beebfaa266c8cfe.jpg">
Tags: ETH::1._Semester::A&D::05._Data_Structures::2._ADT_Dictionary::2._2-3_Trees

Note 16: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: Q3:!A9V`D,
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming
Steps of giving a DP solution:
  1. Define the DP table (dimensions, index, range; meaning of entry): ex: DP[1..n+1][1..k+1]
  2. Computation of Entry (Base Case, recursive formula, pay attention to bounds!)
  3. Calculation Order (what depends on what entries, what variable incremented first)
  4. Extract Solution (How to get final solution out)
  5. Running time proof

Back

ETH::1._Semester::A&D::06._Dynamic_Programming
Steps of giving a DP solution:
  1. Define the DP table (dimensions, index, range; meaning of entry): ex: DP[1..n+1][1..k+1]
  2. Computation of Entry (Base Case, recursive formula, pay attention to bounds!)
  3. Calculation Order (what depends on what entries, what variable incremented first)
  4. Extract Solution (How to get final solution out)
  5. Running time proof

SMIROST (Size, Meaning, Initialisation, Recursive,  Order, Solution, Time)
Field-by-field Comparison
Field Before After
Text Steps of giving a DP solution:<br><ol><li>{{c1::Define the DP table (dimensions, index, range; meaning of entry): ex:&nbsp;<b>DP[1..n+1][1..k+1]</b>}}</li><li>{{c2::Computation of Entry (Base Case, recursive formula, pay attention to bounds!)}}</li><li>{{c3::Calculation Order (what depends on what entries, what variable incremented first)}}</li><li>{{c4::Extract Solution (How to get final solution out)}}</li><li>{{c5::Running time proof}}</li></ol>
Extra SMIROST (Size, Meaning, Initialisation, Recursive,&nbsp; Order, Solution, Time)
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming

Note 17: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: vgCb-fRsjm
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming
Runtime from DP Table

Back

ETH::1._Semester::A&D::06._Dynamic_Programming
Runtime from DP Table

We use the number of entries * the time to compute them (usually \(O(1)\))
Field-by-field Comparison
Field Before After
Front Runtime from DP Table
Back We use the number of entries * the time to compute them (usually&nbsp;\(O(1)\))
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming

Note 18: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: J!K^!6M$e^
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming
Differences between Subarray vs. Subsequence vs. Subset:
  • subarray: continous partition of the original
  • subsequence: non-continous partition
  • subset any subset (order does not matter)

Back

ETH::1._Semester::A&D::06._Dynamic_Programming
Differences between Subarray vs. Subsequence vs. Subset:
  • subarray: continous partition of the original
  • subsequence: non-continous partition
  • subset any subset (order does not matter)
Field-by-field Comparison
Field Before After
Text Differences between Subarray vs. Subsequence vs. Subset:<br><ul><li><b>subarray</b>: {{c1:: continous partition of the original}}</li><li><b>subsequence</b>: {{c2:: non-continous partition}}</li><li><b>subset</b> {{c3:: any subset (order does not matter)}}</li></ul>
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming

Note 19: ETH::A&D

Deck: ETH::A&D
Note Type: Algorithms
GUID: rUd4]Y&$Fr
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming::2._Maximum_Subarray_Sum
Runtime of Maximum Subarray Sum?

Back

ETH::1._Semester::A&D::06._Dynamic_Programming::2._Maximum_Subarray_Sum
Runtime of Maximum Subarray Sum?

\(\Theta(n)\)
Field-by-field Comparison
Field Before After
Name Maximum Subarray Sum
Runtime \(\Theta(n)\)
Approach Table: DP[1..n]<br>Define the "randmax":&nbsp;\( R_j := \max_{1 \leq i \leq j} \sum_{k = i}^j A[k] \)&nbsp;(maximale summe eines teilarrays das an j endet.<br><ul><li>Base Case:&nbsp;\(R_1 = A[1]\)</li><li>Recursion is&nbsp;\(R_j = \max \{ A[j], R_{j - 1} + A[j] \}\)<br>Thus either our current subarray contains the element at j, or not and we start with it again.</li></ul>
Pseudocode <img src="paste-8b50441eb44313fbab2c817e37ae70bb89ab0449.jpg">
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming::2._Maximum_Subarray_Sum

Note 20: ETH::A&D

Deck: ETH::A&D
Note Type: Algorithms
GUID: tYh57HT9#t
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming::3._Jumpgame
Runtime of Jump Game?

Back

ETH::1._Semester::A&D::06._Dynamic_Programming::3._Jumpgame
Runtime of Jump Game?

\(O(n)\) (hyper-optimised version)
Field-by-field Comparison
Field Before After
Name Jump Game
Runtime \(O(n)\)&nbsp;(hyper-optimised version)
Requirements Minimal jumps to get from beginning of array to the end.<br><br>Variable switch: cells which we can reach in&nbsp;\(k\)&nbsp;jumps. Solution is smallest&nbsp;\(k\)&nbsp;for which&nbsp;\(M[k] \geq n\).<br><br>We look at all&nbsp;\(i\)&nbsp;we can reach with exactly&nbsp;\(k-1\)&nbsp;jumps:<br><ul><li>Base Case:&nbsp;\(M[0] = A[0]\),&nbsp;\(M[1] = A[1] + 1\)</li><li>Recursion:&nbsp;\( M[k] = \max \{i + A[i] \ | \ M[k - 2] \leq i \leq M[k - 1]\} \)</li></ul><div>We look exactly 1 at every&nbsp;\(i\), thus&nbsp;\(O(n)\)</div>
Pseudocode <img src="paste-1f13db1cbb6b8d772fa2de2563b63627af8a038f.jpg">
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming::3._Jumpgame

Note 21: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Reverso
GUID: l2vPmFwTj!
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming
Subsequence

Back

ETH::1._Semester::A&D::06._Dynamic_Programming
Subsequence

Teilfolge
Field-by-field Comparison
Field Before After
Front Subsequence
Back Teilfolge
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming

Note 22: ETH::A&D

Deck: ETH::A&D
Note Type: Algorithms
GUID: o-3hRLI()p
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming::4._LCS
Runtime of Longest  Common Subsequence?

Back

ETH::1._Semester::A&D::06._Dynamic_Programming::4._LCS
Runtime of Longest  Common Subsequence?

\(\Theta(n \cdot m)\)
Field-by-field Comparison
Field Before After
Name Longest&nbsp; Common Subsequence
Runtime \(\Theta(n \cdot m)\)
Approach <div>DP-Table: <code>DP[0..n][0..m]</code> for&nbsp;\(n, m\)&nbsp;lengths of the strings</div><div><br></div><div><div>longest common subsequence that two strings share. For example TIGER and ZIEGE share IGE as a LGT.</div></div><div><br></div><div> <div>This gives us the following recursion:&nbsp;&nbsp;\[L(i,j) = \begin{cases} 0, &amp; i = 0 \text{ oder } j = 0 \\ L(i-1, j-1) + 1, &amp; X_i = Y_j \\ \max(L(i-1,j), L(i,j-1)), &amp; X_i \neq Y_j \end{cases}\]</div></div>
Pseudocode <img src="paste-5d0d1e2b1030b40ef6fce29f1fe1bd0e71105b03.jpg">
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming::4._LCS

Note 23: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: i~[|jYI|rt
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming
Backtracking in DP Problems

Back

ETH::1._Semester::A&D::06._Dynamic_Programming
Backtracking in DP Problems

Backtracking can find the solution of the problem from the DP table. From the recursion and it's behaviour we find the "path"

Field-by-field Comparison
Field Before After
Front Backtracking in DP Problems
Back Backtracking can find the solution of the problem from the DP table. From the recursion and it's behaviour we find the "path"<br><br><img src="paste-c186a33203c3cb874cfeb7870ee1a4c5d52bf205.jpg">
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming

Note 24: ETH::A&D

Deck: ETH::A&D
Note Type: Algorithms
GUID: gE_4/z}oud
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming::4._ED
Runtime of Editing Distance?

Back

ETH::1._Semester::A&D::06._Dynamic_Programming::4._ED
Runtime of Editing Distance?

\(\Theta(n \cdot m)\)
Field-by-field Comparison
Field Before After
Name Editing Distance
Runtime \(\Theta(n \cdot m)\)
Approach Minimum amount of edits (insert, delete, replace) to go from s1 to s2 -&gt; LGT gives us the ED.<br><br>Three cases for&nbsp;\(a_i\)&nbsp;last char of&nbsp;\(a\):<br><ul><li>deleted:&nbsp;\(ED(i, j) = 1 + ED(i - 1, j)\)&nbsp;(if deleted, it doesn't matter when)<br><img src="paste-254e45a17676954472f6aebe7c8c4f0517b3d6b5.jpg"></li><li>ends up in&nbsp;\(1, \dots, j-1\): no char&nbsp;\(a_k, k &lt; i\)&nbsp;can be behind&nbsp;\(a_i\)&nbsp;(suboptimal as it would cost 2):&nbsp;\(E1+ ED(i, j -1)\)<br><img src="paste-fae70ea53a12531dc9ac1ac30b00512b6f0c150e.jpg"></li><li>ends up at&nbsp;\(b_j\): cannot insert char behind&nbsp;\(a_i\)&nbsp;thus:&nbsp;\(ED(i-1, j -1) \)&nbsp;if&nbsp;\(a_i = b_j\)&nbsp;else&nbsp;\(1 + ED(i-1, k-1)\)&nbsp;<br><img src="paste-3027dc66600e0cb2f8e3a1b12c8a1be248f13f5c.jpg">&nbsp;</li></ul>
Pseudocode <img src="paste-1a255e78854ef70231b746a53228cd5420abeee8.jpg">
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming::4._ED

Note 25: ETH::A&D

Deck: ETH::A&D
Note Type: Algorithms
GUID: L`3Iw:nx:Z
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming
Runtime of Subset Sum (Teilsummenproblem)?

Back

ETH::1._Semester::A&D::06._Dynamic_Programming
Runtime of Subset Sum (Teilsummenproblem)?

\(\Theta(n \cdot b)\) (Pseudo-Polynomial)
Field-by-field Comparison
Field Before After
Name Subset Sum (Teilsummenproblem)
Runtime \(\Theta(n \cdot b)\)&nbsp;(Pseudo-Polynomial)
Requirements We want to find the subset \(I \subseteq \{1, \dots, n\}\)&nbsp;such that \(\sum_{i \in I} A[i] = b\)&nbsp;(must not exist for all \(b\)).<br><br>\(T(i,s)\)&nbsp;is 1 if there exists a subset from 1 to i that sums to s<br><ul><li>Base Case: T(0, 0) = 1 as we can use&nbsp;</li><li>Recursion:&nbsp;\( T(i, s) = T(i - 1, s) \ \lor \ T(i - 1, s - A[i]) \)</li></ul><div>Either we use A[i] or we don't.</div>
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming

Note 26: ETH::A&D

Deck: ETH::A&D
Note Type: Algorithms
GUID: L~wgr~ELJV
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming::Knapsack
Runtime of Knapsack Problem (Rucksackproblem)?

Back

ETH::1._Semester::A&D::06._Dynamic_Programming::Knapsack
Runtime of Knapsack Problem (Rucksackproblem)?

\(\Theta(n\cdot W)\) or \(\Theta(n \cdot P)\) (Pseudopolynomial)
Field-by-field Comparison
Field Before After
Name Knapsack Problem (Rucksackproblem)
Runtime \(\Theta(n\cdot W)\)&nbsp;or&nbsp;\(\Theta(n \cdot P)\)&nbsp;(Pseudopolynomial)
Approach Subset problem choosing the maximum staying under a weight&nbsp;\(W\).<br>The greedy algorithm fails as a local optimum is not global here.<br><br>Base Cases:&nbsp;\(dp[0][w] = 0, \quad dp[i][0] = 0\)<br>If item weight&nbsp; &gt; max allowed left, don't take it. Otherwise get the max from using it or not:<br>\(dp[i][w] = \begin{cases} dp[i-1][w], &amp; w_i &gt; w \\ \max(dp[i-1][w], dp[i-1][w-w_i] + v_i), &amp; \text{sonst} \end{cases}\)
Pseudocode <img src="paste-dfd5963f4f4fabfa2ea13e840d1530b8d7fe1a4a.jpg">
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming::Knapsack

Note 27: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: o>e0u7Qnuv
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming::Knapsack
What is pseudo-polynomial time?

Back

ETH::1._Semester::A&D::06._Dynamic_Programming::Knapsack
What is pseudo-polynomial time?

runtime dependent on a number \(W\) (like in knapsack) which is not correlated polynomially to input length but exponentially.

The DP-table get's 10x for \(W = 10 \rightarrow 100\) but the input size (binary) only grows from \(\log_2(10) \approx 3 \rightarrow \approx 6\) so x2.
Field-by-field Comparison
Field Before After
Front What is pseudo-polynomial time?
Back runtime dependent on a number&nbsp;\(W\)&nbsp;(like in knapsack) which is not correlated polynomially to input length but exponentially.<br><br>The DP-table get's 10x for&nbsp;\(W = 10 \rightarrow 100\)&nbsp;but the input size (binary) only grows from&nbsp;\(\log_2(10) \approx 3 \rightarrow \approx 6\)&nbsp;so x2.
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming::Knapsack

Note 28: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: pK&d|%vUW(
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming::Knapsack
How can we make Knapsack polynomial using approximation?

Back

ETH::1._Semester::A&D::06._Dynamic_Programming::Knapsack
How can we make Knapsack polynomial using approximation?

round the profits and solve the Knapsack problem for these rounded profits:\(\overline{p_i} := K \cdot \lfloor \frac{p_i}{K} \rfloor\). We then only have to compute every K'th entry to the DP-table.
Field-by-field Comparison
Field Before After
Front How can we make Knapsack polynomial using approximation?
Back round the profits and solve the Knapsack problem for these rounded profits:\(\overline{p_i} := K \cdot \lfloor \frac{p_i}{K} \rfloor\). We then only have to compute every K'th entry to the DP-table.
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming::Knapsack

Note 29: ETH::A&D

Deck: ETH::A&D
Note Type: Algorithms
GUID: C$#TvbwG_l
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming::Knapsack
Runtime of Longest Ascending Subsequence (Längste Aufsteigende Teilfolge)?

Back

ETH::1._Semester::A&D::06._Dynamic_Programming::Knapsack
Runtime of Longest Ascending Subsequence (Längste Aufsteigende Teilfolge)?

\(\Theta(n \log n)\)
Field-by-field Comparison
Field Before After
Name Longest Ascending Subsequence (Längste Aufsteigende Teilfolge)
Runtime \(\Theta(n \log n)\)
Approach For an array A[1..n]&nbsp;<b>longest</b>&nbsp;subsequence (non-continuous) that is ascending.<br><br>DP Table with entry&nbsp;\(M(l) = a\)&nbsp;where a ist the smallest possible ending of a LAT with length&nbsp;\(l\).<br><ul><li>Base Cases:&nbsp;&nbsp;\(M[*] = \infty\)</li><li>Recursion: set&nbsp;\(M[k]\)&nbsp;to&nbsp;\(A[i]\)&nbsp;where&nbsp;\(k\)&nbsp;is the index of the next smallest + 1 in&nbsp;\(M\).</li></ul>We can find the smaller with binary search, thus&nbsp;\(\log n \)&nbsp;search for&nbsp;\(n\)&nbsp;elements -&gt;&nbsp;\(\Theta(n \log n)\).<br><img src="paste-1b9069bf0a881a3cd3900a4de699cac89f0498b8.jpg"><br>
Pseudocode <img src="paste-0cd3692a4a909acf7f7ae0540eb6d714fc346b41.jpg">
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming::Knapsack

Note 30: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: QJ{Y%?s>+w
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::06._Dynamic_Programming
When writing the recursion, make sure that if the index goes out of bound, you specify the "neutral".

Back

ETH::1._Semester::A&D::06._Dynamic_Programming
When writing the recursion, make sure that if the index goes out of bound, you specify the "neutral".

For subset sum, we take \(DP[i-1][B - b_i]\), where if we don't check \(B - b_i\) might go negative and thus oob.
Field-by-field Comparison
Field Before After
Text When writing the recursion, make sure that if the index {{c1:: goes out of bound, you specify the "neutral"}}.
Extra For subset sum, we take&nbsp;\(DP[i-1][B - b_i]\), where if we don't check&nbsp;\(B - b_i\)&nbsp;might go negative and thus oob.
Tags: ETH::1._Semester::A&D::06._Dynamic_Programming

Note 31: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: w{Q]%!`f&#
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::07._Graphs::2._Closed_Eulerian_Walks
Transform Eulerian walk to closed eulerian walk problem:

Back

ETH::1._Semester::A&D::07._Graphs::2._Closed_Eulerian_Walks
Transform Eulerian walk to closed eulerian walk problem:

add an edge connected the start-end points with odd degrees.
Field-by-field Comparison
Field Before After
Front Transform Eulerian walk to closed eulerian walk problem:
Back add an edge connected the start-end points with odd degrees.
Tags: ETH::1._Semester::A&D::07._Graphs::2._Closed_Eulerian_Walks

Note 32: ETH::A&D

Deck: ETH::A&D
Note Type: Algorithms
GUID: AJT5T7qaW3
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::07._Graphs::2._Closed_Eulerian_Walks
Runtime of Find Closed Eulerian Path?

Back

ETH::1._Semester::A&D::07._Graphs::2._Closed_Eulerian_Walks
Runtime of Find Closed Eulerian Path?

\(O(n+m)\)
In an Adjacency Matrix: runtime is \(O(n^2)\) as looping over all edges is \(O(n)\).

In an Adjacency List: we loop \(n\) times over \(O(1 + \deg(u))\).
Using the handshake lemma: \(\sum_{u \in V} (1 + \deg(u)) = n + \sum_{u \in V} \deg(u) = n + 2m\)
Field-by-field Comparison
Field Before After
Name Find Closed Eulerian Path
Runtime \(O(n+m)\)
Approach We want to be able to find closed walks in a graph. We can then merge them together to form a single closed walk, by exploiting shared vertices.<br><br>Algo:<br><ol><li>Start at vertex&nbsp;\(u_0\)&nbsp;arbitrary</li><li>For loop over edges. If not marked, mark and recurse.</li><li>Append vertex to list after execution</li></ol>&nbsp;Returns a list of vertices in order of a closed walk if there is one.<br><br>Example:<br><img src="paste-a669de30c7bc4a38d788fb96b6b5551a4781ec71.jpg"><br>Output:<br><img src="paste-b453826818903aa4da2ac10897e9dc0e177229b6.jpg">
Pseudocode <img src="paste-b2cbbb1cb599a09a77bcc0e991ec4bcb83c586fb.jpg"><br><img src="paste-c82a6519899f9b1f1f49c932a2b252ff64a2184a.jpg">
Extra Info In an Adjacency Matrix: runtime is&nbsp;\(O(n^2)\)&nbsp;as looping over all edges is&nbsp;\(O(n)\).<br><br>In an Adjacency List: we loop&nbsp;\(n\)&nbsp;times over&nbsp;\(O(1 + \deg(u))\).<br>Using the handshake lemma:&nbsp;\(\sum_{u \in V} (1 + \deg(u)) = n + \sum_{u \in V} \deg(u) = n + 2m\)
Tags: ETH::1._Semester::A&D::07._Graphs::2._Closed_Eulerian_Walks

Note 33: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: mLAF6cI?#i
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::07._Graphs::1._Introduction_to_Graphs
Runtime of initialising an adjacency list:  \(O(n + m)\).

Back

ETH::1._Semester::A&D::07._Graphs::1._Introduction_to_Graphs
Runtime of initialising an adjacency list:  \(O(n + m)\).
Field-by-field Comparison
Field Before After
Text Runtime of initialising an adjacency list: {{c1::&nbsp;\(O(n + m)\)}}.
Tags: ETH::1._Semester::A&D::07._Graphs::1._Introduction_to_Graphs

Note 34: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: qYjlu[L8wY
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::07._Graphs::1._Introduction_to_Graphs
Runtime of initialising an adjacency matrix:  \(O(n^2)\).

Back

ETH::1._Semester::A&D::07._Graphs::1._Introduction_to_Graphs
Runtime of initialising an adjacency matrix:  \(O(n^2)\).
Field-by-field Comparison
Field Before After
Text Runtime of initialising an adjacency matrix: {{c1::&nbsp;\(O(n^2)\)}}.
Tags: ETH::1._Semester::A&D::07._Graphs::1._Introduction_to_Graphs

Note 35: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: p{21Af5^Ae
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::07._Graphs::1._Introduction_to_Graphs
If a vertex of degree \(\geq 2\) is not a cut vertex then it must lie on a cycle.

Back

ETH::1._Semester::A&D::07._Graphs::1._Introduction_to_Graphs
If a vertex of degree \(\geq 2\) is not a cut vertex then it must lie on a cycle.
Field-by-field Comparison
Field Before After
Text If a vertex of degree&nbsp;\(\geq 2\)&nbsp;is&nbsp;<b>not</b>&nbsp;a cut vertex then {{c1::it must lie on a cycle}}.
Tags: ETH::1._Semester::A&D::07._Graphs::1._Introduction_to_Graphs

Note 36: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: s@rY_v*&u_
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::07._Graphs::1._Introduction_to_Graphs
A graph is bipartite if and only if it does not contain any cycles of odd length.

Back

ETH::1._Semester::A&D::07._Graphs::1._Introduction_to_Graphs
A graph is bipartite if and only if it does not contain any cycles of odd length.
Field-by-field Comparison
Field Before After
Text A graph is bipartite if and only if {{c1::it does not contain any cycles of odd length}}.
Tags: ETH::1._Semester::A&D::07._Graphs::1._Introduction_to_Graphs

Note 37: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: AqQ}Ty8GRj
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::04._Sorting_Algorithms::6._Quicksort
How do we fix the Quicksort worst-case runtime?

Back

ETH::1._Semester::A&D::04._Sorting_Algorithms::6._Quicksort
How do we fix the Quicksort worst-case runtime?

Chose a random element as the pivot.

Median of medians algo ideal but too complex to implement.
Field-by-field Comparison
Field Before After
Front How do we fix the Quicksort worst-case runtime?
Back Chose a random element as the pivot.<br><br>Median of medians algo ideal but too complex to implement.
Tags: ETH::1._Semester::A&D::04._Sorting_Algorithms::6._Quicksort

Note 38: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: ub(U6EB=d{
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::08._Directed_Graphs::2._Topological_Sorting
A topological ordering of vertices is an order such that for every edge \((u, v) \), \(u\) comes before \(v\).

Back

ETH::1._Semester::A&D::08._Directed_Graphs::2._Topological_Sorting
A topological ordering of vertices is an order such that for every edge \((u, v) \), \(u\) comes before \(v\).

thus all arrows point rightwards.
Field-by-field Comparison
Field Before After
Text A topological ordering of vertices is an order such that for every edge&nbsp;\((u, v) \), {{c1::\(u\)&nbsp;comes before&nbsp;\(v\)}}.
Extra thus all arrows point rightwards.
Tags: ETH::1._Semester::A&D::08._Directed_Graphs::2._Topological_Sorting

Note 39: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: dYrUA*(KY7
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::08._Directed_Graphs::2._Topological_Sorting
 \(\exists\) toposort \(\Longleftrightarrow\)  \(\lnot \exists\) directed closed walk

Back

ETH::1._Semester::A&D::08._Directed_Graphs::2._Topological_Sorting
 \(\exists\) toposort \(\Longleftrightarrow\)  \(\lnot \exists\) directed closed walk
Field-by-field Comparison
Field Before After
Text {{c1::&nbsp;\(\exists\)&nbsp;toposort}}&nbsp;\(\Longleftrightarrow\)&nbsp;{{c2::&nbsp;\(\lnot \exists\)&nbsp;directed closed walk}}
Tags: ETH::1._Semester::A&D::08._Directed_Graphs::2._Topological_Sorting

Note 40: ETH::A&D

Deck: ETH::A&D
Note Type: Algorithms
GUID: kn@H8`z>0t
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Runtime of DFS (Depth First Search)?

Back

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Runtime of DFS (Depth First Search)?

\( \mathcal{O}(|E| + |V|) \) (using Adjacency List)
Can be efficiently implemented using a stack.
Field-by-field Comparison
Field Before After
Name DFS (Depth First Search)
Runtime \( \mathcal{O}(|E| + |V|) \)&nbsp;(using Adjacency List)
Approach Explore as far as possible along each branch before backtracking. Potentially keep track of pre- / post-numbers to make edge classifications.<br><br>We want to find a sink, add it to the list, then backtrack and find the next one.<br><br>The reversed post-order then gives us a toposort.<br><br>Example output:<br><img src="paste-f6163ccea9c72dbfdc9cb9045b600a5a41b8aa6b.jpg">
Pseudocode <img src="paste-60a95ac959791d67c7cee55696da90ab82b8f713.jpg"><br><img src="paste-91ab7e22fbe20ca71b32e8db34b737d2c9366c23.jpg">
Extra Info Can be efficiently implemented using a stack.
Tags: ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search

Note 41: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: bD%.s|4?hI
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Pre-/Post-Ordering Classification for an edge \((u, v)\):
\(\text{pre}(u) < \text{pre}(v) < \text{post}(v) < \text{post}(u)\): tree edge, as \(v\) is a descendant of \(u\)

Back

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Pre-/Post-Ordering Classification for an edge \((u, v)\):
\(\text{pre}(u) < \text{pre}(v) < \text{post}(v) < \text{post}(u)\): tree edge, as \(v\) is a descendant of \(u\)
Field-by-field Comparison
Field Before After
Text Pre-/Post-Ordering Classification for an edge&nbsp;\((u, v)\):<br>\(\text{pre}(u) &lt; \text{pre}(v) &lt; \text{post}(v) &lt; \text{post}(u)\): {{c1:: tree edge, as&nbsp;\(v\)&nbsp;is a descendant of&nbsp;\(u\)}}
Tags: ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search

Note 42: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: rnACRB4[8n
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Pre-/Post-Ordering Classification for an edge \((u, v)\):
\(\text{pre}(v) < \text{pre}(u) < \text{post}(u) < \text{post}(v)\): back edge

Back

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Pre-/Post-Ordering Classification for an edge \((u, v)\):
\(\text{pre}(v) < \text{pre}(u) < \text{post}(u) < \text{post}(v)\): back edge

exists a cycle!
Field-by-field Comparison
Field Before After
Text Pre-/Post-Ordering Classification for an edge&nbsp;\((u, v)\):<br>\(\text{pre}(v) &lt; \text{pre}(u) &lt; \text{post}(u) &lt; \text{post}(v)\): {{c1:: back edge}}
Extra exists a cycle!
Tags: ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search

Note 43: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: Auw]yKf@xT
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Pre-/Post-Ordering Classification for an edge \((u, v)\):
\(\text{pre}(u) < \text{pre}(v) < \text{post}(v) < \text{post}(u)\), but not tree edge: Forward edge

Back

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Pre-/Post-Ordering Classification for an edge \((u, v)\):
\(\text{pre}(u) < \text{pre}(v) < \text{post}(v) < \text{post}(u)\), but not tree edge: Forward edge
Field-by-field Comparison
Field Before After
Text Pre-/Post-Ordering Classification for an edge&nbsp;\((u, v)\):<br>\(\text{pre}(u) &lt; \text{pre}(v) &lt; \text{post}(v) &lt; \text{post}(u)\), but <b>not tree edge</b>: {{c1:: Forward edge}}
Tags: ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search

Note 44: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: Bb-m%-jtI|
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Pre-/Post-Ordering Classification for an edge \((u, v)\):
\(\text{pre}(v) < \text{post}(v) < \text{pre}(u) < \text{post}(u)\): Cross edge, \(u, v\) in different subtrees

Back

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Pre-/Post-Ordering Classification for an edge \((u, v)\):
\(\text{pre}(v) < \text{post}(v) < \text{pre}(u) < \text{post}(u)\): Cross edge, \(u, v\) in different subtrees
Field-by-field Comparison
Field Before After
Text Pre-/Post-Ordering Classification for an edge&nbsp;\((u, v)\):<br>\(\text{pre}(v) &lt; \text{post}(v) &lt; \text{pre}(u) &lt; \text{post}(u)\): {{c1:: Cross edge,&nbsp;\(u, v\)&nbsp;in different subtrees}}
Tags: ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search

Note 45: ETH::A&D

Deck: ETH::A&D
Note Type: Image Occlusion
GUID: EE{ugGOkjL
added

Previous

Note did not exist

New Note

Front

image-occlusion:rect:left=.1725:top=.5468:angle=985:width=.3135:height=.1117:oi=1
image-occlusion:rect:left=.1923:top=.2416:width=.2286:height=.2:oi=1
image-occlusion:rect:left=.5726:top=.7584:width=.2179:height=.0701:oi=1
image-occlusion:text:left=.2051:top=.0987:text=B<-F:scale=1.:fs=.1133:oi=1
image-occlusion:text:left=.6132:top=.8338:text=G<-H:scale=.5385:fs=.1133:oi=1
image-occlusion:text:left=.1645:top=.7065:angle=989:text=E->G:scale=.6858:fs=.1133:oi=1

Back

image-occlusion:rect:left=.1725:top=.5468:angle=985:width=.3135:height=.1117:oi=1
image-occlusion:rect:left=.1923:top=.2416:width=.2286:height=.2:oi=1
image-occlusion:rect:left=.5726:top=.7584:width=.2179:height=.0701:oi=1
image-occlusion:text:left=.2051:top=.0987:text=B<-F:scale=1.:fs=.1133:oi=1
image-occlusion:text:left=.6132:top=.8338:text=G<-H:scale=.5385:fs=.1133:oi=1
image-occlusion:text:left=.1645:top=.7065:angle=989:text=E->G:scale=.6858:fs=.1133:oi=1
Field-by-field Comparison
Field Before After
Occlusion {{c3::image-occlusion:rect:left=.1725:top=.5468:angle=985:width=.3135:height=.1117:oi=1}}<br>{{c1::image-occlusion:rect:left=.1923:top=.2416:width=.2286:height=.2:oi=1}}<br>{{c2::image-occlusion:rect:left=.5726:top=.7584:width=.2179:height=.0701:oi=1}}<br>{{c0::image-occlusion:text:left=.2051:top=.0987:text=B<-F:scale=1.:fs=.1133:oi=1}}<br>{{c0::image-occlusion:text:left=.6132:top=.8338:text=G<-H:scale=.5385:fs=.1133:oi=1}}<br>{{c0::image-occlusion:text:left=.1645:top=.7065:angle=989:text=E->G:scale=.6858:fs=.1133:oi=1}}<br>
Image <img src="paste-92fb45dcbaee894af9f32d9c2de935b1985dd979.jpg">
Tags: ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search

Note 46: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: O%OM.97hp$
added

Previous

Note did not exist

New Note

Front

\(\exists\) back edge \(\Longleftrightarrow\)\(\exists\) Directed closed walk

Back

\(\exists\) back edge \(\Longleftrightarrow\)\(\exists\) Directed closed walk
Field-by-field Comparison
Field Before After
Text {{c1::\(\exists\)&nbsp;back edge}}&nbsp;\(\Longleftrightarrow\){{c2::\(\exists\)&nbsp;Directed closed walk}}

Note 47: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: f2x>M=+L9d
added

Previous

Note did not exist

New Note

Front

\(\forall\) not back-edge \((u,v) \in E\),  \( \text{post}(u)\) \(\geq\) \(\text{post}(v) \)

Back

\(\forall\) not back-edge \((u,v) \in E\),  \( \text{post}(u)\) \(\geq\) \(\text{post}(v) \)
Field-by-field Comparison
Field Before After
Text \(\forall\) not back-edge \((u,v) \in E\),&nbsp;&nbsp;\( \text{post}(u)\) {{c1::\(\geq\)}} \(\text{post}(v) \)

Note 48: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: NR^|^~o+xa
added

Previous

Note did not exist

New Note

Front

How do we get the topo sort from DFS?

Back

How do we get the topo sort from DFS?

Reversed Post order
Field-by-field Comparison
Field Before After
Front How do we get the topo sort from DFS?
Back Reversed Post order

Note 49: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: IE=7&p8[(7
added

Previous

Note did not exist

New Note

Front

In an undirected graph, what is special about pre/post-ordering:
  • back-edges = forward-edges
  • cross edges are not possible

Back

In an undirected graph, what is special about pre/post-ordering:
  • back-edges = forward-edges
  • cross edges are not possible
Field-by-field Comparison
Field Before After
Text In an undirected graph, what is special about pre/post-ordering:<br><ul><li><div>{{c2::back-edges = forward-edges}}</div></li><li><div><div>cross edges {{c1::are not possible}}</div></div></li></ul>

Note 50: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: AY}!l[d)1z
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Name the impossible cases in DFS pre/post ordering for edge \((u, v)\):
  • Overlapping but not Nested Intervals: 
  • {{c2:: \(\text{pre}(u)<\text{pre}(v)<\text{post}(u)<\text{post}(v)\):  as visit(u) would call visit(v) before the recursive call ends}}

Back

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Name the impossible cases in DFS pre/post ordering for edge \((u, v)\):
  • Overlapping but not Nested Intervals: 
  • {{c2:: \(\text{pre}(u)<\text{pre}(v)<\text{post}(u)<\text{post}(v)\):  as visit(u) would call visit(v) before the recursive call ends}}
Field-by-field Comparison
Field Before After
Text Name the impossible cases in DFS pre/post ordering for edge&nbsp;\((u, v)\):<br><ul><li>{{c1::Overlapping but not Nested Intervals:&nbsp;<img src="paste-b7976dbbff12de2b44594553e0c91633f59e9c05.jpg">}}</li><li>{{c2::&nbsp;\(\text{pre}(u)&lt;\text{pre}(v)&lt;\text{post}(u)&lt;\text{post}(v)\):&nbsp;<img src="paste-a6fc070f96de8bd2b8148e3891cf956fd611a0a2.jpg">&nbsp;as visit(u)&nbsp;would call visit(v) before the recursive call ends}}</li></ul>
Tags: ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search

Note 51: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: QBdl=YAmG|
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Check for cycles in DFS algo:

Back

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Check for cycles in DFS algo:

During the recursive call, if we find an adjacent vertex without a post-number, there's a back-edge (\(\implies\)the recursive call for that edge is still active...)
Field-by-field Comparison
Field Before After
Front Check for cycles in DFS algo:
Back During the recursive call, if we find an adjacent vertex <b>without a post-number</b>, there's a back-edge (\(\implies\)the recursive call for that edge is still active...)
Tags: ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search

Note 52: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: v7@jgp_hjT
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Find cross edge in DFS algorithm:

Back

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Find cross edge in DFS algorithm:

If we find vertex with both pre- and post- there's a cross edge.
Field-by-field Comparison
Field Before After
Front Find cross edge in DFS algorithm:
Back If we find vertex with both pre- and post- there's a cross edge.
Tags: ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search

Note 53: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: gCxT2!W2sa
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Runtime of DFS with matrix vs list:

Back

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
Runtime of DFS with matrix vs list:

\(n\) calls to visit. Each takes:
  • Matrix: \(O(n)\) as we loop edges gives \(n \cdot O(n) = O(n^2)\)
  • List: \(O(1 + \deg_{out}(u))\) gives \(n \cdot O(1 + \deg_{out}(v) = |V| + |E|\)
Field-by-field Comparison
Field Before After
Front Runtime of DFS with matrix vs list:
Back \(n\)&nbsp;calls to visit. Each takes:<br><ul><li>Matrix:&nbsp;\(O(n)\)&nbsp;as we loop edges gives&nbsp;\(n \cdot O(n) = O(n^2)\)</li><li>List:&nbsp;\(O(1 + \deg_{out}(u))\)&nbsp;gives&nbsp;\(n \cdot O(1 + \deg_{out}(v) = |V| + |E|\)</li></ul>
Tags: ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search

Note 54: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Classic
GUID: nzhNF&3(!D
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::08._Directed_Graphs::1._Introduction_to_Directed_Graphs
Handshake lemma in directed graphs:

Back

ETH::1._Semester::A&D::08._Directed_Graphs::1._Introduction_to_Directed_Graphs
Handshake lemma in directed graphs:

\[ \sum_{v \in V} \deg_{out}(v) = \sum_{v \in V} \deg_{in}(v) = |E| \]
Field-by-field Comparison
Field Before After
Front Handshake lemma in directed graphs:
Back \[ \sum_{v \in V} \deg_{out}(v) = \sum_{v \in V} \deg_{in}(v) = |E| \]<br>
Tags: ETH::1._Semester::A&D::08._Directed_Graphs::1._Introduction_to_Directed_Graphs

Note 55: ETH::A&D

Deck: ETH::A&D
Note Type: Horvath Cloze
GUID: GA*(aETcmb
added

Previous

Note did not exist

New Note

Front

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
DFS Runtime: In a sparse graph adjacency list better, in a dense graph adjacency matrix is better.

Back

ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
DFS Runtime: In a sparse graph adjacency list better, in a dense graph adjacency matrix is better.

\(|E| \geq |V|^2 / 10\), then DFS has the same runtime in the worst-case using adjacency matrices or lists as \(|V| + |E| \leq |V| + |V|^2 \)which is \(O(n^2)\).
Field-by-field Comparison
Field Before After
Text DFS Runtime: In a sparse graph {{c1:: adjacency list better}}, in a dense graph {{c1:: adjacency matrix is better}}.
Extra \(|E| \geq |V|^2 / 10\), then DFS has the same runtime in the worst-case using adjacency matrices or lists as&nbsp;\(|V| + |E| \leq |V| + |V|^2 \)which is&nbsp;\(O(n^2)\).
Tags: ETH::1._Semester::A&D::09._Graph_Search::1._Depth_First_Search
↑ Top