UNIT I - Algorithmic Problem Solving.pptx

Pradeepkumar964266 227 views 32 slides Jan 20, 2023
Slide 1
Slide 1 of 32
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32

About This Presentation

Python - ALgorithm Solving


Slide Content

UNIT I – Computational thinking and Problem Solving

Syllabus Introduction to fundamentals of computing, Algorithms , building blocks of algorithms (statements, state, control flow, functions), notation (pseudo code, flow chart, programming language), algorithmic problem solving, simple strategies for developing algorithms (iteration, recursion). Illustrative problems: find minimum in a list, insert a card in a list of sorted cards, guess an integer number in a range, Towers of Hanoi.

Representation of program

Algorithm Step by Step description Anybody can easily understand Theoretical explanation of program

Building Blocks of Algorithm Incoming Information Step Numbers Control Flow Statements Outgoing Information Step 1 : Start Step 2 : Declare the variables a, b, c Step 3 : Read the values of a and b Step 4 : Calculate c = a+b Step 5 : Display the Output c Step 6 : Stop

Building Blocks of Algorithm Incoming Information Step Numbers Control Flow Statements Outgoing Information Step 1 : Start Step 2 : Declare the variables a, b, c Step 3 : Read the values of a and b Step 4 : Calculate c = a+b Step 5 : Display the Output c Step 6 : Stop

Building Blocks of Algorithm Incoming Information Step Numbers Control Flow Statements Outgoing Information Step 1 : Start Step 2 : Declare the variables a, b, c Step 3 : Read the values of a and b Step 4 : Calculate c = a+b Step 5 : Display the Output c Step 6 : Stop

Building Blocks of Algorithm Incoming Information Step Numbers Control Flow Statements Outgoing Information Step 1 : Start Step 2 : Declare the variables a, b, c Step 3 : Read the values of a and b Step 4 : Calculate c = a+b Step 5 : Display the Output c Step 6 : Stop

Building Blocks of Algorithm Incoming Information Step Numbers Control Flow Statements Outgoing Information Step 1 : Start Step 2 : Declare the variables a, b, c Step 3 : Read the values of a and b Step 4 : Calculate c = a+b Step 5 : Display the Output c Step 6 : Stop

Building Blocks of Algorithm Incoming Information Step Numbers Control Flow Statements Outgoing Information Step 1 : Start Step 2 : Declare the variables a, b, c Step 3 : Read the values of a and b Step 4 : Calculate c = a+b Step 5 : Display the Output c Step 6 : Stop

Ex. Product of two numbers Step 1 : Start Step 2 : Declare the variables a, b, c Step 3 : Read the values of a and b Step 4 : Calculate c = a * b Step 5 : Display the Output c Step 6 : Stop SEQUENCE

Ex. 2 odd or even Step 1 : Start Step 2 : Declare the variables n Step 3 : Read the values of n Step 4 : Check if(n%2 ==0), else goto step 5 Step 4.1 : Display that the number is Even number Step 4.2 : Goto step 6 Step 5 : Display that the number is Odd number Step 6 : Stop SELECTION

Ex.3 Display the natural numbers upto ‘n’ Step 1 : Start Step 2 : Declare the variables i , n Step 3 : Read the value of n Step 4 : Initialize i =1 Step 5 : Repeat the steps until i <=n, else goto step 6 Step 5.1 : Display ‘ i ’ value Step 5.2 : i =i+1 and goto step 5 Step 6 : Stop ITERATION

Ex.3 Display the odd numbers upto ‘n’ Step 1 : Start Step 2 : Declare the variables i , n Step 3 : Read the value of n Step 4 : Initialize i =1 Step 5 : Repeat the step until i <=n, else goto step 6 Step 5.1 : check if (i%2==1), else i =i+1 and goto step 5 Step 5.1.1 : Display ‘ i ’ value, i =i+1 and goto step 5 Step 6 : Stop

Flow chart Graphical or symbolic representation Effective understanding documentation Terminator Input / Output Process Decision Flow lines Connectors

Ex.1 Product of two numbers Start Read a,b c = a * b Display c Stop

Odd or Even Start Read n Display Odd Number Stop Display Even Number If (n%2==0) Yes No

Displaying Natural Numbers upto ‘n’ Start Read n Stop Display i If ( i <=n) Yes No i =1 i =i+1

Displaying odd Numbers upto ‘n’ Start Read n Stop Display i If ( i <=n) Yes No i =1 i =i+1 If (i%2==1) Yes No

Pseudocode Outline of Program High level description of program Uses the keywords Input : READ, OBTAIN, GET, PROMPT Output: PRINT, DISPLAY, SHOW Compute: COMPUTE, CALCULATE, DETERMINE Initiate: SET, INITIALIZE Add one: INCREMENT Keyword should be capitalized Short code of algorithm

Ex. Product of two numbers START DECLARE a,b,c READ a,b CALCULATE c=a*b DISPLAY c STOP

Ex. Odd or Even START DECLARE n READ n IF n%2 ==0 DISPLAY Even ELSE DISPLAY Odd STOP

Ex.3 Display the natural numbers upto ‘n’ START DECLARE i,n INITIALIZE i =1 DO DISPLAY ‘ i ’ i =i+1 UNTIL i <=n END

Ex.3 Display the odd numbers upto ‘n’ START DECLARE i,n READ n INITIALIZE i =1 IF(i%2==1) DISPLAY i i =i+1 ELSE i =i+1 UNTIL i <=n END

Sum of digits

Algorithm Step 1 : Start Step 2 : Declare the variables r , n, c=0 Step 3 : Read the value of n Step 4 : Repeat the steps until n>0, else goto step 5 Step 4.1 : r = n % 10 Step 4.2 : c = c + r Step 4 .3 : n = n / 10 and goto step 4 Step 5 : Display the value of c Step 6 : Stop

Flowchart Start Read n Stop If (n>0) Yes No Declare r,n,c =0 c = c+r n = n/10 r = n%10 Display c

Pseudocode START DECLARE r , n, c=0 READ n DO r = n % 10 c = c + r n = n / 10 UNTIL n>0 DISPLAY c STOP

Fibonacci series

Algorithm Step 1 : Start Step 2 : Declare the variables i , a= -1, b=1, c, n Step 3 : Read the value of n Step 4 : Initialize i =1 Step 5 : Repeat the steps until i <=n, else goto step 6 Step 5.1 : c = a + b Step 5.2 : Display c Step 5.3 : a=b Step 5.4 : b=c Step 5.5 : i = i+1 Step 6 : Stop

Flowchart Start Read n Stop If ( i <=n) Yes No Declare r,n,c =0 Display c a=b c = a+b i = 1 b=c i = i+1

Pseudocode START DECLARE i , a= -1, b=1, c, n READ n Initialize i =1 Do c = a+b Display c a = b b = c i = i+1 UNTIL i <=n STOP
Tags