Question

In: Computer Science

6. List and explain the worst-case and average-case running times for each LinkedList method below: (a)...

6. List and explain the worst-case and average-case running times for each LinkedList method below:
(a) insert(iterator here, Object item)

(b) insertAtHead

(c) insertAtTail (aka push back)

(d) get(iterator here)

(e) get(index i)

(f) remove(iterator here)

(g) remove(index i)

(h) splice(iterator place here, iterator from here, iterator to here)


7. When should you use a Vector, and when should you use a Linked List?

Solutions

Expert Solution

Question#6

(A)

Average: n/2

Reason: The Position of the itreator can be at the middle of the size of the linklist.

Worst Time case: O(n)

Reason: When we are inserting at the last node of the link lost so we have to be traverse the whole Linklist.

(B)

Average: θ(1)

Reason: Whenever we are inserting at head so we have to attach the present head with a temp node so thats why the time complexity will be θ(1) .

Worst Time case: O(1)

Reason: Whenever we are inserting at head so we have to attach the present head with a temp node so thats why the time complexity will be O(1).

(C)

Average: O(n)

Reason: Whenever we are inserting at tail so we have to go through all the linklist in order to insert at tail as we have to traverse the linklist

Worst Time case: O(n)

Reason:Whenever we are inserting at tail so we have to go through all the linklist in order to insert at tail as we have to traverse the linklist

(D)

Average: n/2

Reason: The Position of the itreator can be at the middle of the size of the linklist.

Worst Time case: O(1)

Reason: As when we are getting the value through get function so might be the case that we have to get the last value so the worst time case will be O(1)

Question#7

Vectors are been useful in the cases when you are going for random read access and insertion and deletion on the back but in some cases the use of vector is not efficient like for insertions and deletions on the front or at any other position.

Where as the link list are very efficient for insertion and deletion of the items on the front or when you are been inserting at the back

PLEASE GIVE A THUMBS UP!!!! DONT GIVE A THUMBS DOWN IF YOU HAVE ANY QUERY SO COMMENT DOWN I WILL CLEAR IT FOR YOU


Related Solutions

Given the below code, compute the values of the best case, worst case and average case...
Given the below code, compute the values of the best case, worst case and average case knowing that the basic operation in the first loop takes 4 ns to execute and the basic operation in the second loop takes 5 ns to execute. int A[20]; for (int i=0; i < 20; i++) {           cin >> A[i]; } for (i=0; i < 20; i++) {           if (A[i] % 3 == 0)                     break; }
For the problem below, please estimate the worst-case Running Time for a random array of size...
For the problem below, please estimate the worst-case Running Time for a random array of size n, and prove that it is indeed ( ). Please show all your work. Just stating something like "since 2 Binary Search runs in ( ) time, our algorithm has the same runtime estimate" is not enough. A rigorous explanation is expected. import java.util.*; public class Main { static int binarySearch(int arr[], int l, int r, int x) { if (r >= l) {...
Show that the worst-case and average-case time complexities for the number of assignments of records performed...
Show that the worst-case and average-case time complexities for the number of assignments of records performed by the Exchange Sort algorithm (Algorithm 1.3) are given by           W(n) = 3n(n-1)/2 ≈ n2/2 and A(n) = 3n(n-1)/4 ≈ n2/4
Select three (3) ways, (from the list below) and EXPLAIN in each case how the experimenter...
Select three (3) ways, (from the list below) and EXPLAIN in each case how the experimenter can become the extraneous variable, (List of extraneous variables - experimenter characteristics and experimenter expectancies as it relates to Physiological ­experimenter characteristics including such aspects as age, sex, and race and Psychological ­experimenter attribute including such personality characteristics as hostility, anxiety, and introversion or extroversion.). Provide an explanation/justification for each way in no less than 200 words. List and explain a method for controlling...
Big-O: Describe the worst case running time of the following pseudocode or functions in Big-Oh notation...
Big-O: Describe the worst case running time of the following pseudocode or functions in Big-Oh notation in terms of the variable n. Show your work a) O( ) int m1(int n, int m) { if (n < 10) return n; else if (n < 100) return happy (n - 2, m); else return happy (n/2, m); } ----------------------------- b) O ( ) void m2 (int n) { j = 0; while (j < n) { for (int i = 0;...
Analyze the worst-case, best-case, and average-case number of comparisons of sequential search if exactly three-tenths of...
Analyze the worst-case, best-case, and average-case number of comparisons of sequential search if exactly three-tenths of the time, the element x to search for is not in the list and if x is in the list, it is equally likely to be in any position.
merge sort Determine the best, average, and worst case inputs for merge sort.
merge sort Determine the best, average, and worst case inputs for merge sort.
6. The worst case scenario in the quick sort occurs when the array is partitioned to...
6. The worst case scenario in the quick sort occurs when the array is partitioned to two equal sized subarray every time that a recursive call takes place. True False 7.Suppose that we want to sort an array of n elements, where each element is a string of at most 1000 characters. What is the time requirement for applying radix sort to sort this array? O(n2) O(1000n) O(l000logn) O(nlogn) 8.Suppose we want to sort the following array of integers using...
Perform an experimental analysis to test and compares the relative running times of this method [HINT:...
Perform an experimental analysis to test and compares the relative running times of this method [HINT: use the following inputs size to check each example (1000). You can generate each array using random number generator to fill the array with the pervious input size]. /** Returns the sum of the integers in given array. */ public static int example1(int[] arr) { int n = arr.length, total = 0; for (int j=0; j < n; j++) // loop from 0 to...
What is the best case and worst case performance for a hashtable lookup explain answer very...
What is the best case and worst case performance for a hashtable lookup explain answer very clearly and answer must be explained how hashtables work and how that relates to performance in both the cases.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT