Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Assume there are cars driving on one side of the interstate which has two lanes. At one point along the road there is construction

1. Assume there are cars driving on one side of the interstate which has two lanes. At one point along the road there is construction that causes only one lane to continue. We want to be able to merge the cars in the two lanes into one lane without having any accidents. Assume that if a car reaches the merging point, and there is no car in the other lane at the same spot, then the car can continue along the road. If a car reaches the merging point and finds one car already there in the other lane, then it must wait its turn. Whenever there are multiple cars waiting in both lanes, the cars should take turns moving forward. Write pseudocode algorithms using semaphores/counters/etc. for cars in the left and right lanes that will allow the merging to occur as described.

2. There are many one lane bridges in the upper Northeast. Assume such a bridge exists between a set of farms and the fields in which the farmers harvest their crops. Also assume that there are 15 farms on one side of the bridge, and every day each farmer that lives on his farm will want to go back and forth across the bridge, harvesting crops in the field and bringing them back to the farm. Not every farmer works at the same pace. If a farmer gets to the bridge and wants to cross it, the following must occur. If there is nobody else on the bridge, the farmer may drive across. If there is already a farmer driving across the bridge in the other direction, the farmer must wait until the bridge is empty before crossing. If there is already a farmer driving across the bridge in the same direction, the new farmer may follow after him and be on the bridge at the same time.

a) Write a pseudocode algorithm using semaphores/counters/etc. for a farmer's daily actions to control access to the bridge and stop any accidents from happening. Assume the bridge is big enough to hold the cars of all 15 farmers at once if necessary.

b) Now assume the bridge is only big enough to allow three cars onto it at the same time. Show how your algorithm needs to be modified to work in this situation.

3. Assume we were to get a teaching assistant for this course that would hold office hours in B 240. He would sit at one of the cubicles and could only help one student in the class at a time. However, assume there are four chairs in the room that students can sit in to wait for the TA to be available to help them. When nobody is around the TA plays video games. If a student shows up and the TA is playing games, he should stop and help the student. If a student arrives, but the TA is busy, the student will sit down in an empty chair if one exists. When the current student is finished, the student who has waited the longest will be helped next. If there is not an empty chair available, the student will go away and come back later.

a) Write a pseudocode algorithm using semaphores/counters/etc. for both the student and the TA to describe their actions so that everybody gets the help they need.

b) Now assume that we get a second TA for the course and he can also help students in the same room. A waiting student can be helped equally well by either TA. Show how the algorithms for the students and TAs would need to be adjusted to handle this situation.

c) Now assume that the second TA must help students for a different course, but still in the same room with a common set of chairs for students to wait in. So, even if there are students waiting in the room for help, if they are not in the course that a TA is helping with, that TA is free to play video games. Show how the algorithms for a student and a TA would need to be adjusted to handle this situation.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

7. Describe phases of multicultural identity development.

Answered: 1 week ago