Algorithms (7A) Young Won Lim 4/18/17

Similar documents
Algorithms Overview (1A) Young Won Lim 3/29/18

Algorithms (7A) Young Won Lim 4/10/17

Functions (4A) Young Won Lim 5/8/17

Functions (4A) Young Won Lim 3/16/18

Binary Search Tree (2A) Young Won Lim 5/17/18

Eulerian Cycle (2A) Young Won Lim 4/26/18

Accessibility (1A) Young Won Lim 8/22/13

Binary Search Tree (3A) Young Won Lim 6/2/18

Pointers (1A) Young Won Lim 1/5/18

Pointers (1A) Young Won Lim 1/9/18

Structure (1A) Component

Pointers (1A) Young Won Lim 11/1/17

RAM (1A) Young Won Lim 11/12/13

Planar Graph (7A) Young Won Lim 5/21/18

Binary Search Tree (3A) Young Won Lim 6/4/18

The Complexity of Algorithms (3A) Young Won Lim 4/3/18

Applications of Pointers (1A) Young Won Lim 12/26/17

Planar Graph (7A) Young Won Lim 6/20/18

Pointers (1A) Young Won Lim 3/5/18

Applications of Arrays (1A) Young Won Lim 2/11/17

Tiny CPU Data Path (2B) Young Won Lim 5/2/16

COE428 Lecture Notes Week 1 (Week of January 9, 2017)

Class (1A) Young Won Lim 9/8/14

Overview (1A) Young Won Lim 9/25/17

Rational numbers as decimals and as integer fractions

Pointers (1A) Young Won Lim 1/14/18

Algorithms Bubble Sort (1B) Young Won Lim 4/5/18

Applications of Arrays (1A) Young Won Lim 3/15/17

Algorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48

FPGA Configuration (1C) Young Won Lim 12/1/13

Binary Search Tree (3A) Young Won Lim 6/6/18

Chapter 3, Algorithms Algorithms

Overview (1A) Young Won Lim 9/14/17

Function Overview (1A) Young Won Lim 10/23/17

Overview (1A) Young Won Lim 9/9/17

Memory Arrays (4H) Gate Level Design. Young Won Lim 3/15/16

GHCi: Getting started (1A) Young Won Lim 5/26/17

A Sudoku Solver Pruning (3A)

Eulerian Cycle (2A) Walk : vertices may repeat, edges may repeat (closed or open) Trail: vertices may repeat, edges cannot repeat (open)

Introduction to Programming in C Department of Computer Science and Engineering\ Lecture No. #02 Introduction: GCD

CSc 225 Algorithms and Data Structures I Case Studies

Operators (2A) Young Won Lim 10/2/13

Graph (1A) Young Won Lim 4/19/18

GAS Tutorial - 6. Expression

Polymorphism Overview (1A) Young Won Lim 2/20/18

Recursion & Performance. Recursion. Recursion. Recursion. Where Recursion Shines. Breaking a Problem Down

Operators (2A) Young Won Lim 10/5/13

Applications of Pointers (1A) Young Won Lim 3/31/18

Monad (1A) Young Won Lim 6/9/17

A Sudoku Solver (1A) Richard Bird Implementation. Young Won Lim 11/15/16

Pointers (1A) Young Won Lim 2/6/18

Arrays (1A) Young Won Lim 12/4/17

Monad Background (3A) Young Won Lim 11/20/17

Latch Based Design (1A) Young Won Lim 2/18/15

HW / SW Implementation Overview (0A) Young Won Lim 7/16/16

Applications of Pointers (1A) Young Won Lim 4/11/18

Pointers (1A) Young Won Lim 1/22/18

CORDIC Fixed Point Simulation. Young Won Lim 2/28/12

CS 6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK

Pointers (1A) Young Won Lim 2/10/18

And Now From a New Angle Special Angles and Postulates LEARNING GOALS

CS1800 Discrete Structures Fall 2017 October 25, CS1800 Discrete Structures Midterm Version B

