17
COMPUTERS AND ALGORITHMIC PROCESSES LSP 121

COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

Embed Size (px)

Citation preview

Page 1: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

COMPUTERS AND ALGORITHMIC PROCESSES

LSP 121

Page 2: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

What Is An Algorithmic Process?

An ordered series of steps that when applied to a problem produces a solution

Some call it “thinking logically”Others refer to it simply as problem solvingOften simply called an algorithm

Page 3: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

Why Should We Know What An Algorithmic Process Is?

Many things in life are algorithmic processes:Music, dance (such as ballet), art, biology (natural selection, nature), math, economics, daily living (buying a car or house, career changes, college choices)

Create useful short programs (called “macros”) in Access, Excel, and Word E.g. Find all the grades for a student, remove the lowest

homework grade, then calculate the average.

Write a simple program to analyze data and write the next article exposing cheaters in your school district (like Freakonomics)

Page 4: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

Computers and Algorithms

Computers are very good at executing algorithms

But computers require precise instructions to perform an operation

This is basically the definition of an algorithm. (A series of precise instructions to perform an operation.)

The instructions cannot be ambiguous (must be clear and concise)

Let’s try an example – Begin today’s activity

Page 5: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

What is an Algorithm?

Algorithms consist of four basic types of operations or instructions:

1. Sequential operations, e.g. Add 1 cup of butter; Subtract the amount of the check from the current account balance; Set the value of x to 1

2. Conditional operations, e.g. If the mixture is too dry, then add ½ cup water; If the current account balance < 0, then account overdrawnThe if-else statement from today’s activity is an example of a conditional.

Page 6: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

What is an Algorithm?

3. Iterative operations, e.g. Repeat the previous two steps until the mixture has thickened; Repeat the following five steps until there are no more checks to be processed; Repeat steps 1,2 and 3 until the value of y is equal to +1‘Looping’ as seen in today’s activity is an example of an iterative operation.

4. Calling a pre-existing algorithm (or function), e.g. Make a reduction with your sauce; date := getDate();

Page 7: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

Algorithm to calculate Miles Per Gallon

Step 1: Get the values for gallons used, starting mileage, ending mileage E.g. Ask the user to type in these values

Step 2: Set the value of distance driven to ending mileage – starting mileage

Step 3: Set the value of average miles per gallon to distance driven / gallons used

Step 4: Print the value of average miles per gallon

Step 5: Stop

Page 8: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

“Fancier” Average Miles Per Gallon

Step 1: Get values for gallons used, starting mileage, ending mileage

Step 2: Set the value of distance driven to ending mileage – starting mileage

Step 3: Set the value of average miles per gallon to distance driven / gallons used

Step 4: Print the value of average miles per gallon (continued on next slide)

Page 9: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

Modified Average Miles Per Gallon Continued

Step 5: If average miles per gallon is greater than 25.0 then Print the message “You are getting good gas

mileage!”Else Print the message “You are NOT getting good gas

mileage.”

Step 6: Stop

Page 10: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

If-Else: e.g. Algorithm: Inviting Friends to a Party

Step 1: For each of your friends do this loop: Step 2:

If this a close friend then Write an invitation Address an envelope Stick on a stamp

Else Put their name on the reserve list

Step 3: Check off their name Repeat Steps 2 and 3 until no more friends

Step 4: Count number of guests (for food)Step 5: Mail invitationsStep 6: Stop This slide is a demonstration of PESUDOCODE

It is similar to programming statements, but are more English-like than programming-like.

Page 11: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

Let’s Try Another Example

Let’s try one together. Write an algorithm (in “pseudocode”) to examine student scores on an exam. You want to count how many students passed (>=70) and how many students failed (<70). When you hit the end of the list, print the total number of students that passed and the total number of students that failed.

Try next activity: Alice

Page 12: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

Well-Known / Common Algorithms

Sorting dataSearching for dataRouting a packet across the InternetFinding an optimal solution to a problem

(such as finding the best route on a map using GPS device or mapping web site)

Page 13: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

HTML

Hyper-Text Markup LanguageAll web pages are made (to varying degrees)

from HTMLRelatively simple: no conditionals (if-else) or

iterative statements (loops)Each HTML command tells the web browser

what to do next, such as start a new paragraph, display an image, or insert a hyperlink (clickable item)

Page 14: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

<html> Begins every HTML document<head> Begins the head section<title>DePaul University</title> Title that appears on browser title bar</head> Ends the head section

<body> Begins the body sectionThis is the first line.<br> Text followed by line Break<p>Start a new paragraph.</p> Begins a new paragraph<h1>First Heading</h1> Level 1 heading (biggest)<h2>A second level heading</h2> Level 2 heading (little smaller)

<hr> Inserts a horizontal rule (straight line)<strong>This line is bold.</strong> Bold text<br><em>This line is italicized</em> Italicized text<br><img src=“\images\banner.gif”> Insert an image here

<a href=“http://www.cs.depaul.edu”> DePaul CS Page</a> Link to another web page

</body> Close the body section</html> Ends every HTML document

Page 15: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

Wanna learn how to create web pages?

CDM offers courses that teach you how: IT-230: You also learn a little bit of programming HCI-201: Uses FrontPage

Page 16: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

HTML

Let’s try creating a web page using HTML Activity – Creating an e-portfolio

Page 17: COMPUTERS AND ALGORITHMIC PROCESSES LSP 121. What Is An Algorithmic Process? An ordered series of steps that when applied to a problem produces a solution

Last Activities

Let’s finish our algorithm topic with the following activities Creating a Google Mash-up VBA coin toss problem If time permits – Google searching techniques