Queues and stacks

Queues and stacks are two fundamental data structures for computer science.

Exercise 1 Advanced

Implement a simple web crawler, that walks a website just like Google. You can try it out on https://docs.python.org/3/ and make it work like this:

    For each page, you need to do the following:
    • Create a processing queue (or stack), your choice, using a simple array.
    • Get the next URL to crawl, make a HTTP GET request to get its content
    • Parse the HTML content to get all the links (anchor elements with a href attribute) and build the final url. You can use XPath or Selectors, your choice.
    • Print the title of the current page to the standard output.
    • Make sure you only get the links for the pages from the same domain and that haven't been processed yet.
    • Put each new link in the processing queue.

Exercise 2 Easy

Implement a priority queue using a simple array. We need to create a PriorityQueue classthat has the following methods:

  • put(item, priority) - inserts a new item in the queue
  • pop() - gets the item from the queue with the highest priority

Extra: Create another class that will return the minimum priority item from the queue instead. Hint: you can inherit from the PriorityClass.

const queue = new PriorityQueue();
queue.put("hello", 2);
queue.put("world", 3);
queue.put("test", 1);
console.log(queue.pop())  // "world" since it has the maximum priority of 3

Exercise 3