**DOWNLOAD FREE PDF** **<<CLICK HERE>>**

## Data Structure Questions and Answers-Balanced Partition

Congratulations - you have completed *Data Structure Questions and Answers-Balanced Partition*.

You scored %%SCORE%% out of %%TOTAL%%.

Your performance has been rated as %%RATING%%

Your answers are highlighted below.

Question 1 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |

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 |

Question 1 Explanation:

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

Question 2 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |

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 |

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 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |

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}) |

Question 3 Explanation:

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

Question 4 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |

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} |

Question 4 Explanation:

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

Question 5 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |

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]. |

Question 5 Explanation:

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

Once you are finished, click the button below. Any items you have not completed will be marked incorrect.

There are 5 questions to complete.