Skip to content

Instantly share code, notes, and snippets.

@pradhuman-soni
Created October 27, 2021 05:22
Show Gist options
  • Select an option

  • Save pradhuman-soni/4965912e82b48ab838b6dc218be2177e to your computer and use it in GitHub Desktop.

Select an option

Save pradhuman-soni/4965912e82b48ab838b6dc218be2177e to your computer and use it in GitHub Desktop.
Any base multiplication
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.
• 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.
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