Code Idea Standard Process

  First introduce a few basic concepts. fff represents the specified function. Every step (step) and every round (round). Assuming a double loop, the outer loop represents one round at a time, and the inner loop represents one step at a time. If it is a single cycle, then the cycle represents one step.

  Take bubble sort as an example, suppose bubble sort is the function fff , the expression isf (x 1, x 2,…, xn) f(x_1,x_2,\dots,x_n)f(x1,x2,,xn) . In order to better understand the complex situation, we first understand the simplest situation:

  Assuming that only a single element is included:
f (x 1) = x 1 f(x_1)=x_1f(x1)=x1

  Assuming the number of elements is two:
f (x 1, x 2) = {x 1, x 2 x 1 <= x 2 x 2, x 1 x 1> x 2 f (x_1, x_2) = \left\ {\begin{array} {l} {x_1, x_2 \quad x_1 <=x_2} \\ {x_2,x_1 \quad x_1>x_2} \end{array} \right.f(x1,x2)={ x1,x2x1<=x2x2,x1x1>x2

  Assuming the number of elements is greater than 2, the expression is f (x 1, x 2,…, xn) f(x_1, x_2, \dots,x_n)f(x1,x2,,xn) , How to deal with it?

  For the convenience of representation, we denote each step of operation as sf (step function), and each round of operation as rf (round function).

  Then each step is expressed as:
sf (x 1) = x 1 sf(x_1)=x_1sf(x1)=x1
s f ( x 1 , x 2 ) = { x 1 , x 2 x 1 < = x 2 x 2 , x 1 x 1 > x 2 sf ( x_1, x_2 ) = \left\{ \begin{array} { l } { x_1, x_2 \quad x_1 <=x_2 } \\ { x_2,x_1 \quad x_1>x_2 } \end{array} \right. sf(x1,x2)={ x1,x2x1<=x2x2,x1x1>x2

  The first round is expressed as
rf (x 1, x 2,…, xn) = sf (sf (x 1, x 2) [1], x 3) [1]… rf(x_1, x_2,\dots,x_n) =sf(sf(x_1,x_2)[1], x_3)[1]\dotsrf(x1,x2,,xn)=sf(sf(x1,x2)[1],x3)[1]

  The second round is expressed as
rf (x 1, x 2,…, xn − 1) rf(x_1, x_2,\dots,x_{n-1})rf(x1,x2,,xn1)

  The nth round is expressed as
rf (x 1) = sf (x 1) = x 1 rf(x_1)=sf(x_1)=x_1rf(x1)=sf(x1)=x1
  Question: For bubble sorting, what kind of processing is done at each step and each round?

  It should be noted that the first round represents f (x 1, x 2,…, xn) f(x_1, x_2, \dots, x_n)f(x1,x2,,xn) , the second round representsf (x 1, x 2,…, xn − 1) f(x_1, x_2,\dots, x_{n-1})f(x1,x2,,xn1) . (This paragraph is just a reminder of what is done in each round)

  Finally, an example must be used to simulate the computer execution process.

Guess you like

Origin blog.csdn.net/herosunly/article/details/106635210
Recommended