Problem Analysis September 18, 2015 CSE 232, Shane Carr.

Slides:



Advertisements
Similar presentations
Recursion Chapter 14. Overview Base case and general case of recursion. A recursion is a method that calls itself. That simplifies the problem. The simpler.
Advertisements

1 Constraint Satisfaction Problems A Quick Overview (based on AIMA book slides)
Efficient access to TIN Regular square grid TIN Efficient access to TIN Let q := (x, y) be a point. We want to estimate an elevation at a point q: 1. should.
A simple example finding the maximum of a set S of n numbers.
Types of Algorithms.
CS4413 Divide-and-Conquer
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 6 Ack : Carola Wenk nad Dr. Thomas Ottmann tutorials.
Robert Pless, CS 546: Computational Geometry Lecture #3 Last Time: Convex Hulls Today: Plane Sweep Algorithms, Segment Intersection, + (Element Uniqueness,
Algorithm Design Strategy Divide and Conquer. More examples of Divide and Conquer  Review of Divide & Conquer Concept  More examples  Finding closest.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Recursion Chapter 7. Spring 2010CS 2252 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn how.
CS 206 Introduction to Computer Science II 10 / 14 / 2009 Instructor: Michael Eckmann.
Fall 2007CS 2251 Recursion Chapter 7. Fall 2007CS 2252 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method.
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
6/29/20151 Efficient Algorithms for Motif Search Sudha Balla Sanguthevar Rajasekaran University of Connecticut.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances.
Please open your laptops, log in to the MyMathLab course web site, and open Daily Quiz 18. You will have 10 minutes for today’s quiz. The second problem.
Math Pacing Graphing Inequalities in Two Variables.
Lecture 6 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
UNC Chapel Hill M. C. Lin Point Location Reading: Chapter 6 of the Textbook Driving Applications –Knowing Where You Are in GIS Related Applications –Triangulation.
Technical Interviews Shane Carr CSE 232, September 11, 2015.
Splash Screen Lesson 5 Contents Example 1Identify Linear Equations Example 2Graph by Making a Table Example 3Use the Graph of a Linear Equation Example.
Data Structures and Algorithm Analysis Hashing Lecturer: Jing Liu Homepage:
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture8.
Recursion Chapter 7. Chapter Objectives  To understand how to think recursively  To learn how to trace a recursive method  To learn how to write recursive.
Reynolds 2006 Complexity1 Complexity Analysis Algorithm: –A sequence of computations that operates on some set of inputs and produces a result in a finite.
Copyright © 2015, 2011, 2007 Pearson Education, Inc. 1 1 Chapter 4 Systems of Linear Equations and Inequalities.
Week 5 - Monday.  What did we talk about last time?  Linked list implementations  Stacks  Queues.
Solving Linear Equations = 13 What number would make this equation true? That is, what value of would make the left side equal to the right side?
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
Analyzing Complexity of Lists OperationSorted Array Sorted Linked List Unsorted Array Unsorted Linked List Search( L, x ) O(logn) O( n ) O( n ) Insert(
Jessie Zhao Course page: 1.
Algorithm Fundamentals Shane Carr CSE 232, Fall 2015.
MA/CSSE 473 Day 23 Student questions Space-time tradeoffs Hash tables review String search algorithms intro.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
Hashing Fundamental Data Structures and Algorithms Margaret Reid-Miller 18 January 2005.
Course 8 Contours. Def: edge list ---- ordered set of edge point or fragments. Def: contour ---- an edge list or expression that is used to represent.
Types of Algorithms. 2 Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together We’ll talk about a classification.
Lecture 7 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Sorting. Sorting Sorting is important! Things that would be much more difficult without sorting: –finding a telephone number –looking up a word in the.
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
A Different Solution  alternatively we can use the following algorithm: 1. if n == 0 done, otherwise I. print the string once II. print the string (n.
3.2 Solving Systems Algebraically When you try to solve a system of equations by graphing, the coordinates of the point of intersection may not be obvious.
Chapter 7.3.  Objective NCSCOS 4.03  Students will know how to solve a system of equations using addition.
CSE 311 Foundations of Computing I Lecture 24 FSM Limits, Pattern Matching Autumn 2011 CSE 3111.
Chapter 9 Recursion © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Computational Geometry
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Chapter 3 Systems of Equations. Solving Systems of Linear Equations by Graphing.
Elimination Method - Systems. Elimination Method  With the elimination method, you create like terms that add to zero.
Computational Geometry
Subject Name: Design and Analysis of Algorithm Subject Code: 10CS43
Modeling with Recurrence Relations
Chapter 4 Divide-and-Conquer
Computer Science 2 Hashing
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
Data Structures Review Session
CMPS 3130/6130 Computational Geometry Spring 2017
Warm Up Solve. 1. 2x + 9x – 3x + 8 = –4 = 6x + 22 – 4x 3. + = 5
CSE 373: Data Structures and Algorithms
Ch. 2: Getting Started.
15th Scandinavian Workshop on Algorithm Theory
11.6 Systems of Equations.
Divide and Conquer Merge sort and quick sort Binary search
Presentation transcript:

Problem Analysis September 18, 2015 CSE 232, Shane Carr

Down By The Bay: Language Stats

Five Strategies Based on those in CtCI and CP3 Brute Force and Fix Base Case and Build Simplify and Generalize Reduce and Relate Do It Yourself

Brute Force and Fix 1. Bottlenecks: Focus on improving the slowest step.  Improving a faster step won’t improve your overall time complexity. 2. Unnecessary Work: Reduce your search space.  Are there cases you’re testing that are redundant? 3. Duplicated Work: Eliminate repeated sub-computations.  Think Fibonacci. Print all positive integer solutions to the equation a 3 + b 3 = c 3 + d 3 subject to the constraints 0 < a < b < < c < d < 1000 a < c CtCI chapter VII

Base Case and Build  Model the problem as a recurrence.  Suppose you were handed the solution to a problem of size N-1. How could you use that information to solve the problem of size N?  Can you split the problem in half, solve each half, and combine the two halves back together? (D&C) Given an array of distinct integer values, count the number of pairs of integers that have difference k. For example, given the array {1, 7, 5, 9, 2, 12, 3} and the difference k=2, you would find the pairs (1,3), (3,5), (5,7), and (7,9). CtCI chapter VII

Simplify and Generalize  Are there constraints you can add or remove from the problem?  Try solving a trivial case, and incrementally make it more difficult until you get the original problem. There is an ant standing at each vertex of a polygon with N sides. If each ant chooses a direction at random and starts walking at the same speed along the edges of the polygon, what is the probability that two ants will run into each other? CtCI problem 6.4

Reduce and Relate  Setting aside the problem’s theme for a moment, does it sound like something we studied before in this class?  Telltale Signs  Graph problems  Binary trees  Strings  Points / Geometry The Prussian Parakeet is known for its unusual mating pattern. At sunrise on April 1 every year, each parakeet flies toward its nearest neighbor, meeting it at the midpoint between their original locations. Given a list of coordinates of parakeets, determine the first point at which mating will occur. Assume all parakeets fly at the same speed.

Do It Yourself  Guess what: you’re a human! Humans are smart!  Try solving the example input yourself. How did you do it? Does it give a hint to an efficient algorithm that a computer could use? You are given two strings of length N. Can you determine is one is an anagram of the other? For example, given the strings “programming” and “imronmrgpag”, you would return True. CtCI problem 1.2

One possible problem- solving process Solve the example input by hand. Think about the problem as a recurrence. Simplify the problem down to a few easy cases. Look for bottlenecks, duplicated work, and unnecessary work. Consider how a new data structure like a Hash Table could help.

Examples How would you solve each of these problems?

Example 1: Palindromes You are given a string of length N. Can you determine if it is a permutation (anagram) of a palindrome? For example, given “Tact Coa”, you would return True, since that string is an anagram of “Taco Cat”. CtCI problem 1.4

Example 2: One Away You are given two strings of lengths M and N, M≤N. You are allowed to make three kinds of edits: insert, remove, and replace. Can you determine if the two strings are one edit (or zero edits) away from each other? For example: PALE, PLE -> truePALES, PALE -> true PALE, BALE -> truePALE, BAE -> false CtCI problem 1.5

Example 3: Intersection You are given two singly linked lists. Determine if the two lists intersect. 3 -> 1 -> 5 -> 9 -> 7 -> 2 -> 1 4 -> 6 --^ 3 -> 1 -> 5 -> 9 -> 7 -> 2 -> 1 4 -> 6 -> 7 -> 2 -> 1 CtCI problem 2.7