Question

In: Computer Science

Find the minimum element from the lists of integers with Java. Input: [[5,2,31,9],[2,1,6,7,11],[55,0,7,8,9]] Output: 0. [The...

Find the minimum element from the lists of integers with Java. Input: [[5,2,31,9],[2,1,6,7,11],[55,0,7,8,9]] Output: 0. [The minimum among the lists of integers] 1. Implement a program of O(N^k) runtime complexity of the problem. 2. Implement a program of ~ O(N*logN) runtime complexity of the above same problem and explain how you have achieved. [Hint: Apply the log rule -> sort the list of integers, then compare the first element of each]

Solutions

Expert Solution

// python

// first will take n^k where n is the number of elements in the list and k is total list since we are accessing the all elements

// for second question we are sorting each list and one list will take to sort nlogn time so to sort all list it will take knlogn as there are k list to sort. and now to compare all elements with zeroth element of every ;list will take k time so knlogn+k so overall time complexity =knlogn.

# minimum from list of list def findMinimum(numbers): minimum=999999999 for i in range(len(numbers)): for j in range(len(numbers[i])): if minimum>numbers[i][j]: minimum=numbers[i][j] return minimum def findMinimumUsingSorting(numbers): minimum=999999999 for i in range(len(numbers)): numbers[i].sort() if minimum>numbers[i][0]: minimum=numbers[i][0] return minimum numbers=[[5,2,31,9],[2,1,6,7,11],[55,0,7,8,9]] print('Minimum using linear search: ',findMinimum(numbers)) print('Minimum using sorting: ',findMinimumUsingSorting(numbers)) 

// Sample output:-

Note: please give me a positive rating thank you:)


Related Solutions

You will find the minimum element from the lists of integers. Input: [[5,2,31,9],[2,1,6,7,11],[55,0,7,8,9]] Output: 0. [The...
You will find the minimum element from the lists of integers. Input: [[5,2,31,9],[2,1,6,7,11],[55,0,7,8,9]] Output: 0. [The minimum among the lists of integers] 1. Implement a program of O(N^k) runtime complexity of the problem. marks   50 2. Implement a program of ~ O(N*logN) runtime complexity of the above same problem and explain how you have achieved. [Hint : Apply the log rule -> sort the list of integers, then compare the first element of each] marks   50 Total   100 You can...
Write Java code to generate 100 random integers ranging from 0..9, inserting each element into an...
Write Java code to generate 100 random integers ranging from 0..9, inserting each element into an ArrayList. Then search for the first instance of the number 3, print the position, and then remove it from the list.
Write a java program to reverse element of a stack. For any given word (from input),...
Write a java program to reverse element of a stack. For any given word (from input), insert every character (from the word) into a stack. The output from the stack should be the same as the input. Your program should be using a stack and a queue to complete this process. 1. Push into stack 2. Pop from stack 3. Enqueue into queue 4. Dequeue from queue 5. Push into stack 6. Pop from stack and display java
JAVA PROGRAMMING Objectives JAVA Practice incremental development. Practice getting input from and printing output for the...
JAVA PROGRAMMING Objectives JAVA Practice incremental development. Practice getting input from and printing output for the user. Write a program with conditional statements. Write a program with loops. Specifications Think of three countries you’d like to travel to and look up the conversion rate between dollars and the money used in those countries. (See http://www.ratesfx.com/ rates/rate-converter.html for conversion rates.) Write a program that will convert money from dollars into each of those three types of currency, or from one of...
Write a java program that inserts 25 random integers from 0 to 100 in order into...
Write a java program that inserts 25 random integers from 0 to 100 in order into a LinkedList object. The program should sort the elements, then calculate the sum of the elements and the floating-point average of the elements.
Written in JAVA Code Write a program that inserts 25 random integers from 0 to 100...
Written in JAVA Code Write a program that inserts 25 random integers from 0 to 100 in order into a LinkedList object. The program should sort the elements, then calculate the sum of the elements and the floating-point average of the elements.
Read three integers from user input.
Read three integers from user input.
Write a program whose input is two integers, and whose output is the first integer and...
Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. import java.util.Scanner; public class LabProgram {...
IN JAVA!!! In this project, you will use radix.txt as the input file, and output the...
IN JAVA!!! In this project, you will use radix.txt as the input file, and output the integers SORTED USING RADIX SORT. You may assume all your input consists of integers <=9999. Your main program will input the integers and put them into a QUEUE. It will then pass this queue to a method called radixSort which will sort the numbers in the queue, passing the sorted queue back to main. The main program will then call another method to print...
Given a minimum unimodal array of integers, run the binary search algorithm to find the minimum...
Given a minimum unimodal array of integers, run the binary search algorithm to find the minimum element. You need to show the initial and the iteration-level values of the left index, right index and middle index as well as your decisions to reduce the search space in each iteration. 42 39 2 6 9 16 20 28 31 34
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT