Problem Statement: You are given n points in a plane. Whenever we find three points that are collinear, we draw a line through them. How many different lines are there? Come up with an efficient algorithm. First, explain your solution. Then provide a code written in C++ or JAVA or python. Or you can just give me a clearly written pseudocode. Hints: 0. We take three points and see if they are collinear or not. If they are collinear, we determine the line's equation. And we store the slope and x intercept of that line in a map data structure. We store the pair (m,c) in a map of pairs. We store (m,c) because this pair defines the line. 1. Every time we find such a line, we save it's slope and x intercept. Suppose Pi,Pj and Pk are collinear. And the equation of the line is: y=mx+c Where m=yj−yixj−xi and c=yi(xj−xi)−xi(yj−yi)xj−xi We can store m and c as floating point values but that is prone to small errors. So, we can store m and c as irreducible fractions.  Suppose m=m1m2 and c=c1c2 where gcd(m1,m2)=1 and gcd(c1,c2)=1. We can store the pair (m,c) as a pair of pairs ((m1,m2),(c1,c2)). 2. For an efficient solution, remember the angular sort technique we used in Graham's Scan algorithm? Can we do the same here? Of course. 3. All values in the input will be integers.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Problem Statement: You are given n points in a plane. Whenever we find three points that are collinear, we draw a line through them. How many different lines are there? Come up with an efficient algorithm. First, explain your solution. Then provide a code written in C++ or JAVA or python. Or you can just give me a clearly written pseudocode.
Hints:
0. We take three points and see if they are collinear or not. If they are collinear, we determine the line's equation. And we store the slope and x intercept of that line in a map data structure. We store the pair (m,c) in a map of pairs. We store (m,c) because this pair defines the line.
1. Every time we find such a line, we save it's slope and x intercept.
Suppose Pi,Pj and Pk are collinear. And the equation of the line is: y=mx+c
Where m=yj−yixj−xi
and c=yi(xj−xi)−xi(yj−yi)xj−xi
We can store m and c as floating point values but that is prone to small errors. So, we can store m and c as irreducible fractions. 
Suppose m=m1m2 and c=c1c2 where gcd(m1,m2)=1 and gcd(c1,c2)=1.
We can store the pair (m,c) as a pair of pairs ((m1,m2),(c1,c2)).
2. For an efficient solution, remember the angular sort technique we used in Graham's Scan algorithm? Can we do the same here? Of course.
3. All values in the input will be integers.

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY