Presentation is loading. Please wait.

Presentation is loading. Please wait.

Michelle Kuttel mkuttel@cs.uct.ac.za Room 304.02 CSC1015F – Introduction to Computer Science and Programming with Python Michelle Kuttel mkuttel@cs.uct.ac.za.

Similar presentations


Presentation on theme: "Michelle Kuttel mkuttel@cs.uct.ac.za Room 304.02 CSC1015F – Introduction to Computer Science and Programming with Python Michelle Kuttel mkuttel@cs.uct.ac.za."— Presentation transcript:

1 Michelle Kuttel mkuttel@cs.uct.ac.za Room 304.02
CSC1015F – Introduction to Computer Science and Programming with Python Michelle Kuttel Room

2 What is Computer Science?

3 What is Computer Science? – one expert’s opinion…
Computer Science is no more about computers than astronomy is about telescopes. E. W. Dijkstra The computer is a tool, not the object of study What can be computed?? What is English? – also hard to define. What is biology? Computer Science is hard to define. Some people use the term “Information Technology”.

4 An easier question: What is a program?

5 An easier question: What is a program?
A program is a set of instructions you write down directions to your house for a friend this is an program your friend “executes” the program when they follow the instructions, in order will she find your house???? (how good is your program?)

6 Exercise Write down instructions for your lecturer to draw the picture below on the black board. You must assume that: your lecturer cannot see or be shown the picture she can only follow verbal instructions

7 What is a program? Every program is written in terms of a few basic operations that the “executor” understands e.g. “turn left”, “go forward three blocks”

8 Programs and algorithms
The general rules in the “recipe” (or recipes) in your program is called an algorithm (or recipe, process, method, technique, procedure, routine) The essence of the problem solution, with all executor- specific details removed. Algorithm (Noun) a process or set of rules to be followed in calculations or other problem-solving operations, esp. by a computer : a basic algorithm for division.

9 Algorithms are independent of language and computer
Analogy: A recipe for fruit cake can be written in either French or English and cooked in any well-equipped kitchen and will produce (approximately) the same cake. All cooks are capable of the same basic operations: setting oven temperature, weighing ingredients All kitchens have the same basic equipment Novice cooks may need more detail in the recipe, but it is the same recipe the recipe is independent of the language and the cook who implements it.

10 Algorithms are independent of language and computer
So, a program is an algorithm (or set of algorithms) written in a particular language to be understood by a particular class of “computers” (people or machines or…)

11 What exactly is an algorithm?
Everyday tasks require algorithms but we usually do not think about them. E.g., running the washing machine, setting the burglar alarm, putting on your shoes…(!) Algorithms must be precise so that they are Repeatable Have a predictable outcome Can be executed by different “computers” (people or machines) Terminate!

12 Check point: is this an algorithm?
Tidy your room!

13 Check point: is this an algorithm?
Tidy your room: Pick up all the stuff on your floor and put it away. Make your bed. Vacuum the floor.

14 Check point: is this an algorithm?
Snakes and Ladders: This game is for players. The first player to hit the last square wins and the game ends. To start, each player takes his/her turn to roll the dice and the one with the highest throw begins. Players then take turns to roll the die. They each move the number of squares indicated by the die. If a player lands on a square depicting the bottom of the ladder, she moves up to the square containing the top of the ladder. If a player lands on the square containing the head of a snake, he slides down to the square containing the tail of the snake. If a player is at square 99 and throws a 3, he has to backspace to square 98 and will not finish until he has an exact throw to reach the last square. Have you said which direction you move in?

15 Check point: is this an algorithm?
To find the sum of three numbers, a, b, c: d = a + b + c

