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

15 October 2013Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Introduction to Programming
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Program Design and Development
1 Computing Functions with Turing Machines. 2 A function Domain: Result Region: has:
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
Computers Organization & Assembly Language
Copyright © 2015 Pearson Education, Inc. Chapter 5: Algorithms.
How Computers Work Dr. John P. Abraham Professor UTPA.
25 November 2014Birkbeck College1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Computer Programming I. Today’s Lecture  Components of a computer  Program  Programming language  Binary representation.
Chapter 3 Section 1 Number Representation Modern cryptographic methods, unlike the classical methods we just learned, are computer based. Representation.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
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.
Introduction to Algorithms By Mr. Venkatadri. M. Two Phases of Programming A typical programming task can be divided into two phases: Problem solving.
Chapter 5 Algorithms Introduction to computer, 2nd semester, 2010/2011 Mr.Nael Aburas Faculty of Information Technology.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
Lecture 11: 10/1/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
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.
Computer Science: An Overview Eleventh Edition
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
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.
Introduction to Computer Systems
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
24 November 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
1 Introduction to Turing Machines
26 February 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
4 March 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Fundamentals of Algorithms MCS - 2 Lecture # 3. Representation of Algorithms.
1 Computing Functions with Turing Machines. 2 A function Domain Result Region has:
Introduction to Programming
Introduction to Programming
Introduction to Computer Systems
Introduction to Programming
Introduction to Programming
Introduction to Programming
Computer Science: An Overview Eleventh Edition
CS1001 Programming Fundamentals 3(3-0) Lecture 2
Introduction to Programming
Lecture 2 Introduction to Programming
Introduction To Flowcharting
Introduction to Programming
Introduction to Programming
University of Gujrat Department of Computer Science
Lecture 2: Introduction to Algorithms
Introduction to Programming
Computing Functions with Turing Machines
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Chapter 6 Programming the basic computer
Introduction to Programming
Presentation transcript:

Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems sjmaybank@dcs.bbk.ac.uk Autumn 2014 Week 8b: Pseudo Code and Algorithms 18 November 2014 Birkbeck College, U. London

Algorithms Definition: an algorithm is an ordered set of unambiguous, executable steps that defines a terminating process. The steps are often called instructions. Termination is by a special instruction: halt. 18 November 2014 Brookshear section 5.1

Brookshear sections 5.1 and 5.2 Terminology Programming language: system for representing algorithms in a human readable form suitable for conversion to machine code. Program: representation of an algorithm in a programming language. Pseudo code: system for the informal representation of algorithms. Hardware: device to carry out the steps or instructions in a program. 18 November 2014 Brookshear sections 5.1 and 5.2

Representation of an Algorithm The same algorithm can be represented in many different ways: F = (9/5)C+32 F <- (9*C)/5+32 To obtain F multiply C by (9/5) and then add 32. Lookup table for Fahrenheit and Centigrade 18 November 2014 Brookshear Section 5.1

Birkbeck College, U. London Program 1 for XOR Input: binary digits a,b Output: a XOR b If a==0 and b==0 Return 0 If a==0 and b==1 Return 1 If a==1 and b==0 Return 1 If a==1 and b==1 Return 0 Halt 18 November 2014 Birkbeck College, U. London

Birkbeck College, U. London Program 2 for XOR Input: binary digits a,b Output: a XOR b If a==b Return 0 Else Return 1 Halt 18 November 2014 Birkbeck College, U. London

Birkbeck College, U. London Program 3 for XOR Input: binary digits a,b Output: a XOR b Convert a to the integer ia Convert b to the integer ib ic=remainder on dividing ia+ib by 2 Return ic Halt 18 November 2014 Birkbeck College, U. London

Pseudo Code for Algorithm Representation Very useful informal representation of algorithms. Preferable to using program code when designing an algorithm. Basic structures (assignment, loops, arrays …) are similar across many programming languages. 18 November 2014 Brookshear section 5.2

Pseudo Code: assignment General form name <- expression Examples funds <- current + savings x <- 10 18 November 2014 Brookshear, Section 5.2

Pseudo Code: conditional selection General form if (condition) then (activity) else (activity) Example if (year is leap year) then d <- total divided by 366 else d <- total divided by 365 Key or reserved words in bold 18 November 2014 Brookshear section 5.2

Pseudo Code: repeated execution General form while (condition) do (activity) Example while (tickets remain) do (sell a ticket) 18 November 2014 Brookshear section 5.2

Pseudo Code: indentation if (not raining) then (if (temperature = hot) then (go swimming) else (play golf) ) else (watch television) if (not raining) then (if (temperature=hot) then (go swimming) else (play golf)) else (watch television) 18 November 2014 Brookshear section 5.2

Procedure Definition: set of instructions which can be used as a single unit in different contexts. A procedure call contains the name of the procedure and any data supplied to the procedure A result calculated by the procedure can be obtained using a return statement. 18 November 2014 Brookshear, Section 5.2

Example of a Procedure Definition of a procedure temp(c) f=(9/5)*c+32; return f; endProcedure f1=temp(34) Procedure call 18 November 2014 Birkbeck College

Pseudo Code: procedures General type procedure name Examples procedure helloWorld //no parameters procedure sort (List) // parameter List 18 November 2014 Brookshear Section 5.2

Pseudo Code: alternatives to brackets procedure name (activity) endProcedure while (condition) do (activity) endDo endWhile 18 November 2014 Brookshear Section 5.2

Exercise 1 Write an algorithm in pseudo code to carry out the following task: input: a 1-dimensional array A of integers output: the integer -1 if A[i]≥ A[i+1] for 0≤i≤Length[A]-2, otherwise the least integer j such that A[j]<A[j+1]. 18 November 2014 Birkbeck College

Brookshear Ch 5 review problems 11 Exercise 2 Design an algorithm for finding all the factors of a positive integer. For example, in the case of the integer 12, your algorithm should report the values 1,2,3,4,6 and 12. 18 November 2014 Brookshear Ch 5 review problems 11

Brookshear Ch 5 review problems 15 Exercise 3 The following is an addition problem in decimal notation. Each letter represents a different digit. Which letter does each digit represent? XYZ + YWY ==== ZYZW 18 November 2014 Brookshear Ch 5 review problems 15