Computational Algorithms David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction.

Slides:



Advertisements
Similar presentations
Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Example - The.
Advertisements

1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Java Coding OOP David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Towards Event-driven programming &
Everyday Algorithms David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction to.
Introduction to UML David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. …Unified Modeling Language.
CS107 Introduction to Computer Science Loops. Instructions Pseudocode Assign values to variables using basic arithmetic operations x = 3 y = x/10 z =
CS107 Introduction to Computer Science
Java Coding 6 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Collections.
Java Coding 2 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Decisions, decisions…!
Java Coding 3 David Davenport Computer Eng. Dept.,
Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Examples.
Review: OOP & Arrays David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. …from CS101.
Robo David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction to the engineering.
BBS Yapısal Programlama (Structured Programming)1 From problem to program In “real world”… Problem in Natural language Top Down Design in pseudo-code.
Java Coding David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey.
Chapter 3 Planning Your Solution
Review Algorithm Analysis Problem Solving Space Complexity
Java Coding 4 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Method madness.
Adapted from slides by Marie desJardins
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
Java Coding 3 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Over & over again!
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
General Programming Introduction to Computing Science and Programming I.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
From Algorithms to Architecture David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
CSE 102 Introduction to Computer Engineering What is an Algorithm?
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Flowcharts.
PSEUDOCODE C Programming Technique – Firdaus-Harun.com.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
Java Coding David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Syntax for Variables & Constants Input,
Lecture 13: 10/10/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Java Coding 6 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Collections.
1. Understand the application of Pseudo Code for programming purposes 2. Be able to write algorithms in Pseudo Code.
CSCI-100 Introduction to Computing
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
Java Coding OOP_3 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Some important Java interfaces +
From Algorithms to Architecture David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Examples.
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
Java Coding 5 – Part 2 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. To object or not…
Comments, Conditional Statements Continued, and Loops Engineering 1D04, Teaching Session 4.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
Programming revision Revision tip: Focus on the things you find difficult first.
Introduction to Computing Science and Programming I
Writing algorithms Introduction to Python.
REPETITION CONTROL STRUCTURE
Java Coding – part 2 David Davenport Computer Eng. Dept.,
Java Coding 2 David Davenport Computer Eng. Dept.,
Java Coding 3 – part2 David Davenport Computer Eng. Dept.,
Java Coding 3 David Davenport Computer Eng. Dept.,
Robo – Software Engineering
Chapter 4 – Control Structures Part 1
Algorithm and Ambiguity
Algorithm Discovery and Design
Java Coding 6-extra David Davenport Computer Eng. Dept.,
Algorithm and Ambiguity
Java Coding 6 – part2 David Davenport Computer Eng. Dept.,
Java Coding 4 (part2) David Davenport Computer Eng. Dept.,
Java Coding 6_part3 David Davenport Computer Eng. Dept.,
The while Looping Structure
Java Coding 6 David Davenport Computer Eng. Dept.,
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Java Coding 6 David Davenport Computer Eng. Dept.,
Presentation transcript:

Computational Algorithms David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction to real-world algorithms

IMPORTANT… Students… This presentation is designed to be used in class as part of a guided discovery sequence. It is not self- explanatory! Please use it only for revision purposes after having taken the class. Simply flicking through the slides will teach you nothing. You must be actively thinking, doing and questioning to learn! Instructors… You are free to use this presentation in your classes and to make any modifications to it that you wish. All I ask is an saying where and when it is/was used. I would also appreciate any suggestions you may have for improving it. thank you, David. David

From problem to program In Robo… d base d pole d roof wwell d equtri(140) roof f( 150) pole d rect( 100, 100) base roofpolebase 140x140x x100 The Problem The Design The Program DESIGN IMPLEMENT Reduce cognitive load & hence mistakes by separating design and coding using top-down design Don’t forget unit and integration testing

From problem to program In “real world”… Do this repeat if something then do this else do the other Print “all done” Problem in Natural language Top Down Design in pseudo-code Program in computer code (code in almost any computer language.) Requirements: A program that does this and that and the other. It must take data from this source and // Program example // David, Oct 2002 import java.io.*; Import cs1.JRobo; public class Example { public static void mai System.out.println( JRobo robby = new J robby.f(100); robby.rect( 150, 50); } DESIGN IMPLEMENT Reduce cognitive load separating design and coding using top-down design The Problem The Design The Program

THE CIRCLE COMPUTER Example…

Area-Circumference Problem Requirements: Compute and report the area and circumference of a circle whose radius the user gives. Welcome to circle computer… Please enter the radius: 5 The area of a circle of radius 5 is and its circumference is Example interaction

Put yourself in the place of the computer and explain what you would do in plain English Area-Circumference Problem To find area & circumference of circle… First say “Welcome to circle computer…” and then ask the user for the radius of their circle and get the radius value the user gives in response. Next, compute the corresponding area as pi times the radius squared, and then compute the circumference as two times pi times the radius. Finally, tell the user that the area of a circle of the radius they gave is the area value you computed, and the circumference is the circumference value you computed.

