introduction to computing lecture 00: part 3 introduction to algorithms and flowcharts (continued)...
TRANSCRIPT
Introduction to Computing Introduction to Computing Lecture 0Lecture 000:: Part 3 Part 3
Introduction to Algorithms and Introduction to Algorithms and Flowcharts (continued)Flowcharts (continued)
Assist.Prof.Dr. Nükhet ÖZBEKEge University
Department of Electrical&Electronics Engineering
Expressing AlgorithmsExpressing Algorithms
• Natural LanguagesNatural Languages
• PseudocodePseudocode
• FlowchartsFlowcharts
• Programming LanguagesProgramming Languages
Natural Language AlgorithmNatural Language AlgorithmCilbirCilbir• 6 eggs6 eggs• ½ kg yogurt½ kg yogurt• 3 large garlic cloves3 large garlic cloves• 4 Tbs fresh butter4 Tbs fresh butter• 1 tsp red pepper, coarsely ground1 tsp red pepper, coarsely ground• 2 middle-sized onions cut horizontally2 middle-sized onions cut horizontally• plenty waterplenty water
• Boil water in a fairly big pot. Break one by one the eggs and pour them in Boil water in a fairly big pot. Break one by one the eggs and pour them in a plate, being careful not to break the yolk. To ensure a homogenous a plate, being careful not to break the yolk. To ensure a homogenous cooking, let them “glide” from the plate into the boiling water. Within cooking, let them “glide” from the plate into the boiling water. Within three minutes the eggs are ready but if you prefer hard-boiled, allow three minutes the eggs are ready but if you prefer hard-boiled, allow them to cook for another minute or so.them to cook for another minute or so.
• Meanwhile brown the butter in a skillet and add the garlic and onion. In Meanwhile brown the butter in a skillet and add the garlic and onion. In the last possible moment add the coarsely ground red pepper and turn the last possible moment add the coarsely ground red pepper and turn off the fire. Remove the eggs from the pot using a skimmer and place off the fire. Remove the eggs from the pot using a skimmer and place them in a deep plate.them in a deep plate.
• Cover the eggs with plenty of yogurt and pour the hot butter over them. Cover the eggs with plenty of yogurt and pour the hot butter over them. Serve immediately.Serve immediately.
From www.gourmet.gr
Pseudocode Algorithm Pseudocode Algorithm ExampleExample
Set moveCount to 1Set moveCount to 1FOR each row on the boardFOR each row on the board FOR each column on the boardFOR each column on the board IF gameBoard position (row, column) is occupied IF gameBoard position (row, column) is occupied
THENTHEN CALL findAdjacentTiles with row, columnCALL findAdjacentTiles with row, column INCREMENT moveCountINCREMENT moveCount END IFEND IF END FOREND FOREND FOREND FOR
Algorithm ExampleAlgorithm Example
Set number counter to zeroSet number counter to zeroSet sum to zeroSet sum to zeroWhile (number counter < 10)While (number counter < 10){{
input a numberinput a numberSum = Sum + NumberSum = Sum + Numberincrement number counter by 1increment number counter by 1
}}Calculate average = sum / 10Calculate average = sum / 10
Labwork Labwork 11
• Write an algorithm to calculate the Write an algorithm to calculate the area of circlearea of circle
Labwork 1Labwork 1
Input radiusInput radius
Set pi = 3.14Set pi = 3.14
Calculate area = pi * radius * radiusCalculate area = pi * radius * radius
Labwork Labwork 22
• Write an algorithm to calculate the Write an algorithm to calculate the sum of multiples of 3 upsum of multiples of 3 up to 100to 100
Labwork Labwork 22
Set number counter to zeroSet number counter to zero
Set sum to zeroSet sum to zero
While (number counter < 10While (number counter < 1000))
{{Sum = Sum + NumberSum = Sum + Number counter counter
increment number counter by increment number counter by 33
}}
FlowchartsFlowcharts
• Flowcharts are schematic representations of Flowcharts are schematic representations of processesprocesses
• Generally the start point, end points, inputs, Generally the start point, end points, inputs, outputs, possible paths and the decisions that outputs, possible paths and the decisions that lead to these possible paths are includedlead to these possible paths are included
• Flow-charts can be created by hand or Flow-charts can be created by hand or manually in most office software, but lately manually in most office software, but lately specialized diagram drawing software has specialized diagram drawing software has emerged that can also be used for the emerged that can also be used for the purpose purpose
Flowchart Symbols (Mostly Flowchart Symbols (Mostly Used)Used)• Start / End symbolStart / End symbol
• ArrowsArrows
• Processing stepsProcessing steps
• Input/OutputInput/Output
• Conditional (Decision)Conditional (Decision)
Flowchart Symbols (Others)Flowchart Symbols (Others)
• DocumentDocument
• Magnetic TapeMagnetic Tape
• DisplayDisplay
• Manual InputManual Input
Flowchart ExampleFlowchart Example
From wikipedia.org
Flowchart ExampleFlowchart Example
From smartdraw.com
Flowchart ExampleFlowchart Example
Read NAME, BALANCE, RATECompute INTEREST as BALANCE x RATEWrite (Display) NAME and INTEREST
Flowchart ExampleFlowchart Example
From wikipedia.org
Flowchart ExampleFlowchart ExampleSTART
Input N
Sum =0C = 0
Input number
Sum = Sum + numberC = C + 1
C = N?
A = Sum / N
END
No
Yes
Print A
Labwork Labwork 33
• Draw a flowchart to find the sum of Draw a flowchart to find the sum of first 50 first 50 countingcounting numbers numbers
Labwork Labwork 33
Labwork Labwork 44
• Draw a flowchart to find the largest Draw a flowchart to find the largest of three numbers A,B, and C.of three numbers A,B, and C.
Labwork 5Labwork 5
• Draw a flowchart to find the product Draw a flowchart to find the product of two numbers using only addition of two numbers using only addition operation operation
Labwork Labwork 55
Labwork 6Labwork 6
• Draw a flowchart to find the division Draw a flowchart to find the division of two integer numbers using only of two integer numbers using only subtraction operation. Find the subtraction operation. Find the division and remainder.division and remainder.
Labwork Labwork 66
SummarySummary
• Problem Solving ProcessProblem Solving Process
• AlgorithmsAlgorithms
• Components of AlgorithmsComponents of Algorithms
• FlowchartsFlowcharts