当前位置:网站首页>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 .
边栏推荐
- [database I] database overview, common commands, view the table structure of 'demo data', simple query, condition query, sorting data, data processing function (single row processing function), groupi
- [Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
- Add IDM to Google browser
- Jenkins configures IP address access
- 基於.NetCore開發博客項目 StarBlog - (14) 實現主題切換功能
- Dare to climb here, you're not far from prison, reptile reverse actual combat case
- Contest3145 - the 37th game of 2021 freshman individual training match_ D: Ranking
- MySQL query
- VRRP+BFD
- Global and Chinese market of cell scrapers 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?

Problems and solutions of several concurrent scenarios of redis

PID of sunflower classic

Johnson–Lindenstrauss Lemma

Redis notes (I) Linux installation process of redis
![[Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)](/img/e9/818bdfeae766dca7d2318b52b4424d.jpg)
[Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)

7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages

What are the conditions for the opening of Tiktok live broadcast preview?

How to use websocket to realize simple chat function in C #

If you have just joined a new company, don't be fired because of your mistakes
随机推荐
No clue about the data analysis report? After reading this introduction of smartbi, you will understand!
what does ctrl + d do?
機器學習基礎:用 Lasso 做特征選擇
2022 Guangxi provincial safety officer a certificate examination materials and Guangxi provincial safety officer a certificate simulation test questions
Database concept and installation
Unity controls the selection of the previous and next characters
Learning video website
Johnson–Lindenstrauss Lemma
The first spring of the new year | a full set of property management application templates are presented, and Bi construction is "out of the box"
Résumé des outils communs et des points techniques de l'examen PMP
2022 registration examination for safety production management personnel of fireworks and firecracker production units and examination skills for safety production management personnel of fireworks an
@Scheduled scheduled tasks
Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
Record a problem that soft deletion fails due to warehouse level error
[latex] production of complex tables: excel2latex and detail adjustment
2022 examination summary of quality controller - Equipment direction - general basis (quality controller) and examination questions and analysis of quality controller - Equipment direction - general b
Easy to win insert sort
Remote work guide
Key knowledge of C language
Global and Chinese market of small batteries 2022-2028: Research Report on technology, participants, trends, market size and share

