You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
-[Notes of Algorithms, Part I](part-I/readme.md)
4
4
-[Notes of Algorithms, Part II](part-II/readme.md)
5
5
6
-
The notes are taken from the *Algorithms* course on Coursera ([Part I](https://www.coursera.org/learn/algorithms-part1), [Part II](https://www.coursera.org/learn/algorithms-part2)). This repository is intended to track my own learning process as well as for future reference.
6
+
The notes are taken from the *Algorithms* course on Coursera ([Part I](https://www.coursera.org/learn/algorithms-part1), [Part II](https://www.coursera.org/learn/algorithms-part2)).
7
7
8
8
> This course covers the essential information that every serious programmer needs to know about algorithms and data structures, with emphasis on applications and scientific performance analysis of Java implementations. Part I covers elementary data structures, sorting, and searching algorithms. Part II focuses on graph- and string-processing algorithms.
| hash table |1<sup>†</sup>|1<sup>†</sup>|1<sup>†</sup>| no | equals()<br/>hashCode() |
3472
+
3473
+
† under uniform hashing assumption
3474
+
3475
+
As with sorting, we can take advantage of properties of strings to develop search methods (symbol-table implementations) that can be more efficient than the general-purpose methods (i.e., BST, hash tables) for typical applications where search keys are strings.
3476
+
3477
+
APIfor a symbol table with string keys
3478
+
3479
+
| `publicclassStringST< Value> `| |
3480
+
| :--: | :--: |
3481
+
| `StringST()` | create a symbol table |
3482
+
| `void put(String key, Value val)` | put key-value pair into the table (remove key if value is null) |
3483
+
| `Value get(String key)` | value paired with key (null if key is absent) |
>-**TST** correspond to **3-way string quicksort** in the same way that
3708
+
>-**BST** correspond to **quicksort** and
3709
+
>-**trie** correspond to **MSD sorting**.
3710
+
3711
+
3712
+
#### 7.2.1.TST vs. hashing
3713
+
3714
+
| algorithm | property |
3715
+
|:--:|:--|
3716
+
|Hashing|<ul><li>Need to examine entire key.</li><li>Search hits and misses cost about the same.</li><li>Performance relies on hash function.</li><li>Does not support ordered symbol table operations.</li></ul>|
3717
+
|TST|<ul><li>Works only for strings (or digital keys).</li><li>Only examines just enough key characters.</li><li>Search miss may involve only a few characters.</li><li>Supports ordered symbol table operations (plus others!).</li></ul>|
3718
+
3719
+
**Bottom line**.TSTs are:
3720
+
-Faster than hashing (especially for search misses).
3721
+
-More flexible than red-black BSTs.
3722
+
3723
+
#### 7.2.2.String symbol table implementation cost summary
3724
+
3725
+
| implementation | character accesses<br/>(typical case)<br/>**search hit**| character accesses<br/>(typical case)<br/>**search miss**| character accesses<br/>(typical case)<br/>**insert**| character accesses<br/>(typical case)<br/>**space (references)**| moby.txt | actors.txt |
3726
+
|:--:|:--:|:--:|:--:|:--:|:--:|:--:|
3727
+
| red-black BST|L+ c lg <sup>2</sup>N| c lg <sup>2</sup>N| c lg <sup>2</sup>N|4N|1.40|97.4|
3728
+
| hash table |L|L|L|4N to 16N|0.76|40.6|
3729
+
|R-way trie |L| log <sub>R</sub>N|L| (R+1) N|1.12| out of memory |
3730
+
|TST|L+ ln N| ln N|L+ ln N|4N|0.72|38.7|
3731
+
|TST with R<sup>2</sup>|L+ ln N| ln N|L+ ln N|4N+R<sup>2</sup>|0.51|32.7|
3732
+
3733
+
3734
+
3735
+
-R-way trie
3736
+
-Method of choice for small *R*.
3737
+
-Too much memory for large *R*.
3738
+
-Challenge. Use less memory, e.g., 65,536-way trie forUnicode!
3739
+
-TST
3740
+
-Can build balanced TSTs via rotations to achieve *L+ log N* worst-case guarantees.
3741
+
-TST is as fast as hashing (for string keys), space efficient.
3742
+
-TST with R<sup>2</sup> branching at root. (Hybrid of R-way trie and TST.)
3743
+
-DoR<sup>2</sup>-way branching at root.
3744
+
-Each of R<sup>2</sup> root nodes points to a TST.
3745
+
3746
+
3747
+
>If space is available, **R-way tries** provide the fastest search, essentially completing the job with a constant number of character compares. For*large alphabets*, where space may not be available forR-way tries, **TSTs** are preferable, since they use a logarithmic number of character compares, while**BSTs** use a logarithmic number of key compares. **Hashing** can be competitive, but, as usual, cannot support ordered symbol-table operations or extended character-based API operations such as *prefix* or *wildcard match*.
3748
+
3749
+
3750
+
### 7.3. Patricia trie
3751
+
3752
+
[PracticalAlgorithm to RetrieveInformationCoded in Alphanumeric]
3753
+
-Remove one-way branching.
3754
+
-Each node represents a sequence of characters.
3755
+
-Implementation: one step beyond this course.
3756
+
3757
+
>**Applications**.
3758
+
>-Database search.
3759
+
>-P2P network search.
3760
+
>-IP routing tables: find longest prefix match.
3761
+
>-Compressed quad-tree forN-body simulation.
3762
+
>-Efficiently storing and querying XML documents.
3763
+
3764
+
3765
+
Also known as: crit-bit tree, radix tree.
3766
+
3767
+
3768
+
### 7.4. Suffix tree
3769
+
3770
+
Suffix tree.
3771
+
-Patricia trie of suffixes of a string.
3772
+
-Linear-time construction: beyond this course.
3773
+
3774
+
>**Applications**.
3775
+
>-Linear-time: longest repeated substring, longest common substring, longest palindromic substring, substring search, tandem repeats, ….
3776
+
>-Computational biology databases (BLAST, FASTA).
3777
+
3778
+
3779
+
3780
+
### 7.5. String symbol tables summary
3781
+
3782
+
| algorithm | property |
3783
+
|:--:|:--|
3784
+
|Red-black BST|<ul><li>Performance guarantee: log N key compares.</li><li>Supports ordered symbol table API.</li></ul>|
3785
+
|Hash tables |<ul><li>Performance guarantee: constant number of probes.</li><li>Requires good hash function for key type.</li></ul>|
3786
+
|Tries. R-way, TST|<ul><li>Performance guarantee: log N characters accessed.</li><li>Supports character-based operations.</li></ul>|
0 commit comments