Skip to main content Accessibility help
Internet Explorer 11 is being discontinued by Microsoft in August 2021. If you have difficulties viewing the site on Internet Explorer 11 we recommend using a different browser such as Microsoft Edge, Google Chrome, Apple Safari or Mozilla Firefox.

Chapter 2: Introduction to Algorithm

pp. 15-40

Authors

, Techno India Hoogly
  • Get access
  • Add bookmark
  • Export citation
  • Share

Extract

Algorithm is a very common word in computer science, especially in case of any procedural programming languages. In this chapter we will know about algorithms, different types of algorithms, different approaches to designing an algorithm, analysis of algorithms, etc. We will also be able to learn how an algorithm can be written using different control structures.

2.1 What Is an Algorithm?

We can define an algorithm as a step-by-step procedure to solve a problem. This is much like a recipe for cooking an item. To cook a new item, we follow the instructions one by one as given in its recipe. Similarly, to write a program we need to follow the algorithm. Once we are able to generate the algorithm of a problem, then writing its code is not a huge task at all. But before writing an algorithm we have to keep in mind that any algorithm must have the following characteristics:

  • • Input: Inputs are the values that are supplied externally. Inputs are those without which we cannot proceed with the problems. Every algorithm must have zero or any number of inputs.

  • • Output: Output is the outcome of an algorithm. Every algorithm produces at least one output.

  • • Definiteness: All the instructions in the algorithm must be clear and should not be ambiguous.

  • • Finiteness: Whatever may be the inputs for all possible values, every algorithm must terminate after executing a finite number of steps.

  • • Effectiveness: All the instructions in the algorithm should be very basic so that every instruction of the algorithm can be converted to programming instruction easily. Effectiveness indicates that every instruction is a step towards the solution.

  • • Feasible: Every instruction must be a feasible instruction.

2.2 Importance of an Algorithm

When we try to write a program, first we need to identify all the tasks. Some tasks are easily identifiable while some tasks maybe hidden within the problem definition. For that a detailed analysis of the problem is required. After proper analysis we are able to find what the expected output is. What are the inputs required using which we can get the output? Using the inputs how we reach the solution? To accomplish this ‘how’, after identifying all the tasks we need to arrange them in a proper sequence.

About the book

Access options

Review the options below to login to check your access.

Purchase options

eTextbook
US$99.99
Paperback
US$99.99

Have an access code?

To redeem an access code, please log in with your personal login.

If you believe you should have access to this content, please contact your institutional librarian or consult our FAQ page for further information about accessing our content.

Also available to purchase from these educational ebook suppliers