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

java - sharing data between threads - atomicreference or synchronize
sessionlistner not working when user closes the browser
How to convert video file(.mp4) format into binary format in android?
incorrect logic in checksum function
android json parsing keeps on loading
Java - Error when removing from an ArrayList more than once. (IllegalStateException)
Implement remote JMS server
Do most JVMs allocate memory for unused methods?
Android API 16 option menu doesn't show .but show menu in android version API 10
JSP program always returning null value
Java Interface - Object to class typecasting
Inconvertible types in Generics [duplicate]
how to set adapter for spinner
JAVA dynamic attributes condition evaluation
Lucene: Searching multiple fields with default operator = AND
App crashing due to FindViewById(), issue with componentInfo

Categories

HOME
ms-access
pdf
osgi
clips
hive
amazon-ec2
pycharm
session
iot
cvs
jira
programming-languages
infragistics
graphql
twitter-bootstrap-4
jxls
opengl-es-2.0
swagger-ui
synchronization
maude-system
tomcat6
u-sql
nstableview
collectd
static-libraries
fortumo
interop
karma-jasmine
alpine
nodatime
paging
autoconf
clickonce
graphicsmagick
blazemeter
xpages-ssjs
apache-commons-io
wpfdatagrid
file-rename
siesta-swift
environment-modules
wixsharp
xenforo
angularjs-factory
dism
mesos-chronos
jvm-languages
ibpy
spring-security-kerberos
flashair
menuitem
xml-documentation
youcompleteme
termination
react-scripts
pubmed
alphabet
idisposable
colorama
worker-thread
directory-structure
lift-json
np-complete
vtigercrm
nxt
login-control
dataview
bluegiga
reactive-banana
kcachegrind
unity3d-gui
operator-precedence
network-interface
java.util.concurrent
algebraic-data-types
page-layout
access-rights
odata4j
flash-builder4.5
django-nonrel
simba
chuck
twrequest
windows-phone-7.1.1
hamachi
iphone-web-app
remember-me
w3wp.exe
suppress
preference
sustainable-pace
text-coloring

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