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.
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.
Consider the following pseudo-code: // Assume i, j, k are integers for i = 1 to...
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 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 } }
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 <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()...
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 (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 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...
Design an algorithm for the following description. Solution can be done in pseudo-code or steps of the algorithm. Describe and analyze an algorithm that takes an unsorted array A of n integers (in an unbounded range) and an integer k, and divides A into k equal-sized groups, such that the integers in the first group are lower than the integers in the second group, and the integers in the second group are lower than the integers in the third group,...
consider this segment of an algorithm: for i := 1 ton n for j:=1 to n top:=ij+j+10 a. find a function f(n) that counts the number of multiplication and additions performed in this segment. b. Give a big O estimate for the number of additions and multiplications used in the segment
pointsConsider this code def f (n,p): for i in range(n): for j in range(i,p): for k in range(n*p): dosomething(i,j,k) + dosomething(j,i,k) Write down the number of calls to dosomething T(n, p) in summation notation