Order Now  +1 678 648 4277 

Analyzing the longest initial reverse substring algorithm in Java assignment help

The goal of the task was to implement and make an analysis of the given algorithm. Our Java assignment helpers use this algorithm to find the maximum length, such that the initial substring of a given string is found in the given string in reverse. The algorithm was given in pseudocode and needed to be implemented in Java. After implementation one had to run the program on different input data lengths to estimate the complexity of the algorithm and draw the plot of algorithm performance.

Determining the Complexity of Reverse Substrings

Main.java import java.io.File; import java.io.IOException; import java.text.MessageFormat; import java.util.Random; import java.util.Scanner; public class Main { private static int longestInitialReverseSubstringLength(String y) { int max = 0; // sum i from 1 to n: i + (n-i) * i for (int i = 1; i <= y.length(); i++ ) { StringBuilder builder = new StringBuilder(); for (int r = i-1; r >= 0; r--) { builder.append(y.charAt(r)); } boolean found = false; String x = builder.toString(); for (int j = 0; j < y.length() - x.length() + 1; j++) { boolean f = true; for (int k = 0; k < x.length(); k++) { if (y.charAt(j + k) != x.charAt(k)) { f = false; break; } } if (f) { found = true; break; } } if (found) { max = i; } else { break; } } return max; } private static long processLine(String line) { int length = line.length(); long start = System.currentTimeMillis(); int result = longestInitialReverseSubstringLength(line); long duration = System.currentTimeMillis() - start; System.out.println(MessageFormat.format("Length = {0}; Duration = {1}; Result = {2}", length, duration, result)); return duration; } private static int[] generateRandomArray(int N) { Random random = new Random(); int[] array = new int[N]; for (int i = 0; i Determining the Complexity of Reverse Substrings