Object
BAN USER
1. Build a Directed graph such that there is a directed edge from manager to each of its reportees.
2. Do a DFS with the manager in question.
cpp implementation:
class employee_hierarchy{
vector<vector<int>> graph;
public:
employee_hierarchy(int N){
graph.resize(N);
}
void addEmployee(int m, int r){
graph[m].push_back(r);
}
void getReportees(int e, vector<int>& reportees){
reportees.push_back(e);
auto direct_reportees = graph[e];
for_each(graph[e].begin(), graph[e].end(), [&reportees, this] (int x) -> void { getReportees(x, reportees); });
}
};
In simple terms,
1. UI: A task should have task id and start time to execute. User has the provision to create/view list of tasks and its status.
2. DB: A table to model task. Columns to hold task id and schedule.
3. Middle tier:
3a. A poling logic in specific time interval which queries the table to retrieve the task whose time has expired.
3b. Each of the retrieved tasks could be added to a thread pool. A thread pool would contain fixed number of threads each carrying out a task at a time. The basic operations of the Thread Pool can be to add task, start the tasks etc. Thread Pool class would have a queue which holds added tasks. A task object can have its Id, Start Time, Status, operations to start/stop/pause. Time slicing or some greedy technique could be introduced to handle long running tasks.
Another case where weak_ptr helps is: To avoid dangling pointer.
A shared_ptr can be used to hold the memory. weak_ptr could be supplied to the user. When shared_ptr resets to a new memory, a weak_ptr gets invalidated thus avoiding dangling pointer. To realize this, weak_ptr has method "lock" which returns shared_ptr which it points to. When shared_ptr is reset, it returns default constructed shared_ptr.
It is obviously done using system calls :) Adding more details specific to Windows:
Following are the bug guys involved here:
1. Kernel Mode driver (Mini Filter Driver)
2. User Mode application
3. Windows Filter Manager
The bidirectional communication between the driver and application takes place via a serial port created by the driver. The security of the serial port is determined by the driver. The driver listens to this port. User mode application creates connection with this port. Windows Filter manager notifies this to the driver. And Filter manager provides appropriate APIs for the user mode app and driver to communicate. Further details can be seen in MSDN.
O(n) Time for initialization, O(logn) time to find LCA, O(n) Space
By doing a DFS:
1. Get the euler's tour path in a vector, v1.
2. Get the level of all the nodes in euler's path in second vector, v2.
3. Get the first occurrence of each node in euler's tour in a third vector, v3.
4. Build a segment tree out of v2.
For the given 2 vertices, to find the LCA:
1. Get the first occurrence of nodes from v3.
2. For the range returned by step 1, get the minimum level node from v2. Segment tree makes this operation logarithmic.
3. Match the idx of the minimum node with euler's tour path v1. This node is the LCA.
This method uses the fact that LCA is equal to the one and only one node that's closest to the root that occurs in the euler's path between the two given nodes.
1. size of array must be specified by a const int var.
2. In spite of the above, the program output would be still undefined. Because the pointer to base is being incremented which is basically adding an address value with the sizeof (base). So we need to have separate definition of derived and base. Or any class which uses "display" method.
So the second change could be to make "display" method a template method as:
template<typename T>
void display(T* obj, int ele)
{
for (int i = 0; i < ele; i++)
{
cout << (obj + i)->getA() << endl;
}
}
RepOliviaJBlack, Consultant at Apkudo
I am Olivia from San Diego. I am working as a checker in the Thom McAn Store company. My strong ...
Repsherrifjenkins, Applications Developer at ASAPInfosystemsPvtLtd
I am Sherri from Richmond USA. I am working as a Clinical laboratory technician worker in P. Samuels Men's ...
- Object November 28, 2019