Question: What is the time complexity of this method with the following signature :b ) public E remove ( int index ) public E remove (

What is the time complexity of this method with the following signature :b) public E remove (int index)
public E remove(int index){
if (index 0|| index > size){
System.out.println("out of
bound");
return null;
}
E element;
if (index ==0){// remove from
front
element = head.getElement();
head = head.getNext();
if (head == null){// special
case, if the only element is removed
tail = null;
}
} else {
curr = head;
for (int i =0; i index -1;
i++){
curr = curr.getNext();
}
element =
curr.getNext().getElement();
if (tail == curr.getNext()){
tail = curr;
}
curr.setNext(curr.getNext().getNext());
}
size--;
return element;
}
What is the time complexity of this method with

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!