Suppose we are given two n-element sorted sequences A and B that may contain duplicate entries. Describe an O(n)-time method for computing a sequence representing all elements in A or B with no duplicates.
#include <bits/stdc++.h>
using namespace std;
int MergeSortedSeq(int A[], int B[], int m, int n)
{
int i = 0, j = 0;
while (i < m && j < n)
{
if (A[i] < B[j])
cout << A[i++] << " ";
else if (B[j] < A[i])
cout << B[j++] << " ";
else
{
cout << B[j++] << " ";
i++;
}
}
while(i < m)
cout << A[i++] << " ";
while(j < n)
cout << B[j++] << " ";
}
int main()
{
int A[] = {0,1,2,3,6,8};
int B[] = {3,4,5,8,9,11,12};
int m = sizeof(A)/sizeof(A[0]);
int n = sizeof(B)/sizeof(B[0]);
MergeSortedSeq(A, B, m, n);
return 0;
}

Suppose we are given two n-element sorted sequences A and B that may contain duplicate entries....
Suppose we are given two n-element sorted sequences A and B that may contain duplicate entries. Describe an O(n)-time method for computing a sequence representing all elements in A or B with no duplicates.(python)
(b) Suppose you are designing a search aggregator, which for a given query fetches search results from two different search engines and presents an intersection of the two search results. Here is a simplified version of this problem: Given two sorted integer arrays of lengths m and n, return a new array with elements that are present in both input arrays. The input array may contain duplicates, but there should be no duplicates in the output array. For example, if...
9. When we have two sorted lists of numbers in non-descending order, and we need to merge them into one sorted list, we can simply compare the first two elements of the lists, extract the smaller one and attach it to the end of the new list, and repeat until one of the two original lists become empty, then we attach the remaining numbers to the end of the new list and it's done. This takes linear time. Now, try...
Suppose that we are given a sorted array of distinct integers A[1, ......, n] and we want to decide whether there is an index i for which A[i] = i. Describe an efficient divide-and-conquer algorithm that solves this problem and explain the time complexity. 1. Describe the steps of your algorithm in plain English. 2. Write a recurrence equation for the runtime complexity. 3. Solve the equation by the master theorem.
Describe an algorithm that takes as input two sorted lists of length n and m and an integer k and outputs the kst smallest element in their union. You can assume both lists contain integers and all entries are different.
When we have two sorted lists of numbers in non-descending order, and we need to merge them into one sorted list, we can simply compare the first two elements of the lists, extract the smaller one and attach it to the end of the new list, and repeat until one of the two original lists become empty, then we attach the remaining numbers to the end of the new list and it's done. This takes linear time. Now, try to...
I need help with this .java implementation: Implement an algorithm that given two sorted arrays of size m and n creates a sorted array of size (n + m) in O(n + m) time. The script must take as an input a command line argument specifying the name of a .txt file which will contain the arrays to be sorted. Each line in the .txt file will contain two arrays, with elements in arrays separated by commas and the arrays...
4. (10 points) Suppose we are given a sequence S of n elements, each of which is colored red or blue. Assuming S is represented by an array, give a linear-time in-place algorithm for ordering S so that all the blue elements are listed before all the red elements. What is the running time of your method?
Given two arrays A and B of n integers both of which are sorted in ascending order. Write an algorithm to check whether or not A and B have an element in common. Find the worst case number of array element comparisons done by this algorithm as a function of n and its Big-O complexity
do (b) please
2. (15 marks) Consider the abstract datatype SEQ whose objects are sequences of elements and which supports two operations . PREPEND(x, S), which inserts element r at the beginning of the sequence S and . ACCESS(S, i), which returns the ith element in the sequence Suppose that we represent S by a singly linked list. Then PREPEND(, S) takes 1 step and ACCESS(S, i) takes i steps, provided S has at least i elements Suppose that S...