java


Tail Recursive function


So I just started learning about recursion and tail recursion.
I've been looking at some methods and have two here for doing to the power of.
The recursive function is fine but I have no idea what is going on in the tail recursive function, can anyone explain?
public static int n_toThePowerof_m(int n, int m){
if(m <0){
throw new IllegalArgumentException("Illegal Arguement");
}
else if (m == 0){
return 1;
}
else{
return n * n_toThePowerof_m(n, m-1);
}
}
public static int n_toThePowerof_mTail(int n, int m, int accum){
while(n !=0 ){
if((n&0x01) != 0x00){
accum *= m;
}
m >>>= 0x01;
m *= m;
}
return accum;`
}

I agree with #cricket_007 the second method would be considered as the induction step (also has a base case (while (n!=0)) or maybe just the iteration step but definitely not recursion (function must call self in body for recursion).
hope that helps !


Related Links

Compare two Json objects with same keys and push into array- java
Liferay Exception while deploying portlet with MappingExeption entity class not found
How do I use the HotSpot DTrace probes on SmartOS?
How to recursively add after increasing index?
Find out if at a certain position in a jTextPane there is a specific char [java]
2d array of 2 numbers in Java
Input and output Streams in java [duplicate]
How to check for NoClassDefFoundError?
lucene BooleanQuery.Builder Build doesn't Work
why am i getting null pointer exception when trying to set a value to “rating” in my rating bar? [duplicate]
Threadlocal on tomcat misbehaviour after upgrading to JAVA 8
Java, Spring : Anyway to capture screenshot of User's browser at given time
Glassfish domain reported as not running although it is started
Java Applet puzzle picture game
How to get the PayPal account balance in Java
ExecutorService doens't work

Categories

HOME
mediawiki
fluentd
homebrew
relayjs
electron
fancybox
slick-slider
primary-key
google-translate
zend-framework3
circular-dependency
try-catch
vaadin7
libtiff
jsdoc
text-rendering
crystal-reports-2008
jprofiler
custom-wordpress-pages
functional-testing
mmap
one-to-many
qhull
rst2pdf
web-api-testing
wtx
http-status-code-503
semantic-versioning
fusionpbx
appfabric
xcode-extension
mesos-chronos
ws-security
galen
azure-application-gateway
strptime
logparser
fancybox-2
mu
tactic
nodebb
hittest
minimization
gnome-shell-extensions
gridpane
py2app
nsfilemanager
ctest
bstr
moveit
blackberry-10
qgraphicsview
revolution-r
netmq
teamcity-8.0
mutation-observers
tmuxinator
web-controls
proj4js
directoryservices
tween
xc16
rdtsc
xcode-6.2
issuu
jquery-mobile-dialog
interface-orientation
pygit2
cascalog
bubble-chart
reddot
xmlspy
xtype
table-footer
recent-documents
krl
winbugs14
oncheckedchanged
firefox4
brewmp
data-driven
privilege
w3wp
grid-system
wsdl.exe
misv





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm