Determine AA on the basis of given
Add statements to AA which initializes the conditions for while loop using the 3 given conditions.
1. 1 lo and hi n
Initially lo will at the start index and hi will be at the end index.
=> lo <- 1, hi <- n
2. If v occurs in A[1...n] then v occurs in A[lo...hi]
This condition also determines the above inferred information for AA, that the range of index for A is lo to hi.
And initiallly values for lo is 1 and for hi is n.
3. If the boolean variable found is true then and A[q] = v
If found becomes true, then v is found in A array. Therefore, initially initialize found as false, so that as soon as v is encountered in A, found becomes true.
=> found <- false
Hence putting all initial conditions together,
AA = lo <- 1, hi <- n, found <- false
Question 2. (24 points. Recall that in Assignment 1, we developed recursive algorithms for implementing the...
PROBLEM 1 (24 points): For each of the recursive functions below and on the next page, give a correct recurrence relation expressing its runtime and then a tight runtime bound for the recurrence relation. Functions that take parameters lo and hi: n=hi-lo+1 RECURRENCE RELATION: int foo(int a[], int lo, int hi) { int x, i, j, m; X = 0; if(lo==hi) return a[10]; for(i=lo; i<=hi; i++) { for(j=i+1; j<=hi; j++) { if(a[i] % 2) x += a[i]; else x -=...
no other details are given, its asking for the invariant programming language: Java Question 3. [15 marks in total Consider the following code fragment with missing statements at ????. Assume that A is a nonempty array of integers and has length N. Assume that it has already been initialised. Refer to this code in parts (a-e) below. A [0] int count 1; int i- 1 while (i< NI1 count> N/2 ) if (xAi]) count++ int x else ???? i+ if...
may i ask for help with this c++ problem? this is the code i have for assignment 4 question 2: #include<iostream> #include<string> #include<sstream> #include<stack> using namespace std; int main() { string inputStr; stack <int> numberStack; cout<<"Enter your expression::"; getline(cin,inputStr); int len=inputStr.length(); stringstream inputStream(inputStr); string word; int val,num1,num2; while (inputStream >> word) { //cout << word << endl; if(word[0] != '+'&& word[0] != '-' && word[0] != '*') { val=stoi(word); numberStack.push(val); // cout<<"Val:"<<val<<endl; } else if(word[0]=='+') { num1=numberStack.top(); numberStack.pop(); num2=numberStack.top(); numberStack.pop();...
I only need help with question 5! Thank you! Question 4 4 pts Consider this variant of the linear search algorithm which attempts to speed up the search by reducing the number of iterations of the for loop by approximately one-half. During each pass of the loop, the algorithm performs two comparisons rather than one comparison as in linear Search(). The two comparisons compare the elements at indices i and pList size() - 1-i to pKey for equality. If a...
Meet is an operation between zero-one matrices and uses Boolean products (C. Join is an operation between zero-one matrices and uses Boolean products d. Join is an operation between zero-one matrices and uses conjunctions 29. Given set S (-2, -1, 0, 1, 2), R is a relation on S. i. R ( (x, y)| x-y 1} Write R as a set of ordered pairs. (Use roster method to write R as a set of tuples) 3pts ill. and matrix representation...
Question 1 Not yet answered Marked out of 1.00 Not flaggedFlag question Question text The statements inside of a Python loop are known as the ____ of the loop. Select one: a. body b. expression c. counter d. block Question 2 Not yet answered Marked out of 1.00 Not flaggedFlag question Question text The Python 3 program below prints the number 3. s = "Python3" print(s[len(s)]) Select one: True False Question 3 Not yet answered Marked out of 1.00 Not...
True False Question 2 (3 points) Given a singly linked list with more than two nodes, to remove the second node from a linked list with only head reference, assume curr - head, next, you do Set curr.next to head.next Oset head. next to curr.next Set head, next to curr Oset head to curr.next TL th Question 3 (3 points) Given the following singly linked list (a list with four nodes), what will be the value stored at the last...
Hi need help for this Question Surface Integral Question: Given Formula Question 2 'Eand G is the surface passing through the points D.E Figure 1 shows 2 curved surfaces. S is the surface passing through the points A, B, Cand D. The equations of both su given in the figure. Determine the unit surface normal for S2 at the poi0,.s a volume directly above S2 and below S 0.5,0.5) and the D1,0,2) S2:z (1-x)(1-y) Figure 1 Equations for curves and...
Question 1 (Quadrature) [50 pts I. Recall the formula for a (composite) trapezoidal rule T, (u) for 1 = u(a)dr which requires n function evaluations at equidistant quadrature points and where the first and the last quadrature points coincide with the integration bounds a and b, respectively. 10pts 2. For a given v(r) with r E [0,1] do a variable transformation g() af + β such that g(-1)-0 and g(1)-1. Use this to transform the integral に1, u(z)dz to an...
Hi, we recently had an assignment and I ended up skipping this question because I didn't understand the question nor how to even start it. Obviously for Matlab! Coding is not my strong point so this was a stitch up. The data we were meant to use is below! For (a) function [n,alpha]=bisect(a,b,eps) alpha=(a+b)/2 n=1; fval=f(alpha); while (b-alpha> eps) & (fval ~= 0) fa=f(a); if fa*fval< 0 b=alpha; else a=alpha; end alpha=(a+b)/2 n=n+1; fval=f(alpha); end end Sample f.m function y=f(w)...