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.
you should just find it directly by using a linear scan of the polygon points. The other two vertices can be found by moving to the left of the circular list of polygon vertices twice. Otherwise, the algorithm looks valid.
C-22.5 Design an O(n)-time algorithm to test whether a given n-vertex polygon is convex. You should...
5. (570/470 bonus) Design an algorithm whose input is a list of n points, (xu, ) for isks n. Your algorithm should run in O(n) time and determine whether or not the convex hull of these n points is a triangle. Also explain why your algorithm runs in O(n) time.
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...
Write a C++ program which has a main-driver and creat a polygon class Poly which has an array of n pairs of floats, x[i] and y[i], creat a derived class Triangle, creat a derived class Quadrilateral class (which you may assume is convex and points given clockwise) You need to compute the area for the two derived classes but use inheritance to compute perimeter in all these classes. Constructors, accessors, mutators, and anything else needed should be written too. Make...
1. a) Describe an O(m)-time algorithm that, given a set of S of n distinct numbers and a positive integer k c n, determines the top k numbers in s b) Describe an O(n)-time algorithm that, given a set of S of n distinct numbers and a positive integer k < n, determines the smallest k numbers in S.
C++ Question 15 20 p Design a recursive algorithm that determines whether the number of leaf nodes of a Binary Search Tree (BST) is even or odd. An empty tree has an even number of leaves. A tree consisting of just a root has an odd number of leaves. Your function should return true for an even number of leaves, and false for an odd number of leaves. Analyze the execution time of your algorithm. Giving only the execution time...
(Q4 - 30 pts: 15, 15) a) Give an O (n) time algorithm for finding the longest (simple) path in a tree on n vertices. Prove the correctness of your algorithm. Give a polynomial time algorithm for finding the longest (simple) path in a graph whose blocks have size bounded by a constant. Prove the correctness of your algorithm. b)
You are given a set of n numbers. Give an O(n^2) algorithm (NOT O(n^3), O(n^2)) to decide if there exist three numbers a, b and c are in the set such that a + b = c (Hint: sort the numbers first).
GIFT WRAPPING ALGORITHM OF JARVIS MARCH In mathematics, the convex hull of a set of points is the smallest convex set that contains these points. The convex hull may be visualized as the shape enclosed by a rubber band stretched around these points (see the figure below). In your first homework, you are going to compute the convex hull of a set of given points in a separate file (input.txt). For the given set of 14 points below, you can...
Let G = (V, E, w) be a connected weighted undirected graph. Given a vertex s ∈ V and a shortest path tree Ts with respect to the source s, design a linear time algorithm for checking whether the shortest path tree Ts is correct or not.(C pseudo)
For the convex hull algorithm we have to be able to test whether a point r lies left or right of the directed line through two points p and q. Let = (px, Py), q , and r-(Tx,rv). a. Show that the sign of the determinant 1 rx iy determines whether r lies left or right of the line. For the convex hull algorithm we have to be able to test whether a point r lies left or right of...