16 Check point: is this an algorithm?
Perfect Soft-Boiled Eggs: Heat med panful h2o to bare simmr; +3-6egg. Maintain at near simmring (no bubbles) uncvrd7m. Rmv from h2o. Aside on references. are the streams of Maureen Evans, a 27-year-old from British Columbia who is studying for a master’s in creative writing at Queen’s University Belfast. I really get a kick out of how complex a recipe I can fit into 140 characters.” Eat Tweet is the world's first cookbook written entirely in Twitterese. The abbreviated form might be a little intimidating at first, but with the aid of the glossary, it will soon become like a second language for you, as it has for so many online readers of twitter.com/cookbook. Reference: Maureen Evans,

17 Algorithm to Boil Water in Kettle
take the lid off kettle If there is enough water in the kettle , go to step 7 Put kettle under tap Open tap While kettle is not full, Wait Close tap Replace lid on kettle Plug kettle into power outlet Turn kettle on While water has not boiled, Wait 5 seconds Turn kettle off Remove plug from power outlet Will this work for the yellow kettle? Specify inputs!

18 Algorithm to make a cup of tea…

19 Exercise Write down an algorithm for finding the maximum of a list of numbers Sort them?

20 find the maximum – class race
plan your algorithm….

21 find the minimum – class race

22 find the maximum – class race

23 Algorithm to find the minimum in a list of numbers
If the list is empty, display an error message and go to step 8 Start at the beginning of the list Set the current minimum to the first number in the list If there are no more numbers, display the current minimum and go to step 8 Move on to the next number in the list If the current number < current minimum, set the current minimum to the current number Go to step 4 Stop

24 Different algorithms The same algorithm can be represented in different ways AND several algorithms for solving the same problem may exist - with different properties

25 Different algorithms to solve a problem: sorting as an example
Sorting a hand of cards. Input: a hand of cards Output: a sorted hand of cards Algorithm – how you do this, step-by-step Many methods! one general method: take the lowest card and move it to the leftmost (or rightmost) position. Next, find the second lowest card and move it to the second leftmost position. Repeat until the cards are sorted. pseudocode

26 choice of the best algorith for a task is a complicated process
choice of the best algorith for a task is a complicated process. often involving sophisticated mathematical analysis

27 What is an Algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem For obtaining a required output for any legitimate input in a finite amount of time Does not require implementation in software Not an answer but a method for deriving an answer Each step of the algorithm must be unambiguous The range of inputs must be specified carefully Implementation - in fact originally computers were people not machines. The first computing machines were named after the job because they fulfilled similar tasks

28 Elements of Algorithms
Sequence Each step is followed by another step Selection A choice may be made among alternatives Iteration A set of steps may be repeated Any language with these 3 constructs can express any classical algorithm.

29 Aside: Derivation of the word
“Algorithm” named after Muhammad ibn Musa al- Khwarizmi – 9th century Persian mathematician < 800 AD to 847AD. Wrote text al-Kitab al-mukhtasar fi hisab al-jabr wa'l- muqabala (“The Compendious Book on Calculation by Completion and Balancing”), from which “Algebra” is derived. Algorithm comes from latinate form of his name. Worked on astronomy, the Jewish Calendar, Hindu numeration system. introduced Hindu-Arabic numerals and the concepts of algebra into European mathematics Where is persia today? Iraq (baghdad)

30 Algorithms in Computer Science
The term algorithm is in used in Computer Science to describe a problem-solving method suitable for implementation in computer programs

31 Programs problem algorithm “computer” input output
A program is a detailed, step-by-step set of instructions telling the computer exactly what to do Program corresponds to an algorithm to solve a problem. The act of writing a program is called programming. Programs are written in a precise language called a programming language. “computer” problem algorithm input output

32 The “Say ‘Hello!’” algorithm…

33 Hello World Java: C++: Python: // Hello World in Java
class HelloWorld { static public void main(String args[]) { System.out.println(“Hello World!”); } } // Hello World in C++ #include <iostream.h> Main() { cout << “Hello World!” << endl; return 0; } # Hello World in Python print(“Hello World!”) Python combines remarkable power with very clean, simple, and compact syntax.

34 What is Computer Science?
Computer Science is not just about programming It is about problem-solving and design Conceptualizing, not programming multiple levels of abstraction

