Question

Consider the following pseudo-code: // Assume i, j, k are integers for i = 1 to...

Consider the following pseudo-code:

// Assume i, j, k are integers

for i = 1 to n do

for j = n-i+1 to n {

k = 1;

while (k*k <= j)

{ perform <op>;

k = k + 1; } }

Find an expression for f(n), the number of times is performed. Find g(n) so that f(n) is Θ(g(n)). Prove your answer.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
First loop is running for n times.
Second loop is running for (i-1) times.
Max value of i is n.
So, Second loop runs max of n times.
Third loop is running for sqrt(n) times.

Add a comment
Know the answer?
Add Answer to:
Consider the following pseudo-code: // Assume i, j, k are integers for i = 1 to...
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
  • What is the Cyclomatic Complexity for the following pseudo-code fragment? i=1; n=10; while (i<n) do             ...

    What is the Cyclomatic Complexity for the following pseudo-code fragment? i=1; n=10; while (i<n) do              j=i+1;     while (j<n) do         if A[i]<A[j] then             swap(A[i], A[j]);         end if         end while;         i=i+1; end while; CC = E – N + 2P E = number of edges (transfers in control) N = number of nodes P = number of disconnected parts of the flow graph (e.g. a calling program and a subroutine)

  • Translate the following code into MIPS code.         j=0; k=0; for (i = 1 ; i...

    Translate the following code into MIPS code.         j=0; k=0; for (i = 1 ; i < 50 ; i = i + 2) { K=k+1;            j = (i + j);             B[k] = j; } Assume the compiler associates the variables i, j, and k to the registers $t0, $t1, and $t2 respectively. Also, assume B is an array of integers and its address is stored at register $s1. PLEASE DO NOT COPY DOWN ANOTHER SOLUTION

  • In Big-Θ notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running...

    In Big-Θ notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running time as a function of the input size (here, n) for(int i=n-1; i >=0; i--){ for(int k=0; k < i*n; k++){ // do something that takes O(1) time } }

  • Individually or in pairs, please write pseudo-code to solve the following problems and state which Big-θ...

    Individually or in pairs, please write pseudo-code to solve the following problems and state which Big-θ category the algorithm belongs to (you don’t have to prove it). An array, A[0…n-2], contains n-1 integers from 0 to n-1 in increasing order – one integer is missing in the range. Design the most efficient algorithm you can to find the missing integer. You have an unsorted sequence of college applications in an array, A[0…n-1]. Each application A contains a name A.name, an...

  • 4. (a) Translate the following pseudo-code into MIPS assembly code. Assume that A, B, C are...

    4. (a) Translate the following pseudo-code into MIPS assembly code. Assume that A, B, C are arrays of size N elements, indexed 0..N-1 I=I; WHILE(I<N AND A[I]<B[I]) C[I] = A[I] + B[I-1]

  • Consider the following C codes to compute the gcd of two integers. /// code 1 #include...

    Consider the following C codes to compute the gcd of two integers. /// code 1 #include <stdio.h> int gcd(int a, int b) {     while (a != b) {         if (a > b) a = a - b;         else b = b - a;     }     return a; } /// code 2 #include <stdio.h> int getint() {     int i;     scanf("%d", &i);     return i; } void putint(int i) {     printf("%d\n", i); } int main()...

  • 1. convert the following number of to minheap using min heap down. for (k=n/2;k>0;k--) minheapdn; array:...

    1. convert the following number of to minheap using min heap down. for (k=n/2;k>0;k--) minheapdn; array: 35,7,67,21,12,32,18.24.20.27 2. consider the code assume n is even for(x=10,j=1;j<=n;j++) x=x+j exactly how many times the condition in statement 1 will execute? 3. consider the code below for(j=1,j<=10;j+=2) outer loop for(k=1; k<=20;k+=4) inner loop p=p+j+k compute f(n) number of primitive operations of the code. please explain every answer.

  • 6. Consider the following basic problem. You're given an array A consisting of n integers A[1],...

    6. Consider the following basic problem. You're given an array A consisting of n integers A[1], A[2], , Aln]. You'd like to output a two-dimensional n-by-n array B in which B[i, j] (for i <j) contains the sum of array entries Ali] through Aj]-that is, the sum A[i] Ai 1]+ .. +Alj]. (The value of array entry B[i. Λ is left unspecified whenever i >j, so it doesn't matter what is output for these values.) Here's a simple algorithm to...

  • show work pls QUESTION 7 Consider the following list of integers indexed from 1 to 8...

    show work pls QUESTION 7 Consider the following list of integers indexed from 1 to 8 (i.e intList[1]-35, intList[8]-38) intList0 (35, 12, 27, 5,18, 45, 16, 38) Consider the following pseudo code version of Bubble Sort (n-8) for j 1 to n-1 do for i-1 to n-1 do f intListl> intListli+11 swap (intListll, intlistli+11) What is the position (index) of element 35 afte the first pass? o a 5 O b.6 none of the above ⓔd.2

  • 1. (15 pts) For the following C statement, what is the corresponding MIPS assembly code? Assume...

    1. (15 pts) For the following C statement, what is the corresponding MIPS assembly code? Assume f, g, h correspond to $80, $s1, and $s2, respectively. f=g+(h-5) 2. (15 pts) For the following pseudo-MIPS assembly instructions, what is the corresponding C code? add f, g, h add f,i, f 3. (30 pts) Provide the instruction type, assembly language instruction, and binary representation of the instruction described by the following MIPS fields: a. op = 0, rs = 18, rt=9, rd...

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