Data Structures Questions and Answers Part-19

1. What should be done when an opening parentheses is read in a balancing symbols algorithm?
a) push it on to the stack
b) throw an error
c) ignore the parentheses
d) pop the stack

Answer: a
Explanation: When an opening bracket/braces/parentheses is encountered, it is pushed on to the stack. When the corresponding end bracket/braces/parentheses is not found, throw an error.

2. When the corresponding end bracket/braces/parentheses is not found, what happens?
a) The stack is popped
b) Ignore the parentheses
c) An error is reported
d) It is treated as an exception

Answer: c
Explanation: When the corresponding end bracket/braces/parentheses is not found, throw an error since they don’t match.

3. If the corresponding end bracket/braces/parentheses is encountered, which of the following is done?
a) push it on to the stack
b) pop the stack
c) throw an error
d) treated as an exception

Answer: b
Explanation: When the corresponding end bracket/braces/parentheses is encountered, the stack is popped. When an opening bracket/braces/parentheses is encountered, it is pushed on to the stack.

4. An error is reported when the stack is not empty at the end?
a) true
b) false

Answer: a
Explanation: When the stack contains elements at the end, it means that the given string of parentheses is not balanced.

5. Is the given statement ((A+B) + [C-D]] valid with respect to balancing of symbols?
a) true
b) false

Answer: b
Explanation: The given statement is invalid with respect to balancing of symbols because the last bracket does not correspond to the opening braces.

6. How many passes does the balancing symbols algorithm makes through the input??
a) one
b) two
c) three
d) four

Answer: a
Explanation: The balancing symbols algorithm makes only one pass through the input since it is linear.

7. Which of the following statement is invalid with respect to balancing symbols?
a) [(A+B) + (C-D)]
b) [{A+B}-{C-[D+E]}]
c) ((A+B) + (C+D)
d) {(A+B) + [C+D]}

Answer: c
Explanation: ((A+B) + (C+D) is invalid because the last close brace is not found in the statement.

8. What is a bit array?
a) Data structure for representing arrays of records
b) Data structure that compactly stores bits
c) An array in which most of the elements have the same value
d) Array in which elements are not present in continuous locations

Answer: b
Explanation: It compactly stores bits and exploits bit-level parallelism.

9. Which of the following bitwise operations will you use to set a particular bit to 1?
a) OR
b) AND
c) XOR
d) NOR

Answer: a
Explanation: 1 OR 1 = 1, 0 OR 1 = 1, any bit OR’ed with 1 gives 1.

10. Which of the following bitwise operations will you use to set a particular bit to 0?
a) OR
b) AND
c) XOR
d) NAND

Answer: b
Explanation: 1 AND 0 = 0, 0 AND 0 = 0, any bit AND with 0 gives 0.