35 Why are algorithms so important? (1/2)
Algorithmics is more than a branch of computer science. It is the core of computer science and, in all fairness, can be said to be relevant to most of science, business and technology. David Harel, Algorithmics: the Spirit of Computing

36 Why are algorithms so important? (2/2)
A person well trained in computer science knows how to deal with algorithms; how to construct them, manipulate them, understand them, analyze them. This knowledge prepares him for much more than writing good computer programs; it is a general-purpose mental tool which will be a definite aid to his understanding of other subjects, whether they be chemistry, linguistics, or music, etc. The reason for this may be understood in the following way. It has often been said that a person does not really understand something until he teaches it to someone else. Actually a person does not really understand something until after teaching it to a computer, i.e., express it as an algorithm. Donald Knuth, 1996

37 But why should I take Donald Knuth’s word for it?
Donald Knuth (b. 1938) Professor Emeritus of The Art of Computer Programming at Stanford University The Art of Computer Programming - seminal multi-volume work Volume Five currently worked on has been called the ‘father’ of the analysis of algorithms Donald Knuth. contributing to the development of and systematizing formal mathematical techniques for the rigorous analysis of the computational complexity of algorithms, and in the process popularizing asymptotic notation. On January 1, 1990, Knuth announced to his colleagues that he would no longer have an address, so that he may concentrate on his work. TeX computer typesetting system, the related METAFONT font definition language and rendering system, and the Computer Modern family of typefaces. A prolific writer and scholar[5], Knuth is also creator of the WEB/CWEB computer programming systems designed to encourage and facilitate literate programming, as well as designer of the MMIX instruction set architecture.

38 The limits of algorithms
There are problems for which : no one has yet found an algorithm there are algorithms, but they take too much time it has been proved that you can’t ever find an algorithm…

39 The limits of algorithms
There are problems for which : no one has yet found an algorithm there are algorithms, but they take too much time it has been proved that you can’t ever find an algorithm… Towers of Hanoi The HALTING problem

40 Check Point Which of the following formulas can be considered an algorithm for computing the area of a triangle whose side lengths are given positive numbers a,b and c ? where p=(a+b+c)/2 The formula can be considered an algorithm if we assume that we know how to compute the square root of an arbitrary positive number. b. The difficulty here lies in computing sin A. Since the formula says nothing about how it has to be computed, it should not be considered an algorithm. This is true even if we assume, as we did for the square root function, that we know how to compute the sine of a given angle. (There are several algorithms for doing this but only approximately, of course.) The problem is that the formula says nothing about how to compute angle A either. c. The formula says nothing about how to compute ha. where A is the angle between sides b and c where ha is the height to base a

41 Problem solving in Computer Science (1/2)
Understand the problem What are the knowns and unknowns? Plan how to solve the problem What algorithm is used to solve the problem? What assumptions are being made? Is this similar to other problems? Can the problem be split into parts? Carry out your plan Write program(s) in suitable langauge to implement algorithm(s). Get the computer to execute the program

42 Problem solving in Computer Science (2/2)
Assess the result Does the program conform to the algorithm? Does the program/algorithm solve the problem? Is the program correct for all cases? Describe what you have learnt ... so you do not make the same mistakes again. Document the solution Write a report for users of the program. Write comments within the program. Reference: Vickers, P How to think like a programmer. Cengage.

43 What is Computer Science?
Computer Science (CS) is the study of: Computer software Algorithms, abstractions and efficiency Theoretical foundations of computation What you learn in Computer Science: Principles of computation How to make machines perform complex tasks How to program a computer What current technology exists and how to use it Problem solving design

44 This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 South Africa License.
original art work by Michelle Kuttel


Download ppt "Michelle Kuttel mkuttel@cs.uct.ac.za Room 304.02 CSC1015F – Introduction to Computer Science and Programming with Python Michelle Kuttel mkuttel@cs.uct.ac.za."

Similar presentations


Ads by Google