以下程序的时间复杂度是多少?

问题描述 投票:-1回答:2

程序反向字符串。我认为它的复杂度为O(n / 2)enter image description here

c algorithm data-structures time-complexity
2个回答
1
投票

是,循环执行n / 2个步骤。但是,时间复杂度仍为O(n)。


1
投票

确实是O(n / 2),与O(n)相同,因为常数因子在大O表示法中无关紧要

© www.soinside.com 2019 - 2024. All rights reserved.