Skip to content

Add PageRank algorithm#1052

Merged
siriak merged 9 commits into
TheAlgorithms:masterfrom
BSZKaneki:Add-PageRank-algorithm-
Jun 28, 2026
Merged

Add PageRank algorithm#1052
siriak merged 9 commits into
TheAlgorithms:masterfrom
BSZKaneki:Add-PageRank-algorithm-

Conversation

@BSZKaneki

@BSZKaneki BSZKaneki commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

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.64539% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.88%. Comparing base (8ba3163) to head (b30b221).

Files with missing lines Patch % Lines
src/graph/page_rank.rs 99.64% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1052      +/-   ##
==========================================
+ Coverage   95.85%   95.88%   +0.02%     
==========================================
  Files         395      396       +1     
  Lines       30160    30442     +282     
==========================================
+ Hits        28910    29189     +279     
- Misses       1250     1253       +3     

☔ 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
Contributor Author

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a PageRank implementation to the graph module, exposing it publicly and documenting it in the repository’s algorithm directory.

Changes:

  • Implemented page_rank in src/graph/page_rank.rs with handling for dangling nodes, duplicate edges, and early convergence.
  • Exported the new algorithm from src/graph/mod.rs.
  • Added an entry for the new algorithm to DIRECTORY.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
src/graph/page_rank.rs New PageRank implementation plus accompanying tests and docs/comments.
src/graph/mod.rs Registers the new module and re-exports page_rank.
DIRECTORY.md Adds a directory listing entry linking to the new implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/graph/page_rank.rs Outdated
Comment thread src/graph/page_rank.rs
Comment thread src/graph/page_rank.rs Outdated
Comment thread src/graph/page_rank.rs
Comment thread src/graph/page_rank.rs Outdated
Comment thread src/graph/page_rank.rs Outdated
@siriak

siriak commented Jun 27, 2026

Copy link
Copy Markdown
Member

Please check the comments

Comment thread src/graph/page_rank.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread src/graph/page_rank.rs
Comment thread src/graph/page_rank.rs
BSZKaneki and others added 2 commits June 28, 2026 12:34
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@siriak siriak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@siriak siriak merged commit c65d014 into TheAlgorithms:master Jun 28, 2026
7 checks passed
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.

4 participants