• recategorized by
734 views
2 2 votes

Consider the following function $\textsf{count},$ that takes as input $a,$ an array of integers, and $\textsf{N}$, the size of the array.

int count(int a[], int N) {
    int i, j, count_FN; 
    count_FN = 0;
    for (i=1 ; i<N ; i++) { 
        j=i-1 ;
            while (a[j]>a[i]) {
                count_FN++; 
                j--; 
            } 
        }
    return count_FN;
}

Further, let $\textsf{count_IS}$ be the number of comparisons made by the insertion sort algorithm on the array $a$.

Which of the following statements is TRUE for some constant $c?$ 

  1. For all $\textsf{N} \geq c$, there exists an array of size $\textsf{N}$ for which $\textsf{count_IS} \geq \textsf{N}^2 / c$, while $\textsf{count_FN} \leq c \textsf{N}$
  2. For all $\textsf{N} \geq c$, there exists an array of size $\textsf{N}$ for which $\textsf{count_FN} \geq \textsf{N}^2 / c$, while $\textsf{count_IS}\leq c \textsf{N}$
  3. For all $\textsf{N} \geq c$, for all arrays of size $\textsf{N, count_FN} \leq \textsf{count_IS} \leq c \times \textsf{count_FN}$
  4. For all $\textsf{N} \geq c$, for all arrays of size $\textsf{N, count_FN} \geq \textsf{N}^2 / c$
  5. None of the above

Please log in or register to answer this question.

Answer:
Position:
Show:

Related questions

2 2 votes
1 1 answer
1.7k
1.7k views
admin asked Sep 1, 2022
1,718 views
Consider the problem of sorting $n$ single digit integers (base $10$). This problem can be solved in time$O(n \log n)$ but not $O(n \log \log n)$$O(n \log \log n)$ but no...
3 3 votes
2 2 answers
1.2k
1.2k views
admin asked Sep 1, 2022
1,182 views
Consider the following algorithm for computing the factorial of a positive integer $n$, specified in binary:prod ← 1 for i from 1 to n prod ← prod × i output prodAssume t...
2 2 votes
0 0 answers
868
868 views
admin asked Sep 1, 2022
868 views
Consider the assertions$\text{(A1)}$ Given a directed graph $G$ with positive weights on the edges, two special vertices $s$ and $t$, and an integer $k$ - it is $\text{NP...
1 1 vote
0 0 answers
650
650 views
admin asked Sep 1, 2022
650 views
Consider a directed graph $G=(V, E)$, where each edge $e \in E$ has a positive edge weight $c_e$. Determine the appropriate choices for the blanks below so that the value...