Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
Given an array of integers, find the minimum number of times its elements must be divided by 2 in order to reduce the sum of
Given an array of integers, find the minimum number of times its elements must be divided by in order to reduce the sum of the array by at least half. Task description An industrial company has N factories, each producing some pollution every month. The company has decided to reduce its total fume emissions by equipping some of the factories with one or more filters. Every such filter reduces the pollution of a factory by half. When a second or subsequent filter is applied, it again reduces by half the remaining pollution emitted after fitting the existing filters For example, a factory that initially produces units of pollution will generate units with one filter, units with two filters and units with three filters. You are given an array of N integers describing the amount of pollution produced by the factories. Your task is to find the minimum number of filters needed to decrease the total sum of pollution by at least half. Write a function: function solutionA; which, given an array of integers A of length N returns the minimum number of filters needed to reduce the total pollution by at least half. Examples: Given A your function should return The initial total pollution is We install two filters at the factory producing units and one filter at the factory producing units. Then the total pollution will be which is less than so we have achieved our goal. Given A your function should return because we may install one filter at each factory. Given A your function should return because it is sufficient to install one filter at each factory producing a nonzero amount of pollution. Write an efficient algorithm for the following assumptions: N is an integer within the range ; each element of array A is an integer within the range
Given an array of integers, find the minimum number of times its elements must be divided by in order to reduce the sum of the array by at least half.
Task description
An industrial company has N factories, each producing some pollution every month. The company has decided to reduce its total fume emissions by equipping some of the factories with one or more filters.
Every such filter reduces the pollution of a factory by half. When a second or subsequent filter is applied, it again reduces by half the remaining pollution emitted after fitting the existing filters For example, a factory that initially produces units of pollution will generate units with one filter, units with two filters and units with three filters.
You are given an array of N integers describing the amount of pollution produced by the factories. Your task is to find the minimum number of filters needed to decrease the total sum of pollution by at least half.
Write a function:
function solutionA;
which, given an array of integers A of length N returns the minimum number of filters needed to reduce the total pollution by at least half.
Examples:
Given A your function should return The initial total pollution is We install two filters at the factory producing units and one filter at the factory producing units. Then the total pollution will be which is less than so we have achieved our goal.
Given A your function should return because we may install one filter at each factory.
Given A your function should return because it is sufficient to install one filter at each factory producing a nonzero amount of pollution.
Write an efficient algorithm for the following assumptions:
N is an integer within the range ;
each element of array A is an integer within the range
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started