Consider the expression T | F ∧ T. In how many ways can the expression be parenthesized so that the output is F (false)?
0
1
2
3
Answer and explanation
The expression can be parenthesized as (T | F) ∧ T, so that the output is F (false).
ObjectiveMcq
Print Protected
This page is protected for print. Use the website to view the content.
Consider the expression T | F ∧ T. In how many ways can the expression be parenthesized so that the output is F (false)?
0
1
2
3
The expression can be parenthesized as (T | F) ∧ T, so that the output is F (false).
Consider the expression T & F ∧ T. What is the number of ways in which the expression can be parenthesized so that the output is T (true)?
0
1
2
3
The expression can be parenthesized as (T & F) ∧ T or T & (F ∧ T), so that the output is T.
Consider the expression T & F | T. What is the number of ways in which the expression can be parenthesized so that the output is T (true)?
0
1
2
3
The expression can be parenthesized as T & (F | T) and (T & F) | T so that the output is T.
You are given a boolean expression which consists of operators &, | and ∧ (AND, OR and XOR) and symbols T or F (true or false). You have to find the number of ways in which the symbols can be parenthesized so that the expression evaluates to true. This is the boolean parenthesization problem. Which of the following methods can be used to solve the problem?
Dynamic programming
Recursion
Brute force
Dynamic programming, Recursion and Brute force
Dynamic programming, Recursion and Brute force can be used to solve the Boolean parenthesization problem.
You are given infinite coins of denominations 3, 5, 7. Which of the following sum CANNOT be achieved using these coins?
15
16
17
4
Sums can be achieved as follows:
15 = {5,5,5}
16 = {3,3,5,5}
17 = {3,7,7}
we can't achieve for sum=4 because our available denominations are 3,5,7 and sum of any two denominations is greater than 4.
You are given infinite coins of denominations 5, 7, 9. Which of the following sum CANNOT be achieved using these coins?
50
21
13
23
One way to achieve a sum of 50 is to use ten coins of 5. A sum of 21 can be achieved by using three coins of 7. One way to achieve a sum of 23 is to use two coins of 7 and one coin of 9. A sum of 13 cannot be achieved.
You are given infinite coins of denominations 1, 3, 4. What is the minimum number of coins required to achieve a sum of 7?
1
2
3
4
A sum of 7 can be achieved by using a minimum of two coins {3,4}.
You are given infinite coins of denominations 1, 3, 4. What is the total number of ways in which a sum of 7 can be achieved using these coins if the order of the coins is not important?
4
3
5
6
A sum of 7 can be achieved in the following ways:
{1,1,1,1,1,1,1}, {1,1,1,1,3}, {1,3,3}, {1,1,1,4}, {3,4}.
Therefore, the sum can be achieved in 5 ways.
Suppose you are given infinite coins of N denominations v1, v2, v3,.....,vn and a sum S. The coin change problem is to find the minimum number of coins required to get the sum S. What is the space complexity of a dynamic programming implementation used to solve the coin change problem?
O(N)
O(S)
O(N^{2})
O(S*N)
To get the optimal solution for a sum S, the optimal solution is found for each sum less than equal to S and each solution is stored. So, the space complexity is O(S).
You are given infinite coins of N denominations v1, v2, v3,.....,vn and a sum S. The coin change problem is to find the minimum number of coins required to get the sum S. What is the time complexity of a dynamic programming implementation used to solve the coin change problem?
O(N)
O(S)
O(N^{2})
O(S*N)
The time complexity is O(S*N).
Suppose you have coins of denominations 1,3 and 4. You use a greedy algorithm, in which you choose the largest denomination coin which is not greater than the remaining sum. For which of the following sums, will the algorithm produce an optimal answer?
14
10
6
100
Using the greedy algorithm, three coins {4,1,1} will be selected to make a sum of 6. But, the optimal answer is two coins {3,3}. Similarly, four coins {4,4,1,1} will be selected to make a sum of 10. But, the optimal answer is three coins {4,3,3}. Also, five coins {4,4,4,1,1} will be selected to make a sum of 14. But, the optimal answer is four coins {4,4,3,3}. For a sum of 100, twenty-five coins {all 4's} will be selected and the optimal answer is also twenty-five coins {all 4's}.
Suppose you have coins of denominations 1, 3 and 4. You use a greedy algorithm, in which you choose the largest denomination coin which is not greater than the remaining sum. For which of the following sums, will the algorithm NOT produce an optimal answer?
20
12
6
5
Using the greedy algorithm, three coins {4,1,1} will be selected to make a sum of 6. But, the optimal answer is two coins {3,3}.
You are given infinite coins of denominations v1, v2, v3,.....,vn and a sum S. The coin change problem is to find the minimum number of coins required to get the sum S. This problem can be solved using ____________
Greedy algorithm
Dynamic programming
Divide and conquer
Backtracking
The coin change problem has overlapping subproblems(same subproblems are solved multiple times) and optimal substructure(the solution to the problem can be found by finding optimal solutions for subproblems). So, dynamic programming can be used to solve the coin change problem.
What is the sum of each of the balanced partitions for the array {5, 6, 7, 10, 3, 1}?
16
32
0
64
The sum of all the elements of the array is 32. So, the sum of all the elements of each partition should be 16.
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]
The line "ans[i][j] || ans[i - arr[j - 1]][j - 1]" completes the above code.
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}
For S1 = {5, 3} and S2 = {4, 2, 1}, sum(S1) - sum(S2) = 1, which is the optimal solution.
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})
In the brute force implementation, all the possible subsets will be formed. This takes exponential time.
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
When the sum of all the elements is odd, it is not possible to have two subsets with equal sum.
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
Dynamic programming, Recursion, Brute force
All of the mentioned methods can be used to solve the balanced partition problem.
What is the space complexity of the above dynamic programming implementation of the assembly line scheduling problem?
O(1)
O(n)
O(n^{2})
O(n^{3})
The space complexity of the above dynamic programming implementation of the assembly line scheduling problem is O(n).