Skip to content

R50-T009: Measure the work done by fibonacci (FibonacciNumberRecursive.js) [Recursive/FibonacciNumberRecursive.js] - #107

Open
stavansomaiya wants to merge 1 commit into
S-AI-Projects:masterfrom
stavansomaiya:student/e26b07f1064/R50-T009
Open

stavansomaiya wants to merge 1 commit into
S-AI-Projects:masterfrom
stavansomaiya:student/e26b07f1064/R50-T009

Conversation

@stavansomaiya

@stavansomaiya stavansomaiya commented Nov 23, 2026 •

Copy link
Copy Markdown

Description

Task R50-T009 · task 9 of 10 · Complexity experiment
Issue #9 · Measure the work done by fibonacci
Student Stavan Somaiya · URN e26b07f1064
File → function Recursive/FibonacciNumberRecursive.js → fibonacci (line 9 at the pinned commit, line 19 after this PR)
Pinned source TheAlgorithms/JavaScript @ 5c39e87 · FibonacciNumberRecursive.js#L9
Branch stavansomaiya:student/e26b07f1064/R50-T009 → S-AI-Projects:master (one commit on 5c39e87)
Outcome The call count is exactly 2·F(n+1) − 1, so time is Θ(φⁿ); this is documented. The implementation is unchanged.

Summary

Adds a complexity statement to Recursive/FibonacciNumberRecursive.js, backed by an experiment, plus a representative regression for the zero-based indexing the source uses.

Complexity (input-size variable: the index n): the call count is exactly C(n) = 2·F(n+1) − 1, from C(0) = C(1) = 1 and C(n) = 1 + C(n−1) + C(n−2). So time is Θ(φⁿ), and space is O(n) for the recursion stack. The function is deterministic, so this is both the worst case and every case. That is the proved claim; the experiment is a separate observation.

Files changed

File Lines What changed
Recursive/FibonacciNumberRecursive.js +10 / −0 JSDoc: indexing convention and complexity statement (no logic change)
Recursive/test/FibonacciNumberRecursive.test.js +15 / −0 indexing regression: 0, 1, 2, 5, 10 → 0, 1, 1, 5, 55
work/R50-T009/ (9 files) evidence check.py runner, README.md write-up, evidence.mjs, results.json and logs; coursework only, kept out of any upstream PR

Related Issue

Fixes: #9

This PR covers only R50-T009. Each of the 10 tasks has its own branch, commit and PR; see All 10 tasks under Additional Notes.

Type of Change

  • Bug Fix
  • New Feature
  • UI/UX Improvement
  • Performance Improvement
  • Tests
  • Documentation
  • Refactoring / Maintenance
  • CI/CD

Changes Made

  • Recursive/FibonacciNumberRecursive.js: JSDoc with the indexing convention and the complexity statement above. No logic change.
  • Recursive/test/FibonacciNumberRecursive.test.js: indices 0, 1, 2, 5 and 10 → 0, 1, 1, 5 and 55.
  • work/R50-T009/: check.py, evidence.mjs and timings.json. For n = 20, 24 and 28 the measured call counts are 21,891, 150,049 and 1,028,457, exactly matching the formula (ratio 6.854 = φ⁴ each step). Timings use 5 repetitions per size and report the median and range.

Screenshots / Recordings

There is no UI, so the recording is the terminal output of a fresh run on 23 Nov 2026. The run used a clean checkout of this branch with a new npm ci from the lockfile. The output is copied verbatim; only the temporary checkout path is replaced by a label.

