Question

In: Computer Science

Write a recursive method to find the smallest int in an unsorted array of numbers. int[]...

Write a recursive method to find the smallest int in an unsorted array of numbers.

int[] findMin = { 0, 1, 1, 2, 3, 5, 8, -42, 13, 21, 34, 55, 89 };

System.out.printf("Array Min: %d\n", arrayMin(findMin, 0)

public static int arrayMin(int[] data, int position) { ??? }

everything I've tried doesn't return the -42 like it should, somehow I think I end up returning a count of the search or something like that and I'm not sure where I'm going wrong. Thanks for the help.

Solutions

Expert Solution

import java.util.Scanner;
public class Main
{
   public static void main(String[] args)
   {
       int[] findMin= { 0, 1, 1, 2, 3, 5, 8, -42, 13, 21, 34, 55, 89 };
       System.out.printf("Array Min: %d\n", arrayMin(findMin, 0));
   }
   public static int arrayMin(int[] data, int position)
   {
   int n = data.length;//to know the length of the array.
int i,min;
min = data[position];
for(i=0;i<n;i++)
{
if(min>data[i])
{
min=data[i];
arrayMin(data,i++);
}
}
return min;
   }
}


Related Solutions

Find the K'th smallest element in an unsorted array of integers. Find the K'th largest element...
Find the K'th smallest element in an unsorted array of integers. Find the K'th largest element in an unsorted array of integers. please make two separate methods in java
Given an array of numbers, find the index of the smallest array element (the pivot), for...
Given an array of numbers, find the index of the smallest array element (the pivot), for which the sums of all elements to the left and to the right are equal. The array may not be reordered. Example arr=[1,2,3,4,6] the sum of the first three elements, 1+2+3=6. The value of the last element is 6. Using zero based indexing, arr[3]=4 is the pivot between the two subarrays. The index of the pivot is 3. Function Description Complete the function balancedSum...
Develop a recursive algorithm to find the smallest and largest element in an array and trace...
Develop a recursive algorithm to find the smallest and largest element in an array and trace the recursive function with appropriate message. using c++ add comment to the code
Write a method which is passed A[], which is an array of int, and an int...
Write a method which is passed A[], which is an array of int, and an int passingScore. The method returns the number of items in A[] which are greater than or equal to passingScore. Write a method which is passed an array of int A[]. The method returns true if A[] is the same backwards and forwards. Write a method same( ), which is passed two arrays of int. The method returns true if the two arrays contain exactly the...
Using Python Implement Recursive Selection Sort with the following recursive method. 1. Find the smallest number...
Using Python Implement Recursive Selection Sort with the following recursive method. 1. Find the smallest number in the list and swaps it with the first number. 2.Ignore the first number and sort the remaining smaller list recursively.
Radix sortCome up with an unsorted array of numbers (integer array). Sort the numbers in ascending...
Radix sortCome up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. I need this in java language.
Radix sort Come up with an unsorted array of numbers (integer array). Sort the numbers in...
Radix sort Come up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. (Write a C# program)
Radix sortCome up with an unsorted array of numbers (integer array). Sort the numbers in ascending...
Radix sortCome up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. I need this in java language. Radix Sort assignment (CISP430 ignore this part) This is only for those who are using Java How many classes do I need? A: Node, Queue, Radix, Driver...
Radix sort Come up with an unsorted array of numbers (integer array). Sort the numbers in...
Radix sort Come up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. C++ program thanks
how to write in java; Write a method int[] coPrime[int num, int[]numbers] { // instructions are...
how to write in java; Write a method int[] coPrime[int num, int[]numbers] { // instructions are that it returns an array of all the elements of the int[] array numbers which are coprime with x } Note that the array that is returned may be an empty array--you will have to count how many times gcf(x, numbers[i]) == 1. ASSUME numbers is not null and not empty.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT