User:Maringtr/sandbox

Overview
The Bezhanov Algorithm is a mathematical algorithm used in web development to increase the effectiveness of average rating calculations in content rating systems. It allows an average rating to be re-calculated upon a new vote only with simple mathematical operations, without the previous ratings having to be retrieved one-by-one from a database, summed up and then divided by their total number like in most traditional solutions based on the standard arithmetic mean equation.

Reducing the number of rows retrieved from the database and avoiding the need of iterating through all of them in order to sum all ratings up, saves valuable server resources, as less memory and CPU processing time are used and less load is incurred on the database server. This usually results in a notable performance boost and cost savings on high-traffic websites.

The algorithm works by placing weights on the current average rating and the newly submitted grade in order to calculate the updated average rating value. Weights are placed based on the total number of votes that will form the new rating.

Formula
The updated average rating is calculated based on the following formula:

new_average_rating = current_average_rating_weight + new_grade_weight

Where:

current_average_rating_weight = current_average_rating * total_number_of_votes / (total_number_of_votes + 1)

new_grade_weight = new_grade * 1 / (total_number_of_votes + 1)

(total_number_of_votes + 1) is basically the total number of votes that will form the new rating, while

total_number_of_votes is the total number of votes that form the current average rating.

Example
- An item has an average rating of 3.82 based on 11 votes cast by people

- A person decides to cast a new vote, rating the item with a grade of '2'

We feed the formulas with the necessary data:

current_average_rating = 3.82

total_number_of_votes = 11

(total_number_of_votes + 1) = 12 (12 votes will form the new rating)

new_grade = 2

current_average_rating_weight = 3.82 * 11 / 12 = 3.50 (rounded to 2 digits)

new_grade_weight = 2 * 1 / 12 = 0.17 (rounded to 2 digits)

new_average_rating = 3.50 + 0.17 = 3.67

Etymology
The algorithm is named after Bulgarian web developer Marin Bezhanov, who is the first person to introduce this solution to the wide public.