Repository navigation
[R45-T019] Document complexity and measure scaling of HeapElement - #59
Open
shyamlibakale1001-alt wants to merge 1 commit into
Open
shyamlibakale1001-alt wants to merge 1 commit into
shyamlibakale1001-alt wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Documents the complexity of
HeapElementinsrc/main/java/com/thealgorithms/datastructures/heaps/HeapElement.java(naming input-size variableNand distinguishing worst-caseO(1)-per-element bounds from JVM wall-clock observations), adds one representative regression test toHeapElementTest.java, adds the scaling and correctness experimentHeapElementScalingTest.java, and addswork/R45-T019/check.py(with timings and evidence saved strictly inwork/R45-T019/). All existing behavior and public interfaces are preserved.Related Issue
Fixes: #19
Type of Change
Changes Made
src/main/java/com/thealgorithms/datastructures/heaps/HeapElement.java(lines 23–31): forNHeapElementinstances, constructors,getKey(), andgetInfo()takeO(1)worst-case time and space per element (O(N)total work, 3 field operations per element in the experiment), distinguishing this worst-case bound from observed per-element wall-clock variance due to JIT warmup and allocation/GC, and notingtoString(),equals(), andhashCode()addO(1)key work plusadditionalInfo's method cost.testSmallestAndOrdinaryContractAndHashCode()tosrc/test/java/com/thealgorithms/datastructures/heaps/HeapElementTest.java(lines 57–70), checking(0.0, null)and(5.0, "Info")with literal expected values (0.0/null/"Key: 0.0 - No additional info"/0, and5.0/"Info"/"Key: 5.0 - Info"/2283881).src/test/java/com/thealgorithms/datastructures/heaps/HeapElementScalingTest.javawith 2 test methods:(0.0, null)and ordinary input(5.0, "Info")with hand-calculated literal expected outputs and precondition line citations.FIXED_SEED = 20261111L, 5 repetitions per size forN in {1000, 10000, 100000}): times only construction +getKey()+getInfo()outside input generation and verification, checks every constructed element outside the timed interval, asserts deterministic operation count3 * N, and imposes no wall-clock pass/fail threshold.work/R45-T019/check.py(with evidence files inwork/R45-T019/), runningmvn testforHeapElementScalingTest, enforcing a nonzero test count, savingcomparisons.txt,timings.txt,result.txt,mvn_output.txt, andtool_versions.txt, and exiting non-zero on failure.Screenshots / Recordings
Not applicable (no UI changes).
Testing
Command:
python3 work/R45-T019/check.py(runs
mvn -B test -Dtest=HeapElementScalingTest -Dsurefire.failIfNoSpecifiedTests=false)Result:
tests=2 failures/errors=0 skipped=0 comparisons=5 timings=3 mvn_exit=0,status=PASSObserved scaling (
work/R45-T019/timings.txt, 5 repetitions per size):N = 1,000:ops = 3,000,median = 46,083 ns,range = 40,584 ns(45,583..86,167 ns),46.08 ns/elemN = 10,000:ops = 30,000,median = 447,333 ns,range = 365,751 ns(113,541..479,292 ns),44.73 ns/elemN = 100,000:ops = 300,000,median = 1,108,875 ns,range = 117,167 ns(1,104,500..1,221,667 ns),11.09 ns/elemNormal suite:
mvn -B test -Dtest=HeapElementTest -Dsurefire.failIfNoSpecifiedTests=false→Tests run: 6, Failures: 0, Errors: 0, Skipped: 0(BUILD SUCCESS).Negative check: temporarily changing
this.key = key;tothis.key = key + 1;on line 48 causedpython3 work/R45-T019/check.pyto printstatus=FAIL(tests=2 failures/errors=2 skipped=0 mvn_exit=1) and exit non-zero; reverted and re-verified.Style:
mvn -B checkstyle:checkreports0 Checkstyle violations(BUILD SUCCESS).Tool versions, comparisons, and timings are saved in
work/R45-T019/tool_versions.txt,work/R45-T019/comparisons.txt, andwork/R45-T019/timings.txt.Checklist
Additional Notes
Timings are kept strictly inside
work/R45-T019/timings.txt(excluded from source code), and no pass/fail threshold depends on wall-clock timing.The
work/R45-T019/evidence folder is for coursework review only and should not go into any later upstream PR.I have read CONTRIBUTING.md.
This pull request is all my own work -- I have not plagiarized it.
All filenames are in PascalCase.
All functions and variable names follow Java naming conventions.
All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
All new algorithms include a corresponding test class that validates their functionality.
All new code is formatted with
clang-format -i --style=file path/to/your/file.java