r/codinginterview • u/bparanj • May 14 '20
Power Function using Recursion
Powers of 2 (warmup)
Exponentiation operator
Implement without using exponentiation operator
Iterative solution
Product accumulator
Powers of a given base
Recursive implementation in linear time
Size of the problem
Base cases
Reduce and combine
Allow negative integer exponents
Problem decomposition
Recursive case
Relationship between reduction step and base case
Function to express recursive case
Multiple recursive cases
Powers in logarithmic time
Handling multiple cases and its effect on recursion diagram
Recursive function with multiple recursive cases
Direct translation of mathematical function to code
2
Upvotes
2
u/nascentmind May 14 '20
Are you referring to the book "Introduction to Recursive Programming" by Manuel Rubio-Sanchez?
I am referring to the same book and revising. The diagrams and exercises look similar.