Question
fundamental algorithm

AllLessThan1 (int C A, B) return bool for (i-1 to |AI) for (j-1 to B if (A[1] >=B[j]) return FALSE ; return TRUE; AllLessThan
C. For any particular arrays A, B, let ti(A, B) and t2(A, B) be the running times of the two algo- rithms for inputs A, B. De
AllLessThan1 (int C A, B) return bool for (i-1 to |AI) for (j-1 to B if (A[1] >=B[j]) return FALSE ; return TRUE; AllLessThan2 (int[] A,B) return bool largeAA[1] for (i 2 to |AI) if (A[i] > largeA) largeA A[i]; for (j = 1 to IBD if (largeA >= B[j]) return FALSE; return TRUE;
C. For any particular arrays A, B, let ti(A, B) and t2(A, B) be the running times of the two algo- rithms for inputs A, B. Design an algorithm AllLessThan3 (A, B) that has a running time that is no more than 2 min(h (AB), t2(A,B)) for every input A, B.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

AllLessThan3(int [] A, B) return bool {

      largeA = A[1]

      for(i = 2 to |A|)

if(A[i] > largeA) largeA = A[i];

       smallB = B[1]

       for(i = 2 to |B|)

            if(B[i] < smallB) smallB = B[i];

       if(largeA >= smallB) return FALSE;

       return TRUE;

}

In this algorithm we are finding largest number in A (say largeA) and smallest number in B (say smallB) . The function will return true if and only if all numbers in A are smaller than all numbers in B. So even largest number (largeA) in A should be smaller than smallest number in B (smallB). Else if largeA is greater than or equal to smallB, function will return false.

Add a comment
Know the answer?
Add Answer to:
fundamental algorithm AllLessThan1 (int C A, B) return bool for (i-1 to |AI) for (j-1 to B if (A[1] >=B[j]) ret...
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
  • • bool test(int a, int& b) { bool res = false; if(a > b) { b...

    • bool test(int a, int& b) { bool res = false; if(a > b) { b = a%2; res = true; } return res; } int main() { int x = 45, y = 43; test(x, y); cout << x << " " << y << endl; return 0; } Question: The output of the above code is: ________________ •Write a function that takes an integer as its sole parameter and returns -1, 0 or 1 depending upon whether the...

  • Consider the following algorithm: ocedure Algorithm (b: integer, n: positive integer,i datinct integem) proc answer :", 0 nand 6 while (j print(j, z, b, answer) if jSn then answer:-j return a...

    Consider the following algorithm: ocedure Algorithm (b: integer, n: positive integer,i datinct integem) proc answer :", 0 nand 6 while (j print(j, z, b, answer) if jSn then answer:-j return answer (8 points] Assume that this algorithm receives as input the numbers b-17 andn9nd the corresponding sequence or iaie i 2 3 4 516 7 8 corresponding sequence of integers 19 Fill out the table below: i 는, ↓answer (b) [I point] Assume that the algorithm receives the same input...

  • Consider the following algorithm. ALGORITHM Enigma(A[0.n - 1]) //Input: An array A[0.n - 1] of integer...

    Consider the following algorithm. ALGORITHM Enigma(A[0.n - 1]) //Input: An array A[0.n - 1] of integer numbers for i leftarrow† 0 to n - 2 do for j leftarrow†† i +1 to n - 1 do if A[i] = = A[j] return false return true a) What does this algorithm do? b) Compute the running time of this algorithm.

  • This is an assignment for my algorithm class which I have written the code partially and...

    This is an assignment for my algorithm class which I have written the code partially and only need to complete it by adding a time function that calculates the average running time. We could use any programming language we want so I am using C++. I am including the instruction and my partial code below. Thank you! Implement linearSearch(a,key) and binarySearch( a,key)functions. Part A.In this part we will calculate theaverage-case running time of each function.1.Request the user to enter a...

  • Consider the following algorithms int add.them (int n, int AI) index iふk; j=0; for (i =...

    Consider the following algorithms int add.them (int n, int AI) index iふk; j=0; for (i = 1; n; i++) jsjtA[i]; for (i = 1; n; i++) return j+ int anysqual (int n, int A) index i,j,k.m; for ( iSn i++) for G-1:jSnj++) for (k = 1; k n: k++) for (m t= 1; m n: m++) return 1 return 0 Note: The array parameter A[ I[1 in any equal is an n x n two-dimensional array. For example when n...

  • Can someone help with this C++ code. I am trying to compile and I keep running...

    Can someone help with this C++ code. I am trying to compile and I keep running into these 4 errors. #include <iostream> #include <cassert> #include <string> using namespace std; typedef int fsm_state; typedef char fsm_input; bool is_final_state(fsm_state state) { return (state == 3) ? true : false; } fsm_state get_start_state(void) { return 0; } fsm_state move(fsm_state state, fsm_input input) { // our alphabet includes only 'a' and 'b' if (input != 'a' && input != 'b') assert(0); switch (state) {...

  • In C++ #include<iostream> using namespace std; //Implement the function below. bool is_fibonacci_array(int*,int); //Param 1: pointer to...

    In C++ #include<iostream> using namespace std; //Implement the function below. bool is_fibonacci_array(int*,int); //Param 1: pointer to the beginning of an array of integers //Param 2: size of that array //Returns: true, is every element in the input array is a Fibonacci number //(the order of the numbers in the array need not be ordered //as per the Fibonacci sequence) //false, otherwise //A Fibonacci sequence is generated as follows. //The first two numbers in the sequence are 0 and 1. //The...

  • The second picture that I attached is the input and output. I already did the code...

    The second picture that I attached is the input and output. I already did the code but I also have to add the partition number assigned to the job (if the job was allocated). Can you please do that for me? I copied and pasted my code below. #include <iostream> #include <string.h> #include <stdio.h> using std::cout; using std::cin; using std::endl; unsigned int memorySize; // Function prototypes unsigned int FirstFit(struct Partition *, int, struct Job *, int); unsigned int BestFit(struct Partition...

  • QUESTION 1 What is the output of the following code snippet? int main() { bool attendance...

    QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...

  • I need a program in c++ the same as below code but I want it to...

    I need a program in c++ the same as below code but I want it to prompt the user to enter the number of elements after that I want it to ask the user to enter the array elements #include<algorithm> #include<stdio.h> #include<string.h> #include<iostream> using namespace std; int a[50]={2,5,4,3}; bool x[100]; int N=4;//number of elements    int k=10;//target sum int sum;//current target sum int cmp(const void *a,const void *b) { return *(int *)b-*(int *)a; } void backtrace(int n) { if(sum>k) return...

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
ADVERTISEMENT