Algorithm For Beginners

Algorithm For Beginners

How expressive and logical is your code...

Introduction

Algorithm , to the beginner , is large ,very difficult part of computer science and software engineering , talking from experience. The goal of this article is to break down the demons of this esoteric science. So let's dive in.

what is Algorithm

Informally, an algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output. An algorithm is thus a sequence of computational steps that transform the input into the output. We can also view an algorithm as a tool for solving a well-specified computational problem. The statement of the problem specifies in general terms the desiredinput/output relationship. The algorithm describes a specific computational proce dure for achieving that input/output relationship. For example, we might need to sort a sequence of numbers into nondecreasing order. This problem arises frequently in practice and provides fertile ground for introducing many standard design techniques and analysis tools. Here is how we formally define the sorting problem:

Input:

A sequence of n numbers {a1, a2,...,an}.

Output:

A permutation (reordering) {a'1,a'2,.....a'n } of the input sequence such that a'1< a'2 < a'3

For example, given the input sequence {31; 41; 59; 26; 41; 58}, a sorting algorithm returns as output the sequence {26; 31; 41; 41; 58; 59}. Such an input sequence is called an instance of the sorting problem. In general, an instance of a problem consists of the input (satisfying whatever constraints are imposed in the problem statement) needed to compute a solution to the problem.

Because many programs use it as an intermediate step, sorting is a fundamental operation in computer science. As a result, we have a large number of good sorting algorithms at our disposal.

Which algorithm is best for a given application depends on among other factors the number of items to be sorted, the extent to which the items are already somewhat sorted, possible restrictions on the item values, the architecture of the computer, and the kind of storage devices to be used: main memory, disks, or even tapes.

An algorithm is said to be correct if, for every input instance, it ends with the correct output. We say that a correct algorithm solves the given computational problem. An incorrect algorithm might not end at all on some input instances, or it might end with an incorrect answer. Contrary to what you might expect, incorrect algorithms can sometimes be useful, if we can control their error rate.

An algorithm can be specified in English or any language of choice, as a computer program, or even as a hardware design. The only requirement is that the specification must provide a precise description of the computational procedure to be followed.