Bird
Raised Fist0

Given the following pseudocode for updating average rating after a new review:

medium📝 Analysis Q13 of Q15
LLD - Design — Food Delivery System
Given the following pseudocode for updating average rating after a new review:
current_avg = 4.0
num_reviews = 5
new_rating = 5
new_avg = (current_avg * num_reviews + new_rating) / (num_reviews + 1)

What is the value of new_avg?
A4.17
B4.16
C4.0
D4.5
Step-by-Step Solution
Solution:
  1. Step 1: Calculate total rating sum before new review

    Total sum = current_avg * num_reviews = 4.0 * 5 = 20
  2. Step 2: Add new rating and compute new average

    New sum = 20 + 5 = 25
    New average = 25 / (5 + 1) = 25 / 6 ≈ 4.1667
  3. Final Answer:

    4.17 -> Option A
  4. Quick Check:

    Average update formula ≈ 4.17 [OK]
Quick Trick: Multiply avg by count, add new, divide by count+1 [OK]
Common Mistakes:
MISTAKES
  • Forgetting to add new rating to total sum
  • Dividing by old count instead of count+1
  • Rounding too early causing wrong average

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes