***Welcome to ashrafedu.blogspot.com * * * This website is maintained by ASHRAF***

    Tuesday, August 16, 2022

    Algorithm

    An algorithm is a set of steps of operations to solve a problem performing calculation, data processing, and automated reasoning tasks. An algorithm is an efficient method that can be expressed within finite amount of time and space.

    An algorithm is the best way to represent the solution of a particular problem in a very simple and efficient way. If we have an algorithm for a specific problem, then we can implement it in any programming language, meaning that the algorithm is independent from any programming languages.

    Algorithm Design

    The important aspects of algorithm design include creating an efficient algorithm to solve a problem in an efficient way using minimum time and space.

    To solve a problem, different approaches can be followed. Some of them can be efficient with respect to time consumption, whereas other approaches may be memory efficient.

    However, both time consumption and memory usage cannot be optimized simultaneously.

    Characteristics of Algorithms

    The following are the characteristics of algorithms:

    Input: An algorithm is supplied with zero or more external quantities as input.

    Output: An algorithm must produce a result, that is, an output.

    Finiteness: An algorithm must halt. Hence, it must have finite number of steps.

    Effectiveness:  Every instruction must be sufficiently basic, to be executed easily.

    Unambiguous:  Each step in an algorithm must be clear and unambiguous.

    Algorithm Design Tools

    The two popular tools used in the representation of algorithms are the following:

    1. Pseudocode

    2. Flowchart

    Pseudocode

    A pseudocode is an English-like presentation of the code required for an algorithm. It is partly English and partly computer language structure code.

    Pseudocode is a precise description of a solution. The pseudocode uses various notations such as header, purpose, pre–post conditions, return, variables, statement numbers, and subalgorithms.

    Ex:

    Algorithm sort(ref A<integer>, val N<integer>)

    Pre array A to be sorted

    Post sorted array A

    Return None

    1. if(N < 1) goto step (4)

    2. M = N − 1

    3. For I = 1 to M do

    For J = I + 1 to N do

    begin

    if(A(I) > A(J))

    then

    begin

    T = A(I)

    A(I) = A(J)

    A(J) = T

    end

    end if

    end

    4. stop

     

    Flow Charts

    A flowchart is a pictorial representation of an algorithm. It hides all the details of an algorithm by giving a picture. It shows how the algorithm flows from beginning to end.

    The primary purpose of a flowchart is to show the design of the algorithm. At the same time, it frees the programmers from the syntax and details of a programming language while allowing them to concentrate on the details of the problem to be solved.



    No comments:

    Post a Comment

    Prim’s algorithm for finding MST (Minimum Spanning Tree)

    Prim's algorithm to find minimum cost spanning tree uses the greedy approach. Prim's algorithm, in contrast with Kruskal's algor...