# Data Structure Questions and Answers-Decimal to Binary using Stacks

## Data Structure Questions and Answers-Decimal to Binary using Stacks

Congratulations - you have completed Data Structure Questions and Answers-Decimal to Binary using Stacks.

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

Your performance has been rated as %%RATING%%

 Question 6 [CLICK ON ANY COICE TO KNOW RIGHT ANSWER]
Write a piece of code which returns true if the string contains balanced parenthesis, false otherwise.
 A public boolean isBalanced(String exp) { int len = exp.length(); Stack stk = new Stack(); for(int i  B public boolean isBalanced(String exp) { int len = exp.length(); Stack stk = new Stack(); for(int i < C public boolean isBalanced(String exp) { int len = exp.length(); Stack stk = new Stack(); for(int i < D public boolean isBalanced(String exp) { int len = exp.length(); Stack stk = new Stack(); for(int i <
Question 6 Explanation:
Whenever a '(' is encountered, push it into the stack, and when a ')' is encountered check the top of the stack to see if there is a matching '(', if not return false, continue this till the entire string is processed and then return true.

 Question 7 [CLICK ON ANY COICE TO KNOW RIGHT ANSWER]
What is the time complexity of the above code?
 A O(logn) B O(n) C O(1) D O(nlogn)
Crack any exam
Question 7 Explanation:
All the characters in the string have to be processed, hence the complexity is O(n). Question 8 [CLICK ON ANY COICE TO KNOW RIGHT ANSWER]
For every matching parenthesis, print their indices.
 A public void dispIndex(String exp) { Stack stk = new Stack(); for (int i = 0; i < len; i++ B public void dispIndex(String exp) { Stack stk = new Stack(); for (int i = 0; i < len; i++ C public void dispIndex(String exp) { Stack stk = new Stack(); for (int i = 0; i < len; i++ D None of the mentioned