Recursive applet example code

高洛峰
Release: 2017-03-22 17:05:25
Original
2128 people have browsed it

This article introduces the recursive applet sample code

# -*- coding:utf-8 -*-
 
__author__ = 'Abel Xu'
 
 
def func(n):
    """
    T(n) = 4T(n/2)+n
    = 2n^2-n
    :param n:
    :return:
    """
    if n==0:
        return 0
 
    return 4 * func(n/2) + n
 
# 另一套写法
f = lambda x: x and 4*f(x/2)+x or 0
 
if __name__ == '__main__':
 
    for i in xrange(0, 6, 2):
        print(func(i))
 
    print f(4)
Copy after login

The above is the detailed content of Recursive applet example code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!