Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having a tough time understanding the requirement for this assignment as well what they are expecting from us in the code I will be

I'm having a tough time understanding the requirement for this assignment as well what they are expecting from us in the code I will be linking an image with the question as well

as an example please provide me with a code in C++image text in transcribedimage text in transcribed

Binary tree traversal to find defective lightbulbs using multi-threading 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 bulbs) 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 bulbs) 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: : 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 "FindDefective 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,1,0,1 1,0,1,1 The correct output answer should be: The bulbs: 113 and 6 are defective. The number of threads for this problem was: 11 Binary tree traversal to find defective lightbulbs using multi-threading 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 bulbs) 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 bulbs) 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: : 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 "FindDefective 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,1,0,1 1,0,1,1 The correct output answer should be: The bulbs: 113 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

Modern Database Management

Authors: Donald A. Carpenter Fred R. McFadden

1st Edition

8178088045, 978-8178088044

More Books

Students also viewed these Databases questions