BLOCK 1

Page 1

Elementary Algorithmics

UNIT 1 ELEMEMTARY ALGORITHMICS Structure 1.0 1.1 1.2 1.3 1.4 1.5 1.6

Introduction Objectives Example of an Algorithm Problems and Instances Characteristics of an Algorithm Problems, Available Tools & Algorithms Building Blocks of Algorithms 1.6.1 1.6.2 1.6.3

1.7

7 9 9 10 12 14 17

Basic Actions & Instructions Control Mechanisms and Control Structures Procedure and Recursion

Outline of Algorithmics 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.7.10

1.8 1.9 1.10

Page Nos.

27

Understanding the Problem Analyzing the Problem Capabilities of the Computer System Approximate vs Exact Solution Choice of Appropriate Data Structures Choice of Appropriate Design Technology Specification Methods for Algorithms Proving Correctness of an Algorithm Analyzing an Algorithm Coding the Algorithm

Summary Solutions/Answers Further Readings

32 33 40

1.0 INTRODUCTION We are constantly involved in solving problem. The problems may concern our survival in a competitive and hostile environment, may concern our curiosity to know more and more of various facets of nature or may be about any other issues of interest to us. Problem may be a state of mind of a living being, of not being satisfied with some situation. However, for our purpose, we may take the unsatisfactory/ unacceptable/ undesirable situation itself, as a problem. One way of looking at a possible solution of a problem, is as a sequence of activities (if such a sequence exists at all), that if carried out using allowed/available tools, leads us from the unsatisfactory (initial) position to an acceptable, satisfactory or desired position. For example, the solution of the problem of baking delicious pudding may be thought of as a sequence of activities, that when carried out, gives us the pudding (the desired state) from the raw materials that may include sugar, flour and water (constituting the initial position)using cooking gas, oven and some utensils etc. (the tools). The sequence of activities when carried out gives rise to a process. Technically, the statement or description in some notation, of the process is called an algorithm, the raw materials are called the inputs and the resulting entity (in the above case, the pudding) is called the output. In view of the importance of the concept of algorithm, we repeat:

Two ideas lie gleaming on the jeweller’s velvet. The first is the calculus; the second, the algorithm. The calculus and the rich body of mathematical analysis to which it gave rise made modern science possible; but it has been the algorithm that has made possible the modern world. David Berlinski in The Advent of the Algorithm, 2000.

An algorithm is a description or statement of a sequence of activities that constitute a process of getting the desired outputs from the given inputs. Later we consider in detail the characteristics features of an algorithm. Next, we define a closely related concept of computer program. 7


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.