/********************************************************************** * HW4 - Blocky * PROGRAM ANALYSIS * * For each method below: * - List the data structure(s) you used. Provide a brief justification * - Provide its big-O. Provide a brief justification * Only answer for 5 methods **********************************************************************/ * random_init (1 pt): ********************************************************************** * getBlock (1 pt): ********************************************************************** * swap (1 pt): ********************************************************************** * smash (1 pt): ********************************************************************** * rotate (1 pt): ********************************************************************** * flatten (1 pt): ********************************************************************** * perimeter_score (0 pt): Runtime analysis: perimeter_score Algorithm: We call flatten() and store the result in a 2D array We go through the array and count the number of border cells with the target color. Analysis: The number of cells in the array is the number of leaf nodes in the QuadTree; since it is a full 4-ary tree, we get the maximum number of leaf nodes when all the levels in the quadtree are full. Then, the number of leaf nodes is roughly equal to (3 * n)/4, with n representing the total number of nodes in the tree. Hence traversing the 2D array runs in O(n). Since the method also call flatten(), the perimeter_score methos described above runs in Max{O(flatten) ,O(n)} **********************************************************************