Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
707 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Amazing outcome | ||
|
||
If this project went really well, what would it be able to do? | ||
|
||
- min stack | ||
- min queue | ||
- Time-travelling key value store | ||
- List with getIndexOfMax | ||
- List with getMax | ||
- Design a data structure that supports the following operations: insert_back(), remove_front() and find_mode(), all in O(1) | ||
- Is there a data structure for key-value pairs that allows insert, update, deletion and finding the minimal value all in log(n)? | ||
- [What data structures support insertion, deletion and selection of a random element with a O(1)O(1) time complexity bound?](https://www.quora.com/What-data-structures-support-insertion-deletion-and-selection-of-a-random-element-with-a-math-O-1-math-time-complexity-bound) | ||
- [How can I design an efficient data structure that supports findMin, findMax, deleteMin, deleteMax, Insert, and delete?](https://www.quora.com/How-can-I-design-an-efficient-data-structure-that-supports-findMin-findMax-deleteMin-deleteMax-Insert-and-delete) | ||
- [What data structures support insertion, deletion and selection of a random element with a O(1) time complexity bound which allow duplicates?](https://www.quora.com/What-data-structures-support-insertion-deletion-and-selection-of-a-random-element-with-a-O-1-time-complexity-bound-which-allow-duplicates) | ||
- [Does a data structure exist which supports logarithmic insertion/removal and constant-time query for the Kth smallest element?](https://www.quora.com/Does-a-data-structure-exist-which-supports-logarithmic-insertion-removal-and-constant-time-query-for-the-Kth-smallest-element) | ||
- What data structure would allow adding an element, removing an element, and querying for the number of elements in the range (a, b), all in O(logn) time? | ||
- [Can I delete an element from the middle of an array using queue in data structures?](https://www.quora.com/Can-I-delete-an-element-from-the-middle-of-an-array-using-queue-in-data-structures) | ||
|
||
## Maximally ambitious version | ||
|
||
is of course to output actual code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
How do you know if f(x, y, z) > g(x, y, z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Different kinds of algorithm problems | ||
|
||
## Compose data structures to support a given API quickly | ||
|
||
lots, eg | ||
|
||
- min stack | ||
- min queue | ||
- Time-travelling key value store | ||
- List with getIndexOfMax | ||
- List with getMax | ||
- Design a data structure that supports the following operations: insert_back(), remove_front() and find_mode(), all in O(1) | ||
- Is there a data structure for key-value pairs that allows insert, update, deletion and finding the minimal value all in log(n)? | ||
|
||
### Support a given API of queries which are compositions of simple operations | ||
|
||
Eg making indexes for different kinds of queries like `blah.map(f).filter(g).count` | ||
|
||
## Graph algorithms | ||
|
||
Lots. Lots of things that are basically shortest-path algorithms. | ||
|
||
## Dynamic programming on arrays | ||
|
||
Build problems out of forall and thereexists and reductions on arrays. | ||
|
||
For example: | ||
|
||
Find the minimum sum subarray of an array: | ||
|
||
array.choose_n_indices(2).minimizeBy((i, j) => array[i..j].sum) | ||
|
||
Find the most evenly balanced subarrays of an array: | ||
|
||
array.choose_n_indices(3) | ||
.minimizeBy((i, j, k) => abs(array[i..j] - array[j..k])) | ||
|
||
Find the amount of water that fills up an array | ||
|
||
array.indices.map((i) => { | ||
min(array.take(i).maximize(_), array.drop(i).maximize(_)) - array[i] | ||
}).sum | ||
|
||
Incidentally, you can generalize that one to graphs. It looks like this: | ||
|
||
graph.nodes.map((node) => { | ||
graph.pathsFromNodeToSet(set(node), boundary).minBy((path) => path.max) | ||
}).sum | ||
|
||
Given a histogram, determine the area of the largest rectangle that can be drawn completely within the bounds of the histogram. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Here's an example of what I want my software to do. | ||
|
||
Suppose you want to make a priority queue which lets you read priorities of elements in it. | ||
|
||
adt DoublePriorityQueue: Table[unique key, value] { | ||
insert: n | ||
getByUnique[key]: n | ||
getByMinimum[value]: n | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## Graphs | ||
|
||
Graphs are just a data structure. Here are some of their methods: | ||
|
||
UnweightedGraph { | ||
nodes | ||
edges | ||
addNode | ||
removeNode | ||
addEdge | ||
removeEdge | ||
edgeWeightFromNode | ||
edgesAtNode | ||
distanceBetweenEdges | ||
} | ||
|
||
Lists are just a particular kind of graph. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
adt MaxStack { | ||
insertAtEnd! | ||
getAtEnd | ||
deleteAtEnd! | ||
getMaximumBy[_] | ||
} | ||
|
||
adt RangeMinimumQuery { | ||
extend!: 1 | ||
twoSidedIndexRangeQuery[1] | ||
} | ||
|
||
adt Queue { | ||
insertAtEnd! | ||
getAtStart | ||
deleteAtStart! | ||
} | ||
|
||
adt QueueWithRandomDeletion extends Queue { | ||
deleteByIndex! | ||
} | ||
|
||
adt SetWithKthSmallest { | ||
setInsert! | ||
setRemove! | ||
getKthSmallest | ||
} | ||
|
||
adt ListWithGetIndexOfMin extends List { | ||
getMinimum | ||
} | ||
|
||
adt ListWithGetMax extends List { | ||
getMaximum | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.