Actual comparison of the time complexity of the eight queens three algorithms

Source: Internet
Author: User

I vaguely felt something wrong. I tried to add a statistic for the can_put function. Theoretically, the number of can_put function executions is O (t)

 
CNT: 352, times: 72378

Real 0m0. 008 s
User 0m0. 004 s
Sys 0m0. 000 s

CNT: 352, times: 1222703298

Real 0m18. 207 s
User 0m18. 193 s
Sys 0m0. 004 s

CNT: 352, times: 459314

Real 0m0. 022 s
User 0m0. 016 s
Sys 0m0. 000 s

The first type is recursion. Besides stack consumption, it should be economical enough.

The second is traversal, which is very economical in space and time-consuming. It is O (n ^ N), that is, the worst.

The third is optimized traversal, and pruning is added (which is probably the case ?), The efficiency is greatly improved, but it is still very bad compared with recursion. I don't know if the algorithm is faulty or the price paid for the stack space?

 

When I finish my work and take a look at it at rest, I always feel that the third algorithm should not be so time-consuming. Where should I write it wrong.

 

Actual comparison of the time complexity of the eight queens three algorithms

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.