Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A java program What does the following function do? public static void mystery(int[] a) { int temp; for (int i = 1; i < a.length;

A java program

What does the following function do? public static void mystery(int[] a) { int temp; for (int i = 1; i < a.length; i++) for (int j = 0; j < a.length - i; j++) if (a[j] > a[j+1]) { temp = a[j]; //<--- how many time executed? a[j] = a[j+1]; a[j+1] = temp; } } How many times is the if statement executed if the array passed has 10 slots. If it has 5 slots? If it has 100 slots. If it has 300,000,000 slots. Put a counter into the program that counts the number of times the if statement is executed to confirm your answers. Can you derive a formula giving the count as a function of the size of the array? Suppose the array has 300,000,000 slots. How much total time is spent executing the if statement in the mystery function. Assume each execution of the if statement takes 1/1000000 seconds.

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

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

13.6 Describe the treatment of autism.

Answered: 1 week ago

Question

Discuss how selfesteem is developed.

Answered: 1 week ago