Class 1
Class 1
Algorithms &
Programming I
COMP 1400-1
Fall 2019
2
ntroduction to Algorithms & Programming I
4
ntroduction to Algorithms & Programming I
M Read Write
Process Documentation Input/Output
• FLOWCHA
Better Communication
RT
Useful for Analysis Process
Process
Helpful in Debugging
Decision
5
ntroduction to Algorithms & Programming I
M
Print (msg) Display the content (value) of the variable msg
• FLOWCHA
RT
End End of the process
1: Start
2: Read (msg)
3: Print (msg)
4: End 6
ntroduction to Algorithms & Programming I
End
7
ntroduction to Algorithms & Programming I
End
8
ntroduction to Algorithms & Programming I
End
9
ntroduction to Algorithms & Programming I
• ALGORITH
No Yes
M
• FLOWCHA
RT Process B Process A
10
ntroduction to Algorithms & Programming I
• ALGORITH
No Yes
M
• FLOWCHA
RT
Process A
11
ntroduction to Algorithms & Programming I
• ALGORITH
Yes
M
• FLOWCHA
No
RT
Process A
12
• ESSENCE OF Example Begin
PROBLEM-
SOLVING
Read
Algorithm 5 (a,b,c)
• ALGORITH 1: Start
2: Read (a, b,c) small a
M
3: small a
• FLOWCHA Yes
4: If small>b Then small > b
RT 5: small b small b
No
6: End If
7: If small >c Then small > c
Yes
8: small c
No small c
9: End If
10: Print “The smallest number is”, small
Print (“The
11: Stop smallest number
is”, b)
End
13
ntroduction to Algorithms & ProgrammingALGORITHM
I AND FLOWCHA
Begin
Algorithm 6
• ESSENCE OF 1: Start Read (n)
PROBLEM-
Main components of a For loop
SOLVING 2: Read (n)
i 1
3: For i 1 to n Do
• ALGORITH
4: If (i%2==0) Then
M No Yes
i
5: Print (i) i i+ 1
• FLOWCHA <=n
6: End If
RT
i Yes
7: End For
%2==0
8: Stop No
Print (i)
End
14
ntroduction to Algorithms & ProgrammingALGORITHM
I AND FLOWCHA
Begin
Algorithm 6_2
• ESSENCE OF 1: Start Read (n)
PROBLEM-
SOLVING 2: Read (n)
i 2
3: i=2
• ALGORITH
4: While (n >=i) Do Yes
M No n
5: Print (i ) >=i
• FLOWCHA
6: i i+2 Print (i)
RT
7: End While
8: Stop i i+ 2
End
15
ntroduction to Algorithms & Programming I
• ESSENCE OF
PROBLEM-
SOLVING
• ALGORITH
How To Write Algorithms
M
ntroduction to Algorithms & Programming I