Question: This code is too use brute force to count the number of triples in a file (in this case: 8Kints.txt) that sum to 0. I

This code is too use brute force to count the number of triples in a file (in this case: "8Kints.txt") that sum to 0.

I have this so far:

public class ThreeSumBrute { public static int count(int[] a) { int n = a.length; int count = 0; for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { for (int k = j+1; k < n; k++) { if (a[i] + a[j] + a[k] == 0) { count++; } } } } return count; } public static void main(String[] args) { In in = new In("8Kints.txt"); int[] a = in.readAllInts(); StdOut.println(count(a)); }

Now what I need to know is, how do I use StdDraw to plot the time it takes for this algorithm to process? Can someone give me a template for the code I need?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!