Introduction to Algorithms | Raveling Tech

Algorithms

    What is an Algorithm?

    An algorithm is a process or set of rules to be followed in calculations or other problem-solving operations. In Computer Science an Algorithm is a step by step procedure for solving computational problems. 
    Example: Greedy algorithm, Divide and conquer algorithm, Backtracking, Randomized algorithm, etc.

    We can classify an algorithm in two types, Iterative and Recursive. The iterative algorithm involves the use of for loop, while loop, or do-while loop wherein recursive algorithm the function call itself several times until it reaches the base case.

    What is the difference between Program and Algorithm?

    An algorithm is a designing part of solving a problem and the Program is the implementation part of solving that problem.  

    An algorithm can be written in any language like in the English language or by using some mathematical notations. But the program for that algorithm must be written using programming languages like C, C++, Java, or Python.  

    An algorithm is not getting change base on the hardware specification and Operating System but the programmer has to write different code for different hardware and operating system, like a programmer have to write different code for Linux OS and different code for Windows OS for the same algorithm.

    Much different analysis is done on an algorithm before the actual implementation (also known as prior analysis) to make it efficient base on its space and time complexity. Where a program is just tested by giving different inputs checking whether it is giving the correct output or not.

    What are the characteristics of an Algorithm?

    There are many things to keep in mind for writing a good algorithm and here is the list of few characteristics that one should know before writing an algorithm for solving any problem.

    Input: The Algorithm may contain no input or many inputs and it should contain well-defined inputs.

    Output: The Algorithm must contain at least one output and it should be well defined.

    Definiteness: Every line of the algorithm should be well defined and have some logical meaning.

    Finiteness: The Algorithm must be finite, it should not go continuous like an infinite loop.

    Effectiveness: The Algorithm must capable of achieving the desired output successfully.

    Algorithms are language-independent, so while thinking about some algorithm you no need to think about the language which you are going to use for the implementation of that algorithm. 

    What do you mean by Algorithm Complexity?

    The complexity of an algorithm is base on the amount of space and time it is consuming for the implementation.

    There are many other factors which affect the efficiency of the algorithm like the speed of the computer, the compiler you are using but the space complexity and time complexity is the most important factor to keep in mind while designing an algorithm.

    Space Complexity: Space complexity is the amount of memory space the algorithm is required for giving the desired output. The memory space is consumed by the input data, temporary data, and the output data of the algorithm.

    Time Complexity: Time complexity is the amount of time required by an algorithm for the execution and providing the desired output. It depends on the number of iterative or recursive steps involve in the execution of the algorithm.

    Note: If any program is not containing an iterative or recursive algorithm then their time complexity is O(1). 

    Next:
    Analysis of Algorithms. 
    Introduction to Asymptotic Notation

    If you like this post and find it useful then you can show your support by donating a small amount from your heart. You can also show your support by following us on Facebook and Twitter. 

    Post a Comment

    Previous Post Next Post