Task 1: Consider the following pseudocode function that describes the R0 Search algorithm:
function R0(key,A1,A2,N)
for 0 <= i < ceiling(N/2)
if(A1[i] == key): return 2*i
for 0 <= i < floor(N/2) if(A2[i] == key):
return 2*i + 1
return -1
In this pseudocode floor(x) and ceiling(x) are the mathematical functions that, respectively, give the largest integer smaller than or equal to x and give the smallest integer larger than or equal to x. You may assume that calculating the floor(x) and ceiling(x) takes constant time. For this algorithm address the following:
-
Identify, and describe very briefly in words, the best-case inputs and the worst-case inputs. Recall that there are four inputs to R0.
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps
- A university assigns student IDs of the form 1, 2, 3, ... such that if n students are currently enrolled, then the next student to enroll will receive and ID of n + 1. Consider the following algorithm that accomplishes this. // Global variable storing number of students currently enrolled current_student_count = 0 // Function that reads the above global variable, calculates new ID, and increments the global count assign_new_id(): count = current_student_count new_id = count + 1 current_student_count = count + 1 return new_id (a) If two different threads run the above code in parallel to enroll two different students, it is possible for the two students to receive the same ID, and for the current_student_count to have a wrong value. Explain how this is possible. (b) Modify the code above so that the problem in (a) does not happen.arrow_forward1 Write a Racket function (is-sorted x) where x is a list of numbers. Function returns true (#t) if numbers are in ascending order, false (#f) if not. Examples > (is-sorted (1 2 34 5)) #t > (is-sorted (2 1 2 3 4)) #f Algorithm If x is one element return #t Else Evaluate 1" element of x < 2n° element of x Evaluate function recursively with argument (cdr x) Value is the AND of the two expressionsarrow_forwardmy_fib 1, TRUE, FALSE) } c) Not allowed to use or other multiplication operators for this one. my_multiply <- function(x, n) { if (length (n) != 1 && is.na(n) || !is.numeric(x) || n %% 1 != 0) { stop ("n must be a whole number and x must be a numeric vector") } else { } while (n = 0) { out <-out + x n <- n - 1 }arrow_forward
- PageRank algorithm for page ranks Run the following algorithm manually and show the steps of computation with results.arrow_forwardIn computing gcd(125, 332) using Euclid's GCD algorithm, the pair (¿[0], k[0]) = (125,332) is replaced by the pair (j[1], k[1]) after the first iteration. Enter your answer for (j[1], k[1]) in the box below as a comma-separated list. For example, if your answer is (1, 2), then enter 1, 2 (without parenthesis). (j[1], k[1]) = ( Next, finish the algorithm to determine gcd(125, 332). gcd(125, 332) =arrow_forward