



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




A chessboard is an n x n grid, where n is a power of 2.
1x1 2x2 4x4 8x
A defective chessboard is a chessboard that has one unavailable (defective) position.
1x1 2x2 4x4 8x
A triomino is an L shaped object that can cover three squares of a chessboard.
A triomino has four orientations.
Find the lightest and heaviest of n elements using a balance that allows you to compare the weight of 2 elements.
Minimize the number of comparisons.
maxElement = 0;
for (int i = 1; i < n; i++)
if (w[maxElement] < w[i]) maxElement = i;
n > 2. Divide the n elements into 2 groups A and B with floor(n/2) and ceil(n/2) elements, respectively. Find the min and max of each group recursively. Overall min is min{min(A), min(B)}. Overall max is max{max(A), max(B)}.
{8,2,6,3,9,1,7,5,4,2,8} {8,2,6,3,9} (^) {1,7,5,4,2,8}
{8,2} {6,3,9}
{6} {3,9}
{1,7,5} {4,2,8}
{1} {7,5}^ {4}^
{2,8}
{8,2}
{2,8} {6} {3,9} (^) {1} {7,5} {4} {2,8}
{6,6} {3,9}
{3,9}
{2,9}
{1,1} {5,7}
{1,7}
{4,4} {2,8}
{2,8}
{1,8}
{1,9}
c(n) = c(floor(n/2)) + c(ceil(n/2)) + 2
{8,2,6,3,9,1,7,5,4,2,8} {8,2,6,3,9} (^) {1,7,5,4,2,8}
{8,2} {6,3,9}
{6} {3,9}
{1,7,5} {4,2,8}
{1} {7,5}^ {4}^ {2,8}
{8,2}
{2,8} {6} {3,9} (^) {1} {7,5} {4} {2,8}
{6,6} {3,9}
{3,9}
{2,9}
{1,1} {5,7}
{1,7}
{4,4} {2,8}
{2,8}
{1,8}
{1,9}