Click here to Skip to main content
15,886,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello All,

Thanks for participation and your precious suggestions, I have done some of the algorithms but I stuck in these two, Could you (experts) find time complexity for the following two algorithm with explanation (steps) so I can solve the rest in future.

Note: I am not been paid nor given task but I wan to solve these algorithm posted in shape of paper on pdfcoffee.com

Algorithm which just sums up for no apparent reason

𝑝𝑟𝑜𝑐𝑒𝑑𝑢𝑟𝑒𝑆𝑜𝑚𝑒𝐴𝑙𝑔3(𝑛)
𝑠𝑢𝑚 = 0
𝑓𝑜𝑟 𝑖 = 1 𝑡𝑜 √𝑛 𝑑𝑜
𝑠𝑢𝑚 = 𝑠𝑢𝑚 + 𝑖
𝑒𝑛𝑑 𝑓𝑜𝑟
𝑓𝑜𝑟 𝑖 = 1 𝑡𝑜 √𝑛 𝑑𝑜
2
𝑠𝑢𝑚 = 𝑠𝑢𝑚 + 𝑖
𝑒𝑛𝑑 𝑓𝑜𝑟
𝑓𝑜𝑟 𝑖 = 1 𝑡𝑜 10 𝑑𝑜
𝑠𝑢𝑚 = 𝑠𝑢𝑚 + 𝑖
𝑒𝑛𝑑 𝑓𝑜𝑟
𝑒𝑛𝑑 𝑝𝑟𝑜𝑐𝑒𝑑𝑢𝑟𝑒


Algorithm which just sums up for no apparent reason

𝑝𝑟𝑜𝑐𝑒𝑑𝑢𝑟𝑒𝑆𝑜𝑚𝑒𝐴𝑙𝑔4(𝑛)
𝑠𝑢𝑚 = 0
𝑓𝑜𝑟 𝑖 = 1 𝑡𝑜 √𝑛 𝑑𝑜
𝑓𝑜𝑟 𝑗 = 1 𝑡𝑜 5 𝑑𝑜
𝑠𝑢𝑚 = 𝑠𝑢𝑚 + 𝑖 ∗ 𝑗
𝑒𝑛𝑑 𝑓𝑜𝑟
𝑒𝑛𝑑 𝑓𝑜𝑟
𝑒𝑛𝑑 𝑝𝑟𝑜𝑐𝑒𝑑𝑢𝑟𝑒


What I have tried:

I have find complexity for an online paper of algorithm posted at pdfcoffee but the two algorithms, I am stuck to. so need help to solve.
Posted
Updated 25-Apr-21 20:16pm
v2
Comments
Patrice T 25-Apr-21 20:27pm    
How are you stuck ? where ?

1 solution

Think about it.
Time complexity depends on n.

In procedureSomeAlg3, there are two consecutive loops ranging from 1 to sqrt(n). What is their contribution?
There is, in addition, a loop ranging from 1 to 10. Does it partecipate to algorithm time-complexity?

In algoritm procedureSomeAlg4, two loops are nested. The outer one ranges from 1 to sqrt(n), while the inner one ranges from 1 to 5.
What it the former one contribution?
Does the latter one contribute to time-complexity?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900