Download presentation
Presentation is loading. Please wait.
Published byAllen Pierce Modified over 9 years ago
1
Programming at a high level
2
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 CompilerLink/load Executable module Source code Machine language Output Input data High-level language Low-level Language
3
Programming Process Grace M. Hopper First “Bug” Algorithm Design (underlying logic of program) Program Composition Debug & test (error free & reliable) Program Documentation Program Maintenance
4
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
5
Algorithm 1. 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) Processing Output (4)
6
Flowchart Symbols Flow Line Start/Stop Input/Output Processing Decision
7
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 Read sheets Set stamps = sheets/5 Round stamps up To next whole # Display stamps End Input Processing Output Flowchart Pseudocode
8
Decisions If condition is true, then Process step(s) 1 Else Process step(s) 2 End if Is condition True? Process Step(s) 1 Process Step(s) 2 No Yes Flowchart Pseudocode
9
Pseudocode Structure Start and stop begin and end Output Return Decisions If-then-else Loops For While-do Repeat-until
10
Real world problems A traffic light A vending machine An elevator An ATM
11
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
12
Average Grade Problem Start Sum=0 Count = 0 Input Grade More grades? Sum = Sum + Grade Count = 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
13
Introduction to Search Algorithms Search: locate an item in a list (array, vector, etc.) of information Two algorithms: Linear search Binary search Interpolation search
14
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
15
Binary Search Algorithm 1. 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.
16
Binary Search Tradeoffs Benefit Much more efficient than linear search (For array of N elements, performs at most log 2 N comparisons) Disadvantage Requires that array elements be ordered
17
Interpolation Search Tradeoffs Benefits Much more efficient than binary search (For array of N elements, performs log 2 log 2 N comparisons on an average) Disadvantage Requires that array elements be ordered Elements need to be uniformly distributed for best performance
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.