HCL
Company
Programming
Database
4) Neha wants to write a program that converts a decimal number into a binary number.
Which of the following data structures should she use to
implement the same?
(a) Queue (b)Stack (c)Array (d)Linked List
Read Solution (Total 9)
-
- converting decimal number to binary, initially we push all the binary digits formed into the stack. After the entire number has been converted into the binary form, we pop one digit at a time from the stack and print it. Therefore we get the decimal number converted into its proper binary form.
- 9 years agoHelpfull: Yes(4) No(0)
- its STACK because to convert a decimal no into binary we need continuous divisiion by 2
the result is calculated by writing the remainders in opposite order i.e. LIFO so stack. - 9 years agoHelpfull: Yes(2) No(1)
- Stack because of last in first out feature.
- 9 years agoHelpfull: Yes(1) No(0)
- answer is stack.
solution is:-
when the remainders are stored while decimal to binary conversion, they are stored using LIFO technique in stack.
example:- 24-decimal number, divide it by 2 i.e. 24%2=0 rem is stored in stack. now, 12%2=0 rem is stored in stack again. so, in stack they are stored as 000110. but to pop the remainders stored, they are popped from stack using same LIFO technique but in reverse order i.e. 011000. so, the answer is (b) Stack. - 7 years agoHelpfull: Yes(1) No(0)
- will u plz elaborate why stack ??
- 9 years agoHelpfull: Yes(0) No(0)
- Stack is right answer
- 9 years agoHelpfull: Yes(0) No(0)
- stack is useful
- 8 years agoHelpfull: Yes(0) No(0)
- Stack (b)
Decimal number can be converted into equivalent binary number using stack - 5 years agoHelpfull: Yes(0) No(0)
- stack because of first in first out
- 4 years agoHelpfull: Yes(0) No(0)
HCL Other Question