Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithms vs. Programming

Similar presentations


Presentation on theme: "Algorithms vs. Programming"— Presentation transcript:

1 Algorithms vs. Programming
CSE 1321 – Module 1 Algorithms vs. Programming 4/13/2019 CSE 1321 Module 1

2 Motivation To learn algorithmic thinking with emphasis on pseudocode development; To understand what an algorithm is and how to write an algorithm; To describe the concept of abstraction To describe the relationship between algorithms and programming 4/13/2019 CSE 1321 Module 1

3 Topics Algorithms Fine, then what is Programming? Definition
Properties of Good Algorithms Describing Algorithms Examples Components of Algorithms Fine, then what is Programming? 4/13/2019 CSE 1321 Module 1

4 What is an Algorithm? What it’s not: a logarithm** What it is:
A set of logical steps to accomplish a specific task A set of direction/instructions You use them everyday, even right now Algorithms contain: Data Instructions that work on that data ** How many words can you make from the word “algorithm”? 4/13/2019 CSE 1321 Module 1 4

5 Algorithms: the visual
Too much screen time Input Data Algorithm Output Data 4/13/2019 CSE 1321 Module 1 5

6 Chocolate Chip Cookies
Algorithms: a Recipe Chocolate Chip Cookies Ingredients: 2 1/4 cups flour tsp salt 1 tsp baking soda 2 eggs 3/4 cup brown sugar tsp vanilla ext. 3/4 cup granulatd sugar cup soft butter 12oz. semi-sweet chocolate chips Instructions Preheat oven to 375°. Combine flour, salt, baking soda, in bowl, set mixture aside. Combine sugars, butter, vanilla, beat until creamy. Add eggs and beat. Add dry mixture and mix well. Stir in chocolate chips Drop mixture by teaspoons onto ungreased cookie sheet Bake 8 to 10 minutes Where’s the: - Input data? - Algorithm? - Output data? 4/13/2019 CSE 1321 Module 1 6

7 Abstraction – the level of detail
a general idea or term an impractical idea; visionary and unrealistic general characteristics apart from concrete realities, specific objects or actual instances (Random House Dictionary of the English Language) In computing: Abstraction refers to the LOGICAL GROUPING of concepts or objects We want to hide the details (in functions – later) We like to think at a high level of abstraction (no details) Too many details overwhelm us! 4/13/2019 CSE 1321 Module 1 7

8 Someone tell me to turn off the lights
Example Someone tell me to turn off the lights 4/13/2019 CSE 1321 Module 1 8

9 What is Wrong with this Algorithm?
(From back of shampoo bottle) Directions: Wet Hair Apply a small amount of shampoo Lather Rinse Repeat Lesson learned: Just because we have algorithm doesn’t mean it’s a good one 4/13/2019 CSE 1321 Module 1 9

10 Properties of Good Algorithms
Good algorithms are: Precise – why? Unambiguous – why? Complete – why? Correct – why? Simple – why? Contain levels of abstraction – why? 4/13/2019 CSE 1321 Module 1 10

11 Describing Algorithm Can be created using:
Natural language (e.g. English) Pictures or flowcharts Pseudocode or a specific programming language We’ll use pseudocode in this course It’s a mixture of languages Not concerned with syntax, but concepts You’ll use it through the rest of your career 4/13/2019 CSE 1321 Module 1 11

12 Example: Natural Language Algorithm
START by make a list of courses you want to register for, in order of priority. Number of hours = 0. Choose highest priority class on list. IF the chosen class is not full and its class time does not conflict with classes already scheduled, THEN register for the class: 4.a. Add the class to the schedule. 4.b. Add the class hours to the number of hours scheduled. Cross that class off of your list. Repeat steps 3 through 5 until the number of hours scheduled is >= 15, or until all classes have been crossed out. END ALGORITHM. 4/13/2019 CSE 1321 Module 1 12

13 Example: Flowchart Algorithm
END START Make list of classes you want to take Num Hours = 0 Choose highest priority class on list Add the class to your schedule. Add class hours to Num Hours. Cross the class off your list. yes no Is this class full? Is there a time conflict? Num Hours >= 15? More classes on list? 4/13/2019 CSE 1321 Module 1 13

14 Components of Algorithm
Any computing algorithm will have AT MOST five kinds of components: • Data structures to hold data • Instructions to change data value • Conditional expressions to make decisions • Control structures to act on decisions • Modules to make the algorithm manageable by abstraction (i.e., grouping related components) 4/13/2019 CSE 1321 Module 1 14

15 Fine! Then what is Programming?
Programming requires two skills: Algorithmic thinking (hard!) Knowledge of programming language syntax The syntax is the easy part Programming: Start by developing a good algorithm Then, convert into a language-specific syntax 4/13/2019 CSE 1321 Module 1 15

16 How to Learn Programming
We use pseudo-code to focus on learning algorithmic thinking Not using a computer to compile and run your program forces you to mentally execute your program and debug it! Too many programmers try to program by brute force and twiddling in an IDE. Wrong approach! 4/13/2019 CSE 1321 Module 1

17 Summary Programming starts with algorithm development
An algorithm is just a set of instructions Abstraction is just the level of detail A good algorithm exhibits precision, clarity, completeness, correctness, and simplicity. An algorithm can be described using a natural language, pictures and diagrams, and pseudocode or a specific programming language. 4/13/2019 CSE 1321 Module 1


Download ppt "Algorithms vs. Programming"

Similar presentations


Ads by Google