## Help authour, Buy PDF Ebook
>>>**Click Here**<<<

## Data Structure Questions and Answers-Balanced Partition

## Click on any option to know the CORRECT ANSWERS

Question 1 |

Given an array, check if the array can be divided into two subsets such that the sum of elements of the two subsets is equal. This is the balanced partition problem. Which of the following methods can be used to solve the balanced partition problem?

Dynamic programming | |

Recursion | |

Brute force | |

All of the mentioned |

**Library science Questions answers**

Question 1 Explanation:

All of the mentioned methods can be used to solve the balanced partition problem.

Question 2 |

In which of the following cases, it is not possible to have two subsets with equal sum?

When the number of elements is odd | |

When the number of elements is even | |

When the sum of elements is odd | |

When the sum of elements is even |

**HRM Questions answers**

Question 2 Explanation:

When the sum of all the elements is odd, it is not possible to have two subsets with equal sum.

Question 3 |

What is the time complexity of the brute force algorithm used to solve the balanced partition problem?

O(1) | |

O(n) | |

O(n ^{2}) | |

O(2 ^{n}) |

**History Questions answers**

Question 3 Explanation:

In the brute force implementation, all the possible subsets will be formed. This takes exponential time.

Question 4 |

Consider a variation of the balanced partition problem in which we find two subsets such that |S1 - S2| is minimum. Consider the array {1, 2, 3, 4, 5}. Which of the following pairs of subsets is an optimal solution for the above problem?

{5, 4} & {3, 2, 1} | |

{5} & {4, 3, 2, 1} | |

{4, 2} & {5, 3, 1} | |

{5, 3} & {4, 2, 1} |

**Economics Questions answers**

Question 4 Explanation:

For S1 = {5, 3} and S2 = {4, 2, 1}, sum(S1) - sum(S2) = 1, which is the optimal solution.

Question 5 |

Consider the following code:

#include<stdio.h> int balanced....partition(int *arr, int len) { int sm = 0, i, j; for(i = 0;i < len; i++) sm += arr[i]; if(sm % 2 != 0) return 0; int ans[sm/2 + 1][len + 1]; for(i = 0; i <= len; i++) ans[0][i] = 1; for(i = 1; i <= sm/2; i++) ans[i][0] = 0; for(i = 1; i <= sm/2; i++) { for(j = 1;j <= len; j++) { ans[i][j] = ans[i][j-1]; if(i >= arr[j - 1]) ans[i][j] = .....; } } return ans[sm/2][len]; } int main() { int arr[] = {3, 4, 5, 6, 7, 1}, len = 6; int ans = balanced....partition(arr, len); if(ans == 0) printf("false"); else printf("true"); return 0; }

Which of the following lines should be inserted to complete the above code?

ans[i - arr[j - 1]][j - 1]. | |

ans[i][j]. | |

ans[i][j] || ans[i - arr[j - 1]][j - 1]. | |

ans[i][j] && ans[i - arr[j - 1]][j - 1]. |

**Library science Questions answers**

Question 5 Explanation:

The line "ans[i][j] || ans[i - arr[j - 1]][j - 1]" completes the above code.

There are 5 questions to complete.