Getting to places from my house...

Similar documents
Computing and Programming

Computing and Programming. Notes for CSC The Beauty and Joy of Computing The University of North Carolina at Greensboro

Algorithms Part 2: Measuring Time

Computing and Programming

Data Representation. Class Reminders. From Last Time... Interpreting bits to give them meaning. Part 2: Hexadecimal and Practical Issues

Data Representation. Interpreting bits to give them meaning. Part 2: Hexadecimal and Practical Issues

Algorithms. Definition. Algorithms we've seen... Part 1: The Basics

Organizing Data. Reminders. A Flood of Data. The Power of Structure...

What is a Fraction? Fractions. One Way To Remember Numerator = North / 16. Example. What Fraction is Shaded? 9/16/16. Fraction = Part of a Whole

Computing and Programming

Organizing Data The Power of Structure...

Types of recursion. Structural vs. general recursion. Pure structural recursion. Readings: none. In this module: learn to use accumulative recursion

Lecture #3: Recursion

Math 4242 Fibonacci, Memoization lecture 13

Lecture #3: Recursion

CSC 148 Lecture 3. Dynamic Typing, Scoping, and Namespaces. Recursion

Types of recursion. Readings: none. In this module: a glimpse of non-structural recursion. CS 135 Winter : Types of recursion 1

The Internet Part 1: Local Area Network Communication

(Refer Slide Time: 01.26)

# track total function calls using a global variable global fibcallcounter fibcallcounter +=1

Search,Sort,Recursion

CSC 101: Lab Manual#9 Machine Language and the CPU (largely based on the work of Prof. William Turkett) Lab due date: 5:00pm, day after lab session

The Beauty and Joy of Computing

The Beauty and Joy of Computing Quest (first exam) in in 16 days!! Lecture #3 : Functions

GEO 425: SPRING 2012 LAB 9: Introduction to Postgresql and SQL

The Beauty and Joy of Computing

Divide and Conquer CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang

Data Representation. Interpreting bits to give them meaning. Part 1: Numbers, Bases, and Binary

Divide and Conquer CISC4080, Computer Algorithms CIS, Fordham Univ. Acknowledgement. Outline

Introduction to Fractions

Do you remember any iterative sorting methods? Can we produce a good sorting method by. We try to divide and conquer: break into subproblems

CISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts)

Google Drive: Access and organize your files

CSC 222: Object-Oriented Programming. Spring 2012

CAD Algorithms. Categorizing Algorithms

The Beauty & Joy of Computing

CSE 2123 Recursion. Jeremy Morris

UEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter

Module 05: Types of recursion

INF2220: algorithms and data structures Series 1

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #17. Loops: Break Statement

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Module 02 Lecture - 45 Memoization

Introduction to Data Structure

MITOCW ocw f99-lec12_300k

The Traveling Salesman Problem Outline/learning Objectives The Traveling Salesman Problem

CSC236 Week 4. Larry Zhang

The Beauty and Joy of Computing

Teaching Math thru Big Ideas Focusing on Differentiation. Marian Small April 2017 San Diego, CA

Technical Interviews Kenny Yu

Last Class: Deadlocks. Where we are in the course

Mergesort again. 1. Split the list into two equal parts

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2010

Math Day 2 Programming: How to make computers do math for you

ESc101 : Fundamental of Computing

Lecture Notes, CSE 232, Fall 2014 Semester

C22a: Problem Solving using Recursion

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Dynamic Programming I Date: 10/6/16

CS 151. Recursion (Review!) Wednesday, September 19, 12

Chapter 8 Algorithms 1

1 Probabilistic analysis and randomized algorithms

CSC 1052 Algorithms & Data Structures II: Linked Lists Revisited

Binary Trees

Today. Types of graphs. Complete Graphs. Trees. Hypercubes.

Recursion CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011

Operational Semantics 1 / 13

Data Representation. Reminders. Sound What is sound? Interpreting bits to give them meaning. Part 4: Media - Sound, Video, Compression

Integrating Microsoft Office Learn about object linking and embedding (OLE) Tutorial 1 Integrating Word and Excel

n! = 1 * 2 * 3 * 4 * * (n-1) * n

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

The Beauty and Joy of Computing

CSE 373: Data Structures and Algorithms

Data structures. Priority queues, binary heaps. Dr. Alex Gerdes DIT961 - VT 2018

Lecture 16: Sorting. CS178: Programming Parallel and Distributed Systems. April 2, 2001 Steven P. Reiss

1. CONVEX POLYGONS. Definition. A shape D in the plane is convex if every line drawn between two points in D is entirely inside D.

Manual Data Validation Excel 2010 List From Another Workbook

CSC 421: Algorithm Design Analysis. Spring 2013

Halting Measures and Termination Arguments

Bits and Bytes. Here is a sort of glossary of computer buzzwords you will encounter in computer use:

ECE 122. Engineering Problem Solving Using Java

