当前位置:网站首页>Recursive structure
Recursive structure
2022-07-04 03:18:00 【hv102】
Recursive structure consists of two parts :
- Define recursive headers . solve : When not to call your own methods . If there is no head , Will fall into a dead cycle , That is, the end condition of recursion .
- Recursive body . solve : When do I need to call my own methods .
- Example : Use recursion to find n
public class Test22 { public static void main(String[ ] args) { long d1 = System.currentTimeMillis(); factorial(10); long d2 = System.currentTimeMillis(); System.out.printf(" Recursive time-consuming :"+(d2-d1)); // Time consuming :32ms } /** The way to find factorial */ static long factorial(int n){ if(n==1){// Recursive header return 1; }else{// Recursive body return n*factorial(n-1);//n! = n * (n-1)! } } }
The execution result is shown in the figure :
The flaw of recursion
Simple algorithm is one of the advantages of recursion . But recursive calls take up a lot of system stack , Memory consumption , When there are many levels of recursive calls, the speed is much slower than the loop , So be careful when using recursion .
边栏推荐
- Zblog collection plug-in does not need authorization to stay away from the cracked version of zblog
- Li Chuang EDA learning notes 13: electrical network for drawing schematic diagram
- A brief talk on professional modeler: the prospect and professional development of 3D game modeling industry in China
- Unity controls the selection of the previous and next characters
- Leetcode 110 balanced binary tree
- WP collection plug-in free WordPress collection hang up plug-in
- Www 2022 | taxoenrich: self supervised taxonomy complemented by Structural Semantics
- [untitled]
- Contest3145 - the 37th game of 2021 freshman individual training match_ J: Eat radish
- Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
猜你喜欢
Jenkins continuous integration environment construction V (Jenkins common construction triggers)
Network communication basic kit -- IPv4 socket structure
[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love
Zblog collection plug-in does not need authorization to stay away from the cracked version of zblog
Teach you how to optimize SQL
Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress
Zhihu million hot discussion: why can we only rely on job hopping for salary increase? Bosses would rather hire outsiders with a high salary than get a raise?
Database concept and installation
Pagoda SSL can't be accessed? 443 port occupied? resolvent
96% of the collected traffic is prevented by bubble mart of cloud hosting
随机推荐
Key knowledge of embedded driver
Setting methods, usage methods and common usage scenarios of environment variables in postman
Recent learning fragmentation (14)
Crawler practice website image batch download
Global and Chinese markets for electroencephalogram (EEG) devices 2022-2028: Research Report on technology, participants, trends, market size and share
Redis notes (I) Linux installation process of redis
Global and Chinese market of digital impression system 2022-2028: Research Report on technology, participants, trends, market size and share
[untitled] the relationship between the metauniverse and digital collections
Rhcsa day 2
1day vulnerability pushback skills practice (3)
Have you entered the workplace since the first 00???
1day vulnerability pushback skills practice (3)
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
Backpropagation formula derivation [Li Hongyi deep learning version]
ZABBIX API batch delete a template of the host
Global and Chinese market of cell scrapers 2022-2028: Research Report on technology, participants, trends, market size and share
Contest3145 - the 37th game of 2021 freshman individual training match_ E: Eat watermelon
Love and self-discipline and strive to live a core life
Node write API
Global and Chinese market of handheld melanoma scanners 2022-2028: Research Report on technology, participants, trends, market size and share