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.
Find the K'th smallest element in an unsorted array of integers. Find the K'th largest element...
Find the K'th smallest element in an unsorted array of integers. Find the K'th largest element in an unsorted array of integers. please make two separate methods in java
Remove the minimum element from the linked list in Java public class LinkedList {      ...
Remove the minimum element from the linked list in Java public class LinkedList {       // The LinkedList Node class    private class Node{               int data;        Node next;               Node(int gdata)        {            this.data = gdata;            this.next = null;        }           }       // The LinkedList fields    Node head;       // Constructor    LinkedList(int gdata)   ...
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.
In Java, a set of integers is given. write a function to find 2 integers in...
In Java, a set of integers is given. write a function to find 2 integers in this set that sums upto a target value. i.e [1,5,2,0,11,3] target = 7 result [5,2] i.e [1,5,4,0,14,-7] target = 9 result [5,4] NOTE: THE SAME INTEGER CANNOT BE USED TWICE !!!
Read three integers from user input.
Read three integers from user input.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT