The main observation pertinent to designing this algorithm is that, as the convex hull requires at least three points, if the convex hull has to be a triangle, then there is a fixed choice of points that can be the vertices of the hull.
Consider the point with the smallest y coordinate. If there are
multiple, choose the one with the smallest x coordinate. Denote
this by
. This point must be a vertex for the convex hull.
The reason for this is simple. If this point is not a vertex, then
it must be generated by a convex combination of the vertices. But,
any other vertex either has a higher x coordinate or a higher y
coordinate. Thus, we derive a contradiction.
Note that this can be carried out in O(n) time.
Now, for each point
, do the following. Calculate the angle the vector from
to
makes with the horizontal ray going outwards in the positive-x
direction. Choose the two points which have the highest and the
lowest angle. If there are multiple points for either the highest
or the lowest angle, choose the ones with the highest
distance.
The newly chosen points now are the candidate vertices for the
triangle convex hull. As argued earlier, say the point with the
maximum angle is not a vertex. Then any other point will have angle
lower than it, thus the angle made by any point which is a convex
combination will have angle lower than the maximum. This is a
contradiction. Similar argument proves this for the point with the
smallest angle.
Note that this can also be done in O(n) time.
Finally, all that remains to check is that all the points belong
to the convex hull of the three chosen points. This is equivalent
to checking whether a point lies in the interior of a triangle.
This is easy to check.
Let
be the vertices of the triangle and
is the vertex to check. Consider the equation of the line joining
. Let this be
. Substitute the coordinates for
and
into the LHS of this equation and check if they give the same
sign. If yes, do this for the other two pairs
and
. If all three checks succeed, the point is in the interior,
otherwise not.
Again, this step takes O(n) time.
This completes the algorithm. Comment in case of any doubts.
5. (570/470 bonus) Design an algorithm whose input is a list of n points, (xu, )...
9. (5 points) Please describe an algorithm that takes as input a list of n integers and finds the number of negative integers in the list. 10. (5 points) Please devise an algorithm that finds all modes. (Recall that a list of integers is nondecreasing if each term of the list is at least as large as the preceding term.) 11. (5 points) Please find the least integer n such that f() is 0(3") for each of these functions f()...
Problem 1 (5+15 points) Consider the set P of n points and suppose we are given the points of P one point at a time. After receiving each point, we compute the convex hull of the points seen so far. (a) As a naive approach, we could run Graham’s scan once for each point, with a total running time of O(n2 log n). Write down the pesuedocode for this algorithm. (b) Develop an O(n2) algorithm to solve the problem. Write...
Design an O(n) algorithm that determines whether or not there is a majority in a list of elements. For example, [3,2,1] is NO and [3,1,3] is YES. I want an answer that doesn't require the use of dictionaries/hash maps. It cannot be "Moore's voting algorithm" or a variation of it. The algorithm also can not use linear sorting algorithms because the input can not be assumed to satisfy the required conditions for any of the linear sorting algorithms my professor...
Give an algorithm for the following problem. The input is made up of two se- quences of n numbers: 01, A2, ..., an and b1,b2, ..., bn. Your algorithm should determine whether or not there is some i and j, where 1 si, j = n, such that az = bj. You should use universal hashing families , and your algorithm should run in an expected time of O(n). Provide inctification that your algorithm is correct and runs in the...
C-22.5 Design an O(n)-time algorithm to test whether a given n-vertex polygon is convex. You should not assume that P is simple.
a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n positive integers and determines whether there are two distinct elements of the list that have as their sum a third element of the list. That is, whether there exists i, j.k such that iヂj, i关k,j关k and ai + aj = ak. The algorithm should loop through all triples of elements of the list checking whether the sum of the first two is the third...
(d) Consider an algorithm A, whose runtime is dependent on some "size" variable n of the input. Explain the difference between the two statements below, and give an explicit example of an algorithm for which one statement is true but the other is false. 1. The worst case time complexity of A is n2. 2. A is O(n). (e) Give an example of an algorithm (with a clear input type) which has a Big-Oh (0) and Big-Omega (12) bound on...
help in design of algorithm answers with steps for study guide (2 points) Why shouldn't we measure time efficiency based on the number of seconds or milliseconds it takes the algorithm 1. to run? is the number of times the most important operation of the (2 points) The 2. algorithm occ Ccurs (3 points) Find the binary representation of the following numbers: 3. BINARY REPRESENTATION (in bits) NUMBER 777 14 684,739 4. (8 points) Write the input size metric and...
2. Design a deterministic algorithm to solve the following problem. input: A directed acyclic graph G = (V, E) stored using adjacency lists. output: A Hamiltonian path, if such a path exists. Otherwise, return NONE. Your algorithm must take O(|V| + |E|) time. You must describe your algorithm in plain English (no pseudocode) and you must explain why the running time of your algorithm is O(|V| + |E|). Maximum half a page
Consider the algorithm to find the closest pair of points in the plane. Let's say you wanted to generalize the algorithm to find the two closest pairs of points in the plane given a set of (unsorted) points (p1, py. Give an algorithm for finding the two distances for this pair. In the step to conquer the two subproblems, you must explain why your algorithm is guaranteed to find the correct result. You do not need to specify the best...