Question

Instead of always selecting the first activity to finish, select the last activity to start that...

Instead of always selecting the first activity to finish, select the last activity to start that is compatible with all previously selected activities. Accomplish this by implementing a greedy algorithm in either Python or C++. This is similar to a first-to-start algorithm, but in reverse; the goal is to select the start-times that appear later. See the example below and ensure that your output matches the example below.

Include a verbal description of your algorithm, pseudocode and analysis of the theoretical running time. The program should read input from a file named “act.txt”. The file contains lists of activity sets with number of activities in the set in the first line followed by lines containing the activity number, start time & finish time.

Example act.txt:

11

1 1 4

2 3 5

3 0 6

4 5 7

5 3 9

6 5 9

7 6 10

8 8 11

9 8 12

10 2 14

11 12 16

3

3 6 8

1 7 9

2 1 2

In the above example the first activity set contains 11 activities with activity 1 starting at time 1 and finishing at time 4, activity 2 starting at time 3 and finishing at time 5, etc.. The second activity set contains 3 activities with activity 3 starting at time 6 and finishing at time 8 etc. The activities in the file are not in any sorted order.

Your results including the number of activities selected and their order should be outputted to the terminal. For the above example the results are:

Set 1

Number of activities selected = 4

Activities: 2 4 9 11

Set 2

Number of activities selected = 2

Activities: 2 1

Note: There is an alternative optimal solution for Set 1. Since activities 8 and 9 have the same start time of 8, 2 4 8 11 would be an alternative solution. Your program only needs to find one of the optimal solutions. For either solution the activities differ from the solution presented in the text which uses the earliest-finish time criteria.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

answering using greedy algorithm, here it goes

we can only get optimal solution if we select last activity to start first

Add a comment
Know the answer?
Add Answer to:
Instead of always selecting the first activity to finish, select the last activity to start that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Activity Selection Last-to-Start | C++ Implementation Develop a program with a greedy algorithm that instead of always...

    Activity Selection Last-to-Start | C++ Implementation Develop a program with a greedy algorithm that instead of always selecting the first activity to finish, instead selects the last activity to start that is compatible with all previously selected activities. The program should read input from a file named “act.txt”. The file contains lists of activity sets with number of activities in the set in the first line followed by lines containing the activity number, start time & finish time. Example act.txt:...

  • 11 The following activity times are given: Determine the following a) Earliest start time b) Earliest...

    11 The following activity times are given: Determine the following a) Earliest start time b) Earliest finish time c) Latest Start Time d) Latest finish time e) Critical Path Activity Completion time( in months) 1-2 5 1-3 6 1-4 2 2-5 3 2-6 1 3-5 3 4-5 0 4-7 2 5-8 9 5-7 5 7-8 4 6-9 7 8-9 3

  • early start early finish Timo - - - ---- A 20 late finish Number of workers...

    early start early finish Timo - - - ---- A 20 late finish Number of workers C 20 required daily for D 5 each activity E 10 F 10 G 15 E ---- FE G ------- - DH Activities GA 1 2 3 4 5 6 7 8 (a) On this diagram, show the total daily workers required (loading) assuming early start times for all activities. Show what portion of the total labor loading each day comes from each activity....

  • 7. Given a set of n activities with start time and finish time F; of an...

    7. Given a set of n activities with start time and finish time F; of an i activity. Find the maximum size set of mutually compatible activities. Implement following string matching algorithms and analyze time complexities: 8. a) Naïve method b) Rabin karp Algorithm c) Finite state Automaton algorithm 9. A hash table is a data structure used to implement an associative array, al structure that can map keys to values. Implement Hashing using Linear and Quadratic Probing.

  • QUESTION 1 G E. H. C A Finish Start D. Complete the network activity diagram using the table below to answer questio...

    QUESTION 1 G E. H. C A Finish Start D. Complete the network activity diagram using the table below to answer questions 1-15. The expected activity completion times are provided in days. Each question is 1 point. Most Probable Activity Optimistic Pessimistic A 7 B 12 C 5 12 7 E 10 15 20 6 9 18 G 6 13 H 11 What is the early start (ES) time for activity F? 13 12 10 None of the above are...

  • Edit: The max number of activities is arbitrary. As written in question; program should ask us...

    Edit: The max number of activities is arbitrary. As written in question; program should ask us to input the id of activities unless a negative number is entered. It is needed to select activities from these activities. Max number is up to us. 323as1) Could you please help me to solve this problem? (ONLY USING C++) Problem: You are requested to create a class called “Activity”. You will use ordered link list to hold Activity’s class information. In order to...

  • Using the information shown in the table below, what is the latest start time for activity E? ACTIVITY Immediate Pred...

    Using the information shown in the table below, what is the latest start time for activity E? ACTIVITY Immediate Predecessor ACTIVITY TIME EARLIEST START EARLIEST FINISH LATEST START LATEST FINISH SLACK A None 2 0 0 2 0 B A 1 2 3 3 4 1 C A 3 2 5 2 5 0 D B 7 3 10 4 11 E B, C 3 5 8 11 F C 5 11 5 11 0 G D ,E, F 4...

  • Suppose n activities apply for using a common resource. Activity ai (1 ≤ i ≤ n)...

    Suppose n activities apply for using a common resource. Activity ai (1 ≤ i ≤ n) has a starting time S[i] and a finish time F[i] such that 0 < S[i] < F[i]. Two activities ai and aj (1 ≤ i, j ≤ n) are compatible if intervals [S[i], F[i]) and [S[j], F[j]) do not overlap. We assume the activities have been sorted such that S [1] ≤ S [2] ≤ …≤ S[n]. (a) Design an O(n2) dynamic programming algorithm...

  • Consider the following project activities: Calculate the expected time (te) for each activity. Draw an Activity...

    Consider the following project activities: Calculate the expected time (te) for each activity. Draw an Activity on Node (AON) diagram to reflect the flow of these activities. Calculate the Early Start (ES), Early Finish (EF), Late Start (LS), and Late Finish (LF) for each activity. Calculate the slack for each activity. Identify all activities on the Critical Path. Use the data to calculate the probability the project will finish in 20 weeks (Hint: z-score). Activity A 8 с D E...

  • also needs daves latest start and latest finish: Dave Fletcher was able to determine the activity...

    also needs daves latest start and latest finish: Dave Fletcher was able to determine the activity times for constructing his laser scanning machine. Fletcher would like to determine ES, EF, LS, LF, and slack for e activity. The total project completion time and the critical path should also be determined. Here are the activity times: Activity Time (weeks) Immediate Predecessor(s) Activity Time (weeks) Immediate Predecessor(s) C, E D, F Dave's earliest start (ES) and earliest finish (EF) are: Activity ES...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT