Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design a Data Structure for web server to store history of visited pages

The server must maintain data for last n days. It must show the most visited pages of the current day first and then the most visited pages of next day and so on.

I'm thinking along the lines of hash map of hash maps. Any suggestions ?

like image 786
Karthik Avatar asked Jun 13 '11 19:06

Karthik


People also ask

Which data structure is best for browsing history?

You'll need two data structures: a hash map and a doubly linked list. The doubly linked list contains History objects (which contain a url string and a timestamp) in order sorted by timestamp; the hash map is a Map<String, History> , with urls as the key.

What data structure is used in Web browser tabs?

We will be using two data structures, namely Stack implemented using doubly linked list and an HashMap. Whenever a new tab is opened, we will create a new node of doubly linked list for that tab, store the address of this node in our HashMap and append this node to the end of the doubly linked list.

What sort of data structure would you use to store and Analyse a transaction network?

Using the graph-oriented data structures, the various entities related to a transaction may be analyzed and additional data associated with a transaction may be retrieved.

How can you apply data structures in a real life situation?

To store a set of fixed key words which are referenced very frequently. To store the customer order information in a drive-in burger place. (Customers keep on coming and they have to get their correct food at the payment/food collection window.) To store the genealogy information of biological species.


1 Answers

Outer hash map with key of type date and value of type hash map.

Inner hash map with key of type string containing the url and value of type int containing the visit count.

Example in C#:

// Outer hash map    
var visitsByDay = 
    new Dictionary<DateTime, VisitsByUrl>(currentDate, new VisitsByUrl());

...

// inner hash map
public class VisitsByUrl
{
    public Dictionary<string, int> Urls { get; set; }

    public VisitsByUrl()
    {
        Urls = new Dictionary<string, int>();
    }

    public void Add(string url)
    {
        if (Urls[url] != null)
            Urls[url] += 1;
        else
            Urls.Add(url, 1);
    }
}
like image 105
Dennis Traub Avatar answered Oct 14 '22 07:10

Dennis Traub