programming at a high level. developing a computer program programmer writes program in source code...
Post on 13-Dec-2015
220 Views
Preview:
TRANSCRIPT
Programming at a high level
Developing a Computer Program
Programmer Writes program in source code (VB or other language)
Compiler Converts source code to machine language code
Linker Combines machine language with libraries & converts them to an
executable module Interpreter
Converts source code to machine language and executes one line at a time
Compiler Link/loadExecutable
module
Source
codeMachinelanguage Output
Input dataHigh-levellanguage
Low-levelLanguage
Programming Process
Grace M. HopperFirst “Bug”
Algorithm Design(underlying logic of program)
Program Composition
Debug & test(error free & reliable)
Program Documentation
Program Maintenance
Programming Tools
Tools to convert algorithms into computer programs Algorithm: Step-by-Step procedure for solving a
problem Example Problem: You write a letter. To mail it,
you must decide how much postage to put on the envelop.
Rule of Thumb: One stamp for every 5 sheets of paper.
Algorithm: see next slide
Algorithm1. Request the number of sheets of paper; call this “Sheets”
2. Divide Sheets by 5
3. Round the quotient up to the next highest whole number; call it “Stamps”
4. Reply with the number Stamps
5. Example:
INPUT(16)
ProcessingOutput
(4)
Flowchart Symbols
Flow Line
Start/Stop
Input/Output
Processing
Decision
Stamp Problem
Program: Determine the proper number of stamps for a letter
Read sheets
Set the number of stamps to sheets/5
Round the number of stamps up to the next whole number
Display the number of stamps
Start
Readsheets
Set stamps = sheets/5
Round stamps upTo next whole #
Displaystamps
End
Input
Processing
Processing
Output
Flowchart Pseudocode
Decisions
If condition is true,
thenProcess step(s) 1
ElseProcess step(s) 2
End if
Is condition
True?
ProcessStep(s) 1
ProcessStep(s) 2
No Yes
Flowchart Pseudocode
Pseudocode Structure
Start and stop begin and end
Output Return
Decisions If-then-else
Loops For While-do Repeat-until
Real world problems
A traffic light A vending machine An elevator An ATM
Mathematical problems
Calculate the summation of a list of numbers Calculate the average of a list of numbers Find the maximum number from a list Find the minimum number from a list
Average Grade Problem
Start
Sum=0Count = 0
InputGrade
More grades?
Sum = Sum + GradeCount = Count + 1
Average = Sum/Count
Stop
No
Yes
Flowchart Pseudocode
BEGIN Average Grade
sum=0 count = 0
DO WHILE grade > 0 sum = sum + grade count = count +1 END DO
average = sum/count
END Average Grade
Introduction to Search Algorithms
Search: locate an item in a list (array, vector, etc.) of information
Two algorithms: Linear search Binary search Interpolation search
Linear Search Tradeoffs
Benefits Easy algorithm to understand Array can be in any order
Disadvantage Inefficient (slow): for array of N elements,
examines N/2 elements on average for value in array, N elements for value not in array
Binary Search Algorithm1. Divide an ordered array into three sections.
middle element elements on one side of the middle element elements on the other side of the middle element
2. If the middle element is the correct value, done. Otherwise, go to step 1, using only the half of the array that may contain the correct value.
3. Continue steps 1 and 2 until either the value is found or there are no more elements to examine.
Binary Search Tradeoffs
Benefit Much more efficient than linear search(For array of N elements, performs at mostlog2N comparisons)
Disadvantage Requires that array elements be ordered
Interpolation Search Tradeoffs Benefits
Much more efficient than binary search(For array of N elements, performs log2log2N
comparisons on an average)
Disadvantage Requires that array elements be ordered Elements need to be uniformly distributed for best
performance
top related