# Reductions - Arup Guha This file will illustrate the idea...

This preview shows pages 1–2. Sign up to view the full content.

// Arup Guha // 7/13/2011 // This file will illustrate the idea of mapping reducibility via // several methods. In particular, solutions to different problems // will be obtained by transforming the input of one problem to the // input of another problem, such that both problems always have // the same answer. / public class Reductions { p // Returns true iff index i stores the minimum value in array. public static boolean isMin(int[] array, int i) { p // Invalid index, so it can't store the min. if (i < 0 || i >= array.length) return false; r // Find an index that stores the min. int minIndex = 0; for (int loop=1; loop<array.length; loop++) if (array[loop] < array[minIndex]) minIndex = loop; m // i stores a minimum value only if these two values are equal. return array[minIndex] == array[i]; } // This is our function that will help us map the max array problem to // the min array problem. It returns a new array that has values that // are the negated values of array. public static int[] maxToMin(int[] array) { p int[] newarray = new int[array.length]; i // Store the negative of each value in the new array. for (int i=0; i<array.length; i++)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 09/16/2011 for the course COT 4210 taught by Professor Staff during the Spring '08 term at University of Central Florida.

### Page1 / 3

Reductions - Arup Guha This file will illustrate the idea...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online