Chapter 1 pp 1-14 Properties of Algorithms Pseudocode.

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

MATH 224 – Discrete Mathematics
Lecture 19. Reduction: More Undecidable problems
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Computability & Complexity. Scenario I can’t write this program because I’m too dumb.
Closest Pair Design an algorithm to find the closest pair of points.
Today’s Agenda  Correctness Issues. Why Correctness?  Programming is engineering Program is a product Program quality to be determined during production.
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
CPSC 411, Fall 2008: Set 12 1 CPSC 411 Design and Analysis of Algorithms Set 12: Undecidability Prof. Jennifer Welch Fall 2008.
1 Module 2: Fundamental Concepts Problems Programs –Programming languages.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Lecture 2: Fundamental Concepts
1 Module 2: Fundamental Concepts Problems Programs –Programming languages.
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
Lecture 14 Go over midterm results Algorithms Efficiency More on prime numbers.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
CSE 830: Design and Theory of Algorithms
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Unit 171 Algorithms and Problem Solving  Introduction  Algorithm Design  Algorithm Properties  Algorithm Control Flow  Examples  Comparing Algorithms.
Chapter 1 pp 1-14 Properties of Algorithms Pseudocode.
Analysis of Algorithms CS 477/677
CS 280 Data Structures Professor John Peterson. Big O Notation We use a mathematical notation called “Big O” to talk about the performance of an algorithm.
1 Algorithms and Problem Solving. 2 Outline  Problem Solving  Problem Solving Strategy  Algorithms  Sequential Statements  Examples.
Syllabus 1. Go to Click Analysis of Algorithms link 4. bookmark course website  Important.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
The Fundamentals: Algorithms, the Integers & Matrices.
1 Design and Analysis of Algorithms تصميم وتحليل الخوارزميات (311 عال) Chapter 1 Introduction to Algorithms.
Algorithms: Selected Exercises Goals Introduce the concept & basic properties of an algorithm.
February 17, 2015Applied Discrete Mathematics Week 3: Algorithms 1 Double Summations Table 2 in 4 th Edition: Section th Edition: Section th.
Computability and Modeling Computation What are some really impressive things that computers can do? –Land the space shuttle (and other aircraft) from.
Programming & Data Structures
Discrete Structures Lecture 11: Algorithms Miss, Yanyan,Ji United International College Thanks to Professor Michael Hvidsten.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
26 Sep 2014Lecture 3 1. Last lecture: Experimental observation & prediction Cost models: Counting the number of executions of Every single kind of command.
Introduction to algorithm design and recursion CS125 Spring 2007 Arthur Kantor.
Fall 2002CMSC Discrete Structures1 Enough Mathematical Appetizers! Let us look at something more interesting: Algorithms.
ALGORITHM CHAPTER 8. Chapter Outlines and Objectives  Define an algorithm and relate it to problem solving.  Define three construct and describe their.
MCA-2012Data Structure1 Algorithms Rizwan Rehman CCS, DU.
Introduction to Data Structures and Algorithms CS 110: Data Structures and Algorithms First Semester,
CSCI 3160 Design and Analysis of Algorithms Tutorial 10 Chengyu Lin.
Chapter Algorithms 3.2 The Growth of Functions 3.3 Complexity of Algorithms 3.4 The Integers and Division 3.5 Primes and Greatest Common Divisors.
1 Algorithms CS 202 Epp section ??? Aaron Bloomfield.
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
Algorithms 1.Notion of an algorithm 2.Properties of an algorithm 3.The GCD algorithm 4.Correctness of the GCD algorithm 5.Termination of the GCD algorithm.
Recursion Chapter 11. How it works “A recursive computation solves a problem by using the solution of the same problem with simpler inputs” Big Java,
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
P, NP, and NP-Complete Problems Section 10.3 The class P consists of all problems that can be solved in polynomial time, O(N k ), by deterministic computers.
How Computers Solve Problems Computers also use Algorithms to solve problems, and change data into information Computers can only perform one simple step.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
CompSci Today’s Topics Computer Science Noncomputability Upcoming Special Topic: Enabled by Computer -- Decoding the Human Genome Reading Great.
The material in this lecture should be review. If you have not seen it before, you should be able to learn it quickly – and on your own. So we are going.
CSE15 Discrete Mathematics 03/06/17
Algorithms and Problem Solving
Growth of Functions & Algorithms
Applied Discrete Mathematics Week 2: Functions and Sequences
Data Structures and Algorithms
GC211Data Structure Lecture2 Sara Alhajjam.
Enough Mathematical Appetizers!
Computation.
Algorithms Chapter 3 With Question/Answer Animations
Applied Discrete Mathematics Week 6: Computation
Algorithms and Problem Solving
Enough Mathematical Appetizers!
Enough Mathematical Appetizers!
Algorithms.
Discrete Mathematics CS 2610
Presentation transcript:

