Data Algorithms (language: Java) Describe what each function does and its Big O? import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.*; public class HW04 { public static boolean checkPrimeNumber(int n){ for(int i = 2; i <= n / 2; i++) if(n % i == 0) return false; return true; } public static List> multiSum(int n) { if(n <= 0){ throw new NumberFormatException("Not supported yet."); } List> p = new ArrayList<>(); p.add(Arrays.asList(1,n)); for(int i = n - 1; i >= Math.sqrt(n); i--){ if(n % i == 0){ int left = n / i; p.add(Arrays.asList(i, left)); if(! checkPrimeNumber(i)) { List> lst = multiSum(i); for(int k = 1; k < lst.size();k++) { List currList = new ArrayList<>(); currList.add(left); for(int j = 0; j < lst.get(k).size(); j++) { currList.add(lst.get(k).get(j)); } p.add(currList); } } } } for(int i = 0; i < p.size(); i++) { Collections.sort(p.get(i)); } LinkedHashSet> set = new LinkedHashSet<>(); for(int i = 0; i < p.size(); i++) { set.add(p.get(i)); } p.clear(); for(List list: set) { p.add(list); } return p; } public static void main(String[] args){ int n = 16; System.out.print("Expected result for " + n + ":\n" + " [[1,16], [2,8], [2,2,4], [2,2,2,2], [4,4]]\n"); System.out.print("A total number of unique results found: 5\n"); System.out.print("------------------------\n"); System.out.print("Actual result for " + n + ": " + multiSum(n)); } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Data Algorithms (language: Java)

Describe what each function does and its Big O?

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;

public class HW04 {

public static boolean checkPrimeNumber(int n){

for(int i = 2; i <= n / 2; i++)
if(n % i == 0)
return false;

return true;
}


public static List<List<Integer>> multiSum(int n) {
if(n <= 0){
throw new NumberFormatException("Not supported yet.");
}

List<List<Integer>> p = new ArrayList<>();
p.add(Arrays.asList(1,n));

for(int i = n - 1; i >= Math.sqrt(n); i--){
if(n % i == 0){

int left = n / i;

p.add(Arrays.asList(i, left));

if(! checkPrimeNumber(i)) {
List<List<Integer>> lst = multiSum(i);
for(int k = 1; k < lst.size();k++) {

List<Integer> currList = new ArrayList<>();
currList.add(left);

for(int j = 0; j < lst.get(k).size(); j++) {
currList.add(lst.get(k).get(j));
}

p.add(currList);
}
}
}
}

for(int i = 0; i < p.size(); i++) {
Collections.sort(p.get(i));
}

LinkedHashSet<List<Integer>> set = new LinkedHashSet<>();
for(int i = 0; i < p.size(); i++) {
set.add(p.get(i));
}
p.clear();

for(List<Integer> list: set) {
p.add(list);
}

return p;
}


public static void main(String[] args){
int n = 16;
System.out.print("Expected result for " + n + ":\n" + " [[1,16], [2,8], [2,2,4], [2,2,2,2], [4,4]]\n");
System.out.print("A total number of unique results found: 5\n");
System.out.print("------------------------\n");
System.out.print("Actual result for " + n + ": " + multiSum(n));
}
}

Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Heapsort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education