Читать книгу Data Structure and Algorithms Using C++ - Sachi Nandan Mohanty - Страница 12

1.3 Algorithm

Оглавление

The step by step procedure to solve a problem is known as the ALGORITHM. An algorithm is a well-organized, pre-arranged, and defined computational module that receives some values or set of values as input and provides a single or set of values as out put. These well-defined computational steps are arranged in sequence, which processes the given input into output.

An algorithm is said to be accurate and truthful only when it provides the exact wanted output.

The efficiency of an algorithm depends on the time and space complexities. The complexity of an algorithm is the function which gives the running time and/or space in terms of the input size.

Steps Required to Develop an Algorithm

 Finding a method for solving a problem. Every step of an algorithm should be defined in a precise and in a clear manner. Pseudo code is also used to describe an algorithm.

 The next step is to validate the algorithm. This step includes all the steps in our algorithm and should be done manually by giving the required input, perform the required steps including in our algorithm and should get the required amount of output in a finite amount of time.

 Finally implement the algorithm in terms of programming language.

Mathematical Notations and Functions

 ❖ Floor and Ceiling Functions

 Floor function returns the greatest integer that does not exceed the number.

 Ceiling function returns the least integer that is not less than the number.

 ❖ Remainder FunctionTo find the remainder “mod” function is being used as

 ❖ To find the Integer and Absolute value of a numberINT(5.34) = 5 This statement returns the integer part of the numberINT(- 6.45) = 6 This statement returns the absolute as well as the integer portion of the number

 ❖ Summation SymbolTo add a series of number as a1+ a2 + a3 +............+ an the symbol Σ is used

 ❖ Factorial of a NumberThe product of the positive integers from 1 to n is known as the factorial of n and it is denoted as n!.

Algorithemic Notations

While writing the algorithm the comments are provided with in [ ].

The assignment should use the symbol “: =” instead of “=”

For Input use Read : variable name

For output use write : message/variable name

The control structures can also be allowed to use inside an algorithm but their way of approaching will be some what different as

Simple If

If condition, then: Statements [end of if structure]

If...else

If condition, then: Statements Else : Statements [end of if structure]

If...else ladder

If condition1, then: Statements Else If condition2, then: Statements Else If condition3, then: Statements ………………………………………… ………………………………………… ………………………………………… Else If conditionN, then: Statements Else: Statements [end of if structure]

LOOPING CONSTRUCT

Repeat for var = start_value to end_value by step_value Statements [end of loop] Repeat while condition: Statements [end of loop] Ex : repeat for I = 1 to 10 by 2 Write: i [end of loop]

OUTPUT

1 3 5 7 9

Data Structure and Algorithms Using C++

Подняться наверх