Closest Pair Design an algorithm to find the closest pair of points.

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
CircularTrip: An Effective Algorithm for Continuous kNN Queries Muhammad Aamir Cheema Database Research Group, The School of Computer Science and Engineering,
Closest Pair Given a set S = {p1, p2,..., pn} of n points in the plane find the two points of S whose distance is the smallest. Images in this presentation.
© Janice Regan Problem-Solving Process 1. State the Problem (Problem Specification) 2. Analyze the problem: outline solution requirements and design.
Chapter 1 pp 1-14 Properties of Algorithms Pseudocode.
Discrete Mathematics Lecture 4 Harper Langston New York University.
Lecture 14 Go over midterm results Algorithms Efficiency More on prime numbers.
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Andrew Kim Stephanie Cleto
Example Input: points p 1, p 2,…,p 8 in a plane. Find a line L 1 such that 4 points are on one side and the other 4 points are.
Classroom Presenter Crystal Hoyer Craig Prince Jonathan Su Richard Anderson.
CSE 830: Design and Theory of Algorithms
Lecture 33 CSE 331 Nov 20, Homeworks Submit HW 9 by 1:10PM HW 8 solutions at the end of the lecture.
CS1001 Lecture 23. Overview Incompleteness and the Halting Problem Incompleteness and the Halting Problem Methods in Artificial Intelligence Methods in.
Rewriting the book on Earthquake Locations Ethan Coon (APAM) Felix Waldhauser (LDEO)
Chapter 1 pp 1-14 Properties of Algorithms Pseudocode.
See the demo slide on the website. 4 Example 1: Whole Process H G F E D C B A Divide H G F E D C B A Merge G H E F C D A B Merge E F G H A B.
Lecture 6 Divide and Conquer for Nearest Neighbor Problem Shang-Hua Teng.
1 Comments for Assignment 1 Q1 is basic part and is also part of outcome 1. Q2 is for outcome 1. Q3 is for outcome 2. To pass outcome 1, you need to get.
CSE 421 Algorithms Richard Anderson Lecture 13 Divide and Conquer.
Syllabus 1. Go to Click Analysis of Algorithms link 4. bookmark course website  Important.
1 Algorithms and Analysis CS 2308 Foundations of CS II.
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
Lecture 4 Discrete Mathematics Harper Langston. Algorithms Algorithm is step-by-step method for performing some action Cost of statements execution –Simple.
Algorithm. An algorithm is a procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed.
1 Design and Analysis of Algorithms تصميم وتحليل الخوارزميات (311 عال) Chapter 1 Introduction to Algorithms.
Sort an array - the selection sort algorithm. Selection Sort Selection sort a classic computer algorithm that is used to sort an array The selection sort.
Algorithm Analysis Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 6 Algorithm Analysis Bernard Chen Spring 2006.
Introduction to algorithm design and recursion CS125 Spring 2007 Arthur Kantor.
Introduction to Computers (L02) * Hardware * Software * Programming Languages * Three Phase of Program Development * Development and Design Steps * Algorithms.
Introduction to Algorithms By Mr. Venkatadri. M. Two Phases of Programming A typical programming task can be divided into two phases: Problem solving.
Advanced Algorithms Analysis and Design By Syed Hasnain Haider.
What is Computer Science? “Computer Science is no more about computers than astronomy is about telescopes.” - Edsger Dijkstra “Computer Science is no more.
Quadratics Solving equations Using “Completing the Square”
Algorithms & Flowchart
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
Algorithm Analysis Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Program Design. The design process How do you go about writing a program? –It’s like many other things in life Understand the problem to be solved Develop.
UNIT-I INTRODUCTION ANALYSIS AND DESIGN OF ALGORITHMS CHAPTER 1:
UNIT 2 LESSON 6 CS PRINCIPLES. UNIT 2 LESSON 6 OBJECTIVES Students will be able to: Write an algorithm for solving the minimum spanning tree (MST) problem.
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
Hierarchical Clustering Produces a set of nested clusters organized as a hierarchical tree Can be visualized as a dendrogram – A tree like diagram that.
CS404 Design and Analysis of Algorithms BBy DDr. M V S Peri Sastry BB.E, PhD(BITS-Pilani)
Lecture 14 Lower Bounds Decision tree model Linear-time reduction.
1 Announcement Change of Venue for Tutorial Session #T01 and #TA1 from Week 6 to Week 13 (except in Week 8): Section Day Time T01 & TA1 Friday 15:00 -
Flowcharts C++ Lab. Algorithm An informal definition of an algorithm is: a step-by-step method for solving a problem or doing a task. Input data A step-by-step.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
Algorithm Analysis Lakshmish Ramaswamy. What Constitutes Good Software? Code correctness Good design Code reusability OO design can help us in achieving.
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.
1 The Role of Algorithms in Computing. 2 Computational problems A computational problem specifies an input-output relationship  What does the.
Algorithms 09/04/13. Algorithm Step-by-step process for solving a problem. Often described in pseudocode language. Unambiguous, Executable and Terminating.
Chapter 2. Divide-and-conquer Algorithms
Modulo-2 Digital coding uses modulo-2 arithmetic where addition becomes the following operations: 0+0= =0 0+1= =1 It performs the.
Stroke Geometry CSE 490ra.
CMIS 102 Education for Service-- snaptutorial.com
Introduction to pseudocode
Find 4 A + 2 B if {image} and {image} Select the correct answer.
Punya Biswas Lecture 15 Closest Pair, Multiplication
Sorting “Example” with Insertion Sort
Algorithms Key Revision Points.
Algorithms.
Convex Hulls Given a set of points (x1,y1),(x2,y2),…,(xn,yn), the convex hull is the smallest convex polygon containing all the points.
What do you do when you don’t know how to get started.
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
WJEC GCSE Computer Science
Advanced Algorithms Analysis and Design
Design and Analysis of Algorithms
Presentation transcript:

