Question

In: Computer Science

Problem 1: You have two sorted lists of integers, L1 and L2. You know the lengths...

Problem 1:

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.

Design a linear running time complexity algorithm (ONLY PSEUDOCODE) to output a sorted list L1 ∧ L2 (the intersection of L1 and L2).

Important Notes:

For this problem, you don’t need to submit any implementation in Java. Only the pseudocode of your algorithm is required.

Pseudocode is a simple way of writing programming code in English. It uses short phrases to write code for programs before you actually create it in a specific language.

• Example of pseudocode:

Set total to zero
Set grade counter to one
While grade counter is less than or equal to ten

Input the next grade

Add the grade into the total
Set the class average to the total divided by ten

Print the class average.

Please make sure answer is given in pseudocode

Solutions

Expert Solution

Pseudocode

Set ordered list L2 with L2 elements                //List2 L2
set i=0                                             //Set variables for looping
set j=0
set k=0
Declare a list L3                                   //List for output
while i<N1 and j<N2                                 //Loop until end of lists
   if L1[i]<L2[j]                                   //Check greater
      i=i+1
   Else If L1[i]>L2[j]                              //Check lesser
       j=j+1
   Else                                             //Check equal
      L3[k]=L2[j]                                   //Add element into output list
      i=i+1
      j=j+1
      k=k+1
   End If
End while


Related Solutions

Given two sorted lists L1 and L2, write a procedure to compute L1∪L2 using only the...
Given two sorted lists L1 and L2, write a procedure to compute L1∪L2 using only the basic list operations. Pseudo-code is acceptable.
Given two sorted lists, L1 and L2, write an efficient C++ code to compute L1 ∩...
Given two sorted lists, L1 and L2, write an efficient C++ code to compute L1 ∩ L2 using only the basic STL list operations. What is the running time of your algorithm?
The intersection of two lists L1 and L2, L1 ∩ L2, is defined as the list...
The intersection of two lists L1 and L2, L1 ∩ L2, is defined as the list containing elements in both L1 and L2 only. Given two sorted lists L1 and L2, write a function, called intersection, to compute L1 ∩ L2 using only the basic list operations. The intersection function is defined as follows template list intersection( const list & L1, const list & L2); C++
1) Equations for two lines L1 and L2 are given. Find the angle between L1 and...
1) Equations for two lines L1 and L2 are given. Find the angle between L1 and L2. L1: ? = 7 + 2?, ? = 8 − 4?, ? = −9 + ? L2: ? = −8 − ?, ? = 3 − 3?, ? = 4 + 3? 2) Find polar form of complex number z : ?) ? = 4√3 − 4? ?) ? = 2√3 − 2i
1. Write a Racket function (set-equal? L1 L2) that tests whether L1 and L2 are equal....
1. Write a Racket function (set-equal? L1 L2) that tests whether L1 and L2 are equal. Two sets are equal if they contain exactly the same members, ignoring ordering (or in other words, two sets are equal if they are a subset of each other). For example (set-equal? '(1 (2 3)) '((3 2) 1)) ---> #t (set-equal? '(1 2 3) '((3 2)1)) ---> #f (set-equal? '(1 2 3) '((1 2 3))) ---> #f 2. Two common operations on sets are...
how do i construct a scatterplot if L1 lists negative values and L2 has values such...
how do i construct a scatterplot if L1 lists negative values and L2 has values such as 0.00339156, 0.00326318, 0.00313725 ? Do i enter the L2 values as exponents??
Python question Write a function int(lofi, alofi) that consumes two sorted lists of distinct integers lofi...
Python question Write a function int(lofi, alofi) that consumes two sorted lists of distinct integers lofi and alofi, and returns a sorted list that contains only elements common to both lists. You must obey the following restrictions: No recursion or abstract list functions, intersect must run in O(n) where n is the combined length of the two parameters. sort function is not allowed as well as list comprehensions math is the only library that can be imported Example: int([4, 13,...
For the Poincare plane, find two lines L1 and L2 and a point P off each...
For the Poincare plane, find two lines L1 and L2 and a point P off each such that through P there are exactly two lines parallel to both L1 and L2.
ABC ltd is a circuit board producer and produces two products, L1 & L2. The company...
ABC ltd is a circuit board producer and produces two products, L1 & L2. The company currently uses traditional costing system for making business decisions. However, recently the company is considering a move towards the Activity-Based Costing (ABC) system. As one of the company’s accountant’s you have been asked to prepare a statement comparing both the costing methods for the next company board meeting. Your supervisor has given you the following quarterly data: - Total Indirect Costs for the quarter:...
Derive Lens equation of two convex lenses (L1 and L2) separated by 5 cm in Air....
Derive Lens equation of two convex lenses (L1 and L2) separated by 5 cm in Air. Write down the System Matrix equation and define each matrix elements.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT