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

How to connect to a embedded Derby database?
why dilate functin give different result when the parameteer is the same
Moving Polygon with mouse cursor in Java - works only once
choropleth map wont show up with Rcaller
SpringBoot embedded tomcat dependency
how to connect sql and mysql database in a single java program?
Distributed Application Migration - To new HA MQ architecture
How to gracefully shutdown a Java application when of closing the Windows console?
Exception in thread “main” java.lang.ExceptionInInitializerError when changing folder structure of Gradle Project
Text clustering program in java
MySql Json object deserialisation optimization
Unsure how to link Variables from a none main class to the main class from objects.
How to test JMS inprocess which take xml as message
Java that adds time [duplicate]
Insert data into database using CrudRepository when table ID is generated using a trigger
how to sort trimmed values in hash map

Categories

HOME
variables
server
push-notification
iterator
raspberry-pi
mean-stack
spagobi
adb
rsync
jsrender
v8
c#-2.0
binary-tree
flyway4
slick-slider
python-unittest
row
postgres-xl
google-cloud-spanner
jplayer
circular-dependency
workload-scheduler
django-admin
beyondcompare
viewport
firefox-webextensions
clickonce
css-animations
extjs5
dxf
buildbot
tdd
url-scheme
windows-error-reporting
msys2
libuv
flink-streaming
nouislider
repo
mozilla
gammu
abstract-class
c11
sqlite2
google-closure
botbuilder
import-from-excel
reactive-cocoa-5
fault
appcompat
typescript1.8
domain-model
yii2-extension
jxcore
worker-thread
android-cursor
sybase-asa
knpmenubundle
synchronous
pintos
static-ip-address
file-writing
lua-5.1
make-install
sdf
bluemix-app-scan
suffix-tree
design-by-contract
ios4
kendonumerictextbox
pervasive-sql
reactive-banana
jms2
jmeter-maven-plugin
twirl
interrupted-exception
asp.net-dynamic-data
onactivityresult
php-5.4
castle
yorick
marmalade
srs
mcts
gnu-smalltalk
jsctypes
seed
orchardcms-1.7
cassini-dev
unc
coderush
uiviewanimation-curve
jquery-ui-layout
code-cleanup
netdna-api
gcj
coercion
cinema-4d
servicehost
inotifycollectionchanged
filtered-index
castle-monorail

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
Mobile App
Mobile App
Mobile App