Recursive and binary algorithms

Source: Internet
Author: User

Recursion: Call the function itself in a function

The maximum depth to be fixed to recursion

Import Sysprint (Sys.setrecursionlimit (100000))

Recursive implementation of level three menus

1menu = {2     'Beijing': {3         'Haidian': {4             'Five crossing': {5                 'Soho': {},6                 'NetEase': {},7                 'Google': {}8             },9             'Zhongguancun': {Ten                 'Iqiyi Art': {}, One                 'Autohome': {}, A                 'Youku': {}, -             }, -             'on the ground': { the                 'Baidu': {}, -             }, -         }, -         'changping': { +             'Shahe': { -                 'old boy': {}, +                 'Beihang University': {}, A             }, at             'Tin Tong Court': {}, -             'Huilongguan': {}, -         }, -         'Chaoyang': {}, -         'Dongcheng': {}, -     }, in     'Shanghai': { -         'Minhang': { to             "People's square": { +                 'Fried Chicken Shop': {} -             } the         }, *         'Zhabei': { $             'Train Warfare': {Panax Notoginseng                 'Ctrip': {} -             } the         }, +         'Pudong': {}, A     }, the     'Shandong': {}, + } -  $ defThree (DIC): $      forKeyinchDIC: -         Print(Key) -K = input ('>>>>>>>') the     ifKinchDIC: - three (dic[k])WuyiThree (DIC)
Detailed Examples

Two-point lookup algorithm:

L = [2,3,5,10,15,16,18,22,26]def Find (L,aim,start,end):    mid = (end+start)//2    if L[mid] > aim:    #中间值大于目标值 , left search        end = Mid   #头部不变,        return Find (l,aim,start,end)    elif L[mid] < aim:        start= mid        return Find (L,aim,start,end)    else:        return Midprint (Find (L,15,start=0,end=len (L)-1))

  

Recursive and binary algorithms

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.