سوال ۵۷ کنکور ارشد مهندسی کامپیوتر ۱۴۰۲
اهمیت
۰/۵
مرتبه زمانی الگوریتم زیر کدام است؟
for(i = ۱ ; i <= n ; i++)
for(j = ۱ ; j <= ⌊n/i⌋ ; j++)
S.O. ...
پاسخ صحیح: گزینهٔ C —
پاسخ تشریحی
The inner loop body runs once for each from to , so for a fixed outer index it executes times. The total number of basic operations is therefore
Drop the floor (it changes each term by at most , contributing only overall):
where is the -th harmonic number. The harmonic number satisfies
Hence
The matching answer is option 3, .
Pitfall: A bound of on the inner loop is the textbook signature of the harmonic sum, giving — NOT . The naive guess wrongly assumes the inner loop runs times for every , but it shrinks as grows.
Note on the answer key: the preliminary key marks option 2 (), but the double loop runs — option 3.
#asymptotic-analysis#nested-loops#harmonic-series#time-complexity#floor-division