Giter Club home page Giter Club logo

algorithm's Introduction

目前正在学习算法,所以相关的C/C++代码都会放到这个仓库下面

  • 算法练习相关代码主要是来自剑指Offer与LeetCode题目

关于递归和迭代

递归优点

  • 简洁

递归缺点

  • 递归需要用到函数调用,函数调用需要时间和空间的消耗:每一次函数调用都需要在内存栈中分配空间来保存参数、返回地址及临时变量;对于栈中数据的压入和弹出都需要一定的时间。
  • 递归有可能计算了多次重复,例如Fibonacci数列
  • 更严重的问题:每一次调用函数都需要栈空间,每个进程的栈的容量有限,当调用层级太大的时候,就会超出栈的容量,导致调用栈溢出。写一个简单的1+2+3..+n就可以知道,如果n太大,递归就会出错。

迭代优点

  • 可以避免以上的缺点

迭代缺点

  • 需要较多代码

algorithm's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.