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

Writing Chess Game, Trouble Getting One Square Object From Another
Using static fragment in Fragment Page Adapter
Java PHP Application calculate or get IPv6 from IPv4 if available
ScrollView going behind button in Android
Passing integers from file to array
Tomcat 7 java.lang.NullPointerException when wrong credential entered using Active Directory authentification
How to update 2 tables using one query in JPA native query?
Running separate process from Java applet using internal class
Response time out when pinging an IP address in Java
Alignment in combined OHLC chart
Log4j2 Servlet 3.0 not logging
Refresh a Loader when data is changed - android
DataAccessException vs SQLException
Expandable list view, child on click new activity with information
Maven dependency (MySQL-Connector) not found during testing phase
flyway:clean doesnot clean multiple schema

Categories

HOME
pdf
single-sign-on
include
q
youtube-api-v3
frameworks
sqlite3
dxl
ip
cross-browser
gitpitch
adobe-analytics
volttron
kentor-authservices
task
fallback
decimal
try-catch
jtextfield
errorlevel
p-value
info.plist
dbclient
objectanimator
directx-10
functor
oracle-fusion-middleware
jspresso
fog
catch-all
nssegmentedcontrol
simplexml
multilingual
elasticsearch-plugin
keydown
angular-resource
outlook-2013
jedis
zip4j
clean-architecture
winscp-net
tizen-native-app
colorama
crypt
snmptrapd
windows-iot-core-10
webdriverjs
vtigercrm
quartz-composer
medium.com
deadbolt-2
intrusion-detection
ready-api
dlna
yaws
browser-link
ford-fulkerson
unity-networking
rtbkit
prerequisites
jms2
google-places
thredds
tmuxinator
kcachegrind
varargs
muse
vstest.console.exe
operator-precedence
tween
relocation
android-2.2-froyo
message-driven-bean
flash-builder4.5
pushbackinputstream
sqlperformance
http-unit
dmoz
newtonscript
ocx
asyncfileupload
libc++
stage
rfc1123
gdlib
lang
coda-slider
compiler-specific
uiq3

Resources

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
javascript
java
csharp
php
python
android
jquery
ruby
ios
html