Download Complexity Analysis of SetSize Method and Implementation of LinkedList and more Exams Data Structures and Algorithms in PDF only on Docsity! Solution 1: The worst case complexity of the SetSize(int size) method will be O(n) and best case complexity can be O(1). The code is as follows: /** Extension of array implementation of Linear List*/ package dataStructures; import java.util.*; import utilities.*; public class ArrayLinearListExt extends ArrayLinearList { public ArrayLinearListExt(int capacity) { super(capacity); } public void SetSize(int size) { if(size>element.length) { throw new IllegalArgumentException("The size should be smaller than the capacity of the List"); } if(this.size<size) { for(int i=this.size+1;i<=size;i++) { element[i]=null; } this.size=size; } else if(this.size>size) { for(int i=this.size-1;i>=size;i--) { element[i]=null; } this.size=size; } } public static void main(String [] args) { // test default constructor ArrayLinearListExt x = new ArrayLinearListExt(10); // test size System.out.println("Initial size is " + x.size()); // test isEmpty if (x.isEmpty()) System.out.println("The list is empty"); else System.out.println("The list is not empty"); // test put x.add(0, new Integer(2)); x.add(1, new Integer(6)); x.add(0, new Integer(1)); x.add(2, new Integer(4)); System.out.println("List size is " + x.size()); //test SetSize x.SetSize(5); System.out.println("List size is " + x.size()); x.SetSize(3); System.out.println("List size is " + x.size()); x.SetSize(11); System.out.println("List size is " + x.size()); } } Solution 2: Complexity of void Add( int element) is O(1) Complexity of void Delete()is O(1) Only two temporary reference variable must be required to implement void Reverse(Node start)in O(n) time. The code is as follows: package applications; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class LinkedList { private Node start; public LinkedList() { start=null; } public void Create(int nodeNum) { System.out.println("\nEnter the data to be added: "); for(int i=0;i<nodeNum;i++)