复杂性问题 [英] Problem with complexity issue

查看:81
本文介绍了复杂性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我希望对这个程序的复杂性(空间和时间)有很好的清晰解释

thx。



Hey guys, i wish for good and clear explanation for this program complexity(space&time)
thx.

#include <stdio.h>

void main()
{
    char s[50]="Crrosssection";
    int i,k=0;
    char res[50];

    for(i=0;s[i]!=0;i++){
          if(s[i]!=s[i+1]) res[k]=s[i],k+=1; 
    }
}

推荐答案

空间复杂度O(2n)其中n是字符串缓冲区大小。

时间复杂度为O(m),其中m是字符串的实际大小。



BTW,如果分配了字符串会发生什么缓冲区长度超过49个字符?



干杯!
The space complexity O(2n) where n is the string buffer size.
The time complexity is O(m) where m is the actual size of the string.

BTW, what will happen if the string assigned to the buffer is more than 49 characters long?

Cheers!


如果你安装了Visual Studio Team System它随附代码复杂性分析工具。有许多免费工具可供代码复杂性分析试试这个一个 [ ^ ]或 google [ ^ ]它用于更多工具。
If you have Visual Studio Team System Installed it comes with Code Complexity Analysis tools. there are many free tools available for code complexity analysis try this one[^] or google [^] it for more tools.


这篇关于复杂性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