Task 2 Written Part Definitions and Assumptions • Boggle Board: – A Boggle board is a…
- User
Task 2 Written Part Definitions and Assumptions • Boggle Board: – A Boggle board is a grid of size n × n, where n is a positive integer. Each cell of the grid contains a single letter from a specified alphabet. • Word Definition: – A word in Boggle is any sequence of letters formed by moving from one cell to an adjacent cell, including horizontal, vertical, and diag- onal neighbors. The word can be of any length from 1 to n2 letters. A word can be any combination of letters. • Alphabet Size: – The alphabet size x denotes the number of distinct letters that can be used on the Boggle board. Current Complexity In the current setup of Boggle where letters can be reused: • Branching Factor: After the initial move, each subsequent move is lim- ited to a branching factor of 7, as the previous square cannot be revisited. This reduces the number of paths the algorithm must explore from any starting point to a maximum of 7 after the initial step. • Recurrence Relation: – Base Case: For a single letter, the complexity is T (1) = n2, as every cell in the grid can be a starting point. – First Move: For the first move, the complexity is T (2) = T (1) × 8, since there are eight possible directions to move from any starting point. – Subsequent Moves: For k ≥ 3 until n2 − 1, the recurrence relation becomes T (k) = T (k − 1) × 7, as each subsequent move is constrained to the remaining 7 directions. The last square can’t have any valid moves as all other squares in the board have been visited. 6 • Big O Complexity: The overall complexity is: T (k) = O
n2 × 7(n2−2) Impact of Disallowing Repeated Letters on Com- plexity And Using A Memoization Table Memoization and Complexity To analyze the theoretical Big O runtime of the algorithm using a DFS approach with a memoization table, we consider the following factors: • Position (x, y) on the board: There are n2 possible positions on an n × n board. • State of the Visited Cells Array: Each of the n2 cells can either be visited or not, resulting in 2n2 possible states. • State of the Used Letters Array: Each letter in the alphabet (size X) can either be used or not, resulting in 2X possible states. Combining the Components To determine the total number of unique memoization states, we multiply the number of possibilities for each component: • Positions: n2 • States of the visited array: 2n2 • States of the used letters array: 2X Thus, the total number of unique memoization states is: n2 × 2n2 × 2X Theoretical Big O Runtime Considering memoization, the complexity can be expressed as: O
n2 · 2n2+X 7 Explanation • The term n2 represents the number of starting points (each cell in the grid). • The 2n2 term accounts for the exponential number of possible states for the visited cells array. • The 2X term accounts for the exponential number of possible states for the used letters array. Handling Word Length Implicitly In Boggle, the word lengths vary from 1 to n2. This variation in word lengths is implicitly managed by the states of the visited array: • As the DFS progresses, the visited array keeps track of the cells that have been included in the current path. • Each unique state of the visited array corresponds to a specific sequence of cells visited, which directly correlates to the length of the word formed so far. • For example, if the visited array has 5 cells marked as visited, it implies that the current word being formed is of length 5. • Thus, different lengths of words are naturally represented by the different states of the visited array as the DFS explores various paths on the board. Conclusion Under the new rule that each letter can only be used once per word, the theo- retical Big O runtime of the algorithm using a DFS approach with memoization is: O
- Assistant