JDKozlova
19.05.2021 •
Computers and Technology
Assume you have access to a magical function called magicHash that takes in a string and outputs a unique number with no collisions, Using this magical function, complete the below implementation of MyHashSet, which will store strings. Specifically, you should have a constructor, a working add() method, and a working contains() method. The add and contains() methods must have a worst-case running time in O(1). You can assume that the hash set will never need to hold more than 1,000 strings. You may use any libraries except for HashSet.
Solved
Show answers
More tips
- S Sport How to Learn to Pull Up on Monkey Bars?...
- L Leisure and Entertainment Scrapbooking: What is it and Why is it Becoming More Popular?...
- H Horoscopes, Magic, Divination How to Cast a Love Spell on a Guy? Guide for Guys...
- F Family and Home How to Sew Curtain Tapes: Best Tips from Professionals...
- S Style and Beauty How are artificial nails removed?...
- S Style and Beauty How to Make Your Lips Fuller? Ideas and Tips for Beautiful Lips...
- F Food and Cooking The Disease That Haunted Abraham Lincoln...
- C Computers and Internet How to Get Rid of Windows Genuine Check?...
- H Health and Medicine How to perform artificial respiration?...
- S Style and Beauty Tricks and Tips: How to Get Rid of Freckles...
Answers on questions: Computers and Technology
- C Computers and Technology Underinflated tires flex too much and build up heat, which can lead to tire blowouts. true or false...
- C Computers and Technology The Nigerian 4-6-9 scam refers to a fraudulent activity whereby individuals claiming to be from a foreign country will promise a victim large sums of money for assisting them...
- C Computers and Technology Develop a C program or algorithm that takes the input of 5 subjects having 3+0 credit hour of 16 weeks calculate CG PA. Less than 2.5 GPA marks as fail and above 3.5 marks as...
- M Mathematics Franz needs to measure the mass of an iron cube about the size of a table tennis ball. which units are most appropriate for him to use?...
- M Mathematics Acarpenter compares the mass of two types of wood. a cubic meter os aspen is 420 kg.a cubic meter of spruce is 540 kg what is the ratio of the spruces mass to the aspens mass...
- B Biology Jed was hospitalized for a hip surgery. he is eight years old, and is now exhibiting confusion about the time of day or day of week. he is unable to focus on anything. these...
- B Biology What are the vein arrangements in leaves?...
- S Social Studies Summarize suffragettes ( the early women s movement)...
- H History Post world war ii agreements placed which two countries in the position of super powers?...
- H History What are three achievement of the new deal?...
Ответ:
/ Sierpinski.java
public class Sierpinski {
// method to find the height of an equilateral triangle with side length =
// length
public static double height(double length) {
// formula= length*sqrt(3)/2
double h = (length * Math.sqrt(3)) / 2.0;
return h;
}
// method to draw a filled triangle (pointed downwards) with bottom vertex
// x,y
public static void filledTriangle(double x, double y, double length) {
// finding height
double h = height(length);
// filling triangle as a polygon
// passing x, x-length/2, x+length/2 as x coordinates
// and y, y+h, y+h as y coordinates
StdDraw.filledPolygon(new double[] { x, x - (length / 2.0),
x + (length / 2.0) }, new double[] { y, y + h, y + h });
}
// method to draw an n level sierpinski triangle
public static void sierpinski(int n, double x, double y, double length) {
// checking if n is above 0 (base condition)
if (n > 0) {
// drawing a filled triangle with x, y as bottom coordinate, length
// as side length
filledTriangle(x, y, length);
// drawing the triangle(s) on the top
sierpinski(n - 1, x, y + height(length), length / 2);
// drawing the triangle(s) on the left side
sierpinski(n - 1, x - (length / 2.0), y, length / 2);
// drawing the triangle(s) on the right side
sierpinski(n - 1, x + (length / 2.0), y, length / 2);
}
}
public static void main(String[] args) {
// parsing first command line argument as integer, if you dont provide
// the value while running the program, this program will cause
// exception.
int n = Integer.parseInt(args[0]);
// length of the outline triangle
double length = 1;
// finding height
double h = height(length);
// drawing a triangle (pointed upwards) to represent the outline.
StdDraw.polygon(new double[] { 0, length / 2, length }, new double[] {
0, h, 0 });
// drawing n level sierpinski triangle(s) with length / 2, 0 as x,y
// coordinates and length / 2 as initial side length
sierpinski(n, length / 2, 0, length / 2);
}
}