Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below is a linear time complexity algorithm Max-Min-VER1 to find the biggest and smallest element a given list. Input : A is a given list

Below is a linear time complexity algorithm Max-Min-VER1 to find the biggest and smallest element a given list.

Input: A is a given list

Output: two integers

Example: Given A = {1, 5, 9, -3}. It returns -3 (the smallest element), and 9 (the biggest element)

Max-Min-VER1(A, n)

Line 1: large A[0]

Line 2: for I from 1 to n - 1 do //n 1 iterations

Line 3: large Math.max(large, A[I]) // one comparison

Line 4: small A[0]

Line 5: for I from 1 to n - 1 do

Line 6: small Math.min(small, A[I])

Line 7: return large and small

  1. Implement this algorithm (java)
  2. Answer the question - How many comparisons are used in the algorithm?

Improve the above Max-Min-VER1(A, n) to decrease the number of comparisons. Name your algorithm Max-Min-VER2.

Requirements

  1. using the format show in ( to write your pseudocode)

Input: A is a given list

Output: two integers

Example: Given A = {1, 5, 9, -3}. It returns -3 (the smallest element), and 9 (the biggest element)

Max-Min-VER2(A, n)

Line 1:

Line 2:

Line 3:

Line 4:

Line 5:

  1. implementation of Max-Min-VER2 (you may use any language, such as Java, C++, C#, python etc)
  2. Compare Max-Min-VER1 and Max-Min-VER2 using a table or graph for the time used in milliseconds for running 100 randomly generated lists of each input size 102, 104, and 106.

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

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions

Question

X Open soreaduhet Qvevions 2. Which supcles is mors abst-effertive

Answered: 1 week ago