Focused tests: npx vitest run … --reporter=verbose, 9/9 passed
$ npx vitest run Recursive/test/FibonacciNumberRecursive.test.js --reporter=verbose
 RUN  v1.2.1 <clean checkout of student/e26b07f1064/R50-T009>
 ✓ Recursive/test/FibonacciNumberRecursive.test.js > FibonacciNumberRecursive > should return 0
 ✓ Recursive/test/FibonacciNumberRecursive.test.js > FibonacciNumberRecursive > should return 1
 ✓ Recursive/test/FibonacciNumberRecursive.test.js > FibonacciNumberRecursive > should return 5
 ✓ Recursive/test/FibonacciNumberRecursive.test.js > FibonacciNumberRecursive > should return 9
 ✓ Recursive/test/FibonacciNumberRecursive.test.js > FibonacciNumberRecursive indexing > fibonacci(0) is 0
 ✓ Recursive/test/FibonacciNumberRecursive.test.js > FibonacciNumberRecursive indexing > fibonacci(1) is 1
 ✓ Recursive/test/FibonacciNumberRecursive.test.js > FibonacciNumberRecursive indexing > fibonacci(2) is 1
 ✓ Recursive/test/FibonacciNumberRecursive.test.js > FibonacciNumberRecursive indexing > fibonacci(5) is 5
 ✓ Recursive/test/FibonacciNumberRecursive.test.js > FibonacciNumberRecursive indexing > fibonacci(10) is 55
 Test Files  1 passed (1)
      Tests  9 passed (9)
Automated check: python3 work/R50-T009/check.py, exit 0
$ python3 work/R50-T009/check.py
[PASS] fibonacci(0)
       input:    0
       expected: 0
       actual:   0
       source:   FibonacciNumberRecursive.js:8 zero-based indexing; :20-21 base case n < 2
[PASS] fibonacci(1)
       input:    1
       expected: 1
       actual:   1
       source:   FibonacciNumberRecursive.js:8 zero-based indexing; :20-21 base case n < 2
[PASS] fibonacci(2)
       input:    2
       expected: 1
       actual:   1
       source:   FibonacciNumberRecursive.js:8 zero-based indexing; :20-21 base case n < 2
[PASS] fibonacci(5)
       input:    5
       expected: 5
       actual:   5
       source:   FibonacciNumberRecursive.js:8 zero-based indexing; :20-21 base case n < 2
[PASS] fibonacci(10)
       input:    10
       expected: 55
       actual:   55
       source:   FibonacciNumberRecursive.js:8 zero-based indexing; :20-21 base case n < 2
[PASS] n = 20: value and exact call count
       input:    20
       expected: {"value": 6765, "calls": 21891}
       actual:   {"value": 6765, "calls": 21891}
       source:   FibonacciNumberRecursive.js:23 two recursive calls per n >= 2
[PASS] n = 24: value and exact call count
       input:    24
       expected: {"value": 46368, "calls": 150049}
       actual:   {"value": 46368, "calls": 150049}
       source:   FibonacciNumberRecursive.js:23 two recursive calls per n >= 2
[PASS] n = 28: value and exact call count
       input:    28
       expected: {"value": 317811, "calls": 1028457}
       actual:   {"value": 317811, "calls": 1028457}
       source:   FibonacciNumberRecursive.js:23 two recursive calls per n >= 2
[KILLED] mutant base case widened (n < 2 becomes n <= 2): '  if (n < 2) {\n' -> '  if (n <= 2) {\n'
       failed:  FibonacciNumberRecursive should return 5
       failed:  FibonacciNumberRecursive should return 9
       failed:  FibonacciNumberRecursive indexing fibonacci(2) is 1
       failed:  FibonacciNumberRecursive indexing fibonacci(5) is 5
       failed:  FibonacciNumberRecursive indexing fibonacci(10) is 55

focused tests: 9/9 passed  (node_modules/.bin/vitest run Recursive/test/FibonacciNumberRecursive.test.js --reporter=json --outputFile=work/R50-T009/vitest-focused.raw.json)
npm test:      11975/11975 passed  (npm test -- --reporter=json --outputFile=work/R50-T009/vitest-full.raw.json)

R50-T009: all checks passed
(exit 0)

Testing

Automated check: python3 work/R50-T009/check.py installs from the lockfile and runs the focused tests. It then prints input / expected / actual for every fixture row, runs each deliberate mutant in a temporary copy, and finally runs the repository test script in non-watch mode. It exits non-zero if any assertion or step fails, and records every command in commands.log.

To reproduce:

git fetch https://github.com/stavansomaiya/TheAlgorithms-JavaScript.git student/e26b07f1064/R50-T009
git checkout FETCH_HEAD
python3 work/R50-T009/check.py

Recorded results (committed in results.json; tool versions in versions.txt):

