Download presentation
Presentation is loading. Please wait.
Published byCharleen Flynn Modified over 6 years ago
1
Topic:- ALGORITHM Incharge Faculty – Lokesh Sir.
Name of students – Jerin Varghese(T0114ME201), Vivek Vasava(T0114ME158).
2
ALGORITHM Review
3
ALGORITHM Definition: -
An algorithm can be defined as a finite sequence of well defined steps or operations for solving a problem in systematic manner. These are rules for solving any problems in proper manner. Instruction are written in the natural language. It is also called step by step solution.
4
ALGORITHM There are various types of algorithm techniques,
according to types of problems: - Divide and Conquer. Greedy method. Branch and Bound. Recursion. Effectiveness. An algorithm can be defined as a finite sequence of well defined steps or operations for solving a problem in systematic manner. These are rules for solving any problems in proper manner. Instruction are written in the natural language. It is also called step by step solution.
5
ALGORITHM Divide and conquer: - Greedy method: -
The divide and conquer technique is used to solve complex problems easily. Complex problems are decomposed into several step, which make problem easy to solve. Greedy method: - This method is used to solve optimization problem. With several possible solution one best solution is selected With help of this method.
6
ALGORITHM Branch and bound: - Recursion: -
when there are several statements or certain part of logic repeated this type of concept is used. A branch and bound algorithm computes a number(bound) at a node to determine whether the node is promised. Recursion: - When procedure calls itself is called recursion.
7
ALGORITHM Effectiveness: -
All operations can be carried out in predefined time and sequence.
8
ALGORITHM Example 1: - Write an algorithm to find out sum of two numbers. Step 1 : input two numbers : a, b Step 2 : calculate sum = a + b Step 3 : Print “total = “ , sum Step 4 : stop
9
ALGORITHM Example 2: - Write an algorithm to find average of three numbers. Step 1 : input three numbers : a, b, c Step 2 : calculate sum = a + b + c Step 3 : avg = sum / 3 Step 4 : print “average = “ , avg Step 5 : stop
10
ALGORITHM Example 3: - Write an algorithm to find whether given number is positive or negative. Step 1 : input number : num Step 2 : check if num < 0 then go to step 5 Step 3 : print “Positive “ Step 4 : stop Step 5 : print “Negative “ Step 6 : stop
11
ALGORITHM Example 4: - Write an algorithm to find out minimum number from three numbers. Step 1 : input three numbers : a, b, c Step 2 : if a < b then go to next step else go to step 8 Step 3 : if a < c then go to next step else go to step 6 Step 4 : print “Minimum = “ , a Step 5 : stop Step 6 : print “Minimum = “ , c Step 7 : stop Step 8 : if b < c then go to next step else go to step 11 Step 9 : print “Minimum = “ , b Step 10 : stop Step 11 : print “Minimum = “, c Step 12 : stop
12
ALGORITHM Example 5: - Write an algorithm to find factorial of given number. Step 1 : input number : num Step 2 : i = 1 Step 3 : f = 1 Step 4 : repeat from step 4 to step 6 until I <= num Step 5 : f = f * i Step 6 : i = i + 1 Step 7 : print “Factorial = “ , f Step 8 : stop
13
ALGORITHM Example 6: - Write an algorithm to reverse given number.
Step 1 : input number : num Step 2 : sum = 0 Step 3 : repeat from step 3 to step 6 until num > 0 Step 4 : calculate r = num % 10 Step 5 : calculate sum = sum * 10 + r Step 6 : calculate num = num / 10 Step 7 : print “Reverse number = “ , sum Step 8 : stop
14
ALGORITHM Example 7: - Write an algorithm to solve following series 1! + 2! + 3! + …… + n!. Step 1 : input number : num Step 2 : f = 1 Step 3 : sum = 0 Step 4 : i = 1 Step 5 : repeat from step 5 to step 8 until i <= num Step 6 : f = f * i Step 7 : sum = sum + f Step 8 : i = i + 1 Step 9 : print “Sum = “ , sum Step 10 : stop
15
ALGORITHM Example 8: - Write an algorithm to find if the given number is Armstrong or not. Step 1 : input number : num Step 2 : sum = 0, temp = num Step 3 : repeat from step 3 to step 6 until num > 0 Step 4 : calculate r = num / 10 Step 5 : calculate sum = sum + r * r * r Step 6 : calculate num = num % 10 Step 7 : if temp = sum then next step else go to step 9 Step 8 : print temp, “Is not Armstrong number” Step 9 : stop Step 10 : print temp, “Is not Armstrong number” Step 11 : stop
16
ALGORITHM Example 9: - Write an algorithm to store sum of 10 different numbers. Step 1 : sum = 0 Step 2 : i = 1 Step 3 : repeat from step 3 to step 6 until i <= 10 Step 4 : read num Step 5 : sum = sum + num Step 6 : i = i + 1 Step 7 : print “Total = “ , sum Step 8 : stop
17
ALGORITHM Example 10: - Write an algorithm to find whether given number is prime or not. Step 1 : read num Step 2 : i = 2 Step 3 : repeat from step 3 to step 6 until i < num Step 4 : if num % i = 0 then go to next step else go to step 7 Step 5 : print num “Is not prime “ Step 6 : stop Step 7 : i = i + 1 Step 8 : print num, “Is prime “ Step 9 : stop
18
THANK YOU
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.