Introducing Algorithms and Data Structures
Computer science is a field of study that solves a variety of problems by using computers. The problem to be solved could be as simple as performing the addition of two numbers, or it can be as complex as designing a robot capable of making decisions in a real-time environment.
ROLE OF ALGORITHMS
1.Set the value of counter to 1.
2.display counter.3.Increment counter by 1
4.If counter <=10, go to step2.
An Algorithm has the following five important properties:
* Finiteness: It terminates after a finite number of steps.
* Definiteness: Each step in an algorithm is unambiguous. This means that the action specified by the step cannot be interpreted in multiple ways and can be performed without any confusion.
* Input:It accepts zero or more inputs.
* output: It produces at least one output
Effectiveness:It Consists of basic instructions that are attainable. This means that the the instructions can be performed by using the given inputs in a definite amount of time.
ROLE OF DATA STRUCTURES
Multiple algorithms can be designed to solve a particular problem. However, that algorithms may differ in the extent of efficiency to which they can solve the problem. In such a situation, an algorithm that provides maximum efficiency should be used for solving the problem. Here, efficiency means that the algorithm should work in minimal time and use minimal memory.
One of the basic techniques for improving the efficiency of algorithms is to structure the data that they operate on in such a way that the resulting operations can be efficiency performed.
The way in which the various data elements are organized in memory, with respect to each other, is called a data structure.
To understand the use of an appropriate data structure, which helps in simplifying the solution to a problem, let us consider an example where you have to find the maximum value in a set of 50 numbers. In such a case, you can either use 50 variables or use a data structure, such as an array of size 50, to store the number. When 50 different variables are used to store the numbers, the following algorithm can be used to determine the maximum value among the numbers:
1. Accept 50 numbers and store them in num1, num2, num3, ........, num50.
2. Set Max-num1.
3. if num2>max then:
max=num2
4.If num3 > max then:
max=num3
5.If num4 > max then:
max=num4
.
.
6. If num50>max then:
max = num50
7. Display max.
On the other hand, when an array size 50 is used, the following algorithm can be used to determine the maximum value among the element in an array:
1.set max=num[0].
2.Repeat step 3 varying i from 1 to 49.
3. If num[i] > max then:
max = num[i]
4. Display max.
Computer science is a field of study that solves a variety of problems by using computers. The problem to be solved could be as simple as performing the addition of two numbers, or it can be as complex as designing a robot capable of making decisions in a real-time environment.
ROLE OF ALGORITHMS
1.Set the value of counter to 1.
2.display counter.3.Increment counter by 1
4.If counter <=10, go to step2.
An Algorithm has the following five important properties:
* Finiteness: It terminates after a finite number of steps.
* Definiteness: Each step in an algorithm is unambiguous. This means that the action specified by the step cannot be interpreted in multiple ways and can be performed without any confusion.
* Input:It accepts zero or more inputs.
* output: It produces at least one output
Effectiveness:It Consists of basic instructions that are attainable. This means that the the instructions can be performed by using the given inputs in a definite amount of time.
ROLE OF DATA STRUCTURES
Multiple algorithms can be designed to solve a particular problem. However, that algorithms may differ in the extent of efficiency to which they can solve the problem. In such a situation, an algorithm that provides maximum efficiency should be used for solving the problem. Here, efficiency means that the algorithm should work in minimal time and use minimal memory.
One of the basic techniques for improving the efficiency of algorithms is to structure the data that they operate on in such a way that the resulting operations can be efficiency performed.
The way in which the various data elements are organized in memory, with respect to each other, is called a data structure.
To understand the use of an appropriate data structure, which helps in simplifying the solution to a problem, let us consider an example where you have to find the maximum value in a set of 50 numbers. In such a case, you can either use 50 variables or use a data structure, such as an array of size 50, to store the number. When 50 different variables are used to store the numbers, the following algorithm can be used to determine the maximum value among the numbers:
1. Accept 50 numbers and store them in num1, num2, num3, ........, num50.
2. Set Max-num1.
3. if num2>max then:
max=num2
4.If num3 > max then:
max=num3
5.If num4 > max then:
max=num4
.
.
6. If num50>max then:
max = num50
7. Display max.
On the other hand, when an array size 50 is used, the following algorithm can be used to determine the maximum value among the element in an array:
1.set max=num[0].
2.Repeat step 3 varying i from 1 to 49.
3. If num[i] > max then:
max = num[i]
4. Display max.
No comments:
Post a Comment