【问题标题】:Time Complexity of the Palindrome recursive algorithm回文递归算法的时间复杂度
【发布时间】:2020-07-16 10:12:37
【问题描述】:

以下检查给定输入是否为回文的代码的时间复杂度是多少?

public boolean isPalindromeRecursion(String input, int first, int last) {
    if (input.charAt(first) != input.charAt(last)) {
        return false;
    } else if (first >= last) {
        return true;
    }
    return isPalindromeRecursion(input, first + 1, last - 1);
}

【问题讨论】:

    标签: java time-complexity palindrome


    【解决方案1】:

    算法的时间复杂度是:

    1. 严格来说-O(n/2);
    2. 使用渐近分析语言 - O(n),当我们使用大 O 分析时,constant factors are disregardedit's good,它们被忽略了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-12
      • 1970-01-01
      • 1970-01-01
      • 2017-07-15
      • 1970-01-01
      相关资源
      最近更新 更多