Question

(10 pts.) Count the worst-case number of array element comparisons (A[j] < A[j-1]) made by InsertionSort...

  1. (10 pts.) Count the worst-case number of array element comparisons (A[j] < A[j-1]) made by InsertionSort on arrays of size n:
                    void InsertionSort(int A[], int n)
                    {
                            for (int i = 1; i < n; ++i)
                                    for (int j = i; j > 0 && A[j] < A[j-1]; --j)
                                            swap(A[j], A[j-1]);
                    }
                    
    Do the same for the number of swap's.

2. Which function grows faster: 2^((lg?))2 or ?^(2019)? Justify your answer.

3. Use "name and conquer" to give a derivation of the identity:

∑?=0 b^? = (b^(?+1) −1) / (b−1).

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
(10 pts.) Count the worst-case number of array element comparisons (A[j] < A[j-1]) made by InsertionSort...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello this is my java sorting algorithm program i need all of my errors corrected so...

    Hello this is my java sorting algorithm program i need all of my errors corrected so I can run it. thank you!! import java.util.Scanner;    public class SortingAlogs { public static void main(String[]args){ int array [] = {9,11,15,34,1}; Scanner KB = new Scanner(System.in); int ch; while (true) { System.out.println("1 Bubble sort\n2 Insertion sort\n3 Selection sort\n"); ch = KB.nextInt(); if (ch==1)    bubbleSort(array); if (ch==2)    insertion(array); if (ch==3)    Selection(array); if (ch==4) break;    print(array);    System.out.println(); }    }...

  • How can i make a counter for the number of exchanges made in the linear algorithm?? The binary counter works but the lin...

    How can i make a counter for the number of exchanges made in the linear algorithm?? The binary counter works but the linear doesn't. Here's my code. #include <iostream> using namespace std; void selectionSort(int[], int, int& ); void showSelection(int[], int); void sortArray(int[], int, int&); void showArray(const int[], int); int main() {    int values[25] = { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24...

  • Show your work Count the number of operations and the big-O time complexity in the worst-case...

    Show your work Count the number of operations and the big-O time complexity in the worst-case and best-case for the following code int small for ( i n t i = 0 ; i < n ; i ++) { i f ( a [ i ] < a [ 0 ] ) { small = a [ i ] ; } } Show Work Calculate the Big-O time complexity for the following code and explain your answer by showing...

  • Data Structure Question. I need help solving this question. I know quicksort has the worst case...

    Data Structure Question. I need help solving this question. I know quicksort has the worst case of O(n^2) if it is implemented choosing the pivot as the first element. A[1] is the first element here. Please justify why the number of comparison is the smallest possible number assuming the array ensures that. And give an example of that type of an array. Thank you thumbs up will be given for correct and justified answer! qs(A): if A has at most...

  • Example 1.9: 1.23 "The median of an ordered set is an element such that the number...

    Example 1.9: 1.23 "The median of an ordered set is an element such that the number of elements less than the median is within one of the number that are greater, assuming no ties. a. Write an algorithm to find the median of three distinct integers a, b, and c. b. Describe D. the set of inputs for your algorithm. in light of the discussion in Sec- tion 1.4.3 following Example 1.9. c. How many comparisons does your algorithm do...

  • 4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up t...

    4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up to n, anda number num which we wish to insert into A, in the proper sorted position. The function Search finds the minimum index i such that num should be inserted into Ali]. It searches the array sequentially until it finds the location i. Another function MakeRoom moves A[i], .., AIn] to Ali+1]...AIn+1] same sort...

  • I'm trying to code a C program so it sorts an array of integer numbers of...

    I'm trying to code a C program so it sorts an array of integer numbers of size n in ascending order. My code is written below but its not working properly, its giving me errors, I think my sort and swap functions aren't done right maybe, please help and fix. It says "undefined reference to "SelectionSort" as an error. But the question asks to not change the PrintArray and Main function. #include <stdio.h> void PrintArray(int size, int array[]) { for...

  • QUESTION 5 What is the worst-case complexity of line 10 of function bar? A. O(1) B....

    QUESTION 5 What is the worst-case complexity of line 10 of function bar? A. O(1) B. O(N) C. O(i) D. O(log N) E. O(sqrt N) F. O(A[i]) G. O(N sqrt N) H. O(N log N) I. O(N^2) J. O(i^2) K. None of the above QUESTION 6 What is the worst-case complexity of lines 8-11 of function bar? A. O(1) B. O(N) C. O(i) D. O(log N) E. O(sqrt N) F. O(A[i]) G. O(N sqrt N) H. O(N log N) I....

  • 1. (10 pts total) For parts (1a) and (1b), justify your answers in terms of deterministic...

    1. (10 pts total) For parts (1a) and (1b), justify your answers in terms of deterministic QuickSort, and for part (1c), refer to Randomized QuickSort. In both cases, refer to the versions of the algorithms given in the lecture notes for Week 3. (a) (3 points) What is the asymptotic running time of QuickSort when every element of the input A is identical, i.e., for 1 ≤ i,j ≤ n, A[i] = A[j]? Prove your answer is correct. (b) (3...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT