Maximum number of merge applications

The function below merges two lists of numbers, each sorted in increasing order.


racket
(define (merge lon1 lon2)
  (cond [(and (empty? lon1) (empty? lon2)) empty]
        [(empty? lon1) lon2]
        [(empty? lon2) lon1]
        [(< (first lon1) (first lon2))
         (cons (first lon1) (merge (rest lon1) lon2))]
        [else (cons (first lon2) (merge lon1 (rest lon2)))]))


Suppose lon1 has 7 elements and lon2 has 5 elements, all values distinct. Over all possible such sorted lists, what is the largest number of applications of merge that a single initial call can produce, counting the initial application? Give your answer as a whole number.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Simultaneous Recursion Questions: