(Solved) : Someone Help Solve Question Hash Table Pseudo Code Fine Thank Q42767516 . . .

Can someone help solve this question about hash table? Justpseudo code is fine. Thank you!

Suppose we are given an array A containing n distinct points pi = (x, Yi), for i = 1,2,... ,n, in the 2-dimensional plane. Th

Suppose we are given an array A containing n distinct points pi = (x, Yi), for i = 1,2,… ,n, in the 2-dimensional plane. The coordinates xi and yi of each point pi in A are integers. Design an efficient algorithm that determines whether there exists a line y = ax + b with a e {-2,2} and bE Z that passes through at least two of the points in A. In other words, we are interested in designing an efficient algorithm that, given A, decides whether or not there exist at least two points in A that lie on the same line with slope -2 or on the same line with slope 2. See Figure 1 for examples. (As we recall from our calculus or geometry course, given the equation y = ax +b of a line, a is called the slope and b is called the intercept of the line.) a line l with slope 2 a line l with slope -2 2L 2L Figure 1: Left: A set of n points in which at least two of the points lie on the same line with slope 2. Right. A set of points in which at least two of the points lie on the same line with slope -2 A brute-force algorithm for the problem is as follows. For each pair (pi, Pi) of points in A, compute the line that goes through pi and pj. Then, check whether the slope of the line is either 2 or -2. If YES, then return YES and stop If none of the pairs of points go through a line with slope either 2 or -2 then return NO and stop. Since there are “1) pairs of points, the running time of the brute-force algorithm is O(n2) 2 The goal of the exercise is present a faster algorithm. Thus, design an algorithm for the problem that runs in O(n) expected time. You can use a hash table T of size n. You may also assume the existence of a hash function h Z 1,2,. , n} with simple uniform hashing. Do not forget to analyze the running time of your algorithm Show transcribed image text Suppose we are given an array A containing n distinct points pi = (x, Yi), for i = 1,2,… ,n, in the 2-dimensional plane. The coordinates xi and yi of each point pi in A are integers. Design an efficient algorithm that determines whether there exists a line y = ax + b with a e {-2,2} and bE Z that passes through at least two of the points in A. In other words, we are interested in designing an efficient algorithm that, given A, decides whether or not there exist at least two points in A that lie on the same line with slope -2 or on the same line with slope 2. See Figure 1 for examples. (As we recall from our calculus or geometry course, given the equation y = ax +b of a line, a is called the slope and b is called the intercept of the line.) a line l with slope 2 a line l with slope -2 2L 2L Figure 1: Left: A set of n points in which at least two of the points lie on the same line with slope 2. Right. A set of points in which at least two of the points lie on the same line with slope -2 A brute-force algorithm for the problem is as follows. For each pair (pi, Pi) of points in A, compute the line that goes through pi and pj. Then, check whether the slope of the line is either 2 or -2. If YES, then return YES and stop If none of the pairs of points go through a line with slope either 2 or -2 then return NO and stop. Since there are “1) pairs of points, the running time of the brute-force algorithm is O(n2) 2 The goal of the exercise is present a faster algorithm. Thus, design an algorithm for the problem that runs in O(n) expected time. You can use a hash table T of size n. You may also assume the existence of a hash function h Z 1,2,. , n} with simple uniform hashing. Do not forget to analyze the running time of your algorithm

Expert Answer


Answer to Can someone help solve this question about hash table? Just pseudo code is fine. Thank you!…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us