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%%
Your answers are highlighted below.
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.
public boolean isBalanced(String exp) { int len = exp.length(); Stack<Integer> stk = new Stack<Integer>(); for(int i | |
public boolean isBalanced(String exp) { int len = exp.length(); Stack<Integer> stk = new Stack<Integer>(); for(int i < | |
public boolean isBalanced(String exp) { int len = exp.length(); Stack<Integer> stk = new Stack<Integer>(); for(int i < | |
public boolean isBalanced(String exp) { int len = exp.length(); Stack<Integer> stk = new Stack<Integer>(); 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?
O(logn) | |
O(n) | |
O(1) | |
O(nlogn) |
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.
public void dispIndex(String exp) { Stack<Integer> stk = new Stack<Integer>(); for (int i = 0; i < len; i++ | |
public void dispIndex(String exp) { Stack<Integer> stk = new Stack<Integer>(); for (int i = 0; i < len; i++ | |
public void dispIndex(String exp) { Stack<Integer> stk = new Stack<Integer>(); for (int i = 0; i < len; i++ | |
None of the mentioned |
Question 8 Explanation:
Whenever a '(' is encountered, push the index of that character into the stack, so that whenever a corresponding ')' is encountered, you can pop and print it.
Digital Education is a concept to renew the education system in the world. It is a program that endeavors to bridge the literacy slippage by delivering education through a digital platform to children and teachers. You can tell your friends regarding our intiative, click share button below.
There are 8 questions to complete.