Concept explainers
(Geometry: gift-wrapping
/** Return the points that form a convex hull */
public static ArrayList<Point2D> getConvexHull(double[][] s)
Point2D is defined in Section 9.6.3.
Write a test
How many points are in the set? 6
Enter 6 points: 1 2.4 2.5 2 1.5 34.5 5.5 6 6 2.4 5.5 9
The convex hull is
(1.5, 34.5) (5.5, 9.0) (6.0, 2.4) (2.5, 2.0) (1.0, 2.4)
Want to see the full answer?
Check out a sample textbook solutionChapter 22 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Java How To Program (Early Objects)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Artificial Intelligence: A Modern Approach
C Programming Language
C++ How to Program (10th Edition)
- Question 4 Write Java code for the following: a. Create an Arraylist that can hold Integer objects. b. Check and display whether the Arraylist is empty or not. c. Add an element 50 into the Arraylist. d. Add another element 60 in the position of 0 in the Arraylist. e. Replace the element to 70 in index 1.arrow_forward5. Now examine the for-loops in the above Java program. (assume that we have the have replaced the array with an ArrayList) a) Which ArrayList method should you use to control the for-loop iterations? b) Explain why the first for-loop cannot be controlled by that ArrayList method (but the other two for-loops can). Here is a quick review of how array elements are modified and accessed: 1. public class BasicArray{ 2. public static void main(String[] args) int[] basic = new int[4]; for (int i=0; iarrow_forwardWrite method body of followingfunction: void deleteRange(int from, int to){ } Above function deletes whole range of elements from an array by asking user for starting value and ending value. (Dont use pointers) Write best solution for worst case scenario.arrow_forwardvoid mystery2(int list[], int length) { for (int i = 0; i < length - 1; i++) { if (i % 2 == 0) { list[i]++; } else { list[i]--; } }} For each array below, indicate what the array's contents would be after the function were called and passed that array as its parameter. use the following as input. {6, 3} {2, 4, 6} {1, 2, 3, 4} {2, 2, 2, 2, 2} {7, 3, 2, 0, 5, 1}arrow_forwardShift Right k Cells (Use Python) Consider an array named source. Write a method/function named shifRight( source, k) that shifts all the elements of the source array to the right by 'k' positions. You must execute the method by passing an array and number of cells to be shifted. After calling the method, print the array to show whether the elements have been shifted properly. Example: source=[10,20,30,40,50,60] shiftRight(source,3) After calling shiftRight(source,3), printing the array should give the output as: [ 0,0,0,10,20,30 ]arrow_forwardlet a = {x:0}; for (let i = 0; i < 4; i++) { a = Array.create (2, a); } a = 1; After running the last line of code above, how many objects (including arrays) can be garbage collected?arrow_forwardJava question: A program that simulates a Bingo game declares an array of BingoCard. BingoCard[] players = new BingoCard[10]; //assuming no error occurs Why does a for-loop correctly constructs each BingoCard, whereas a for-each loop does not? for (BingoCard card : players) card = new BingoCard(); //I am thinking: "for each element of players, instantiate a new BingoCard object" for (int i=0;i<players.length;i++) players[i] = new BingoCard(); //I think for-loop also does the same thing.arrow_forward/*Code: Construct BST From Sorted ArraySend FeedbackGiven a sorted integer array A of size n, which contains all unique elements. You need to construct a balanced BST from this input array. Return the root of constructed BST.Note: If array size is even, take first mid as root.Input format:The first line of input contains an integer, which denotes the value of n. The following line contains n space separated integers, that denote the values of array.Output Format:The first and only line of output contains values of BST nodes, printed in pre order traversal.Constraints:Time Limit: 1 secondSample Input 1:71 2 3 4 5 6 7Sample Output 1:4 2 1 3 6 5 7 */public class SortedArrayToBst { /* Binary Tree Node class * * class BinaryTreeNode<T> { T data; BinaryTreeNode<T> left; BinaryTreeNode<T> right; public BinaryTreeNode(T data) { this.data = data; } } */…arrow_forwardDefine a class Car as follows:class Car { public String make; public String model; public int mpg;// Miles per gallon}a) Implement a comparator called CompareCarsByMakeThenModel that can be passed as an argument to the quicksort method from the lecture notes. CompareCarsByMakeThenModel should return a value that will cause quicksort to sort an array of cars in ascending order (from smallest to largest) by make and, when two cars have the same make, in ascending order by model.b) Implement a comparator called CompareCarsByDescendingMPG that can be passed as an argument to the quicksort method from the lecture notes. CompareCarsByDescendingMPG should return a value that will cause quicksort to sort an array of cars in descending order (from largest to smallest) by mpg.c) Implement a comparator called CompareCarsByMakeThenDescendingMPG that can be passed as an argument to the quicksort method from the lecture notes.…arrow_forwardA) Consider the generic print() method, write a method that takes an array of E, where E must be Comparable or extend a type that is Comparable, and returns a reference to the greatest object in the array. In this case, the greatest value is one for which compareTo() would return 0 or more for any other object in the array. If there is more than one possible largest value (these would have to be equal to each other but greater than any other objects in the array), it does not matter which one you choose. B) Write a generic Java queue class (a plain queue, not a priority queue). Call it GenericQueue, because the JDK already has an interface called Queue. The class must be able to create a queue of objects of any reference type. Consider the GenericStack class shown in the lecture notes for some hints. Like the Stack, the GenericQueue should use an underlying ArrayList<E>. Write these methods and any others you find useful: enqueue() adds an E to the queue peek() returns a…arrow_forwardPROBLEM STATEMENT: Return an ArrayList containing the largest and smallest integer inan array. If the array is empty, return the largest andsmallest as 0. public class FindMaxMinArray{public static ArrayList<Long> solution(int[] nums){// ↓↓↓↓ your code goes here ↓↓↓↓return new ArrayList<>();} Can you please help me with this Java question please use the code i provided above to anser the questionarrow_forward•• 8. Write a method that returns the sum of a given row in a two-dimensional array. Complete this code: ArrayUtil.java 1 public class ArrayUtil 2 { /** Computes the sum of a given row in a two-dimensional array. @param values the array @param the row whose sum to compute @return the sum of the given row */ public static int rowSum(int[][] values, int row) { 3 4 8 10 11 } 13 } 12 RowSumTester.java 1 public class RowSumTester 2 { public static void main(String[] args) { 4 6. int[][] counts = { 1, 0, 1 }, { 1, 1, 0 }, { 0, 0, 1 }, { 1, 0, 0 }, { 0, 1, 1 }, { 0, 1, 1 }, { 1, 1, 0 } 10 11 12 13 14 }; int sum = ArrayUtil.rowSum(counts, 5); 15 16 System.out.println(sum); System.out.println("Expected: 2"); 17 18 19 int[][] magicSquare = { { 16, 3, 2, 13 }, { 5, 10, 11, 8 }, { 9, 6, 7, 12 }, { 4, 15, 14, 1 }, }; 20 21 22 23 24 25 26 for (int row = 0; row <= 3; row++) { System.out.println(ArrayUtil. rowSum(magicSquare, row)); System.out.println("Expected: 34"); } 27 28 29 30 31 32 33 }arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education