Top Banner
Introduction to Computing Introduction to Computing Lecture 0 Lecture 0 0 0 : : Part 3 Part 3 Introduction to Algorithms Introduction to Algorithms and Flowcharts (continued) and Flowcharts (continued) Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical&Electronics Engineering
25

Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

Dec 22, 2015

Download

Documents

Rose Dawson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

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

[email protected]

Page 2: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

Expressing AlgorithmsExpressing Algorithms

• Natural LanguagesNatural Languages

• PseudocodePseudocode

• FlowchartsFlowcharts

• Programming LanguagesProgramming Languages

Page 3: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

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

Page 4: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

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

Page 5: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

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

Page 6: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

Labwork Labwork 11

• Write an algorithm to calculate the Write an algorithm to calculate the area of circlearea of circle

Page 7: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

Labwork 1Labwork 1

Input radiusInput radius

Set pi = 3.14Set pi = 3.14

Calculate area = pi * radius * radiusCalculate area = pi * radius * radius

Page 8: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

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

Page 9: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

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

}}

Page 10: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

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

Page 11: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

Flowchart Symbols (Mostly Flowchart Symbols (Mostly Used)Used)• Start / End symbolStart / End symbol

• ArrowsArrows

• Processing stepsProcessing steps

• Input/OutputInput/Output

• Conditional (Decision)Conditional (Decision)

Page 12: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

Flowchart Symbols (Others)Flowchart Symbols (Others)

• DocumentDocument

• Magnetic TapeMagnetic Tape

• DisplayDisplay

• Manual InputManual Input

Page 13: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

Flowchart ExampleFlowchart Example

From wikipedia.org

Page 14: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

Flowchart ExampleFlowchart Example

From smartdraw.com

Page 15: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

Flowchart ExampleFlowchart Example

Read NAME, BALANCE, RATECompute INTEREST as BALANCE x RATEWrite (Display) NAME and INTEREST

Page 16: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

Flowchart ExampleFlowchart Example

From wikipedia.org

Page 17: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

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

Page 18: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

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

Page 19: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

Labwork Labwork 33

Page 20: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

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.

Page 21: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

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

Page 22: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

Labwork Labwork 55

Page 23: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

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.

Page 24: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

Labwork Labwork 66

Page 25: Introduction to Computing Lecture 00: Part 3 Introduction to Algorithms and Flowcharts (continued) Introduction to Computing Lecture 00: Part 3 Introduction.

SummarySummary

• Problem Solving ProcessProblem Solving Process

• AlgorithmsAlgorithms

• Components of AlgorithmsComponents of Algorithms

• FlowchartsFlowcharts