1 Elementary number theory

Math Introduction to Advanced Mathematics

Haskell Overview III (3A) Young Won Lim 10/4/16

Arrays (1A) Young Won Lim 1/27/17

Lecture 2: Sorting and the Big O. Wednesday, 16 September 2009

Libraries (1A) Young Won Lim 6/5/17

Discrete Mathematics Lecture 4. Harper Langston New York University

COP 4516: Math for Programming Contest Notes

Applications of Pointers (1A) Young Won Lim 3/21/18

Haskell Overview IV (4A) Young Won Lim 10/13/16

Applications of Pointers (1A) Young Won Lim 3/14/18

Solutions to the Second Midterm Exam

JavaScript (5A) JavaScript

FPGA RAM (C1) Young Won Lim 5/13/16

Adders (A) Young Won Lim 10/7/13

Number System (1A) Young Won Lim 7/7/10

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Computational Complexity: Measuring the Efficiency of Algorithms

COMPUTER SCIENCE TRIPOS

Side Effects (3B) Young Won Lim 11/20/17

Applications of Pointers (1A) Young Won Lim 4/24/18

Discrete mathematics , Fall Instructor: prof. János Pach

Structure (1A) Young Won Lim 7/30/13

DESIGN AND ANALYSIS OF ALGORITHMS

CS 137 Part 7. Big-Oh Notation, Linear Searching and Basic Sorting Algorithms. November 10th, 2017

Monoid (4A) Young Won Lim 8/12/17

State Monad (3D) Young Won Lim 9/25/17

Standard Version of Starting Out with C++, 4th Edition. Chapter 19 Recursion. Copyright 2003 Scott/Jones Publishing

Memory (1A) Young Won Lim 9/7/17

Pointers (1A) Young Won Lim 12/4/17

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

The HTTP Protocol HTTP

Tree Traversal (1A) Young Won Lim 6/6/18

Example 1. Young Won Lim 11/17/17

Minimum Spanning Tree (5A) Young Won Lim 5/11/18

Applied Cryptography and Network Security

Tree Traversal (1A) Young Won Lim 5/26/18

Side Effects (3A) Young Won Lim 1/13/18

Transcription:

Algorithms (7A)

Copyright (c) 2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". Please send corrections (or suggestions) to youngwlim@hotmail.com. This document was produced by using OpenOffice and Octave.

