Graduate Essay Writers
Only the most qualified writers are selected to be a part of our research and editorial team, with each possessing specialized knowledge in specific subjects and a background in academic writing.
Fill the order form details in 3 easy steps - paper's instructions guide.
Posted: January 28th, 2022
PerformanceTest program
The PerformanceTest program within the exercise bundle, accommodates three strategies that implement the algorithms(options) for computing the vary of numbers in an array.
AssignmentTutorOnline
For this train, we are going to have a look at algorithm efficiency by observing which of the three algorithm runs the quickest. We’ll examine every algorithm utilizing knowledge units that improve in measurement. This efficiency is set by operating the algorithm and measuring how lengthy it takes to finish every knowledge set in milliseconds (ms).
Vary
The vary is the distinction between the best and lowest numbers within the array.
Algorithm 1 : Vary$1
Description: This algorithm makes use of nested loops to look at each pair of components within the array , computing their distinction and remembering the most important distinction discovered.
maxDiff = zero;
for (every index i)
for (every index j)
replace maxDiff, if components i and j differ greater than max.
Algorithm 2 : Vary$2
Description: This algorithm reduces the quantity of computations carried out by disregarding one of many (i, j) and (j, i) pairs, that give similar comparisons. It nonetheless makes use of nested loops to look at each pair of components within the array however now solely as soon as, computes their distinction and remembering the most important distinction discovered.
maxDiff = zero;
for (every index i)
for (every index j = i + 1)
replace maxDiff, if components i and j differ greater than max.
Algorithm three : Vary$three
Description: This algorithm makes use of a loop to search out the most important worth and smallest worth within the array, compute their distinction and return this distinction.
max = factor[0]
min = max
for (every index i)
discover max.
discover min.
return max – min
Assessment/Questions
Directions: Reply the questions on in a doc/spreadsheet and undergo your github repository.
Obtain and study the Range_RunTimes EXCEL file, which accommodates the placement to populate the run time knowledge of the three (three) algorithms listed above. There are three (three) totally different spreadsheets, one for every algorithm. Observe the fourth (4th) spreadsheet combines the info for all three algorithms on one graph, nonetheless, algorithm three makes use of the secondary scale at high and proper of graph.
Run the PerformanceTest program and enter the out of the present run time for the info units listed for every of the vary algorithms in L2_Range_RunTimes EXCEL file.
If you’re experiencing an OutOfMemoryError : Java heap house in your PerformanceTest program. That is presumably resulting from your Java Digital Machine (JVM) needing extra reminiscence to run this utility. A fast repair for this may be to do the next: Go to Run > Run Configurations > choose PerformanceTest from left window > choose (x) = Arguments
Kind within the field beneath within the VM arguments window: -Xmx3200m.
This units a three.2GB allocation, which needs to be sufficient, however for those who want extra you’ll be able to simply substitute 3200 with a bigger quantity like 3800 and so forth…
What do observe for every of the algorithms proven with their corresponding knowledge set? Are you able to inform which algorithm was essentially the most environment friendly?
For algorithms 1 and a pair of, did decreasing the quantity of computations by half enhance the runtime considerably? Clarify your reasoning, for those who felt it had a small or giant change.
For algorithms 2 and three, did decreasing the variety of loops enhance the runtime considerably? Clarify your reasoning, for those who felt it had a small or giant change.
Fibonacci Sequence
About
The Fibonacci sequence/collection is a mathematical mannequin that’s typically utilized in numeric optimization. It’s based mostly on a sequence of numbers wherein the primary two numbers within the collection are zero and 1, and every subsequent quantity is the sum of the earlier two numbers.
n zero 1 2 three four 5 6 7 eight 9…
worth: zero 1 1 2 three 5 eight 13 21 34…
Replace the recursive methodology fib to compute the Fibonacci worth of n, in FibonacciTest of lab-01. This needs to be the Fibonacci sequence answer in its most elementary type.
Modify the program FibonacciTest in order that it finds the variety of occasions the fib methodology is known as. Use a static variable to maintain monitor of the calls and increment it each time the strategy is known as.
Create a efficiency check, much like that proven for the ranges in Exercise 1 for the strategy in Question Assignment 1 for fib(50). Plot 5-6 (5 to 6) knowledge factors in your Range_RunTimes EXCEL file , what do you observe? Are the outcomes as anticipated? How does this match with the theoretical mannequin of the collection?
The code in Question Assignment 1 was inefficient, as a result of it takes too many recursive calls. It finally ends up re-computing every Fibonacci quantity many occasions. This code runs very sluggish for even comparatively small values of n. It will probably take minutes or hours to compute even the 40th or 50th Fibonacci quantity on sure computer systems. Write a brand new model of the Fibonacci methodology memoFib that’s nonetheless recursive however is extra environment friendly than the one in Question Assignment 1. Do that by making a helper methodology that accepts a further parameter, the storage for the earlier Fibonacci numbers, which you could carry by and modify throughout every recursive name.
Write a brand new model of the Fibonacci methodology itrFib that makes use of iteration to generate the consequence for the nth worth within the Fibonacci sequence.
Replace the program FibonacciTest to run the same empirical exams for the three Fibonacci sequence algorithms on this exercise (Q1, This fall, Q5) and replace your Range_RunTimes EXCEL file to indicate the outcomes.
Worst Case Run Time Equation
About
Discover the worst case runtime f(n) for the next algorithms.
Specify the variety of operations executed for an enter measurement n, for the worst case run time as a perform of n.
Circle assertion(s) and draw a line to the proper aspect specifying the variety of operations.
If assertion(s) are part of an iteration of n, specify the whole variety of iterations as a perform of n.
See: Worst Case Run Time Tutorial (as reference)
Algorithm-01
int sum = zero;
int j = 1;
whereas (j <= n)
sum++;
j = j * 2;
Algorithm-02
int sum = zero;
for (int i = 1; i <= n * 2; i++)
for (int j = 1; j <= n; j++)
sum++;
for (int j = 1; j < 100; j++)
sum++;
sum++;
Algorithm-03
int sum = zero;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= 1000000; j++)
sum += 10;
sum += 9999;
Algorithm-04
int sum = zero;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= i; j++)
sum = sum + i + j;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= 20; j++)
sum++;
bundle exercise;
public class PerformanceTest
public static int[] dataSet(int n)
lengthy startTime = System.currentTimeMillis();
//just a few tom foolery
int[] knowledge = new int[n];
//start: tom foolery
for (int i = zero; i < n; i++)
knowledge[i] = i + 105;
lengthy endTime = System.currentTimeMillis();
System.out.print(“DataSet: n = ” + n + “t”);
System.out.println(“RunTime: ” + (endTime – startTime) + ” ms”);
return knowledge;
public static int findRangeAlgo01(int[] knowledge)
int diff = zero;
int maxDiff = zero;
for (int i = zero; i < knowledge.size; i++)
for (int j = zero; j < knowledge.size; j++)
diff = Math.abs(knowledge[j] – knowledge[i]);
if(maxDiff < diff)
maxDiff = diff;
return maxDiff;
public static int findRangeAlgo02(int[] knowledge)
int diff = zero;
int maxDiff = zero;
for (int i = zero; i < knowledge.size; i++)
for (int j = i + 1; j < knowledge.size; j++)
diff = Math.abs(knowledge[j] – knowledge[i]);
if(maxDiff < diff)
maxDiff = diff;
return maxDiff;
public static int findRangeAlgo03(int[] knowledge)
int max = knowledge[0];
int min = max;
for (int i = zero; i < knowledge.size; i++)
if (knowledge[i] > max)
max = knowledge[i];
else if(knowledge[i]< min)
min = knowledge[i];
return max – min;
public static void timeAlgoRange01(int[] knowledge)
lengthy startTime = System.currentTimeMillis();
int vary = findRangeAlgo01(knowledge);
lengthy endTime = System.currentTimeMillis();
System.out.print(“Vary ” + vary + “t”);
System.out.print(“DataSet: n = ” + knowledge.size + “t”);
System.out.println(“RunTime: ” + (endTime – startTime) + ” ms”);
public static void timeAlgoRange02(int[] knowledge)
lengthy startTime = System.currentTimeMillis();
int vary = findRangeAlgo02(knowledge);
lengthy endTime = System.currentTimeMillis();
System.out.print(“Vary ” + vary + “t”);
System.out.print(“DataSet: n = ” + knowledge.size + “t”);
System.out.println(“RunTime: ” + (endTime – startTime) + ” ms”);
public static void timeAlgoRange03(int[] knowledge)
lengthy startTime = System.currentTimeMillis();
int vary = findRangeAlgo03(knowledge);
lengthy endTime = System.currentTimeMillis();
System.out.print(“Vary ” + vary + “t”);
System.out.print(“DataSet: n = ” + knowledge.size + “t”);
System.out.println(“RunTime: ” + (endTime – startTime) + ” ms”);
public static void important(String[] args)
System.out.println(“Knowledge Set – 1 to eight”);
int[] data1 = dataSet(1000);
int[] data2 = dataSet(5000);
int[] data3 = dataSet(10000);
int[] data4 = dataSet(25000);
int[] data5 = dataSet(50000);
int[] data6 = dataSet(75000);
int[] data7 = dataSet(100000);
int[] data8 = dataSet(125000);
int[] data9 = dataSet(250000);
int[] knowledge10 = dataSet(500000);
System.out.println();
System.out.println(“Vary 1 – Run Time Assessment”);
timeAlgoRange01(data1);
timeAlgoRange01(data2);
timeAlgoRange01(data3);
timeAlgoRange01(data4);
timeAlgoRange01(data5);
timeAlgoRange01(data6);
timeAlgoRange01(data7);
timeAlgoRange01(data8);
timeAlgoRange01(data9);
timeAlgoRange01(knowledge10);
// System.out.println();
// System.out.println(“Vary 2 – Run Time Assessment”);
// timeAlgoRange02(data1);
// timeAlgoRange02(data2);
// timeAlgoRange02(data3);
// timeAlgoRange02(data4);
// timeAlgoRange02(data5);
// timeAlgoRange02(data6);
// timeAlgoRange02(data7);
// timeAlgoRange02(data8);
// timeAlgoRange02(data9);
// timeAlgoRange02(knowledge10);
//
// System.out.println();
// System.out.println(“Knowledge Set – 9 to 18 for Vary three”);
//
// int[] knowledge11 = dataSet(10000000);
// int[] knowledge12 = dataSet(20000000);
// int[] knowledge13 = dataSet(40000000);
// int[] knowledge14 = dataSet(60000000);
// int[] knowledge15 = dataSet(80000000);
// int[] knowledge16 = dataSet(100000000);
// int[] knowledge17 = dataSet(125000000);
// int[] knowledge18 = dataSet(150000000);
// int[] knowledge19 = dataSet(200000000);
// int[] knowledge20 = dataSet(250000000);
//
// System.out.println();
// System.out.println(“Vary three – Run Time Assessment”);
// timeAlgoRange03(data1);
// timeAlgoRange03(data2);
// timeAlgoRange03(data3);
// timeAlgoRange03(data4);
// timeAlgoRange03(data5);
// timeAlgoRange03(data6);
// timeAlgoRange03(data7);
// timeAlgoRange03(data8);
// timeAlgoRange03(data9);
// timeAlgoRange03(knowledge10);
// timeAlgoRange03(knowledge11);
// timeAlgoRange03(knowledge12);
// timeAlgoRange03(knowledge13);
// timeAlgoRange03(knowledge14);
// timeAlgoRange03(knowledge15);
// timeAlgoRange03(knowledge16);
// timeAlgoRange03(knowledge17);
// timeAlgoRange03(knowledge18);
// timeAlgoRange03(knowledge19);
// timeAlgoRange03(knowledge20);
bundle exercise;
public class FibonacciTest
/***********************************************************
* returns the results of a Fibonacci Sequence.
* @param n integer of the Fibonacci Sequence.
* @return consequence with expanded house for bigger integers.
* *********************************************************/
public static lengthy fib(int n)
//TODO : COMPLETE BODY
return zero;
/***********************************************************
* returns a dynamic results of a Fibonacci Sequence.
* @param n integer of the Fibonacci Sequence.
* @return consequence with expanded house for bigger integers.
* *********************************************************/
public static lengthy memoFib(int n)
//TODO : COMPLETE BODY
return zero;
//TODO : Algo 2 -> Create Helper Methodology for _fib
non-public static lengthy memoFib(int n, int[] x)
//TODO : COMPLETE BODY
return zero;
//TODO : Algo three -> Use Iteration
public static lengthy itrFib()
//TODO : COMPLETE BODY
return zero;
public static void important(String[] args)
int n = 9;
// QUICK CHECK : depend of nth factorial
System.out.print(“——————————— nth Fibonnacci “);
System.out.println(“——————————-“);
for (int i = zero; i <= n; i++ )
System.out.print(i + “t”);
System.out.println();
//worth for nth factorial
for (int i = zero; i <= n; i++ )
System.out.print(fib(i) + “t”);
System.out.println();
bundle recursion;
// you probably did good job
public class PalindromeTestProgram
/***********************************************************
* returns true if the given string reads the identical forwards
* as backwards.Trivially true for empty or 1-letter strings.
* @param s ,string of textual content as enter.
* @throws IllegalArgumentException for adverse numbers.
* *********************************************************/
public static boolean isPalindrome(String s)
//TODO : COMPLETE BODY
return false;
public static void important(String[] args)
System.out.println();
String[] strings = new String[11];
strings[0] = “madam”;
strings[1] = “racecar”;
strings[2] = “tacocat”;
strings[3] = “step on no pets”;
strings[4] = “in a position was I ere I noticed elba”;
strings[5] = “Java”;
strings[6] = “rotater”;
strings[7] = “byebye”;
strings[8] = “notion”;
strings[9] = “”;
strings[10] = “a”;
for (String str : strings)
System.out.printf(“Is ”%s” a palindrome? %6sn”, str, isPalindrome(str));
bundle recursion;
public class SequenceTestProgram
/************************************************************
* returns the results of a factorial all the way down to zero factorial.
* @param n ,takes a optimistic integer and 0 as enter.
* @throws IllegalArgumentException for adverse numbers.
* @return computed consequence as output.
* **********************************************************/
public static int fac(int n)
//TODO: COMPLETE BODY
return zero;
/***********************************************************
* returns the results of the Fibonacci sequence of numbers.
* @param n ,takes an integer as enter
* @throws IllegalArgumentException for adverse numbers.
* @return computed consequence as output.
* *********************************************************/
public static int fib(int n)
//TODO : COMPLETE BODY
return zero;
/***********************************************************
* returns the results of a double precision floating level
* quantity x to the nth energy.
* @param x ,double precision floating level quantity
* @param n ,optimistic integer
* @throws IllegalArgumentException for adverse exponents.
* @return computed consequence as output.
* *********************************************************/
public static double pow(double x, int n)
//TODO: COMPLETE BODY
return zero;
/***********************************************************
* returns the results of the sum of n integers.
* @param n , optimistic integer as enter.
* @throws IllegalArgumentException for adverse numbers.
* @return computed consequence as output.
* *********************************************************/
public static int sum(int n)
//TODO : COMPLETE BODY
return zero;
/***********************************************************
* runs the program
* @param args program arguments
* *********************************************************/
public static void important(String[] args)
int n = 5;
//depend of nth factorial
System.out.println(“————- nth factorial ————–“);
for (int i = zero; i <= n; i++ )
System.out.print(i + “t”);
System.out.println();
//worth for nth factorial
for (int i = zero; i <= n; i++ )
System.out.print(fac(i) + “t”);
System.out.println();
n = four;
System.out.println();
System.out.println(“————– sum(n) ————-“);
//summation of n integers
int sum = n * (n + 1) / 2;
System.out.println(“sum of ” + n + ” integers: ” + sum);
System.out.println(“sum of ” + n + ” integers: ” + sum(n));
//two to the facility of n
n = 16;
double twoToN = Math.pow(2, n);
System.out.println();
System.out.println(“————– pow(2, n) ————-“);
System.out.println(“pow(2, n): ” + n + ” offers ” + twoToN);
System.out.println(“pow(2, n): ” + n + ” offers ” + pow(2, n));
System.out.println();
//e to the facility of n
n = eight;
double xToN = Math.pow(Math.E, n);
System.out.println(“————– pow(x,n) ————-“);
System.out.println(“x(n): ” + n + ” offers ” + xToN);
System.out.println(“pow(e, n): ” + n + ” offers ” + pow(Math.E, n));
bundle sierpinski.attracts;
import java.awt.*;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JLabel;
public class ControlPanel extends JPanel
non-public static last lengthy serialVersionUID = 1L;
public static last int WIDTH = Viewer.WIDTH – 25;
public static last int HEIGHT = Viewer.HEIGHT – 75;
non-public int degree; //set starting degree
public JButton plusButton;
public JButton minusButton;
public JLabel label;
public JPanel subPanel;
non-public Level p1, p2, p3;
//****************************************************
//* Test the boundaries of the show
//****************************************************
public ControlPanel()
degree = 1;
subPanel = new JPanel();
plusButton = new JButton(“+”);
minusButton = new JButton(“-“);
label = new JLabel(“n: ” + degree);
subPanel.setBackground(Shade.GRAY);
plusButton.addActionListener(occasion ->
degree++;
label.setText(“n: ” + degree);
);
minusButton.addActionListener(occasion ->
if (degree != 1)
degree–;
label.setText(“n: ” + degree);
);
subPanel.add(plusButton);
subPanel.add(minusButton);
subPanel.add(label);
setPoints();
//****************************************************
//* draw Triangles at new degree
//****************************************************
public void drawFigure(Graphics pen, int degree, Level p1, Level p2, Level p3)
//finish case: triangle degree 1
if( degree == 1)
Polygon triangle = new Polygon();
triangle.addPoint(p1.x, p1.y);
triangle.addPoint(p2.x, p2.y);
triangle.addPoint(p3.x, p3.y);
pen.drawPolygon(triangle);
else
Level p4 = midPoint(p1, p2);
Level p5 = midPoint(p2, p3);
Level p6 = midPoint(p1, p3);
//recursively draw the three triangles
drawFigure(pen, degree – 1, p1, p4, p6);
drawFigure(pen, degree – 1, p4, p2, p5);
drawFigure(pen, degree – 1, p6, p5, p3);
repaint();
public Level midPoint(Level p1, Level p2)
return new Level( (p1.x + p2.x ) / 2 , (p1.y + p2.y) / 2 );
//****************************************************
//* Choose three factors in proportion to the pane measurement
//****************************************************
public void paintComponent(Graphics pen)
tremendous.paintComponent(pen);
pen.setColor(Shade.WHITE);
drawFigure(pen, degree, p1, p2, p3);
//****************************************************
//* Units the three vertices of the primary degree
//* of the Triangle
//****************************************************
non-public void setPoints()
p1 = new Level( WIDTH / 2 , 10 );
p2 = new Level( 25 , HEIGHT – 25);
p3 = new Level( WIDTH – 25, HEIGHT – 25);
bundle sierpinski.attracts;
import javax.swing.JFrame;
import java.awt.*;
import javax.swing.BorderFactory;
import javax.swing.border.BevelBorder;
public class Viewer
public static last int WIDTH = 500;
public static last int HEIGHT = 500;
public static last int LEFT_X = 750;
public static last int TOP_Y = 100;
public static void important(String[] args)
ControlPanel panel = new ControlPanel();
panel.setBackground(Shade.BLACK);
panel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Shade.GRAY, Shade.WHITE));
panel.subPanel.setBorder(BorderFactory.createTitledBorder(“Degree”));
JFrame body = new JFrame(“Sierpinski Triangle Viewer”);
body.setLayout(new BorderLayout());
panel.setBackground(Shade.BLACK);
body.add(panel, BorderLayout.CENTER);
body.add(panel.subPanel, BorderLayout.SOUTH);
body.setSize(WIDTH, HEIGHT);
body.setLocation(LEFT_X, TOP_Y);
body.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
body.setVisible(true);
bundle sierpinski.fills;
import java.awt.Shade;
import java.awt.Graphics;
import java.awt.Level;
import java.awt.Polygon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.occasion.ActionEvent;
import java.awt.occasion.ActionListener;
public class ControlPanel extends JPanel
non-public static last lengthy serialVersionUID = 1L;
public static last int WIDTH = Viewer.WIDTH – 25;
public static last int HEIGHT = Viewer.HEIGHT – 75;
non-public Shade shade;
non-public int degree; //set starting degree
non-public JButton plusButton;
non-public JButton minusButton;
non-public JLabel label;
public JPanel subPanel;
non-public Level p1, p2, p3;
public ControlPanel()
shade = new Shade(200, zero, zero);
degree = 1;
subPanel = new JPanel();
plusButton = new JButton(“+”);
minusButton = new JButton(“-“);
label = new JLabel(“n: ” + degree);
plusButton.addActionListener( new ActionListener()
public void actionPerformed(ActionEvent occasion)
degree++;
label.setText(“n: ” + degree);
);
minusButton.addActionListener( new ActionListener()
public void actionPerformed(ActionEvent occasion)
if (degree != 1)
degree–;
label.setText(“n: ” + degree);
);
subPanel.add(plusButton);
subPanel.add(minusButton);
subPanel.add(label);
setPoints();
public void drawFigure(Graphics pen, int degree, Level p1, Level p2, Level p3)
//finish case: triangle degree 1
if( degree == 1)
Polygon triangle = new Polygon();
triangle.addPoint(p1.x, p1.y);
triangle.addPoint(p2.x, p2.y);
triangle.addPoint(p3.x, p3.y);
pen.setColor(shade);
pen.fillPolygon(triangle);
else
Level p4 = midPoint(p1, p2);
Level p5 = midPoint(p2, p3);
Level p6 = midPoint(p1, p3);
//recursively draw the three triangles
drawFigure(pen, degree – 1, p1, p4, p6);
drawFigure(pen, degree – 1, p4, p2, p5);
drawFigure(pen, degree – 1, p6, p5, p3);
repaint();
//****************************************************
//* midpoint of two factors
//****************************************************
public Level midPoint(Level p1, Level p2)
return new Level( (p1.x + p2.x ) / 2 , (p1.y + p2.y) / 2 );
//****************************************************
//* Choose three factors in proportion to the pane measurement
//* some computer systems want the father or mother panel reset with:
//* tremendous.paintComponent(pen);
//****************************************************
public void paintComponent(Graphics pen)
tremendous.paintComponent(pen);
drawFigure(pen, degree, p1, p2, p3);
//****************************************************
//* Helper Methodology: Units the three vertices
//* of the primary order Triangle
//****************************************************
non-public void setPoints()
p1 = new Level(WIDTH / 2, 10);
p2 = new Level(25, HEIGHT – 25);
p3 = new Level(WIDTH – 25, HEIGHT – 25);
Every Student Wants Quality and That’s What We Deliver
Only the most qualified writers are selected to be a part of our research and editorial team, with each possessing specialized knowledge in specific subjects and a background in academic writing.
Our prices strike the perfect balance between affordability and quality. We offer student-friendly rates that are competitive within the industry, without compromising on our high writing service standards.
No AI/chatgpt use. We write all our papers from scratch thus 0% similarity index. We scan every final draft before submitting it to a customer.
When you decide to place an order with Nursing.StudyBay, here is what happens:
Place an order in 3 easy steps. Takes less than 5 mins.