Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.) Write an efficient algorithm for finding the smallest element in an unsorted

ID: 3564206 • Letter: 1

Question

1.) Write an efficient algorithm for finding the smallest element in an unsorted list. Compare your algorithm with the algorithm in your text. Specifically give the exact number of comparisons required by your algorithm vs. the exact number of comparisons for the algorithm in the book.

2.) Put the following recurrence relation into closed form.

                T(n) = 4T(n/4)+n-2

                T(1) = 3

1.) Write an efficient algorithm for finding the smallest element in an unsorted list. Compare your algorithm with the algorithm in your text. Specifically give the exact number of comparisons required by your algorithm vs. the exact number of comparisons for the algorithm in the book. 2.) Put the following recurrence relation into closed form. T(n) = 4T(n/4)+n-2 T(1) = 3

Explanation / Answer

public class SmallestPositiveNumber

{

public static void main(String str[])

{
int array[] = { 2, 3, -7, 6, 8, 1, -10, 15 };

int i=0;
int answer=0;
while(array[i]<0)i++;
int minumum = array[i];
int maximum = array[i];
for(int j=i;j<array.length;j++)

{
if(array[j]>0 && minumum>array[j])
minumum = array[j];
if(array[j]>0 && maximum<array[j])
maximum=array[j];
}

}