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


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

public boolean isBalanced(String exp) { 	int len = exp.length(); 	Stack<Integer> stk = new Stack<Integer>(); 	for(int i 
B

public boolean isBalanced(String exp) { 	int len = exp.length(); 	Stack<Integer> stk = new Stack<Integer>(); 	for(int i <
C

public boolean isBalanced(String exp) { 	int len = exp.length(); 	Stack<Integer> stk = new Stack<Integer>(); 	for(int i <
D

public boolean isBalanced(String exp) { 	int len = exp.length(); 	Stack<Integer> stk = new Stack<Integer>(); 	for(int i <
English grammar Questions answers
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<Integer> stk = new Stack<Integer>(); 	for (int i = 0; i < len; i++
B

public void dispIndex(String exp) { Stack<Integer> stk = new Stack<Integer>(); for (int i = 0; i < len; i++
C

public void dispIndex(String exp) { Stack<Integer> stk = new Stack<Integer>(); for (int i = 0; i < len; i++
D
None of the mentioned
Computer science (GATE/NET) Questions answers
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. Share it
There are 8 questions to complete.