zoukankan      html  css  js  c++  java
  • 【SICP练习】92 练习2.65

    练习2.65

    最后一道题了,来个总结倒是很不错。要完成两个函数,我们就要用到前面所学,首先用练习2.63中的函数将树变成表,这样有利于后续的处理,而根据前面的习题,用tree->list-2会更加快速。然后要实现并集或补集的功能,也要用到第104页相关的函数。题目要求的是平衡二叉树,因此还要用到练习2.64中的list->tree函数将最后的结果平衡。这三个函数的复杂度都出奇的一致为n,因此最终的函数的复杂度也为n。因为其中要用到intersection-set等函数,因此我们将最终题目所求的函数稍微改下名。

    (define (union-tree tree1 tree2)
        (list->tree (union-set (tree->list-2 tree1)
                             (tree->list-2 tree2))))
    (define (intersection-tree tree1 tree2)
        (list->tree (intersection-set (tree->list-2 tree1)
                                   (tree->list-2 tree2))))

    相信大家已经看到了,这道题并不难,只要我们能够想到运用前面所学的知识。



    感谢访问,希望对您有所帮助。 欢迎关注或收藏、评论或点赞。


    为使本文得到斧正和提问,转载请注明出处:
    http://blog.csdn.net/nomasp


    版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。

  • 相关阅读:
    vb.net的数据类型
    PHP常用函数
    399. Evaluate Division
    329. Longest Increasing Path in a Matrix
    415. Add Strings
    463 Island Perimeter
    400. Nth Digit
    401. Binary Watch
    391. Perfect Rectangle
    406. Queue Reconstruction by Height
  • 原文地址:https://www.cnblogs.com/NoMasp/p/4786127.html
Copyright © 2011-2022 走看看