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 8837013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:37:20+00:00 2026-06-14T09:37:20+00:00

Lets ay you are building a analytics program for your site, in which you

  • 0

Lets ay you are building a analytics program for your site, in which you log the address of the page every time you visit it, so your log.txt could be

x.com/a
x.com/b
x.com/a
x.com/c
x.com/a

There is no counter, its just a log file and no sql is used, given that this had thousands of elements your a thousand or so unique domains addresses (x.com/a x.com/b), what’s the most efficient way of going though this list and spitting out the top 10 urls.

My best solution would go through the log file, then if that domain does not exist in hashtable add it in as key, and increment it’s value; then search on hash for largest 10 values.

I’m not convinced this is the best solution, not only because of the space complexity (what happens if the unique domain went from a few thousands to few million), and because I would need to conduct another search on hashtable to find the largest values.

  • 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-14T09:37:21+00:00Added an answer on June 14, 2026 at 9:37 am

    Even for few thousands or few millions entries – your approach is just fine – it has a linear on average (O(n)) run time – so it is not that bad.

    However, you can use a map-reduce approach if you want more scalability.

    map(file):
       for each entry in file:
             emitIntermediate(getDomainName(entry),"1"))
    reduce(domain,list):
       emit(domain,size(list))
    

    The above will efficiently give you the list of (domain,count) tupples, and all you have to do is select the top 10.

    Selecting the top 10 can be done using a map-reduce (distributed) sort for scalability – or using a min heap (iterate while maintaining the top 10 elements encountered in the heap). The second is explained with more details in this thread


    About space complexity: If you are using a 64 bit system, you can use it as RAM, and let the OS do what it cans (by swapping elements to disk when needed), it is very unlikely that you will need more then the amount of Virtual Memory you have on a 64 bits machine. An alternative is to use a hash table (or a B+ tree) optimized for file systems and do the same algorithm on it.


    However, if this is indeed the case – and the data does not fit RAM, and you cannot use map-reduce, I suspect sorting and iterating – though will be O(nlogn) will be more efficient (using external sort) – because the number of DISK ACCESSES will be minimized, and disk access is much slower then RAM access.

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

Sidebar

Related Questions

I'm building a site with django that lets users move content around between a
Lets say I'm building a base class which will be extended upon by the
I'm building a Rails application which lets users have like a personal folder where
I am building a system which lets users upload shapefiles. It then converts those
I'm building an ajax based web application which lets Facebook users who login to
I am building a gui which lets me select a subset of a data.frame
I'm building a page admin in php and have a function that lets me
I'm building ASP.NET MVC2 website that lets users store and analyze data about goods
I'm building a Flex application, which is going to perform many server requests (let's
I'm building a little tool that lets user to place some geometric figures on

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.