SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size
Data Structure & Algorithm

What is Algorithm in Computer Science?

E-mail Print PDF

Algorithm is a process of problem-solving in step by step to get result. Algorithm is very importance for programmers to do computer programming because it figures out the programming process. Algorithm is a part of problem-solving techniques. After the problem has been raise, we have to analyze the problem first then the inputs and outputs are defined. After that we start to design the algorithm that is a process to transform inputs into outputs.

Problem-solving technique



 
Example
 
Problem: Given the values of parameters a, b and c. Design algorithm to find root x of the equation ax+b=c.

After problem has been raised, we have to do the analysis.

Analyze:
  • What are the results of the problem? (outputs)
    =>That is value of x
  • What is the information we do need to find solution? (inputs)
    =>Value of parameter a
    =>Value of parameter b
    =>Value of parameter c
  • How to transform inputs into output? (processes and formulas)
    =>If (a=0 and c-b=0) then x has infinite root
    =>if(a=0 and c-b#0) then x has no root
    =>otherwise x=(c-b)/a
Algorithm:
1. Get value of a
2. Get value of b
3. Get value of c
4. Calculate x with the following formula
   if a not equal to 0 then
        x=(c-b)/a
   otherwise
        if c-b=0 then Show "x has infinite root"
        otherwise Show "x has no root"