Alterna · учебный материал

Dynamics and effective data processing

41.3: Dynamics and effective data processing: Short theory, one example and Python stepway.

Что в этом материале

Содержание и основные понятия

For EGE No. 27, the correct answer is not enough: the complete overtaking of O(n2) pairs is replaced by a state that is updated per passage.
substance and practice
Grade 11
OGE No. 6/16
EEG No. 16/17/23 - 27
01
How it works.
Big data require not only the right formula, but also the right amount of work. First assess the complexity, then keep the minimum state sufficient for the next step.
O(n²).
Overtaking all pairs quickly becomes unfit for hundreds of thousands of values.
One passage.
Each entrance is read once; time is usually O(n).
It's the rest class.
When calculating pairs with multiple k, it's enough to keep a count for k classes of residuals.
Prefix.
The amount accumulated, or at least to the current item, replaces the countdown.
02
One example in execution
Start the short program and go over the lines. The visualiser only shows the code, current line, variables and output.
In the task of number of pairs with multiple k, the current balance r requires all previous elements of the balance (-r) % k: their number is stored
count[need]
First, the current element is checked as the right boundary and added
count[need]
to answer, then to increase
count[r]
; otherwise one element forms a pair with itself. For another purpose, e.g. the maximum sum of the pair, the best class candidate is stored instead of the meter.
Algorithm map
Read from left to right, then run the code.
1
Start
2
Take Value
3
Find the rest of it
4
Compute the previous balance
5
Use status class
03
Remember
First check the pair with the previous data, then update the class of the current element.
Determine behavior in the absence of an acceptable couple.
In order to limit the distance, add elements to the state only after the required delay.
Syntax of this page
[None] * k
Creates a set of k independent links to unchangeable None.
value % k
It gives the residual class value at k > 0.
(-value) % k
Finds a balance that supplements value to the number k.
max
Updates the best answer found.
is None
Checks the candidate's absence; don't get confused with = 0.
for value in values
One linear passage from the data.
print
The answer is agreed; no-solution must be described as a condition.

Structural map of textbooks