LSP 121 - PowerPoint PPT Presentation


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


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation

LSP 121


LSP 121 Computers and Algorithmic Processes – PowerPoint PPT presentation

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


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

Title: LSP 121

LSP 121
  • Computers and
  • Algorithmic Processes

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

  • 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?

  • 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.

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!)

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

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

One Possible Scenario
  • There are a number of functions running in a
  • 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)

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,
steps form what we call an algorithmic process.
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

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

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

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

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

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,

  • Add two values
  • 32542
  • 42892

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

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)

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
  • Else
  • Print the message You are NOT getting good gas
    mileage. Buy a Chevy Volt
  • Step 6 Stop

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

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!

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

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

  • 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
  • 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

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

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

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

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

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

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)

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

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

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

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

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.

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
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

Data Encryption/Security
  • Go ahead and do Activity 15

Data Errors
  • Go ahead and do Activity 16