Docsity

Data Structure And Algorithm, Lecture notes of Data Structures and Algorithms

Toggle sidebar
bg1
DATA STRUCTURES AND ALGORITHMS
What is an Algorithm?
In computer programming terms, an algorithm is a set of well-defined
instructions to solve a particular problem. It takes a set of input(s) and
produces the desired output. For example,
An algorithm to add two numbers:
1. Take two number inputs
2. Add numbers using the + operator
3. Display the result
Qualities of a Good Algorithm
Input and output should be defined precisely.
Each step in the algorithm should be clear and unambiguous.
Algorithms should be most effective among many different ways to
solve a problem.
An algorithm shouldn't include computer code. Instead, the algorithm
should be written in such a way that it can be used in different
programming languages.
Algorithm 1: Add two numbers entered by the
user
Step 1. Start
Step 2. Declare variables num1, num2 and sum.
Step 3. Read values num1 and num2.
Step 4. Add num1 and num2 and assign the result to sum.
Sum <- num1 + num2
pf3

Partial preview of the text

Download Data Structure And Algorithm and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

DATA STRUCTURES AND ALGORITHMS

What is an Algorithm?

In computer programming terms, an algorithm is a set of well-defined instructions to solve a particular problem. It takes a set of input(s) and produces the desired output. For example, An algorithm to add two numbers:

  1. Take two number inputs
  2. Add numbers using the + operator
  3. Display the result

Qualities of a Good Algorithm

 Input and output should be defined precisely.  Each step in the algorithm should be clear and unambiguous.  Algorithms should be most effective among many different ways to solve a problem.  An algorithm shouldn't include computer code. Instead, the algorithm should be written in such a way that it can be used in different programming languages.

Algorithm 1: Add two numbers entered by the

user

Step 1. Start Step 2. Declare variables num1, num2 and sum. Step 3. Read values num1 and num2. Step 4. Add num1 and num2 and assign the result to sum. Sum <- num1 + num

Step 5. Display sum. Step 6. Stop.

TYPES OF ALGORITHMS

Brute Force Algorithm:

This is the most basic and simplest type of algorithm. A Brute Force Algorithm is the straightforward approach to a problem i.e., the first approach that comes to our mind on seeing the problem. More technically it is just like iterating every possibility available to solve that problem.

Recursive Algorithm:

This type of algorithm is based on recursion. In recursion, a problem is solved by breaking it into subproblems of the same type and calling own self again and again until the problem is solved with the help of a base condition.

Divide and Conquer Algorithm:

In Divide and Conquer algorithms, the idea is to solve the problem in two sections, the first section divides the problem into subproblems of the same type. The second section is to solve the smaller problem independently and then add the combined result to produce the final answer to the problem.

Dynamic Programming Algorithm:

This type of algorithm is also known as the memorization technique because in this the idea is to store the previously calculated result to avoid calculating it again and again. In Dynamic Programming, divide the complex problem into smaller overlapping subproblems and storing the result for future use.

Greedy Algorithm:

In the Greedy Algorithm, the solution is built part by part. The decision to choose the next part is done on the basis that it gives the immediate benefit. It never considers the choices that had taken previously.