LSP 121 - PowerPoint PPT Presentation

Loading...

PPT – LSP 121 PowerPoint presentation | free to download - id: 7d16fd-ZDU5M



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

LSP 121

Description:

LSP 121 Computers and Algorithmic Processes – PowerPoint PPT presentation

Number of Views:16
Avg rating:3.0/5.0
Slides: 40
Provided by: cwh50
Category:
Tags: lsp | counter | decimal

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: LSP 121


1
LSP 121
  • Computers and
  • Algorithmic Processes

2
What Is A Processor?
  • All computers, cell phones, iPods, iPads,
    Kindles, automobiles, have a processor (or two
    or more) inside
  • A processor accepts some kind of input, performs
    a computation, and produces some kind of output
  • For example, one processor in an automobile
    inputs engine conditions and outputs fuel control

3
Multi-tasking
  • Many processors can work on only ONE task at a
    time! (Dual-core/quad-core processors are
    exceptions to this rule)
  • But they jump from one task to the next so
    quickly, it appears they are working on many
    tasks simultaneously
  • We say these processors can multi-task
  • Can you multi-task?

4
Multi-tasking
  • Not too well
  • Many people can do two tasks at once, as long as
    one of the tasks doesnt require much cognitive
    thought (such as casual listening to music)
  • But three or more tasks? Or tasks that require
    concentration? Sorry, you arent a computer.

5
Sometimes We ActLike Processors
  • Lets say you work alone in a candy store
  • You (the processor) wait on customers, ring up
    their orders, and answer the phone
  • On slow days, you sit staring out the window,
    waiting for input (someone to enter the shop or
    for the phone to ring)
  • (What happens on Valentines Day? You work
    REALLY fast or you hire another processor or the
    line goes out the door!)

6
A Sample Computer
  • Lets examine your cell phone
  • What are the inputs?
  • Buttons, touch screen, cell tower calling you,
    microphone, keypad
  • What are the outputs?
  • Speaker, screen, sending signal to cell tower

7
A Sample Computer
  • The cell phone processor waits until an input
    comes in
  • When an input comes in, the processor processes
    something, then maybe produces an output (or
    maybe it just waits for more input)
  • Some spin in a loop and some go to sleep

8
One Possible Scenario
  • There are a number of functions running in a
    cellphone
  • One function converts data into a signal
  • Another converts a signal into data
  • Another accepts keystrokes on the keypad
  • Another accepts touches on the touch screen
  • (Weve seen other functions PMT, NORMDIST, LOG)

9
REPEAT THE FOLLOWING STEPS Is there data from
the keypad? If yes, then process it. Is there
data from the touch screen? If yes, then process
it. Is there a signal coming in from a cell
tower? If yes, Is there data that has to go
out to a cell tower? If yes, Is there data
that has to go out to the speaker? If yes, Is
there data coming in from the microphone? If yes,
UNTIL SHUT-OFF SEQUENCE IS CALLED These
steps form what we call an algorithmic process.
10
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 solving
  • Often simply called an algorithm

11
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,
    life (buying a car or house, career changes, grad
    school choice), work
  • You can create useful macros in Access, Excel,
    and Word
  • You can create iPhone apps and maybe make lots of
    money

12
Why Should We Know What An Algorithmic Process Is?
  • You can write simple programs to analyze data and
    write the next article exposing cheaters in your
    school district (like Freakonomics)
  • At work you can create financial models
    (business), reprogram digital synthesizers/
    converters (music, cinema), design political
    districts (poly sci), weather prediction (earth
    sciences), create neural networks (psychology),
    model cultural evolution (sociology), diabetes
    management (medicine), create genetic algorithms
    (biology)

13
Computers and Algorithms
  • Computers are very good at executing algorithms
  • But computers require precise instructions to
    perform an operation
  • The instructions cannot be ambiguous (must be
    clear and concise)
  • Lets see what this means Lets do Activity 12

14
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 lt 0, then transfer funds
    immediately

15
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
  • 4. Calling a pre-existing algorithm (or
    function), e.g. Make a reduction with your sauce
    date getDate() normdist(x, mean, stdev,
    true)

16
Example
  • Add two values
  • 32542
  • 42892

How would you describe this operation to someone
in grade school?
17
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
  • Step 5 Stop

18
Modified 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)

19
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. Buy a Chevy Volt
  • Step 6 Stop

20
Inviting Friends to a Party
  • Step 1 For each of your friends do this loop
  • Step 2 If this a close friend then
  • Put them in the e-vite list
  • Else
  • Put their name on the B 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 invitations
  • Step 6 Stop

