20.11 Imagine you have a square matrix, where each cell is filled with either black or white. Design an algorithm to find the maximum subsquare such that all four borders are filled with black pixels. // A brute force solution. // n * n // iterate fr
20.6 Describe an algorithm to find the largest 1 million numbers in 1 billion numbers. Assume that the computer memory can hold all one billion numbers. // can hold all numbers. // Cheating! // Do we know the max or min? // Consider using bitmap // I
20.2 Write a method to shuffle a deck of cards. It must be a perfect shuffle - in other words, each 52! permutations of the deck has to be equally likely. Assume that you are given a random number generator which is perfect. // Randomly generate a in
20.4 Write a method to count the number of 2s between 0 and n. // What this mean? // Given a n. // for (int i = 0 -> n) // { // result += numOf2In(i); // } // This is purely a math problem.
20.9 Numbers are randomly generated and passed to a method. Write a program to find and maintain the median value as new values are generated. class MedianNum { // O(n) void insert(int n) { if (size == 0) { head = new Node(n);
import CtCILibrary.AssortedMethods; public class Question { // Assume string has sufficient free space at the end public static void replaceSpaces(char[] str, int length) { int spaceCount = 0, index, i = 0; for (i = 0; i < length; i++) { if (str[i] =