{"record":{"id":"27458acd279e931f","repo":"TheAlgorithms/Java","slug":"damping-factor-must-be-between-0-and-1","errorCode":null,"errorMessage":"Damping factor must be between 0 and 1","messagePattern":"Damping factor must be between 0 and 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/others/PageRank.java","lineNumber":188,"sourceCode":"        }\n\n        return pageRankValues.clone();\n    }\n\n    /**\n     * Validates input parameters for PageRank calculation\n     *\n     * @param totalNodes    the total number of nodes\n     * @param dampingFactor the damping factor\n     * @param iterations    number of iterations\n     * @throws IllegalArgumentException if parameters are invalid\n     */\n    private void validateInputParameters(int totalNodes, double dampingFactor, int iterations) {\n        if (totalNodes < 1 || totalNodes > MAX_NODES) {\n            throw new IllegalArgumentException(\"Total nodes must be between 1 and \" + MAX_NODES);\n        }\n        if (dampingFactor < 0 || dampingFactor > 1) {\n            throw new IllegalArgumentException(\"Damping factor must be between 0 and 1\");\n        }\n        if (iterations < 1) {\n            throw new IllegalArgumentException(\"Iterations must be at least 1\");\n        }\n    }\n\n    /**\n     * Initializes PageRank values for all nodes\n     *\n     * @param totalNodes      the total number of nodes\n     * @param initialPageRank the initial PageRank value\n     * @param verbose         whether to print output\n     */\n    private void initializePageRanks(int totalNodes, double initialPageRank, boolean verbose) {\n        for (int i = 1; i <= totalNodes; i++) {\n            pageRankValues[i] = initialPageRank;\n        }\n","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/others/PageRank.java#L170-L206","documentation":"Thrown by PageRank.validateInputParameters when dampingFactor is outside [0, 1]. The damping factor weights the random-surfer contribution in the PageRank formula; values below 0 or above 1 break the probabilistic model and the convergence of the iteration.","triggerScenarios":"Triggering a calculation that calls validateInputParameters with dampingFactor < 0 or dampingFactor > 1; passing a percentage (e.g. 85) instead of a fraction (0.85).","commonSituations":"Supplying a percentage (85) instead of a fraction (0.85); a slider/config yielding an out-of-range value; defaulting an unset parameter to 0 and then nudging it negative.","solutions":["Pass dampingFactor as a fraction in [0, 1] (the classic default is 0.85).","If your input is a percentage, divide by 100 before passing.","Clamp the value to [0, 1] at the boundary.","Validate at config-load time so the error surfaces with full context."],"exampleFix":"// before\npageRank.calc(totalNodes, 85, iterations); // 85 > 1 -> throws\n\n// after\ndouble damping = percent / 100.0; // e.g. 85 -> 0.85\npageRank.calc(totalNodes, damping, iterations);","handlingStrategy":"validation","validationCode":"double damping = Math.max(0.0, Math.min(1.0, dampingFactor));\npageRank.calc(totalNodes, damping, iterations);","typeGuard":"public static boolean isValidDamping(double d) {\n    return d >= 0.0 && d <= 1.0;\n}","tryCatchPattern":"try {\n    pageRank.calc(total, damping, iters);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Damping\")) {\n        pageRank.calc(total, 0.85, iters); // classic default\n    } else throw e;\n}","preventionTips":["Pass damping as a fraction in [0, 1]; the classic value is 0.85.","If input is a percentage, divide by 100 first.","Clamp the value at the config boundary."],"tags":["validation","pagerank","input-validation","range","numeric"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}