Closest Pair Design an algorithm to find the closest pair of points

Closest Pair Designing algorithms is more of an art than a science.

Closest Pair Visually this problem is very simple to solve, but what if I gave you 1 million points?

Closest Pair What if I asked you to solve this problem for 1 million different cases?

Closest Pair What is the input? What is the output? What are the precise step-by-step instructions? Will the algorithm terminate? Will it produce correct answers all the time? How much time will it take to solve? How much memory is required to solve the problem?

Closest Pair The input: 2D point, a pair values (x, y) –Point p; –p.x; –p.y; An array of n Points –Point P[n] –P[0], P[1], P[2], P[3], …, P[n-1]

Closest Pair The output: Two points P[a] and P[b] where the distance between P[a] and P[b] is minimum among all possible pairs of points. Sometimes describing the output with precision gives you clues about how to solve the problem.

Closest Pair 1. How do you compute the distance between to points? 2. How do you find a distance is minimum among all possible pairs of points?

Closest Pair dist(a,b){ d = sqrt[ pow((a.x – b.x),2) + pow((a.y – b.y),2) ]; return d; }

Closest Pair d = dist(P[0], P[1]); Compare all possible pairs of points, i.e., compare P[0] with P[1], P[2], P[3], …, P[n-1] compare P[1] with P[2], P[3], P[4], …, P[n-1] compare P[2] with P[3], P[4], P[5], …, P[n-1] compare P[3] with P[4], P[5], P[6], …, P[n-1] … compare P[n-3] with P[n-2], P[n-1] compare P[n-2] with P[n-1]

Closest Pair ClosestPair(P[ ], n) { min_dist = dist(P[0],P[1]); for (x = 1 to n-1) { d = dist(P[0], P[x]); if (d < min_dist) { min_dist = d; } return min_dist; } This is not correct!

Closest Pair ClosestPair(P[ ], n) { min_dist = dist(P[0],P[1]); for (y = 0 to n-1) { for (x = 1 to n-1) { d = dist(P[y], P[x]); if (d < min_dist) { min_dist = d; }} return min_dist; }

Closest Pair Compare P[a] and P[b] a b n n-1

Closest Pair Compare P[a] and P[b] a b n-1 0 X 1 X 2 X 3 X... X n-1 X

Closest Pair Compare P[a] and P[b] a b n-1 0 X 1 X 2 X 3 X... X n-1 X

Closest Pair ClosestPair(P[ ], n) { min_dist = dist(P[0],P[1]); for (y = 0 to n-1) { for (x = y+1 to n-1) { d = dist(P[y], P[x]); if (d < min_dist) { min_dist = d; }} return min_dist; }

Closest Pair This matrix is n x n = n 2 entries. How many of these n 2 entries must we compute? a b n n-1

Summations n-1 + n-2 + n