Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q1 (a)Write the java code for doing a Linear Search on the array given below. Write your code in the space below, (b) What would

Q1

(a)Write the java code for doing a Linear

Search on the array given below.

Write your code in the space below,

(b) What would your search method return if we asked to search for the number 2 and

return its index position?

[24][2][45][20]56][75][2][56][99][53][12]

Q2.

Calculate the Big Oh performance for the following:

Given that an Array of size n=10 takes 3 seconds to search, how long does it take a search Array of size n=100?

(a)Linear Search of an array of size n=100 Given O(n)

(b) Merge Sort performance of an array is O(n log(n)),

given that an Array of size n=10 takes 3 seconds to sort, how long does it take to sort an Array of size n=100?

Q3

(a) Convert the following iterative method to recursive method.

(b) What is the advantage and disadvantage of using recursion?

Write your code in the space below, (no need to submit .javafile)

public static

int factorialIterative(int n) {

int res = 1;

while (n > 0) {

res = res * n;

n

--

;

}

return res;

}

Q4

Write aprogram where you use Selec tion Sort to sort the following array in ascending order.

24,2,45,20,56,75,2,56,99,53,12

a) Declare an array of integers called unsortedarr and load it with the integers above. Notice we have 11 numbers, and the number 2 is repeated which is fine.

Display the array as it is by printing it before the sort.

b) Sort the array using the insertion sort technique and display the array after you sort it. Here is the beginning of the code, complete it, run it, test it, submit it.

import java.util.*

;

public class MySelectSort{

public static void main(String[]args) {

int arr[] = {24,2,45,20,56,75,2,56,99,53,12};

System.out.println("---------------------------unsorted");

System.out.println(arr);

// continue ... write your code

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

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

How do marketers modify the components of attitude?

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago