Pradeepkumar964266
227 views
32 slides
Jan 20, 2023
Slide 1 of 32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
About This Presentation
Python - ALgorithm Solving
Size: 146.03 KB
Language: en
Added: Jan 20, 2023
Slides: 32 pages
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