This GitHub Classroom lab is for Module 5: Recursion + Algorithms.
You will implement recursive and iterative solutions using a game server theme:
- recursive and iterative binary search on sorted match IDs
- recursive and iterative flood-fill / connected tile counting on a map
- recursive tournament bracket search with a helper method
By the end of this lab, you should be able to:
- Identify the base case and recursive case in a recursive method
- Use a helper method to simplify recursion
- Compare recursion and iteration on the same problem
- Explain when recursion is a natural fit and when a loop is simpler
Implement the TODO methods in GameAlgorithms.java:
findMatchRecursive(int[] sortedMatchIds, int target)findMatchIterative(int[] sortedMatchIds, int target)countConnectedTilesRecursive(char[][] map, int startRow, int startCol)countConnectedTilesIterative(char[][] map, int startRow, int startCol)containsMatch(BracketNode root, String target)using a recursive helper
- Do not change method names or parameter lists.
- Do not edit the tests.
- Keep all code in the package
edu.sdccd.cisc191. - For the recursive methods, make sure each recursive call moves toward a base case.
- For map traversal, mark visited tiles so you do not count the same tile twice.
mvn test- Read the tests first.
- Implement iterative binary search.
- Implement recursive binary search.
- Implement recursive bracket search with a helper method.
- Implement recursive tile counting.
- Implement iterative tile counting using a stack.
Answer these in comments at the top of GameAlgorithms.java or in your submission notes:
- What is the base case for your recursive binary search?
- Why is recursion natural for the bracket tree?
- Why might the iterative tile-counting method be safer on a very large map?
- Which problems in this lab felt more natural with loops, and which felt more natural with recursion?