for loop - Java Method Complexity - Troubling Figuring it Out -
I was testing a computer science process for UIL when I encountered this segment code ( Then the question asked me to determine the most restrictive complexity of the However, the correct answer actually came from O (N ^ 2) I'm confused about why this is so, would anyone explain this to me? Because I thought O (n ^ 2) complexity nested This is O (n ^ 2) because the recursive function is a built-in translucency of structure & Lt; E & gt; class, but they were not relevant to the problem):
public class structure & lt; E & gt; {Private E data; Private Structure & lt; E & gt; S; Structure (id) {data = D; } Add Public Zero (id) {if (S == blank) S = New structure & lt; E & gt; (D); Else s.add (d); }} / / Client method public structure & lt; Integer & gt; Demo (int [] vals) {structure & lt; Integer & gt; S; S = new structure & lt; Integer & gt; (Wall [0]); (Int i = 0; i & lt; vals.length; i ++) s.add (wal [i]) for; Return s; }
demo () client method. I read on big o notation (before taking the course exam!) And it has been said that there should be linear complexity, by adding a loop operation in one list at a time, or O (N) .
for loops ... P>
addition , i.e., second loop In it, something like this:
s = new structure & lt; Integer & gt; (Wall [0]); For (Int i = 0; I
Comments
Post a Comment