I'm trying to simulate a interval scheduling algorithm detecting the earliest finishing time using greedy technique. My problem is that what are the inputs if it will be created in a console application? What are the approaches? Thank you very much.
1 Answers
The inputs for each task are the start time and the end time (e.g. 10:00 start time and 14:00 end time). You can parse the console inputs into Dates or something along those lines, but if this is just a simulation then you might as well just have the console inputs be non-negative integers (e.g. 4 start time and 9 end time) since it will make your job of parsing the input easier.
There are several greedy approaches you can take, such as always selecting the shortest task (meaning the task with the shortest interval); the optimal approach is to always select the task that finishes first (e.g. you could sort the tasks according to ending time and select the next task that doesn't conflict, although there may be a linear-time algorithm to accomplish this).

- 17,888
- 4
- 41
- 69
-
Thank you for the quick response. Should I not limit it to a certain number of tasks? For example, input start and end time for 5 tasks. Then process it afterwards. Or is it more advisable to just let the user input any number of tasks then process it after he tells it to do so? And another one, as you said in your comment. "you could sort the tasks according to ending time and select the next task that doesn't conflict" My understanding with this is that I need to check every ending time(shortest tasks) of each task and sum them up in order to get the most minimal number of time? Am I right? – Luke Villanueva Apr 17 '13 at 04:08
-
You can limit the input size if you like, but the user will eventually get bored on their own accord and stop entering data. And you can sum up the tasks in two ways: sum up their run times (end time - start time), or determine the total time spent (end time of last task - 0). – Zim-Zam O'Pootertoot Apr 17 '13 at 13:31