mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +08:00
Compare commits
2 Commits
6117583026
...
583340ebb7
Author | SHA1 | Date | |
---|---|---|---|
|
583340ebb7 | ||
|
89330bf573 |
@ -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 → `overalProfit = Max(keepProfit, buySellProfit)`.
|
The overall profit would be equal to → `overallProfit = 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.
|
||||||
|
|
||||||
|
@ -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 probablity of a false positive is:
|
The formula to calculate probability of a false positive is:
|
||||||
|
|
||||||
( 1 - e <sup>-kn/m</sup> ) <sup>k</sup>
|
( 1 - e <sup>-kn/m</sup> ) <sup>k</sup>
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ end remove
|
|||||||
findParent(value, root)
|
findParent(value, root)
|
||||||
Pre: value is the value of the node we want to find the parent of
|
Pre: value is the value of the node we want to find the parent of
|
||||||
root is the root node of the BST and is != ø
|
root is the root node of the BST and is != ø
|
||||||
Post: a reference to the prent node of value if found; otherwise ø
|
Post: a reference to the parent node of value if found; otherwise ø
|
||||||
if value = root.value
|
if value = root.value
|
||||||
return ø
|
return ø
|
||||||
end if
|
end if
|
||||||
|
@ -143,7 +143,7 @@ end remove
|
|||||||
findParent(value, root)
|
findParent(value, root)
|
||||||
Pre: value is the value of the node we want to find the parent of
|
Pre: value is the value of the node we want to find the parent of
|
||||||
root is the root node of the BST and is != ø
|
root is the root node of the BST and is != ø
|
||||||
Post: a reference to the prent node of value if found; otherwise ø
|
Post: a reference to the parent node of value if found; otherwise ø
|
||||||
if value = root.value
|
if value = root.value
|
||||||
return ø
|
return ø
|
||||||
end if
|
end if
|
||||||
|
Loading…
Reference in New Issue
Block a user