# What is the Big-O run-time of linear search and binary search in the best, average and worst cases?

1. What is the Big-O run-time of linear search and binary search in the best, average and worst cases?

Linear Search                  Binary Search

Don't use plagiarized sources. Get Your Custom Essay on
What is the Big-O run-time of linear search and binary search in the best, average and worst cases?
Just from \$8 /Page 0r 300 words

Best:

### Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

Worst:

Average:

2. What is the Big-O runtime of the following linked list methods?

• toString()

What is the Big-O runtime of the below Stack method?

• isSorted(Node n)

3. What is the Big-O runtime of the below methods:

```Method A: Stack Copy Constructor Option 1

public Stack(Stack<T> original) {
if(original == null) {
return;
} else if (original.length == 0) {
this();
} else {
Node current = original.top;
Stack<T> temp = new Stack<>();
while (current != null) {
temp.push(current.data);
current = current.next;
}       current = temp.top;
while (temp != null) {
this.push(current.data);
current = current.next;
}
this.length = original.length;
}
}

Method B: Stack Copy Constructor Option 2
public Stack(Stack<T> original) {
if (original.length == 0) {
top = null;
length = 0;
} else {
top = new Node(original.top.data);
Node temp1 = original.top;
Node temp2 = top;
for (int i = 0; i < original.getLength() - 1; i++) {
temp1 = temp1.next;
temp2.next = new Node(temp1.data);
temp2 = temp2.next;
}
length = original.length;
}
}
Method C: Stack Copy Constructor Option 3:

public Stack(Stack<T> original) {
if (original == null) {
return;
} else if (original.length == 0) {
this.length = 0;
this.top = null;
} else {
int count = original.getLength();
while (count > 0) {
count--;
Node temp = original.top;
int i = 0;
while (temp.next != null && i < count) {
i++;
temp = temp.next;
} //end inner while
push(temp.data);
} //end outer while
} //end else
}//end method```

In: Computer Science