21
Next Quarters Class Schedule
  • I need a history class, an arts literature
    class, and a religious dimensions class
  • I need to take the next two classes in my major
  • I dont want a class before 1000am
  • I definitely dont want a Saturday class
  • If I can get all my classes on Mon/Wed
  • This is NOT a trivial algorithm, yet you do this
    each quarter!

22
Lets Try Another Example
  • Lets try one together. Write the pseudocode to
    examine student scores on an exam. You want to
    count how many students passed (gt70) and how
    many students failed (lt70). When you hit the end
    of the list, print the total number of students
    that passed and the total number of students that
    failed.

23
Classic Applications of Algorithms
  • Sorting large data sets
  • Searching for data (like Google)
  • Routing a packet across the Internet
  • Finding an optimal solution to a problem (such as
    finding the best route on a map using a GPS
    device or mapping web site)
  • Detecting and correcting transmission errors
  • Compressing data
  • Making data secure

24
Alice
  • For our next activity, lets use the programming
    system called Alice
  • Look for the application Alice on your machine.
    (You can download Alice at home for free from
    alice.org)
  • Run the Skater Tutorial first, to get an idea of
    how Alice works
  • Observe the if statements and loop statements as
    you insert them into your code
  • Do Activity 13 - Alice

25
Visual Basic
  • Here is an example of an If statement
  •  
  • if Row lt 100 then
  • Cells(Row, 2) 1
  • else
  • Cells(Row, 2) 0
  • end If

26
Visual Basic
  • Here is an example of a while loop
  •  
  • Counter 0
  • while Counter lt 20
  • Counter Counter 1
  • end while

27
Visual Basic
  • Here is an example of a For loop
  • for Row 1 To 50
  • Y rnd(a)
  • X X Y
  • next Row
  • You can now try Activity 14

28
CompressionLossless versus Lossy
  • Compression is a technique used to squeeze data
    into a smaller space
  • Two basic groups of compression
  • Lossless when data is uncompressed, original
    data returns
  • Lossy when data is uncompressed, you do not
    have the original data

29
Where is Compression Used?
  • DVDs and Blu-Ray movies
  • Broadcast television and cable television signals
  • Music players such as iPods and Nanos, as well as
    the music players within cell phones
  • Transferring large data files over the Internet

30
Lossless or Lossy?
  • Compress a financial file?
  • You want lossless (e.g. Lempel-Ziv)
  • Compress a video image, movie, or audio file?
  • Lossy is usually OK (e.g. MPEG, JPEG, MP3)
  • Some people like their music uncompressed (e.g.
    FLAC, ALAC, Monkeys Audio)

31
Lossless Compression
  • Run-length encoding
  • Replaces runs of 0s with a count of how many 0s.
  • 0000000000000010000000001100000000000000000000111
    000000000001
  • (30 0s)
  • 14 9 0 20 30 0
    11

32
Run-length Encoding (continued)
  • Now replace each decimal value with a 4-bit
    binary value (nibble)
  • Note If you need to code a value larger than 15,
    you need to use two consecutive 4-bit nibbles
  • The first is decimal 15, or binary 1111, and the
    second nibble is the remainder
  • For example, if the decimal value is 20, you
    would code 1111 0101 which is equivalent to 15 5

33
Run-length Encoding (continued)
  • If you want to code the value 15, you still need
    two nibbles 1111 0000
  • The rule is that if you ever have a nibble of
    1111, you must follow it with another nibble

34
Lossy Compression
  • Audio and video dont compress well using
    run-length compression
  • And it is possible to trick the eyes and ears
  • So use lossy compression on video and music

35
Video Compression
  • In one color video frame, not much is alike
  • But what about from frame to frame?
  • Send a frame, store it in a buffer
  • Next frame is just difference from previous frame
  • Then store that frame in buffer, etc.

36
Lossy Compression (continued)

5 7 6 2 8 6 6 3 5 6 6 5 7 5 5 6 3 2 4 7 8 4 6 8 5
6 4 8 8 5 5 1 2 9 8 6 5 5 6 6 First Frame
5 7 6 2 8 6 6 3 5 6 6 5 7 6 5 6 3 2 3 7 8 4 6 8 5
6 4 8 8 5 5 1 3 9 8 6 5 5 7 6 Second Frame
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 -1 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 Difference
37
Lossy Compression (continued)
  • What about a single image?
  • JPEG (Joint Photographic Experts Group)
  • Consists of 3 phases
  • Discrete cosine transformations (DCT)
  • Quantization
  • Run-length encoding

38
Data Encryption/Security
  • Go ahead and do Activity 15

39
Data Errors
  • Go ahead and do Activity 16
About PowerShow.com