25 November 2014Birkbeck College1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems

Slides:



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

Introduction to Programming
25 March 2013Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
11 November 2014Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1 Overview 7.1 Introduction to Arrays 7.2 Arrays in Functions 7.3.
HST 952 Computing for Biomedical Scientists Lecture 9.
ITEC113 Algorithms and Programming Techniques
D IVIDE AND CONQUER STRATEGY, D ATA TYPE, A LGORITHM DESIGN AND PRACTICE. Week 13 Mr.Mohammed Rahmath.
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
Chapter 8 Arrays and Strings
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
CHAPTER 7: SORTING & SEARCHING Introduction to Computer Science Using Ruby (c) Ophir Frieder at al 2012.
Introduction to Computer Systems
1 “Not all recursive solutions are better than iterative solutions…” “… recursion, however, can provide elegantly simple solutions to problems of great.
CC112 Structured Programming Lecture 4 1 Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer.
Course Web Page Most information about the course (including the syllabus) will be posted on the course wiki:
Chapter 8 Arrays and Strings
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
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.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system.
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
Lecture 5 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
111/18/2015CS150 Introduction to Computer Science 1 Announcements  I have not graded your exam yet.
COSC 235: Programming and Problem Solving Ch. 2: Your first programs!!! Instructor: Dr. X.
Introduction to Computer Programming
29 September 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering Problem Solving and Logic.
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.
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
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.
Introduction to Programming Python Lab 3: Arithmetic 22 January PythonLab3 lecture slides.ppt Ping Brennan
Introduction to Computer Systems
24 November 2015Birkbeck College, U. London1 Introduction to Computer Systems 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
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 3. Time Complexity Calculations.
11 March 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
CS314 – Section 5 Recitation 10
Introduction to Computer Systems
Introduction to Programming
Introduction to Programming
REPETITION CONTROL STRUCTURE
COP 3503 FALL 2012 Shayan Javed Lecture 15
Introduction To Repetition The for loop
Data Structures and Algorithms
Introduction to Programming
Introduction to Programming
Applied Algorithms (Lecture 17) Recursion Fall-23
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
Introduction to Programming
MSIS 655 Advanced Business Applications Programming
Programming Funamental slides
Introduction to Programming
Introduction to Programming
Introduction to Programming
Notes Over 9.1 Finding Square Roots of Numbers
Summary of what we learned yesterday
Introduction to Programming
Introduction to Programming
Discrete Mathematics CS 2610
Presentation transcript:

25 November 2014Birkbeck College1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems Autumn 2014 Week 9a: Algorithm Design

Review: Pseudo Code Structures Assignment if … then … else while … do … end while procedure … end procedure 25 November 2014Birkbeck College2

Review: Exercise procedure descending(A) j=0; flag=0; while flag==0 && j<Length[A]-1 do if A[j]<A[j+1] then flag=1; print(j); j=j+1; end while if flag==0 then print(-1); end procedure 25 November 2014Birkbeck College3

25 November 2014Brookshear, Section 5.34 Bottom Up Strategy Solve many small parts of the problem and gradually accumulate the information needed to solve the entire problem. Examples: evaluation of Boolean expressions, searching an unsorted list.

Example: Evaluation of a Boolean expression Suppose that A, B, C are Boolean variables such that A=0, B=1, C=0. Evaluate the Boolean expression (A AND B AND C) OR (A AND NOT(B)) 25 November 2014Birkbeck College5

Example: Searching an Unsorted List input: list L and element a output: 1 if a is in L otherwise 0 procedure search (L, a) if Length(L)==0 then print 0 and return; e=L[0]; while ((a<>e) && (e is not last entry of L)) do e=next entry of L; end while; if e==a then print 1 else print 0; return; end procedure 25 November 2014Compare Brookshear Section 5.46

25 November 2014Brookshear Section 5.37 Top Down Strategy Divide the problem into two or more simpler problems. Solve the simpler problems and then combine the answers. Examples: route finding, binary search of a sorted list.

Binary Search of a Sorted List input: sorted list L, element a output: 1 if a is in L, otherwise 0 procedure searchSortedList(L, a) if Length(L)==0 then print 0 and return; i1=0; i2=Length(L)-1; while i2>i1+1 do j=largest integer ≤ (i1+i2)/2; if L[j]==a then print 1 and return; if a<L[j] then i2=j else i1=j; end while; if a==L[i1] or a==L[i2] then print 1 else print 0; return; end procedure 25 November 2014Compare Brookshear, Section 5.58

25 November 2014Birkbeck College9 Other Strategies Find out if somebody else has solved the problem. Solve a simpler but related problem. Iteration: repetition of a standard calculation Find a data structure for the problem suited to a computer. Enumeration.

25 November 2014Birkbeck College10 Solve a Simpler but Related Problem Program to draw a polygon in any part of the display screen Program to draw a polygon at the centre of the display screen Program to draw a square in any part of the display screen

25 November 2014Birkbeck College11 Example: iteration input: none output: estimate of the square root of 2 procedure sqrt2 x=1; while (x 2 > 2.001) or (x 2 < ) do x=(1/x)+(x/2); end while; print x; end procedure;

25 November 2014Birkbeck College12 Enumeration List all the possible states of the problem and search for the solution. Example 1: find all numbers which divide 10 by checking 1,2,…10. Advantages: thorough, simple, good for small cases. Disadvantages: very long run times, inefficient.

25 November 2014Birkbeck College13 Ferry Problem A man wishes to ferry a wolf, a sheep and a bale of hay across a river. His boat will only hold one item at a time. The wolf cannot be left with the sheep and the sheep cannot be left with the hay. How can he ferry the three items?

25 November 2014Birkbeck College14 Data Structure State: WSHb Red: start side of river Blue and underlined italic : other side of river Example: WSHb There are 16 states of which 10 are allowed

25 November 2014Birkbeck College15 Solution HSWb

25 November 2014Birkbeck College16 Question 11 from 2003 Exam Write an algorithm for calculation of tax for a yearly salary. The tax is zero when the salary is £3000 or less. It is 10% for the next salary band from £3001 to £8000. It is 20% for the part from £8001 to £20000, and it is 40% for any part of the salary over £20000.

25 November 2014Birkbeck College17 Question Design an algorithm that lists all possible rearrangements of the symbols in a string of five distinct characters.