In this assignment, you will analyze the exact number of statements executed by various algorithms and express your results as mathematical functions of the input size n.
By completing this assignment, you will:
- Master statement counting: Learn to count every statement execution in algorithms
- Understand growth patterns: See how different algorithmic structures lead to different growth rates
- Practice mathematical analysis: Express algorithm complexity as precise mathematical functions
- Verify theoretical analysis: Use code execution traces to validate your mathematical work
- Connect theory to practice: Bridge the gap between abstract analysis and concrete implementation
- Download and extract the PA1 starter code zip file
- Open the folder in VS Code
- When prompted, click "Reopen in Container"
- Wait for the container to build (first time setup)
- The Java 21 development environment will be automatically configured
Requirements:
- Java 21 or higher
- Gradle (or use included wrapper)
- Git (optional)
Verify setup:
java -version
./gradlew --version
Analyze algorithms 1-5 from the provided pseudocode and determine the exact number of statements executed as a function of n.
Count every statement that executes, including:
- Variable initializations (
s = 0
,t = 1
) - Loop body statements (
s = s + t * b[i]
) - Array assignments (
A[i,j,k] = ...
)
Do NOT count:
- Loop condition checks
- Function calls or returns
- Comments or blank lines
Each algorithm is provided as pseudocode in the assignment PDF and implemented in Java with detailed logging. The Java implementations help you:
- See execution traces: Every iteration prints its work
- Verify statement counts: Actual counts are displayed
- Test different input sizes: Run with various values of n
- Understand the patterns: See how growth changes with n
The comprehensive test suite shows detailed execution traces for all algorithms:
./gradlew test
This will run all algorithms with various input sizes and print detailed execution information including:
- Every loop iteration
- Variable values at each step
- Statement counts for verification
- Expected vs actual results
Use the main method for additional testing:
./gradlew run
You can modify the main method in AlgorithmAnalysis.java
to test specific cases or input sizes.
Fill out the ANALYSIS.md
file with step-by-step explaination and a final f(n) function expressing the exact statement count for each algorithm.
- Pattern: Simple loop with array access
- Key insight: Each iteration does the same amount of work
- Pattern: Every combination of i and j from 1 to n
- Key insight: Inner loop always executes n times
- Pattern: Three-dimensional processing
- Key insight: Cubic growth pattern
- Pattern: Inner loop bound depends on outer loop variable
- Key insight: Not all nested loops are equal!
- Pattern: Repeatedly divide input by 2
- Key insight: How many times can you halve n?
For Algorithm 1:
- Read the pseudocode and understand what it does
- Run the test and observe the execution trace
- Count initialization statements:
s = 0
andt = 1
→ 2 statements - Analyze the loop: executes n times, 2 statements per iteration → 2n statements
- Combine: f₁(n) = 2 + 2n
- Complete
ANALYSIS.md
with your mathematical analysis - Test your work using
./gradlew test
to verify your functions - Create submission file using one of these methods:
tar -czf pa1-YOURNAME.zip /workspace
Then download the file from the container.
Right-click the assignment folder and compress to ZIP.
Your compressed file should contain:
ANALYSIS.md
- Your completed mathematical analysis- All original starter code files (unchanged Java files are fine)
- Any additional test cases you created (optional)
Important: The Java implementations are provided to help your analysis - you don't need to modify them unless you want to test additional cases.
- Submission (33.3%): Work made available to instructoras required by submission guidelines. Software artifacts are located and named as specified in the assignment.
- Completeness (33.3%): All problems are attempted. Incomplete problems are also incorrect.
- Correctness (33.3%): Work demonstrates a clear understanding of the material.
- Office Hours: Tuesday & Wednesday 12:30-1:30 PM (Herman 207)
- Syllabot: Use the course AI assistant for conceptual questions
- Discussion: Talk through approaches with classmates (but write your own analysis)
This is an individual assignment. You may:
- Discuss approaches and concepts with classmates
- Use course materials and textbook
- Ask questions during office hours
- Use the provided Java code to understand the algorithms
You may NOT:
- Copy analysis from other students
- Use AI tools to generate mathematical solutions
- Submit work you don't understand
- Share your completed ANALYSIS.md file
The goal is to understand why these algorithms have different growth patterns and develop skills in systematic algorithm analysis.
Course content developed by Declan Gray-Mullen for WNEU with Claude