Reductions - / / / / / / / Arup Guha 7/13/2011 This file...

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

View Full Document Right Arrow Icon
// 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++)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

Reductions - / / / / / / / Arup Guha 7/13/2011 This file...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online