Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7764943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:03:10+00:00 2026-06-01T15:03:10+00:00

I have a table Rating row1 = (V1, K1, 5); row2 = (V2, K2,

  • 0

I have a table Rating

  • row1 = (V1, K1, 5);
  • row2 = (V2, K2, 7);
  • row2 = (V1, K1, 3);

I need to aggregate the Points in an AggregateRating table
such that the table contains

  • row1 = (V1, K1, 8);
  • row2 = (V2, K2, 7);

I loop once through the Rating table and
create a map with [key = (Col1,Col2), value = Points]
If the key exists I add the points else create a new map entry.
The Rating table can contain close to 100+ entries so I wanted to avoid making multiple passes.

Is this the most efficient way to go about it??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:03:11+00:00Added an answer on June 1, 2026 at 3:03 pm

    It depends on what data structure you use to store the map. If you use hash map than storing and reading from it will be constant in complexity (O(1)). Then you make a single pass with one query and at most one insert for every entry in the array. This means that the whole complexity of your algorithm will be O(n).

    However, the input alone is O(n), which means you can not do any better.

    Keep in mind that if you choose different implementation of the map, e.g. tree map, the complexity will change and you will not get the most efficient solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ratings table, that contains (as a foreign key) the ID for
Let's say I have a Blog posts table that has a rating field which
I have a table which contains ratings. Included with the rating is data the
I have a database with one table, like so: UserID (int), MovieID (int), Rating
I have table with 50 entries (users with such details like Name Surname Location
I have table with some fields that the value will be 1 0. This
I have a rating table. It boils down to: rating_value created +2 april 3rd
I have a table that maintains rows of products that are for sale (
in my project i need to allow rating system for users only once. i
I have a mysql table called RATING with this structure: ID, USERNAME, RATING, RATER,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.