Chapter 1 pp 1-14 Properties of Algorithms Pseudocode

What is an algorithm? You tell me.

Algorithms step by step method for solving a problem. formal solution method implementing a problem solution with computer code is pretty darn formal

Algorithms have properties Input Output Precision Determinism Finiteness Correctness Generality

Examples first Lets look at an example first and we’ll try to identify the properties. 1. Max of three numbers 2. Shortest pair problem

Max of 3 numbers int Max(int a, int b, int c) { if (a > b) { if (a > c) return a; else return c; } else { if (b > c) return b; else return c; }

Max of 3 Input: 3 numbers a, b, and c Output: 1 number that is the max of a, b, and c. (duh?) Is the algorithm precisely defined? What would an imprecise algorithm look like? Code by its very nature is precise.

Determinism Same input, same steps  Some outcome Non-determinism –Same input, same steps  Different outcome Code by its nature is deterministic How do your write a non-deterministic program?

Finiteness Will it run infinitely? The definition of an algorithm is a formally defined solution to a problem. Is it really a solution if it runs forever?

Correctness It is very easy to write incorrect code. Verifying correctness is wicked hard This is where proofs come in handy.

Generality Can the algorithm be applied to all sets of possible input? Here an algorithm that is correct but not general. int max(a, b) { if (a > 10 && b < 10) return a; }

Pseudocode resembles C++ and Java like short-hand max(a,b) { if a > b return a else return b } This is where algorithms get imprecise

Pseudocode easier to specify loops easier to define data structures mystery(a[], n, x) { for i = 0 to n-1 if (x == a[i]) return true return false; }

Example: Shortest pair Given n points (x,y)-pairs –Where x and y are real numbers. Return the distance of the two closest points. –You could also return the two points Describe how you would solve this in words.

Example: Shortest pair Given n points (x,y)-pairs –Where x and y are real numbers. Return the distance of the two closest points. –Also return the two points Describe how you would solve this in words. #1 INPUT: Here the input is well-defined #2 OUTPUT: The details here can have big impact on the actual algorithm #3 PRECISION: Some algorithms can be precisely described with word, some cannot.

Example: Shortest pair Compute the distance between every pair of points. Return the two points with minimum distance #3 PRECISION: This is not precise because important details are not described: 1. Computing Distance is not trivial 2. Iterating over every pair of points is not a simple operation.

Example: Shortest pair Input: An array of n points p[i] Output: A distance d, which is the minimum among all pairs of points Algorithm: d = ; for i = 1 to n for j = i+1 to n temp = dist(p[i], p[j]) if (temp < d) d = temp return d;

Example: Shortest pair float dist(a, b) { return sqrt((a.x – b.x) 2 + (a.y – b.y) 2 ); } Is this as precise as you can get? BTW, there are six mathematical operations here Two ( – ) one clock cycle each One ( + ) one clock cycle Two ( * ) one clock cycle each One ( sqrt function ) ? clock cycles