Question

In: Computer Science

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 choose either C#, Python, Java to implement 1 & 2.

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:-


Related Solutions

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]
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 {...
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.
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
Write a C program whose input is two integers, and whose output is the first integer...
Write a C 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. For coding simplicity, output a...
Input: An array of non-negative integers, where each element in the array represents your maximum jump...
Input: An array of non-negative integers, where each element in the array represents your maximum jump length at that position. Output: A boolean value if you are able to reach the last index starting if you start at the first spot in the array. [Please write a recursion function!] Example 1: Input: [2,4,1,2,4,1] Output: True (Ex. 0 to 1 to 5 or 0 to 2 to 3 to 5) Example 2: Input: [3,2,1,0,4] Output: false (You will always arrive at,...
module traffic(clk, reset, P1, P2, P3, P4, PL); input clk; input reset; output[4:0] P1; output[4:0] P2;...
module traffic(clk, reset, P1, P2, P3, P4, PL); input clk; input reset; output[4:0] P1; output[4:0] P2; output[4:0] P3; // four roads output [4:0] P4; output[3:0] PL; //Pl is pedestrian reg [4:0] P1; reg [4:0] P2; reg [4:0] P3; reg [4:0] P4; reg [3:0] PL; reg [4:0] sig; always @(posedge clk or negedge reset) begin    if(reset == 1'b0)begin        P1 <= 5'b00100;        P2 <= 5'b00100;        P3 <= 5'b00100;        P4 <= 5'b00100;       ...
How would you take a given array of non-repeating random integers and sort every 5th element. Meaning index 0 is the smallest element in the array.
JAVA ProgrammingHow would you take a given array of non-repeating random integers and sort every 5th element. Meaning index 0 is the smallest element in the array. index 4 is the 5th smallest element in the array, index 9 is the 10th smallest element in the array and so on...- this array could be small (like 5 indexes) or large (like 100,000 indexes).- all other numbers do not change position
6.25 LAB: Swapping variables Write a program whose input is two integers and whose output is...
6.25 LAB: Swapping variables Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 The output is: 8 3 Your program must define and call the following function. swap_values() returns the two values in swapped order. def swap_values(user_val1, user_val2) **in Python, please
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT