mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-14 23:12:58 +08:00
Compare commits
1 Commits
0be2d8a7be
...
6475244043
Author | SHA1 | Date | |
---|---|---|---|
|
6475244043 |
@ -48,8 +48,6 @@ be accessed and modified efficiently. More precisely, a data structure is a coll
|
|||||||
values, the relationships among them, and the functions or operations that can be applied to
|
values, the relationships among them, and the functions or operations that can be applied to
|
||||||
the data.
|
the data.
|
||||||
|
|
||||||
Remember that each data has its own trade-offs. And you need to pay attention more to why you're choosing a certain data structure than to how to implement it.
|
|
||||||
|
|
||||||
`B` - Beginner, `A` - Advanced
|
`B` - Beginner, `A` - Advanced
|
||||||
|
|
||||||
* `B` [Linked List](src/data-structures/linked-list)
|
* `B` [Linked List](src/data-structures/linked-list)
|
||||||
|
@ -46,7 +46,7 @@ Let's say we have an array of prices `[7, 6, 4, 3, 1]` and we're on the _1st_ da
|
|||||||
1. _Option 1: Keep the money_ → profit would equal to the profit from buying/selling the rest of the stocks → `keepProfit = profit([6, 4, 3, 1])`.
|
1. _Option 1: Keep the money_ → profit would equal to the profit from buying/selling the rest of the stocks → `keepProfit = profit([6, 4, 3, 1])`.
|
||||||
2. _Option 2: Buy/sell at current price_ → profit in this case would equal to the profit from buying/selling the rest of the stocks plus (or minus, depending on whether we're selling or buying) the current stock price → `buySellProfit = -7 + profit([6, 4, 3, 1])`.
|
2. _Option 2: Buy/sell at current price_ → profit in this case would equal to the profit from buying/selling the rest of the stocks plus (or minus, depending on whether we're selling or buying) the current stock price → `buySellProfit = -7 + profit([6, 4, 3, 1])`.
|
||||||
|
|
||||||
The overall profit would be equal to → `overallProfit = Max(keepProfit, buySellProfit)`.
|
The overall profit would be equal to → `overalProfit = Max(keepProfit, buySellProfit)`.
|
||||||
|
|
||||||
As you can see the `profit([6, 4, 3, 1])` task is being solved in the same recursive manner.
|
As you can see the `profit([6, 4, 3, 1])` task is being solved in the same recursive manner.
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ and return false.
|
|||||||
queen here leads to a solution.
|
queen here leads to a solution.
|
||||||
b) If placing queen in [row, column] leads to a solution then return
|
b) If placing queen in [row, column] leads to a solution then return
|
||||||
true.
|
true.
|
||||||
c) If placing queen doesn't lead to a solution then unmark this [row,
|
c) If placing queen doesn't lead to a solution then umark this [row,
|
||||||
column] (Backtrack) and go to step (a) to try other rows.
|
column] (Backtrack) and go to step (a) to try other rows.
|
||||||
3) If all rows have been tried and nothing worked, return false to trigger
|
3) If all rows have been tried and nothing worked, return false to trigger
|
||||||
backtracking.
|
backtracking.
|
||||||
|
@ -93,7 +93,7 @@ three factors: the size of the bloom filter, the
|
|||||||
number of hash functions we use, and the number
|
number of hash functions we use, and the number
|
||||||
of items that have been inserted into the filter.
|
of items that have been inserted into the filter.
|
||||||
|
|
||||||
The formula to calculate probability of a false positive is:
|
The formula to calculate probablity of a false positive is:
|
||||||
|
|
||||||
( 1 - e <sup>-kn/m</sup> ) <sup>k</sup>
|
( 1 - e <sup>-kn/m</sup> ) <sup>k</sup>
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ export default class Heap {
|
|||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
pairIsInCorrectOrder(firstElement, secondElement) {
|
pairIsInCorrectOrder(firstElement, secondElement) {
|
||||||
throw new Error(`
|
throw new Error(`
|
||||||
You have to implement heap pair comparison method
|
You have to implement heap pair comparision method
|
||||||
for ${firstElement} and ${secondElement} values.
|
for ${firstElement} and ${secondElement} values.
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user