What is the Big-O notation for this java code? (Running time and space analysis.
ID: 671606 • Letter: W
Question
What is the Big-O notation for this java code? (Running time and space analysis.) Provide a small descriprion to support the notation.
3. Provide the big-O notation for the running time and space analysis for the following method and brief explain your reasoning. @param items input array @return the first node of the linked list build from the input array public static Node buildList(E[] items) Node head null; if (items!-null && items.length>0) ( head - new Node (items[0], null), Node tail = head; for (int i=1; icitens.length; 1++) { tail.next -new NodeE>(items[i], tail = tail.next; nul1); return head;Explanation / Answer
O(n) for this.
It is because of the insertion in the linked list structure. Basically the for loop will run for length of the array.
Based on this the linked list will be created so basically it means that it will be insertion for the size of the array. Now for the space complexisty it will be equal to the size of the array i.e linked list will be created for the size of the array.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.