Area-Circumference Problem To find area & circumference of circle… First say “Welcome to circle computer…” and then ask the user for the radius of their circle and get the radius value the user gives in response. Next, compute the corresponding area as pi times the radius squared, and then compute the circumference as two times pi times the radius. Finally, tell the user that the area of a circle of the radius they gave is the area value you computed, and the circumference is the circumference value you computed.

Area-Circumference Problem To find area & circumference of circle… First say “Welcome to circle computer…” and then ask the user for the radius of their circle and get the radius value the user gives in response Next, compute the corresponding area as pi times the radius squared, and then compute the circumference as two times pi times the radius. Finally, tell the user that the area of a circle of the radius they gave is the area value you computed, and the circumference is the circumference value you computed.

Area-Circumference Problem To find area & circumference of circle… 1. Say “Welcome to circle computer…” 2. Ask the user for the radius of their circle and get the radius value the user gives in response 3. Compute the corresponding area as pi times the radius squared, 4. Compute the circumference as two times pi times the radius. 5. Tell the user that the area of a circle of the radius they gave is the area value you computed, and the circumference is the circumference value you computed.

Area-Circumference Problem To find area & circumference of circle… 1. Print welcome message 2. Ask for & get radius from user 3. Compute area as pi.radius.radius 4. Compute circumference as 2.pi.radius 5. Report area, circumference & radius Once we are sure that this is correct, move on to solve any non- trivial sub-problems. Identify preconditions ( for each step ) & ensure they are satisfied.

Area-Circumference Problem Solve… 2. Ask for & get radius from user 1. Ask (prompt) the user to enter radius 2. Get radius value from user Welcome to circle computer… Please enter the radius: _ Welcome to circle computer… _

Area-Circumference Problem To find area & circumference of circle… 1. Print welcome message 2. Ask for & get radius from user 3. Compute area as pi.radius.radius 4. Compute circumference as 2.pi.radius 5. Report area, circumference & radius The area of a circle of radius 5 is and its circumference is The area of a circle of radius 10 is and its circumference is 62.84

Area-Circumference Problem Take care with spaces, number formats & line breaks! Solve … 5. Report area, circumference & radius 1. Print msg “The area of a circle with radius ” 2. Print radius value 3. Print msg “ is ” 4. Print area value and move to next line 5. Print msg “ and its circumference is ” 6. Print circumference value 7. Print blank line

EXAM AVERAGE PROBLEM Example…

Exam average problem Requirements: Given a set of already graded exam papers, compute and report the average grade. Algorithm 1.Print welcome message 2.Given the set of exam papers find the number of papers and the sum of all the grades on the papers 3.Compute average grade as sum of all the grades / number of papers 4.Report the average grade 5.Print “all done” message

Exam average problem Revised algorithm Algorithm 1.Print welcome message 2.Given the set of exam papers find the number of papers and the sum of all the grades on the papers 3.if number of papers is zero then 3TPrint msg “no grades entered” else 3F.1Compute average grade as sum of all the grades / number of papers 3F.2Report the average grade 4. Print “all done” message

Exam average problem Solve … 2. Given the set of exam papers find the number of papers and the sum of all the grades on the papers 1. Ask user for & get the number of papers 2. For each paper read the grade from the paper and add it to the sum of grades so far. 3. Sum of all the grades is now sum of grades so far

Exam average problem Solve… (Alternative) 2. Given the set of exam papers find the number of papers and the sum of all the grades on the papers 1. Set count of papers so far to zero, then for each paper add one to the count of papers so far. 2. Set sum of grades so far to zero, and then for each paper read the grade from the paper and add it to the sum of grades so far. 3. Number of papers is now count of papers so far 4. Sum of all grades is now sum of grades so far

Exam average problem Solve… (Yet another alternative) 2. Given the set of exam papers find the number of papers and the sum of all the grades on the papers 1. Set count of papers so far to zero 2. Set sum of grades so far to zero 3. For each paper, read the grade from the paper, add it to the sum of grades so far and add one to the count of papers so far 4. Number of papers is now count of papers so far 5. Sum of all grades is now sum of grades so far

Exam average problem Solve… (& yet another alternative) 2. Given the set of exam papers find the number of papers and the sum of all the grades on the papers 1.Set count of papers so far to zero 2.Set sum of grades so far to zero 3.For each paper 3.1read the grade from the paper, 3.2add grade to the sum of grades so far 3.3add one to the count of papers so far 4.Number of papers is now count of papers so far 5.Sum of all grades is now sum of grades so far

OF NOTE…

Sentence forms - control Sequence “Do this and then do that and then do the other and …” Decision/alternation “if this condition is true then do this else do that” “if this condition is true then do this” Repetition “for each/every/all do this” “repeat this until condition is true” “while this condition is true do this” “do this while condition holds”

Sentence forms - data Input “get value from user” Computation “compute this as some function of that” Output “print this message” “print/report this value” ERRORS Syntax Logical Run-time

Types & Layout (of algorithm steps) n.do step while condition indent 1.step 2.step 3.step 4.step Sequence n.if condition then nT step else nF step indent Decision n.while condition do step indent Repetition Any step can be replaced with one of the other types or input, output, assignment. n.for so many times do step