How can I merge two lists and sort them working in 'linear' time?

Posted by Sergio Tapia on Stack Overflow See other posts from Stack Overflow or by Sergio Tapia
Published on 2010-03-21T21:55:15Z Indexed on 2010/03/21 22:01 UTC
Read the original article Hit count: 256

Filed under:
|
|
|

I have this, and it works:

# E. Given two lists sorted in increasing order, create and return a merged
# list of all the elements in sorted order. You may modify the passed in lists.
# Ideally, the solution should work in "linear" time, making a single
# pass of both lists.
def linear_merge(list1, list2):
  finalList = []
  for item in list1:
    finalList.append(item)
  for item in list2:
    finalList.append(item)
  finalList.sort()
  return finalList
  # +++your code here+++
  return

But, I'd really like to learn this stuff well. :) What does 'linear' time mean?

© Stack Overflow or respective owner

Related posts about python

Related posts about newbie