Insertion Sort
Which are true of Insertion Sort (traditional implementation, without optimizations)?
Multiple answers:You can select more than one option.
Please, include the explanation with the answer.
A) It uses Θ(n^2) comparisons in the worst case
B) It uses Θ(n^2) comparisons in the average case
C) It uses Θ(n^2) comparisons in the best case
D) It uses Θ(n^2) movements of elements in the worst case
E) It uses Θ(n^2) movements of elements in the average case
F) It uses Θ(n^2) movements of elements in the best case
Two correct options should be: A and C
Reason: Counting comparisons or swaps(movement of elements) yields similar results. Each time through the inner for loop yields both a comparison and a swap, except the last (i.e., the comparison that fails the inner for loop's test), which has no swap. Thus, the number of swaps for the entire sort operation is n−1 less than the number of comparisons. This is 0 in the best case, and O(n^2) in the average and worst cases.
For reference Insertion sort algorithm goes like:
INSERTION-SORT(A)
for i = 1 to n //outer loop run n times in best case
key = A [i]
j = i – 1
while j > = 0 and A[j] > key //inner loop for comparison & swapping
A[j+1] = A[j]
j = j – 1
End while
A[j+1] = key
End for
NOTE: For any further queries you can ask over comments.
Insertion Sort Which are true of Insertion Sort (traditional implementation, without optimizations)? Multiple answers:You can select...
Which are true of Selection Sort? please explain Multiple answers:You can select more than one option A) It uses Θ(n^2) comparisons in the worst case B) It uses Θ(n^2) comparisons in the average case C) It uses Θ(n^2) comparisons in the best case D) It uses Θ(n^2) swaps in the worst case E) It uses Θ(n^2) swaps in the average case F) It uses Θ(n^2) swaps in the best case
1. Randomized Binary Search Which are true of the randomized Binary Search algorithm? Multiple answers:You can select more than one option A) It uses a Variable-Size Decrease-and-Conquer design technique B) Its average case time complexity is Θ(log n) C) Its worst case time complexity is Θ(n) D) It can be implemented iteratively or recursively E) None of the above 2. Randomized Binary Search: Example Assume you have an array, indexed from 0 to 9, with the numbers 1 4 9...
Which of the following are always true of the LPS function? explain Multiple answers:You can select more than one option A LPS[i][i] = 1 B LPS[i][i+1] = 2 C LPS[i][j]) = 2 + LPS[i+1][j-1] for j > i D LPS[i][j]) = 0 for i > j E None of the above
Inal Examination 17. Which of the sorting algorithms listed below has the time fastest best case run (a) Heap sort (b) Merge sort (c) Quick sort (d) Insertion sort 18. Which statement below is false: (a) Quick uick sort and merge sort are divide and conquer algorithte (b) Counting sort is a linear time sorting algorithm. (e) Insertion sort and quicksort have similar best case (d) Generic minimum spanning tree algorithm is 19. Counting sort and radix sort are linked...
Data Structures, C++, SORT running time. Would help is small
explanation is included.
Problem 1. Select the worst-case running time of each function. bool search (int x, int* A, int n) if (linear search(x, A, n)) return true; insertion_sort(A, n); return binary_search (x, A, n); bool search_n_sort (int* A, int n) for (int x = 1; x <= n; ++x) if (linear_search(x, A, n)) ae()og(n) n) return true; insertion_sort(A, n); return false; bool sort_n_search (int* A, int n) insertion_sort(A, n);...
4.1 4.1 Insertion Sort 4. Design 137 the a algorithm for generating the power set of a set of n elements. (The power set of a set s is the set of all the subsets of S,including empty set and S itself.) 5. Consider the following algorithm to check connectivity of graph defined by adjacency a ALGORITHM Connected (A 0...n-1, 0..n ij) Input: Adjacency matrix Alo..n 1,0. n -1) of an undirected graph G //Output: 1 (true) if G is...
Please help me to solve the problem with java language! An implementation of the Merge Sort algorithm. Modify the algorithm so that it splits the list into 3 sublists (instead of two). Each sublist should contain about n/3 items. The algorithm should sort each sublist recursively and merge the three sorted sublists. The traditional merge sort algorithm has an average and worst-case performance of O(n log2 n). What is the performance of the 3-way Merge Sort algorithm? Merge Sort algorithm...
2. Short programming assignment. Implement a bottom-up mergesort that first sorts blocks of M elements using insertion sort. Test your program with large sets of random data and determine what value of M works best. 3. The following refer to linked list mergesort Explain why mergesort is more suitable for linked lists than other sorting methods. a. Explain why mergesort is more suitable for linked lists than other b. Consider a file that is “mostly sorted.” Explain how the principles...
Homework. Answered Which is not true of the Transmission Control Protocol (TCP)? Multiple answers: You can select more than one option O A it supports full duplex communication o B it has graceful connection shutdown O с its connections are logical D it uses the message paradigm E it is an end-to-end protocol O F None of the above Answered Change your responses to resubmit Match the NIST Framework Category with the Task Premise Response Drag and drop to match...
1. Fractional Knapsack Problem Algorithm Which best describes the tightest range of the number of items with only fractional inclusion (i.e. not entirely included or excluded) in the knapsack? (Let n denote the number of items for possible inclusion.) A) At least 0 items and at most n items B) At least 1 items and at most n items C) Exactly n items D) At least 0 items and at most n-1 items E) At least 1 items and at...