29 September 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.

Slides:



Advertisements
Similar presentations
8 October 2013Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Advertisements

1 March 2013Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
8 October 2013Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
15 October 2013Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Introduction to Programming
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
11 November 2014Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Algorithm Design CS105. Problem Solving Algorithm: set of unambiguous instructions to solve a problem – Breaking down a problem into a set of sub- problems.
Introduction to Computer Systems
Simple Program Design Third Edition A Step-by-Step Approach
25 November 2014Birkbeck College1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
6 October 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
6 October 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Data Structures and Algorithms Introduction to Algorithms M. B. Fayek CUFE 2006.
Chapter 1 Program design Objectives To describe the steps in the program development process To introduce the current program design methodology To introduce.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
29 September 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems
17 November 2015Birkbeck College1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems
10 November 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
20 October 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
13 October 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
3 November 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
17 November 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Chapter 3: User-Defined Functions I
22 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
29 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
5 February 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
12 February 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
24 November 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
19 February 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
27 October 2015 Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
26 February 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
4 March 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
11 March 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Introduction to Programming
Introduction to Programming
Introduction to Computer Systems
Introduction to Programming
Introduction to Programming
Introduction to Programming
Chapter 6: User-Defined Functions I
Introduction to Programming
INTRODUCTION TO PROBLEM SOLVING
Introduction to Computer Systems
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Algorithms and Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Basics Prof. Hsin-Mu (Michael) Tsai (蔡欣穆)
Introduction to Programming
COMPUTING.
Presentation transcript:

29 September 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems Autumn 2015 Week 1b: Algorithms

29 September 2015Birkbeck College, U. London2 Informal Algorithms Directions to go from one place to another. Cooking recipes. How to use a device (TV, microwave, etc.) How to assemble flat pack furniture A list of instructions for Tom

Example of a Cooking Algorithm 1. Obtain a basked of unshelled pea pods and an empty bowl. 2. As long as there are unshelled pea pods in the basket 3. Take a pea pod from the basket 4. Break open the pea pod 5. Dump the peas from the pod into the bowl 6. Discard the pod 29 September 2015Brookshear Section 5.13

Commentary Input: basket of unshelled pea pods and an empty bowl Output: bowl of peas and the pea pods Variable: the number of pea pods in the basket The instructions are carried out in a strict order, one after the other Instruction 2 affects the order in which the other instructions are carried out. 29 September 2015Birkbeck College, U. London4

Effect of Removing Instruction 2 1. Obtain a basket of unshelled pea pods and an empty bowl 2. Do nothing 3. Take a pea pod from the basket 4. Break open the pea pod 5. Dump the peas from the pod into the bowl 6. Discard the pod 29 September 2015Birkbeck College, U. London5

Flow Chart 29 September 2015Birkbeck College, U. London6 is there a pea pod in the basket? halt no carry out 3, 4, 5, 6 yes

Reduced Version of the Cooking Algorithm 1. Store a non-negative integer in a memory location called basket 2. As long as the value stored in basket is strictly greater than 0 3. Subtract 1 from the value stored in basket 29 September 2015Birkbeck College, U. London7

Variables 1 A variable is a named memory location e.g. the variable q. q=5 // store the value 5 in the memory location specified by q q=5 // assign the value 5 to the variable q The exact memory location specified by q is chosen when the program runs 12 October 2010Birkbeck College, U. London8

Variables 2 q=5+2 // evaluate the right hand side. Assign the resulting value to q. q=q+2 // evaluate the right hand side. Assign the resulting value to q. 5=q // error 29 September 2015Birkbeck College, U. London9

29 September 2015Birkbeck College, U. London10 Definition of an Algorithm An algorithm is an ordered set of unambiguous executable steps that defines a terminating process. It is implicit that something (e.g. a machine) carries out the steps.

Commentary Terminating process: print all the integers in the range 1 to 10 Non-terminating process: print all the integers Executable step: assign to x the value 1 Non executable step: attempt to assign to x a value larger than any that can be stored. 12 October 2010Birkbeck College, U. London11

29 September 2015Birkbeck College, U. London12 Algorithms and Computers An algorithms is converted into a list of instructions (program) for a particular computer. The details of the instructions vary from one computer to another If an algorithm is programmable on one computer, then in principle it is programmable on any computer.

29 September 2015Birkbeck College, U. London13 First Example of an Algorithm Input: integers 12, 5 Output: quotient q and remainder r on dividing 12 by 5 Algorithm 1. q = 0; r = Subtract 5 from r; Increase q by 1 3. Subtract 5 from r; Increase q by 1 4. Output q, r 5. Halt

29 September 2015Birkbeck College, U. London14 Second Example of an Algorithm Input: strictly positive integers m, n Output: quotient q and remainder r on dividing m by n Algorithm 1. q = 0 2. r = m 3. If r < n, Output q, r; Halt 4. r = r-n 5. q = q+1 6. go to 3

29 September 2015Birkbeck College, U. London15 Third Example of an Algorithm Input: strictly positive integers m, n Output: quotient q and remainder r on dividing m by n Algorithm 1. q = 0 2. r = m 3. While r >= n, 4. r = r-n 5. q = q+1 6. EndWhile 7. Output q, r 8. Halt

29 September 2015Birkbeck College, U. London16 Exercise Sketch an algorithm that takes as input a strictly positive integer n and outputs an integer k such that