Skip to content

Add PageRank algorithm#1052

Open
BSZKaneki wants to merge 2 commits into
TheAlgorithms:masterfrom
BSZKaneki:Add-PageRank-algorithm-
Open

Add PageRank algorithm#1052
BSZKaneki wants to merge 2 commits into
TheAlgorithms:masterfrom
BSZKaneki:Add-PageRank-algorithm-

Conversation

@BSZKaneki

@BSZKaneki BSZKaneki commented Jun 26, 2026

Copy link
Copy Markdown

Description

This pull request implements the PageRank algorithm under the graph module.

Algorithm Overview

PageRank is an algorithm used to rank elements in a network based on their structure of incoming links. It computes a probability distribution representing the likelihood that a person randomly clicking on links will arrive at any particular page.

For more details, see the Wikipedia article: https://en.wikipedia.org/wiki/PageRank

Implementation Details

  • Genericity: Uses a generic type Node: Hash + Eq + Clone, meaning it can rank nodes of any type (e.g., String, integer types, or custom hashable structures).
  • Dangling Nodes: Accurately handles "dangling nodes" (nodes with no outbound edges) by redistributing their rank mass evenly across all nodes in the graph during each iteration.
  • Deduplication: Handles duplicate/parallel edges between the same source and destination to prevent artificial weight skewing.
  • Convergence: Performs power iteration with an early exit check using an L1 norm difference calculation against a user-defined threshold.
  • Testing: Includes 18 tests covering edge cases (such as self-loops, disconnected components, and linear chains) and checking against known analytical results. The entire test suite completes in approximately 0.01s.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I ran below commands using the latest version of rust nightly.
  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked CONTRIBUTING.md and my code follows its guidelines.

@BSZKaneki BSZKaneki requested a review from imp2002 as a code owner June 26, 2026 16:23
@codecov-commenter

codecov-commenter commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.63768% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.88%. Comparing base (8ba3163) to head (1d202fd).

Files with missing lines Patch % Lines
src/graph/page_rank.rs 99.63% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1052      +/-   ##
==========================================
+ Coverage   95.85%   95.88%   +0.03%     
==========================================
  Files         395      396       +1     
  Lines       30160    30436     +276     
==========================================
+ Hits        28910    29185     +275     
- Misses       1250     1251       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@BSZKaneki

Copy link
Copy Markdown
Author

@siriak Hello could you please take a look at this pull request when you have a moment?

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.

2 participants