-
-
Save pradhuman-soni/4965912e82b48ab838b6dc218be2177e to your computer and use it in GitHub Desktop.
Any base multiplication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1) Which base is the most common and used everywhere? | |
| Answer) Base (10) i.e. the decimal number system. | |
| 2) Why are we multiplying our single digit product with power before adding it to answer ? | |
| Answer) We need to multiply it with power, because if you can recall, when we used to product two numbers manually, then after | |
| each single digit product when we changed the line, we used to add a trailing 0 to the next single digit product, that's why we use this power. | |
| 3) How to decide what the carry should be ? | |
| Answer) The carry depends upon the base of the numbers that we are working on, so let's say if we are working on base 8, | |
| then the carry will be calculated by this formula : carry = num / 8, and the number to keep will be num % 8. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| • Try to break the problem into parts. | |
| • Create a function that will give us the product of one number with the single digit of other number. | |
| • Using the above function, do the product of all digits. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1) What is the time complexity ? | |
| a• O(1) | |
| b• O(log n) | |
| c• O(log m) | |
| d• O(log n * log m) | |
| ans) d• O(log n * log m) | |
| 2) What is the space complexity ? | |
| a• O(1) | |
| b• O(log n) | |
| c• O(n^2) | |
| d• O(log m) | |
| ans) a• O(1) | |
| 3) What will be the value of 'a' by this equation : a = b % 10 if b is 189 ? | |
| a• 18 | |
| b• 1 | |
| c• 89 | |
| d• 9 | |
| ans) d• 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment