Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using java Consider there is a series of lightbulbs connected in a sequential manner. In this situation, if one of the bulbs is defective it

Using java

image text in transcribedimage text in transcribed

Consider there is a series of lightbulbs connected in a sequential manner. In this situation, if one of the bulbs is defective it will cause all the bulbs to be off. A potential solution to find quickly the faulty bulb(s) is to divide recursively the series into subseries and keep investigating the subseries that do not show light. We assume the subseries with no faulty bulb(s) will show light. Goal: Write a recursive threading method to find the defective bulbs and the number of threads that have been created for this purpose Your design and implementation should meet the following requirements: - The main function should read an input text file and fill into an array of integers. The first line of input defines the size of the array (the number of bulbs) and status of each bulb is given in one line as: The input will consist of the state of each bulb: 0: to indicate the bulb is defective 1: to indicate the bulb is functioning properly - The main thread runs "Find Defective function as a new thread and passes the input array to that thread. The main function should wait until Find Defective terminate and then print out the position in the array of the defective bulbs. - The "Find Defective function is responsible to select a "pivot" ) and divide its input array (e.g. arr) into two sub-arrays (e.g. leftArr and rightArr). It will then call the "Find Defective" recursively in a new thread for leftArr and rightArr. The main requirement of this assignment is that the implementation should enable traversing concurrently leftArr and rightArr. Here is an example of input file: We have 8 bulbs: Input.txt - The recursion should be invoked as long as there is at least one defective bulb in the sub-series and the subseries is not lightning up. An example of recursion and expected output is given below for the aforementioned input: 1,1,0,1,1,0,1,1 1 0 1 1 1/1 0 1 1,1,0,1 1,0, 1,1 0 1 1,0 1,1 0,1 1.1 1 0 O The correct output answer should be: The bulbs: #3 and #6 are defective. The number of threads for this problem was: 11 Consider there is a series of lightbulbs connected in a sequential manner. In this situation, if one of the bulbs is defective it will cause all the bulbs to be off. A potential solution to find quickly the faulty bulb(s) is to divide recursively the series into subseries and keep investigating the subseries that do not show light. We assume the subseries with no faulty bulb(s) will show light. Goal: Write a recursive threading method to find the defective bulbs and the number of threads that have been created for this purpose Your design and implementation should meet the following requirements: - The main function should read an input text file and fill into an array of integers. The first line of input defines the size of the array (the number of bulbs) and status of each bulb is given in one line as: The input will consist of the state of each bulb: 0: to indicate the bulb is defective 1: to indicate the bulb is functioning properly - The main thread runs "Find Defective function as a new thread and passes the input array to that thread. The main function should wait until Find Defective terminate and then print out the position in the array of the defective bulbs. - The "Find Defective function is responsible to select a "pivot" ) and divide its input array (e.g. arr) into two sub-arrays (e.g. leftArr and rightArr). It will then call the "Find Defective" recursively in a new thread for leftArr and rightArr. The main requirement of this assignment is that the implementation should enable traversing concurrently leftArr and rightArr. Here is an example of input file: We have 8 bulbs: Input.txt - The recursion should be invoked as long as there is at least one defective bulb in the sub-series and the subseries is not lightning up. An example of recursion and expected output is given below for the aforementioned input: 1,1,0,1,1,0,1,1 1 0 1 1 1/1 0 1 1,1,0,1 1,0, 1,1 0 1 1,0 1,1 0,1 1.1 1 0 O The correct output answer should be: The bulbs: #3 and #6 are defective. The number of threads for this problem was: 11

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

Distinguish between positive and negative confirmations.

Answered: 1 week ago

Question

=+b. What are the values of SSResid, SSTo, r 2 , and se

Answered: 1 week ago