Algorithms Flow chart of an algorithm (Euclid's algorithm) for calculating the greatest common divisor (gcd) two numbers a and b in locations named A and B. successive subtractions in two loops: IF the test B A, THEN B B A Similarly, IF A > B, THEN A A B. terminates when (the contents of) B is 0, yielding the g.c.d. in A. (Algorithm derived from Scott 2009:13; symbols and drawing style from Tausworthe 1977). https://en.wikipedia.org/wiki/algorithm Algorithms (7A) 3

Euclid Algorithm Euclid's method for finding the greatest common divisor (GCD) of two starting lengths BA and DC, both defined to be multiples of a common "unit" length. The length DC being shorter, it is used to "measure" BA, but only once because remainder EA is less than DC. EA now measures (twice) the shorter length DC, with remainder FC shorter than EA. Then FC measures (three times) length EA. Because there is no remainder, the process ends with FC being the GCD. On the right Nicomachus' example with numbers 49 and 21 resulting in their GCD of 7 (derived from Heath 1908:300). https://en.wikipedia.org/wiki/euclidean_algorithm Algorithms (7A) 4

Informal Definitions An informal definition could be "a set of rules that precisely defines a sequence of operations." which would include all computer programs, including programs that do not perform numeric calculations. Generally, a program is only an algorithm if it stops eventually. A prototypical example of an algorithm is the Euclidean algorithm to determine the maximum common divisor of two integers; https://en.wikipedia.org/wiki/algorithm Algorithms (7A) 5

Best, Worst, Average Case Complexities The best, worst and average case complexity refer to three different ways of measuring the time complexity (or any other complexity measure) of different inputs of the same size. Since some inputs of size n may be faster to solve than others. This complexity is only defined with respect to a probability distribution over the inputs. For instance, if all inputs of the same size are assumed to be equally likely to appear, the average case complexity can be defined with respect to the uniform distribution over all inputs of size n. https://en.wikipedia.org/wiki/algorithm Algorithms (7A) 6

Best, Worst, Average Case Complexities Best-case complexity: the complexity of solving the problem for the best input of size n. Worst-case complexity: the complexity of solving the problem for the worst input of size n. Average-case complexity: the complexity of solving the problem on an average. https://en.wikipedia.org/wiki/algorithm Algorithms (7A) 7

Upper and Lower Bounds To classify the computation time (or similar resources, such as space consumption), one is interested in proving upper and lower bounds on the minimum amount of time required by the most efficient algorithm solving a given problem. The complexity of an algorithm is usually taken to be its worst-case complexity, unless specified otherwise. Analyzing a particular algorithm falls under the field of analysis of algorithms. To show an upper bound T(n) on the time complexity of a problem, one needs to show only that there is a particular algorithm with running time at most T(n). However, proving lower bounds is much more difficult, since lower bounds make a statement about all possible algorithms that solve a given problem. https://en.wikipedia.org/wiki/algorithm Algorithms (7A) 8

Upper and Lower Bounds The phrase "all possible algorithms" includes not just the algorithms known today, but any algorithm that might be discovered in the future. To show a lower bound of T(n) for a problem requires showing that no algorithm can have time complexity lower than T(n). Upper and lower bounds are usually stated using the big O notation, which hides constant factors and smaller terms. This makes the bounds independent of the specific details of the computational model used. For instance, if T(n) = 7n 2 + 15n + 40, in big O notation one would write T(n) = O(n2). https://en.wikipedia.org/wiki/algorithm Algorithms (7A) 9

Upper and Lower Bounds Diagram of complexity classes provided that P NP. The existence of problems in NP outside both P and NP-complete in this case was established by Ladner.[3] https://en.wikipedia.org/wiki/algorithm Algorithms (7A) 10

Algorithm Analysis Graphs of number of operations, N vs input size, n for common complexities, assuming a coefficient of 1 https://en.wikipedia.org/wiki/algorithm Algorithms (7A) 11

Upper and Lower Bounds https://en.wikipedia.org/wiki/https://en.wikipedia.org/wiki/big_o_notation Algorithms (7A) 12

Upper and Lower Bounds https://en.wikipedia.org/wiki/https://en.wikipedia.org/wiki/big_o_notation` Algorithms (7A) 13

Big O Notation witness (C, k) f (x) C g(x) for x > k f (x) is O(g(x)) Discrete Mathematics, Rosen Algorithms (7A) 14

Big O Notation Examples witness (C, k) f (x) C g(x) for x > k f (x) is O(g(x)) x 2 +2 x+1 is O(x 3 ) 1 < x 1 < x 2 x < x 2 x 2 +2 x+1 < x 2 +2 x 2 + x 2 = 4 x 2 x 2 +2 x+1 < 4 x 2 Discrete Mathematics, Rosen Algorithms (7A) 15

f(x) = x 2 + 2x + 1, g(x) = x 2 Algorithms (7A) 16

The same class function examples x 2 x f 1 (2 x) 4 f 1 (x) f 2 (2 x) 4 f 2 (x) f 3 (2 x) 4 f 3 ( x) Algorithms (7A) 17

Growth Examples (1) 3 n 2 n n 4 n 3 3 n 2 n n 4 3 n 2 n n 4 n 3 n 3 Algorithms (7A) 18

Growth Examples (2) 3 n 2 n n 4 n 3 (log 2 n) 3 3 n 2 n n 4 n 3 n 3 Algorithms (7A) 19

References [1] http://en.wikipedia.org/ [2]