How do we get from what we know (score of data given a tree) to what we want (score of the tree, given the data)?

The divide and conquer strategy has three basic parts. For a given problem of size n,

CSC148, Lab #4. General rules. Overview. Tracing recursion. Greatest Common Denominator GCD

What is a minimal spanning tree (MST) and how to find one

Architectural Documentation 1

The Internet. Warning... In-class exercise: You are the network! Basic Communication and Security

Recursion. CSE 2320 Algorithms and Data Structures University of Texas at Arlington

1 Dynamic Programming

Resources matter. Orders of Growth of Processes. R(n)= (n 2 ) Orders of growth of processes. Partial trace for (ifact 4) Partial trace for (fact 4)

Algorithm. An algorithm is a computational process for solving a problem. computational: a computer must be able to perform the steps of the process

COUNTING AND CONVERTING

Introduction to Engineering Using Robotics Laboratories Algorithms

How Pixar Tells a Story By Rachel Slivnick 2018

Data parallel algorithms 1

USER GUIDE. Lync Standard. Contents. This guide will take you through the step by step features of Lync Standard. 1. Starting Lync

Introduction to Concurrent Software Systems. CSCI 5828: Foundations of Software Engineering Lecture 08 09/17/2015

The Beauty and Joy of Computing

THINGS WE DID LAST TIME IN SECTION

O(1) How long does a function take to run? CS61A Lecture 6

Chapter 9: Quality Control (QC)

Lecture #2. 1 Overview. 2 Worst-Case Analysis vs. Average Case Analysis. 3 Divide-and-Conquer Design Paradigm. 4 Quicksort. 4.

Transcription:

Reductions, Self-Similarity, and Recursion Relations between problems Notes for CSC 100 - The Beauty and Joy of Computing The University of North Carolina at Greensboro Getting to places from my house... Now I buy a new house!

Get anywhere by first going to old house Things to notice... What I want to do... What I know how to do... Things to notice... What I want to do... What I know how to do... Terminology: I have reduced the problem of traveling from my new house to the problem of traveling from my old house. Important points: Solution is easy to produce (often easier than direct solution) Solution is easy and compact to describe Solution may not be the most efficient to execute

Things to notice... What I want to do... What I know how to do... Question: Is a reduction a property of problems or algorithms? Things to notice... Problem Problem Reductions are between problems The reduction operation is an algorithm Abstraction: We don't care how the "known algorithm" works! The Basics A reduction is using the solution of one problem (problem A) to solve another problem (problem B). We say "problem B is reduced to problem A". Reductions are a fundamental "big idea" in computer science Lots of types of reductions - you could spend a lifetime studying this! Our reductions use a small amount of work in addition to a constant number of calls to problem A. As a result, can say problem B is not much harder than problem A True even if we don't know the most efficient way to solve problem A!

An example from Lab 4 To find least common multiple (LCM): An example from Lab 4 To find least common multiple (LCM): But if you already have GCD What have we done? We have reduced the problem of computing LCM to the problem of computing GCD. An example from Lab 4 To find least common multiple (LCM): Not a great algorithm... But if you already have GCD What have we done? We have reduced the problem of computing LCM to the problem of computing GCD. So: LCM is no harder computationally than GCD. And remember... Euler's algorithm is a very efficient GCD algorithm!

Similarity and Self-Similarity Reducing LCM to GCD identifies similarities between the two problems. Many problems are structured so that solutions are "self-similar" - large solutions contain solutions to smaller versions of the same problem! Example: Recall sum of list items as parallel algorithm - each thread solved a smaller version of the same problem! An algorithm can solve a large problem by breaking it down to smaller versions of the same problem - this is called recursion. Example: Adding up a list Sum of 20 items ( = 76) 7 2 3 1 5 4 3 2 5 8 6 8 3 5 3 2 2 4 2 1 Sum of 19 items ( = 75) + 76 Example: Adding up a list Sum of 20 items ( = 76) 7 2 3 1 5 4 3 2 5 8 6 8 3 5 3 2 2 4 2 1 Sum of 19 items ( = 75) + 76

Breaking it down Base case: Handling smallest case directly Recursive case: Solving a smaller version of the same problem. Constant amount of work to use answer from subproblem to compute answer to overall problem. Breaking it down Workhorse Function Base case: Handling smallest case directly Recursive case: Solving a smaller version of the same problem. Driver Function Constant amount of work to use answer from subproblem to compute answer to overall problem. Driver function: sets up first call to recursion Another example: Sorting "Selection sort" from algorithms lab:

Another example: Sorting "Selection sort" from algorithms lab: Recursive version: Base case: One item - nothing to do! Setting up recursion: Swap max item to last position Recursion: Sort all the rest Summary Finding relations between problems can simplify solutions: Sometimes relations between different problems (reductions) Sometimes relation to smaller version of the same problem (recursion) What you should know: Recognize reductions and recursion Understand the basic principles We will explore this more in a lab!