Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Scala Programming Question: Write a function unionOfLists that inputs two lists of integers (sorted in ascending order) and returns a list of integers. The function

Scala Programming

Question:

Write a function unionOfLists that inputs two lists of integers (sorted in ascending order) and returns a list of integers. The function must compute the union of the two input lists to return a list that is also sorted in ascending order. Note that in performing the union, each number can appear at most once in the output list.

Example Input lists List(1, 3, 4, 6), and List(2, 3, 4, 5), the output should be List(1, 2, 3, 4, 5, 6)

Input lists List(1, 2, 3, 4) and List(1, 2, 3, 5), the output should be List(1, 2, 3, 4, 5)

Restrictions Suppose the lists are of size 1n1 and 2n2, respectively, the entire algorithm must run in linear time: (1+2)O(n1+n2). Please do not use inbuilt sort algorithms (they would take ((1+2)log(1+2))O((n1+n2)log(n1+n2)) time. Also note that when you append one list to another using ++ operator or an element to the end of a list using :+ operator inside a loop, the result may actually violate the linear time complexity restriction.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

Why do living creatures die? Can it be proved that they are reborn?

Answered: 1 week ago

Question

=+Is it possible to operate union-free?

Answered: 1 week ago

Question

=+impact member states and MNEs?

Answered: 1 week ago