Introduction to Computer 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
8 February 2013Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
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.
Introduction Dr. Ying Lu RAIK 283: Data Structures & Algorithms.
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
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.
29 September 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
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.
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
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
22 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
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.
Introduction to Computer Systems
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
Problem Solving & Computer Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Algorithms, Part 1 of 3 The First step in the programming process
Introduction to Programming
Introduction to Computer Systems
Algorithms I: An Introduction to Algorithms
Introduction to Programming
Introduction to Programming
Introduction to Programming
Computer Science 101 While Statement.
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Algorithm Discovery and Design
Introduction to Programming
Introduction to Programming
Introduction to Algorithms and Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Lecture 4: Expressions and Variables
Introduction to Programming
Introduction to Programming
Introduction to Programming
Basics Prof. Hsin-Mu (Michael) Tsai (蔡欣穆)
Introduction to Programming
Presentation transcript:

Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems sjmaybank@dcs.bbk.ac.uk Spring 2017 Week 1b: Algorithms 10 January 2017 Birkbeck College, U. London

Birkbeck College, U. London 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 10 January 2017 Birkbeck College, U. London

Example of a Cooking Algorithm Obtain a basket of unshelled pea pods and an empty bowl. As long as there are unshelled pea pods in the basket Take a pea pod from the basket Break open the pea pod Dump the peas from the pod into the bowl Discard the pod 10 January 2017 Brookshear Section 5.1

Birkbeck College, U. London 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. 10 January 2017 Birkbeck College, U. London

Effect of Removing Instruction 2 Obtain a basket of unshelled pea pods and an empty bowl Do nothing Take a pea pod from the basket Break open the pea pod Dump the peas from the pod into the bowl Discard the pod 10 January 2017 Birkbeck College, U. London

Birkbeck College, U. London Flow Chart is there a pea pod in the basket? no halt yes carry out 3, 4, 5, 6 10 January 2017 Birkbeck College, U. London

Reduced Version of the Cooking Algorithm Store a non-negative integer in a memory location called basket As long as the value stored in basket is strictly greater than 0 Subtract 1 from the value stored in basket 10 January 2017 Birkbeck College, U. London

Birkbeck College, U. London 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 10 January 2017 Birkbeck College, U. London

Birkbeck College, U. London 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 10 January 2017 Birkbeck College, U. London

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. 10 January 2017 BB Section 5.1

Birkbeck College, U. London 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. 10 January 2017 Birkbeck College, U. London

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. 10 January 2017 Birkbeck College, U. London

First Example of an Algorithm Input: integers 12, 5 Output: quotient q and remainder r on dividing 12 by 5 Algorithm q = 0; r = 12 Subtract 5 from r; Increase q by 1 Output q, r Halt 10 January 2017 Birkbeck College, U. London

Second Example of an Algorithm Input: strictly positive integers m, n Output: quotient q and remainder r on dividing m by n Algorithm q = 0 r = m If r < n, Output q, r; Halt r = r-n q = q+1 go to 3 10 January 2017 Birkbeck College, U. London

Third Example of an Algorithm Input: strictly positive integers m, n Output: quotient q and remainder r on dividing m by n Algorithm q = 0 r = m While r >= n, r = r-n q = q+1 EndWhile Output q, r Halt 10 January 2017 Birkbeck College, U. London

Building a New Algorithm Give the third algorithm a name: division(m, n) Show how division(m, n) can be used in a new algorithm to print out all the exact divisors of m, i.e. those integers n ≥1 for which m/n is an integer. 10 January 2017 Birkbeck College, U. London

Birkbeck College, U. London Exercise Sketch an algorithm that takes as input a strictly positive integer n and outputs an integer k such that 10 January 2017 Birkbeck College, U. London