Question

3.2 L5 To solve the problem: problem decomposition: we would like to find the requests one by one. Idea 1: select the request

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

Since it has been depicted through examples/figure that idea 1, idea 2 and idea 3 does not work so we will directly utilise idea 4 for solving this question.

For the sake of convenience, let's write the requests in the following ways:-

  1. <0, 2>
  2. <0, 4>
  3. <3, 6>
  4. <5, 7>
  5. <8, 10>
  6. <0, 11>
  7. <9, 12>
  8. <14, 15>
  9. <13, 16>

Now, we will sort the requests in the increasing order of their finish time, so that we can greedily select the requests from the sorted list. After sorting the list, it looks looks as follows:

  1. <0, 2> // this request has the earliest finishing time.....
  2. <0, 4>
  3. <3, 6>
  4. <5, 7>
  5. <8, 10>
  6. <0, 11>
  7. <9, 12>
  8. <14, 15>
  9. <13, 16>

Now, comes the most tricky part, How to select the requests from this sorted list?

1) Selects the first request directly and add it to the new list ans.

2) Select next request from the sorted list, and check if this request's time interval clashes/overlaps with any of the requests in ans then discard that request otherwise add this request into ans.

.We will run step 1 and 2 on our example to clearly demonstrate what is going on actually,

  • <0, 2> is selected and added into ans. So our ans = { <0, 2> }
  • <0, 4> has a overlapping of interval with requests already present in ans i.e <0, 4> is overlapping with <0, 2>, so <0, 4> must not be included in ans and our ans = { <0, 2> }
  • For <3, 6>, it does not clash with <0, 2> so it will add in ans and our ans = { <0, 2> , <3, 6>}
  • For <5, 7>, as it clashes with <3, 6> , so it will not be added and our ans = { <0, 2> , <3, 6>}.
  • For <8, 10>, as it does not clashes with any request inside ans so it will added to ans and our ans = { <0, 2> , <3, 6>, <8, 10>}.
  • For <0, 11>, it clearly clashes with some requests in ans so it should be discarded and our ans = { <0, 2> , <3, 6>, <8, 10>}.
  • For <9, 12>, it clearly clashes with <8,10> (present in ans) so must not be included in ans and our ans = { <0, 2> , <3, 6>, <8, 10>}.
  • For <14, 15>, no clashes can be found in ans so it will be added in ans and our new ans = { <0, 2> , <3, 6>, <8, 10>, <14, 15>}.
  • For last request <13, 16>, it is clashing with <14, 15>(present in ans) so must not be added in ans and our ans = { <0, 2> , <3, 6>, <8, 10>, <14, 15>}

So finally our list ans contains the maximum subset of requests that can be handled with ans = { <0, 2> , <3, 6>, <8, 10>, <14, 15>}. I have run algorithm given in the book written by Thomas H. Cormen so you can refer there for it's proof and all other stuff that you may want.

Add a comment
Know the answer?
Add Answer to:
3.2 L5 To solve the problem: problem decomposition: we would like to find the requests one...
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
  • Consider the following greedy strategies for this problem: 1. Select the earliest finishing interval and discard...

    Consider the following greedy strategies for this problem: 1. Select the earliest finishing interval and discard overlapping intervals. Keep doing this until all intervals have been eliminated (either selected or discarded). 2. Select the earliest starting interval and discard overlapping intervals. Keep doing this until all intervals have been eliminated (either selected or discarded). 3. Select the pair of non-overlapping intervals that have the smallest gap between them: find a pair of intervals i # j such that s; -...

  • 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...

  • Decrease-by-Half Algorithm We can solve the same problem using a decrease-by-half algorithm. This...

    Convert the pseudocode into a C++ function Decrease-by-Half Algorithm We can solve the same problem using a decrease-by-half algorithm. This algorithm is based on the following ideas: In the base case, n 1 and the only possible solution is b 0, e 1 In the general case, divide V into a left and rnight half; then the maximum subarray can be in one of three places: o entirely in the left half; o entirely in the right half; or o...

  • Please formulate and solve the following problem. Problem 2: Consider a taxi company scheduling drivers for...

    Please formulate and solve the following problem. Problem 2: Consider a taxi company scheduling drivers for its taxis. The requirement for taxis varies from hour to hour because of customer demand as shown in the figure. Time 0 on the figure represents midnight, and times are shown with a 24 hour clock starting at midnight. For example, four taxis must run from midnight to 4 a.m., while eight taxis must run from 4 a.m. until 8 a.m. We assume that...

  • There is an old fairy tale where some elves secretly help an old shoemaker finish his...

    There is an old fairy tale where some elves secretly help an old shoemaker finish his work for the day. In this version, the shoemaker and the elves collaborate openly Each day the shoemaker receives n orders for custom-made shoes. In the evening, n elves arrive to help him assemble the shoes. The shoemaker first cuts out the leather pieces for one pair of shoes. Then an elf stitches the pieces together to complete the shoes. For each i, let...

  • In the bin packing problem, items of different weights (or sizes) must be packed into a...

    In the bin packing problem, items of different weights (or sizes) must be packed into a finite number of bins each with the capacity C in a way that minimizes the number of bins used. The decision version of the bin packing problem (deciding if objects will fit into <= k bins) is NP-complete. There is no known polynomial time algorithm to solve the optimization version of the bin packing problem. In this practice problem you will be examining three...

  • Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A*...

    Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* search algorithm. 1. Objectives • To gain more experience on using pointers and linked lists in C programs. • To learn how to solve problems using state space search and A* search algorithm. 2. Background A* search and 15-puzzle problem have been introduced in the class. For more information, please read the wiki page of 15-puzzle problem at https://en.wikipedia.org/wiki/15_puzzle, and the wiki page of...

  • Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* s...

    Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* search algorithm. Please include pictures that the code runs and shows the different states as it reaches goal state please. 1. Objectives • To gain more experience on using pointers and linked lists in C programs. • To learn how to solve problems using state space search and A* search algorithm. 2. Background A* search and 15-puzzle problem have been introduced in the class....

  • Write a C program for: One technique for dealing with deadlock is called “detect and recover.” In...

    Write a C program for: One technique for dealing with deadlock is called “detect and recover.” In this scheme, some procedure is used to identify when a deadlock occurs, and then another procedure is used to deal with the blocked processes. One technique to identify a deadlock is to maintain a resource graph that identifies all processes, all resources, and the relationships between them (that is, which processes exclusively own which resources, and which processes are blocked waiting for which...

  • CSC 142 Music Player You will complete this project by implementing one class. Afterwards, your program...

    CSC 142 Music Player You will complete this project by implementing one class. Afterwards, your program will play music from a text file. Objectives Working with lists Background This project addresses playing music. A song consists of notes, each of which has a length (duration) and pitch. The pitch of a note is described with a letter ranging from A to G.   7 notes is not enough to play very interesting music, so there are multiple octaves; after we reach...

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
Active Questions
ADVERTISEMENT