Skip to content

Commit

Permalink
add more notes
Browse files Browse the repository at this point in the history
  • Loading branch information
kekeandzeyu committed Sep 6, 2024
1 parent e75eefa commit 0811cd0
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 83 deletions.
10 changes: 5 additions & 5 deletions Writerside/topics/Data-Structures-and-Algorithms-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -3743,7 +3743,7 @@ corresponding value.</p>
</li>
</list>
#### 9.1.1 Sequential Search (unordered list)
#### 9.1.1 Sequential Search (unordered list) {id="sequential-search"}
<p>Method: Maintain an (unordered) linked list of key-value pairs.</p>
Expand All @@ -3758,7 +3758,7 @@ until find a match; if no match add to front.</p>
</li>
</list>
#### 9.1.2 Ordered Array
#### 9.1.2 Ordered Array {id="ordered-array"}
<p><format color = "BlueViolet">Method</format>: Maintain an ordered
array of key-value pairs.</p>
Expand All @@ -3784,7 +3784,7 @@ array of key-value pairs.</p>
}
```
### 9.2 Binary Search Trees
### 9.2 Binary Search Trees {id="BST"}
<p>Def: A BST is a <format color = "OrangeRed">binary tree</format> in
<format color = "OrangeRed">symmetric order.</format></p>
Expand Down Expand Up @@ -4472,7 +4472,7 @@ current node's right subtree.</p>
</tr>
</table>

### 10.1 2-3 Trees
### 10.1 2-3 Trees {id="2-3-trees"}

<p>Basic properties: </p>

Expand Down Expand Up @@ -4571,7 +4571,7 @@ for search and insert.</p>
</list>
</tip>

### 10.2 Red-Black BSTs
### 10.2 Red-Black BSTs {id="red-black-bsts"}

#### 10.2.1 Left-Leaning Red-Black BSTs

Expand Down
176 changes: 117 additions & 59 deletions Writerside/topics/Data-Structures-and-Algorithms-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,76 +17,132 @@
<td rowspan = "2">Key Interface</td>
</tr>
<tr>
<td>search</td>
<td>insert</td>
<td>delete</td>
<td>search hit</td>
<td>insert</td>
<td>delete</td>
<td>Search</td>
<td>Insert</td>
<td>Delete</td>
<td>Search Hit</td>
<td>Insert</td>
<td>Delete</td>
</tr>
<tr><td>sequential search (unordered list)</td><td><math>N</math></td>
<td><math>N</math></td><td><math>N</math></td><td><math>
\frac {N}{2}</math></td><td><math>N</math></td><td><math>N</math>
</td><td>no</td><td><code>equals()</code></td></tr>
<tr><td>binary search (ordered list)</td><td><math>\lg N</math></td>
<td><math>N</math></td><td><math>N</math></td><td><math>
\lg N</math></td><td><math>\frac {N}{2}</math></td>
<td><math>\frac {N}{2}</math></td><td>yes</td>
<td><code>compareTo()</code></td></tr>
<tr><td>BST</td><td><math>N</math></td><td><math>N</math></td>
<td><math>N</math></td><td><math>1.39 \log N</math></td>
<td><math>1.39 \log N</math></td><td>?</td><td>yes</td>
<td><code>compareTo()</code></td></tr>
<tr><td>2-3 tree</td><td><math>c \log N</math></td>
<td><math>c \log N</math></td><td><math>c \log N</math></td>
<td><math>c \log N</math></td><td><math>c \log N</math></td>
<td><math>c \log N</math></td><td>yes</td><td><code>compareTo()</code></td></tr>
<tr><td>red-black BST</td><td><math>2 \log N</math></td>
<td><math>2 \log N</math></td><td><math>2 \log N</math></td>
<td><math>1.00 \lg N</math></td><td><math>1.00 \lg N</math></td>
<td><math>1.00 \lg N</math></td><td>yes</td><td><code>compareTo()
</code></td></tr>
<tr><td>separate chaining</td><td><math>\log N</math></td>
<td><math>\log N</math></td><td><math>\log N</math></td>
<td><math>3-5</math></td><td><math>3-5</math></td>
<td><math>3-5</math></td><td>no</td><td><code>equals
</code><code>hashCode()</code></td></tr>
<tr><td>linear probing</td><td><math>\log N</math></td>
<td><math>\log N</math></td><td><math>\log N</math></td>
<td><math>3-5</math></td><td><math>3-5</math></td>
<td><math>3-5</math></td><td>no</td><td><code>equals
</code><code>hashCode()</code></td></tr>
<tr>
<td><a href="Data-Structures-and-Algorithms-1.md" anchor
="sequential-search" summary="Sequential Search (unordered list)">
Sequential Search (unordered list)</a></td>
<td><math>N</math></td>
<td><math>N</math></td>
<td><math>N</math></td>
<td><math>\frac {N}{2}</math></td>
<td><math>N</math></td>
<td><math>N</math></td>
<td>no</td>
<td><code>equals()</code></td>
</tr>
<tr>
<td><a href="Data-Structures-and-Algorithms-1.md" anchor
="ordered-array" summary="Binary Search (ordered array)">
Binary Search (ordered list)</a></td>
<td><math>\lg N</math></td>
<td><math>N</math></td>
<td><math>N</math></td>
<td><math>\lg N</math></td>
<td><math>\frac {N}{2}</math></td>
<td><math>\frac {N}{2}</math></td>
<td>yes</td>
<td><code>compareTo()</code></td>
</tr>
<tr>
<td><a href="Data-Structures-and-Algorithms-1.md" anchor="BST"
summary="Binary Search Tree">BST</a></td>
<td><math>N</math></td>
<td><math>N</math></td>
<td><math>N</math></td>
<td><math>1.39 \log N</math></td>
<td><math>1.39 \log N</math></td>
<td>?</td>
<td>yes</td>
<td><code>compareTo()</code></td>
</tr>
<tr>
<td><a href="Data-Structures-and-Algorithms-1.md" anchor=
"2-3-trees" summary="2-3 Tree">2-3 Tree</a></td>
<td><math>c \log N</math></td>
<td><math>c \log N</math></td>
<td><math>c \log N</math></td>
<td><math>c \log N</math></td>
<td><math>c \log N</math></td>
<td><math>c \log N</math></td>
<td>yes</td>
<td><code>compareTo()</code></td>
</tr>
<tr>
<td><a href="Data-Structures-and-Algorithms-1.md" anchor=
"red-black-bsts" summary="Red-Black BST">Red-Black BST</a></td>
<td><math>2 \log N</math></td>
<td><math>2 \log N</math></td>
<td><math>2 \log N</math></td>
<td><math>1.00 \lg N</math></td>
<td><math>1.00 \lg N</math></td>
<td><math>1.00 \lg N</math></td>
<td>yes</td>
<td><code>compareTo()</code></td>
</tr>
<tr>
<td><a anchor="separate-chaining" summary="Separate Chaining">
Separate Chaining</a></td>
<td><math>\log N</math></td>
<td><math>\log N</math></td>
<td><math>\log N</math></td>
<td><math>3-5</math></td>
<td><math>3-5</math></td>
<td><math>3-5</math></td>
<td>no</td>
<td><code>equals</code><code>hashCode()</code></td>
</tr>
<tr>
<td><a anchor="linear-probing" summary="Linear Probing">Linear
Probing</a></td>
<td><math>\log N</math></td>
<td><math>\log N</math></td>
<td><math>\log N</math></td>
<td><math>3-5</math></td>
<td><math>3-5</math></td>
<td><math>3-5</math></td>
<td>no</td>
<td><code>equals</code><code>hashCode()</code></td>
</tr>
</table>

### 12.1 Hash Tables

<p><format color="BlueViolet">Definitions:</format> </p>

<list type = "decimal">
<li>
<p><format color = "BlueViolet">Hashing</format>: Save items in a key-indexed
table (index is a function of the key).</p>
<p><format color = "OrangeRed">Hashing</format>: Save items in a
key-indexed table (index is a function of the key).</p>
</li>
<li>
<p><format color = "BlueViolet">Hash function</format>: Method for
<p><format color = "OrangeRed">Hash function</format>: Method for
computing array index from key.</p>
<p>Issues:</p>
<list type = "alpha-lower">
<li>
<p><format color = "BlueViolet">Equality test</format>: Method
for checking whether two keys are equal.</p>
</li>
<li>
<p><format color = "BlueViolet">Collision resolution</format>:
Algorithm and data structure to handle two keys that hash to the
same array index.</p>
</li>
</list>
<list type = "alpha-lower">
<li>
<p><format color = "Fuchsia">Equality test</format>: Method
for checking whether two keys are equal.</p>
</li>
<li>
<p><format color = "Fuchsia">Collision resolution</format>:
Algorithm and data structure to handle two keys that hash to the
same array index.</p>
</li>
</list>
</li>
<li>
<p><format color = "BlueViolet">Hash code</format>: An int between
<p><format color = "OrangeRed">Hash code</format>: An int between
<math>-2^31</math> and <math>2^31-1</math>.</p>
</li>
<li>
<p><format color = "BlueViolet">Hash function</format>: An int
<p><format color = "OrangeRed">Hash function</format>: An int
between 0 and M-1 (for use of array index).</p>
</li>
</list>
Expand All @@ -111,7 +167,7 @@ public final class StringTest {

### 12.2 Collision Solution &#8544; - Separate Chaining & Variant

#### 12.2.1 Separate Chaining
#### 12.2.1 Separate Chaining {id="separate-chaining"}

<list type = "alpha-lower">
<li>
Expand All @@ -120,17 +176,19 @@ public final class StringTest {
</li>
<li>
<p><format color = "Fuchsia">Insert:</format> put at front of
<math>i ^ {th}</math> chain (if not already there).</p>
<math>i ^ {\text{th}}</math> chain (if not already there).</p>
</li>
<li>
<p><format color = "Fuchsia">Search:</format> need to search
only <math>i ^ {th}</math> chain.</p>
only <math>i ^ {\text{th}}</math> chain.</p>
</li>
</list>

<img src = "../images_data/d12-2-1.png" alt = "Separate Chaining"/>

<list>
<p><format color="BlueViolet">Properties:</format> </p>

<list type="bullet">
<li>
<p>Number of probes for search/insert/delete is proportional to
<math>\frac {N}{M}</math>.
Expand Down Expand Up @@ -245,7 +303,7 @@ private:
### 12.3 Collision Solution &#8545; - Open Addressing
#### 12.3.1 Linear Probing
#### 12.3.1 Linear Probing {id="linear-probing"}
<p><format color = "DarkOrange">Open addressing:</format> When a new
key collides, find next empty slot, and put it there.</p>
Expand Down
66 changes: 47 additions & 19 deletions Writerside/topics/Data-Structures-and-Algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ part to Java Programming.</p>

<list type = "alpha-lower">
<li>
<format color = "Fuchsia">Sequential Storage Structure</format>
<p><format color = "Fuchsia">Sequential Storage Structures:</format> </p>
<list type = "bullet">
<li><p>Linear list</p></li>
<li><p>Array</p></li>
<li><p>Vector</p></li>
</list>
</li>
<li>
<format color = "Fuchsia">Linked Storage Structure</format>
<p><format color = "Fuchsia">Linked Storage Structure</format> </p>
<list type = "bullet">
<li>Linked list</li>
</list>
</li>
<li>
<format color = "Fuchsia">Index Storage Structure</format>
<p><format color = "Fuchsia">Index Storage Structure</format> </p>
<list>
<li>B-Tree/B+-Tree</li>
</list>
</li>
<li>
<format color = "Fuchsia">Hashing Storage Structure</format>
<p><format color = "Fuchsia">Hashing Storage Structure</format> </p>
<list>
<li>Hash table</li>
</list>
Expand All @@ -49,10 +49,18 @@ part to Java Programming.</p>
#### 1.1.2 Data Logical Structures

<list type = "decimal">
<li>Set</li>
<li>Linear</li>
<li>Tree</li>
<li>Graph</li>
<li>
<p><format color="Fuchsia">Set</format> </p>
</li>
<li>
<p><format color="Fuchsia">Linear</format> </p>
</li>
<li>
<p><format color="Fuchsia">Tree</format> </p>
</li>
<li>
<p><format color="Fuchsia">Graph</format> </p>
</li>
</list>

### 1.2 Mathematical Models
Expand All @@ -63,18 +71,38 @@ part to Java Programming.</p>
<li>
<p><format color = "Fuchsia">Cost Model</format>: Use some
basic operations as a proxy for running time.</p>
<table>
<tr><td>Operation</td><td>Frequency</td></tr>
<tr><td>Variable declaration</td><td><math>N + 2</math></td></tr>
<tr><td>Assignment statement</td><td><math>N + 2</math></td></tr>
<tr><td>Less than compare</td><td><math>\frac {(N + 1)(N + 2)} {2}
</math></td></tr>
<tr><td>Equal to compare</td><td><math>\frac {N(N - 1)} {2}</math>
</td></tr>
<tr><td>Array access</td><td><math>N(N - 1)</math></td></tr>
<tr><td>Increment</td><td><math>\frac {N(N - 1)} {2}</math> to <math>
N(N - 1)</math></td></tr>

<table style="header-row">
<tr>
<td>Operation</td>
<td>Frequency</td>
</tr>
<tr>
<td>Variable declaration</td>
<td><math>N + 2</math></td>
</tr>
<tr>
<td>Assignment statement</td>
<td><math>N + 2</math></td>
</tr>
<tr>
<td>Less than compare</td>
<td><math>\frac {(N + 1)(N + 2)} {2}</math></td>
</tr>
<tr>
<td>Equal to compare</td>
<td><math>\frac {N(N - 1)} {2}</math></td>
</tr>
<tr>
<td>Array access</td>
<td><math>N(N - 1)</math></td>
</tr>
<tr>
<td>Increment</td>
<td><math>\frac {N(N - 1)} {2}</math> to <math>N(N - 1)</math></td>
</tr>
</table>

</li>
<li>
<list type = "bullet">
Expand Down

0 comments on commit 0811cd0

Please sign in to comment.