Given two sorted lists, L1 and L2, write a procedure to computeL1 ∪ L2 using only the basic list operations.
function merge (list1, list2)
{
arr = create new list of size (list1.length + list2.length)
i = 0;
j = 0;
index = 0;
// loop until either of the list is completely
// iterated
while i < list1.length && j < list2.length
{
// if the current element of list1 is smaller
if list1[i] <= list2[j]
{
arr[index++] = list1[i]
i++
}
// if the current element of list2 is smaller
else
{
arr[index++] = list2[j]
j++
}
}
// traverse through the left over list1
while i < list1.length
{
arr[index++] = list1[i]
i++
}
// traverse through the left over list2
while( j < list2.length )
{
arr[index++] = list2[j]
j++
}
return arr
}
Given two sorted lists, L1 and L2, write a procedure to computeL1 ∪ L2 using only...
Given two sorted lists, L1 and L2, write a C++ function to compute L1 ∪ L2 using only the basic list operations.
You have two sorted lists of integers, L1 and L2. You know the lengths of each list, L1 has length N1 and L2 has length N2. (a) Design an efficient algorithm (only pseudocode) to output a sorted list L1 ∩ L2 (the intersection of L1 and L2). (b) If you know that N2 > N1. What is the running time complexity of your algorithm? Justify. Important Note: For this problem, you don’t need to submit any implementation in Java. Only...
c++ Write pseudocode that merges two sorted lists into a new third sorted list by using only ADT sorted list operations.
Question 3 (13] (a) Write a procedure filter (L,PredName, L1,L2) that accepts a list L and returns two lists Li and L2, where Li contains all elements in L for which PredName (x) fails, and L2 contains all elements in L for which PredName (x) succeeds. The predicate PredName/1 should be defined when calling the procedure filter. For example: let test be defined as test(N).- N > 0. 7- filter((-6,7,-1,0),test,L1,L2). L1 - (-6.-1) L2 - [7, 0] NB Use the...
PYTHON 3. Write code using zip and filter so that these lists (l1 and l2) are combined into one big list and assigned to the variable opposites if they are both longer than 3 characters each. l1 = ['left', 'up', 'front'] l2 = ['right', 'down', 'back']
1)Given two lists L1 and L2, create a new list L3 consisting of the first element of L1 and the last element of L2. For example, if L1=[1,2,3] and L2=["a","b","c"], L3 should be [1,"c"] 2)given a string s, create a new string odd_letters that contains only the odd letters of s (two ways to solve this problem are to use slicing, or a while or for loop), i.e. starting at the first letter or the zeroth index: if s="banana", odd_letters...
Data Structure C++ Write pseudocode that merges two sorted lists into a new third sorted list by using only ADT sorted list operations.
Problem #1: (15 points) You have two sorted lists of integers, L, and L2. You know the lengths of each list, L1 has length N, and L2 has length N2 (a) Design an efficient algorithm (only pseudocode) to output a sorted list L L2 (the intersection of L and L2). (b) If you know that N2> Ni. What is the running time complexity of your algorithm? Justify Important Note For this problem, you don't need to submit any implementation in...
L1 and L2 are lists. L3 = L1 + L2 This is an example of mutation of L is this true or false?
PYTHON QUESTION
2. Write a function called first_day_greater that takes two lists, L1 and L2 , representing the daily measured weights of rat 1 and rat 2, respectively, and returns the index of the first day for which the weight for the fist rat is greater than the weight of the second rat.If there are no such days then the function should return -1. You may NOT assume that L1 and L2 are the same length. Use the following to...