rotovegasBoy
Programmer
Before I start I will point out that rather than some programming problem from a course this is something I've run into at my job and any solution posted might get put into an actual product. Hopefully I'll be sufficiently vague to avoid any intelectual property issues. Here we go.
There is a bar frequented by engineers that has a finite amount of space. Engineers have 2 attributes 1. how much beer they can drink and 2. the time they entered the bar. At any time the bar manager wants to know whos been in the bar the longest or who has been there for a specific amount of time. As the bar fills up to its capacity the bar manager decides to kick out the engineers who can drink the least beer. Assume the attibutes of each engineer is unique.
For speeds sake we'd implement this using a binary tree based on the entry time as this is the most frequent request from the bar manager. We assume that the time between requests from the bar manager is much greater than the time between engineers arriving at the bar. So we can safely reorganise the root of the tree on entry of each engineer with little overhead.
How can we remove the engineer that can drink the least beer given that the engineers are arranged by their entry time attribute.
Pictorally[tt]
engineer = 13.33(entry time)
6 (beers)
12.00
3
/ 11.30 12.30
6 2
/ \ / 11.15 11.45 12.15 12.45
10 1 4 9
[/tt]
We want to remove the engineer that arrived at 11.45 to make room for a new engineer.
Anybody know of an algorithm that can find the engineer that can drink the least beer. My first solution was a recursive function that searched each subtree but this seemed inefficient anybody got a better idea. Try to avoid using straight c code to keep away from any intellectual property/copyright issues. "There are no stupid questions, just lots of inquisitive idiots" - anon
There is a bar frequented by engineers that has a finite amount of space. Engineers have 2 attributes 1. how much beer they can drink and 2. the time they entered the bar. At any time the bar manager wants to know whos been in the bar the longest or who has been there for a specific amount of time. As the bar fills up to its capacity the bar manager decides to kick out the engineers who can drink the least beer. Assume the attibutes of each engineer is unique.
For speeds sake we'd implement this using a binary tree based on the entry time as this is the most frequent request from the bar manager. We assume that the time between requests from the bar manager is much greater than the time between engineers arriving at the bar. So we can safely reorganise the root of the tree on entry of each engineer with little overhead.
How can we remove the engineer that can drink the least beer given that the engineers are arranged by their entry time attribute.
Pictorally[tt]
engineer = 13.33(entry time)
6 (beers)
12.00
3
/ 11.30 12.30
6 2
/ \ / 11.15 11.45 12.15 12.45
10 1 4 9
[/tt]
We want to remove the engineer that arrived at 11.45 to make room for a new engineer.
Anybody know of an algorithm that can find the engineer that can drink the least beer. My first solution was a recursive function that searched each subtree but this seemed inefficient anybody got a better idea. Try to avoid using straight c code to keep away from any intellectual property/copyright issues. "There are no stupid questions, just lots of inquisitive idiots" - anon