Check Command Result
Install from lockfile npm ci --ignore-scripts --no-audit --no-fund ✅ exit 0
Focused tests vitest run Recursive/test/FibonacciNumberRecursive.test.js ✅ 9/9 passed
Fixture evidence (input / expected / actual / source line) node work/R50-T009/evidence.mjs ✅ 8/8 rows match
Mutant (temporary copy): base case widened (n < 2 becomes n <= 2) applied by check.py ✅ caught by fibonacci(2) is 1
Repository test script, non-watch npm test (vitest run) ✅ 11975/11975 passed
Code style npm run check-style (Prettier) ✅ passes
Spelling (CI settings) codespell ✅ no new findings

Acceptance criteria → evidence:

# Done when (quoted from #9) Evidence in this PR
1 The checked behavior is tied to fibonacci in Recursive/FibonacciNumberRecursive.js; every assertion has an explicit expected value. ✅ fibonacci(0) is 0, fibonacci(1) is 1, fibonacci(2) is 1, fibonacci(5) is 5, fibonacci(10) is 55: each asserts a literal value.
2 Use indices 0, 1, 2, 5 and 10 with the indexing convention stated by the source; the conventional zero-based values are 0, 1, 1, 5 and 55. ✅ Indices 0, 1, 2, 5, 10 → 0, 1, 1, 5, 55, using the zero-based convention the source defines (n < 2 returns n, lines 20-21).
3 Existing supported behavior and the public interface are preserved unless a failing regression demonstrates and documents a defect. ✅ No logic change (JSDoc only). The 4 existing tests pass, and the full suite passes (11975/11975).
4 The complexity statement names its input-size variable and distinguishes worst-case claims from observations. ✅ The JSDoc names the input-size variable, the index n. The call count is exactly 2·F(n+1) − 1, so time is Θ(φⁿ) and space O(n). This is a proved bound that holds for every input, worst case included; the timings are labelled as an observation.
5 No pass/fail threshold depends on wall-clock speed; all measured cases pass correctness checks. ✅ Pass/fail uses only values and exact call counts, never wall-clock time. Sizes n = 20, 24 and 28 use 5 repetitions each, reporting median and range. Every measured result is checked against an independent iterative implementation, outside the timed interval.

Evidence files: check.py · README.md (contract, fixture, baseline, findings) · evidence.mjs · results.json · vitest-focused.json

Checklist

  • I have tested my changes locally.
  • I have added or updated tests, if needed.
  • I have updated documentation, if needed.
  • I have followed the project's coding guidelines.
  • I have run the relevant tests and checks.
  • I have addressed previous review feedback, if applicable. (No review feedback yet.)

Additional Notes

No pass/fail threshold depends on wall-clock speed; only values and exact call counts are asserted. Timing excludes process startup, module loading, I/O and JIT warm-up, and all outputs are checked against an independent iterative implementation outside the timed interval. Sensitivity check: widening the base case to n <= 2 in a temporary copy fails fibonacci(2) is 1.

Scope: the PR changes only Recursive/FibonacciNumberRecursive.js, its test file and work/R50-T009/. work/R50-T009/ is coursework evidence and would be removed from any later upstream PR.

All 10 tasks (one PR each)
Task Issue Branch Pull request
R50-T001: Lock down the contract of setBit #1 R50-T001 #99
R50-T002: Define the supported boundaries of checkKeywordValidity #2 R50-T002 #100
R50-T003: Cross-check getParentPosition #3 R50-T003 #101
R50-T004: Test an invariant of swap #4 R50-T004 #102
R50-T005: Make verification repeatable for newGeneration #5 R50-T005 #103
R50-T006: Simplify one responsibility in countLetters #6 R50-T006 #104
R50-T007: Publish a runnable example for DisjointSetTreeNode #7 R50-T007 #105
R50-T008: Cover the failure behavior of TrieNode #8 R50-T008 #106
R50-T009: Measure the work done by fibonacci #9 R50-T009 #107 (this PR)
R50-T010: Strengthen the tests of OpenKnightTour #10 R50-T010 #108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stavan Somaiya — R50-T009: Measure the work done by fibonacci (FibonacciNumberRecursive.js) [Recursive/FibonacciNumberRecursive.js]

1 participant