Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CMS_term_Andrushchenko.doc
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
370.18 Кб
Скачать

2.3. Basic Algorithms of Data Processing

Arithmetic operations with DL data in terms of arrays may be realized via the following basic procedures:

  • integration of data structures;

  • comparison of data structures;

  • addition and subtraction of appropriate elements of data structures;

  • sorting of data structures;

  • collecting terms of data structure elements.

Consider each of them in detail.

Integration of DL data structures is a procedure in which some fields of DL codes are integrated, e.g., the initial DL structures are joined to the resultant DL structure. Here, the field of the number Q of significant units in the resultant structure is written with the sum of values of the analogous fields of DL structures being integrated. The field of the sign of the result is not changed. The DL structure of the resultant «number» will contain unordered DL codes. This form of DL numbers makes algorithms of data processing more complex. That’s why a procedure of sorting (ordering) Q elements in the field of DL codes should be applied.

Comparison of DL data structures is a procedure that allows determining which of two DL structures of operands contains the greater or the lesser numeric code (number) and determines their equivalence as well. The comparing of DL data is performed bit-by-bit beginning from the most significant digits.

Here is an algorithm of comparing two DL numbers in a pithy form:

1) comparison of appropriate digits of the DL codes of operands. If the digit of the first operand is greater than that of the second operand, the first operand is determined as the greater operand and transition to step 4 is performed. If the digit of the second operand is greater than that of the first operand, the second operand is determined as the greater operand, and transition to step 4 is performed;

2) if the appropriate digits are equal and the number of comparing has not reached the least number of significant digits in the DL structures of operands, the number of digits being compared is incremented by one and step 1 is performed.

3) if the appropriate digits are equal and the number of comparisons has reached the least number of significant digits in the DL structures of operands, and if of the first operand is equal to of the second one, the operands are equal and transition to step 4 is performed. If of the first operand is greater than of the second one, the first operand is determined as the greater and transition to step 4 is performed. If of the second operand is greater than of the first one, then the second operand is determined as the greater and transition to step 4 is performed;

4) end of comparison.

Addition and subtraction of appropriate elements of data structures is done in the cases when, according to the rules of performing digital operations in DL arithmetic (Table 2.2), addition and subtraction of definite digits of DL codes of a number should be done. Such actions are done when addition, subtraction, multiplication, and number shift by m digits are performed.

Sorting of DL data structures is a procedure in which elements in the field of the DL codes of a number are ordered by a certain key. The sorting is necessary to decrease the number of operations and simplify the calculation. Particularly, ordered DL codes simplify algorithms of subtraction, division, and collecting terms that are considered below. The view of a number А, when for all and ( ) , is the most convenient and practical, i.e., the DL codes of numbers are sorted in decreasing order.

Collecting terms of data structure elements is a procedure in which two digits and are in the same DL structure and . These digits are merged into one by the rule Ni =Ni+1, and Nk is eliminated from the processing.

This procedure for a number А is done until all and ( ) . Collecting terms, according to the rules of performing digital operations in DL arithmetic (Table 2.2), is done in operations of addition and subtraction.

Consider algorithms of performing arithmetic operations with data in DL representation in detail.

The rules of performing digital operations when adding DL data are given in Table 2.2, namely, the following actions must be done for each pair of codes:

Ni + Nk = Ni, Nk, if Ni >Nk;

Ni + Nk = Ni+1, if Ni= Nk, where Ni, Nk are the codes of nonzero digits of the operands.

The addition begins with the codes of the least weight. The algorithm of adding numbers with the same sign in DL representation, in a pithy form, may have the following stages:

1) checking the operands on their being egual to zero. If one of the operands is equal to zero, the DL value of the other one is written into the DL structure of the result and the operation ends (transition to step 6). If both operands are equal to zero, zero is written into the DL structure of the result and the operation ends (transition to step 6);

2) integration of the DL structures of the operands into the DL structure of the result;

3) sorting of the DL structure of the result;

4) collecting terms in the DL structure of the result;

5) assigning the sign of the first operand to the sign of the result;

6) end.

The algorithm of sorting used may be as follows.

Algorithm of Sorting (АS):

INPUT: A=signA QA {ai};B= signB QB{bi}

result: Х={a1...ak...bf...bt}; a1 ... ak ... bf bt.

1. Integration of the DL structures of codes A and B into an array Х.

2. Calculation of the common index Q = QA + QB.

3. For i = 1 to Q-1 execute:

3.1. If хі хi +1, rewrite codes (с=хі , хі = хi +1 , хi +1 =с).

RESULT: Х={х1...хk....хf ...хt}; х1 ...хk ... хf хt.

Algorithm of Collecting Terms (АCT) may be as follows:

INPUT: A=signA QA {ai};B= signB QB{bi}

RESULT: Х={х1...хk....хf ...хt}; х1 ≠...хk ≠... хf ≠ …хt.

1. Integration of the DL structures of codes A and B into an array Х.

2. Calculation of the common index Q = QA + QB.

3. For i = 1 to Q-1 execute:

3.1. If хі = хi+1, хі = хі +1; eliminating the element хi+1 by shifting the array Х by one element; Q=Q-1:

Else go to step 3.

4. If there is no coincidence in the whole array, the operation of collecting terms ends.

RESULT: Х={х1...хk....хf ...хt}; х1 ≠...хk ≠... хf ≠ …хt.

The algorithm of addition (SUM) including the algorithms of sorting (AS) and collecting terms (АCT) may be as follows:

Algorithm SUM:

INPUT: A=signA QA {ai};B= signB QB{bi}

RESULT: S= signS QS{si}.

1. Checking the operands on their equality to zero.

2. Integration of the DL structures of codes A and B into array Х.

3. Calculation of the common index Q = QA + QB.

4. Call the algorithm AS for processing the array Х.

5. Call the algorithm АCT for processing arrays.

6. Set signS as the sign of the result.

RESULT: S = signS QS{si} .

Let us give an example of adding numbers А and В in the DL form according to the above mentioned algorithm. Let number A be А=0.10.14.10.9.8.5.4.3.1.0.-1., and number В=0.6.17.15.10.6.-2.-15.

Since the operands are not equal to zero, we go to step 2 of the algorithm SUM. After the integration, the DL structure of the result looks like:

0.16. 14.10.9.8.5.4.3.1.0.-1.17.15.10.6.-2.-15.

Then the DL codes of the numbers are sorted in decreasing order:

0.16.17.15.14.10.10.9.8.6.5.4.3.1.0.-1.-2.-15.

After collecting terms in this array and assigning the sign of the first operand to the sign of the result, we get:

0.15.17.15.14.11.9.8.6.5.4.3.1.0.-1.-2.-15.

Different variants of realization of the addition operation with different procedures of sorting and collecting terms are also possible. The considered algorithms may be programmed as models of performing the operations of DL arithmetic.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]