Answer:
Pseudocode is as follows:
// below is a function that takes two parameters:1. An array of items 2. An integer for weight W
// it returns an array of selected items which satisfy the given condition of sum <= max sum.
function findSubset( array items[], integer W)
{
initialize:
maxSum = 0;
ansArray = [];
// take each "item" from array to create all possible combinations of arrays by comparing with "W" and // "maxSum"
start the loop:
// include item in the ansArray[]
ansArray.push(item);
// remove the item from the items[]
items.pop(item);
ansArray.push(item1);
start the while loop(sum(ansArray[]) <= W):
// exclude the element already included and start including till
if (sum(ansArray[]) > maxSum)
// if true then include item in ansArray[]
ansArray.push(item);
// update the maxSum
maxSum = sum(ansArray[items]);
else
// move to next element
continue;
end the loop;
// again make the item[] same by pushing the popped element
items.push(item);
end the loop;
return the ansArray[]
}
Explanation:
You can find example to implement the algorithm.
Answer:
array = input("Enter the list of computer memory: ").split(',')
int_arr = [int(x) for x in array]
segment = int(input("Enter the length of segment to analyze: "))
list_len = len(int_arr)
segList = []
mini = []
for x,i in enumerate(int_arr):
seg = int_arr[i-1:segment+i-1]
if len(seg) == segment:
segList.append(seg)
for x in segList:
mini.append(min(x))
result = mini.index(min(mini))
print("Segment with the minimum memory is: ",segList[result])
Explanation:
The python program prints out the segment after analysis, with the smallest disk memory space. The code gets the array of computer rows from the user input and segments the array with the number of segment input, then the minimum is compared for all segments in the network.