Algorithm to determine most popular article last week, month and year?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Determining the most popular articles over specific time periods like the last week, month, or year is essential for media companies and content platforms. It helps in understanding audience preferences, optimizing content strategy, and enhancing user engagement. This article delves into the algorithmic approach to identify the most popular articles using metrics such as views, shares, comments, and more.
Algorithm Overview
The algorithm to determine the most popular articles is fundamentally a ranking system based on multiple popularity metrics. Here's a step-by-step explanation.
Data Collection
Collect data related to article performance. The common metrics include: • Views: Number of times an article is viewed. • Shares: Number of times an article is shared on social media or other platforms. • Comments: Number of user comments on an article. • Engagement Time: The amount of time users spend on the article page.
Data Normalization
These metrics often have different scales and units. Apply normalization to ensure fair comparison. One common approach is Min-Max normalization:
Where:
• is the original value.
• $x_\{min\}$ and $x_\{max\}$ are the minimum and maximum values of the metric respectively.
• is the normalized value.
Scoring Function
Develop a scoring function that aggregates the normalized metrics into a single popularity score. The scoring function can be a weighted sum:
Where: • are weights for each metric, representing their relative importance.
Time Partitioning
Partition the data according to the desired time frame (week, month, or year). Ensure that the metrics are aggregated over these periods for each article.
Sorting and Ranking
Sort the articles based on the aggregated popularity score for each time period. Ranking is straightforward: the higher the score, the more popular the article.
Implementation Example
Below is a simplified example in Python, illustrating how to compute and rank articles using the algorithm outlined above.
Related reading
- Algorithm to find optimal groups
- Algorithm to find top 10 search terms
- Algorithm to group sets of points together that follow a direction
- Algorithm to smooth a curve while keeping the area under it constant
- Algorithm to determine the best team and formation?
- Algorithm to determine the highest and lowest possible finishing position of a team in a league
- algorithm used to calculate 5 star ratings
- Algorithmic / coding help for a PySpark markov model

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.