Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For each of the methods you wrote in Lab 2, figure out the time complexity of the method you wrote. To turn in this portion,

For each of the methods you wrote in Lab 2, figure out the time complexity of the method you wrote. To turn in this portion, attach a printout of the code and specify the time complexity of each. import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Main { // checking for unique list private static boolean unique(List list) { for (int i = 0; i < list.size() - 1; i++) { for (int j = i + 1; j < list.size(); j++) { // checking whether there is mutilpe values or not if (list.get(i).equals(list.get(j))) return false; } } return true; } // checking for mutiples from the list private static List allMultiples(List list, int num) { List newList = new ArrayList<>(); for (Integer i : list) { // checking if num is mutiple of list element if ((i % num) == 0) newList.add(i); } return newList; } // finding size of the given length size string private static List allStringOfSize(List list, int length) { List newList = new ArrayList<>(); for (String str : list) { // checking for list element which of given length if (str.length() == length) newList.add(str); } return newList; } // chekcing for permutation private static boolean isPermutation(List list1, List list2) { // if size of bith list differe return false if (list1.size() != list2.size()) return false; // using comparator for sorting Comparator comp = new Comparator() { @Override public int compare(E o1, E o2) { return o1.toString().compareTo(o2.toString()); } }; // sorting the list Collections.sort(list1, comp); Collections.sort(list2, comp); // checking for permutation for (int i = 0; i < list1.size(); i++) { if (!list1.get(i).equals(list2.get(i))) return false; } return true; } // convert String to list of words private static List stringToListWords(String str) { List words = new ArrayList<>(); String[] ar = str.split(" ");// spliting list into array for (String i : ar) { words.add(i.replaceAll("\\p{Punct}", ""));// adding words to the list after remove all punctuation } return words; } // removing all given instance from the list private static void removeAllInstances(List list, E item) { for (int i = 0; i < list.size(); i++) { if (list.get(i).equals(item))// chekcing for matching instance list.remove(i);// removing it from the list } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

More Books

Students also viewed these Databases questions