Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8826905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:15:24+00:00 2026-06-14T07:15:24+00:00

I am implementing merge sort in scheme, and I must do it by defining

  • 0

I am implementing merge sort in scheme, and I must do it by defining two helper methods: merge and split.

Merge takes two lists (already in increasing order) and merges them together. I have done this as follows:

(define merge 
   (lambda (list1 list2)
       (if (null? list1)
          list2
             (if (null? list2)
                list1
                   (if (< (car list1) (car list2))
                      (cons (car list1) (merge (cdr list1) list2))
                      (cons (car list2) (merge (cdr list2) list1)))))))

The split method has me stumped though. I’ve found an example that accomplishes this in two separate methods (‘odd-numbers’ and ‘even-numbers’), but I was wondering if there was a way to combine these into one method called ‘split’?

Example found here: merge sort in scheme

I am obviously quite new to scheme, can anyone help me understand how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:15:27+00:00Added an answer on June 14, 2026 at 7:15 am

    A simplistic split implementation, suitable for use as part of a mergesort, follows:

    (define (split lst)
      (let ((half (quotient (length lst) 2)))
        (list (take lst half)
              (drop lst half))))
    

    It splits the input list in two halves, returning them in a list of lists – the first list corresponds to the first half, and the second list corresponds to the second half of the input list.

    Another alternative, as requested in the question, would be to split the list in odd/even elements like this:

    (define (split lst)
      (list (filter odd? lst)
            (filter even? lst)))
    

    Yet another alternative, by using partition you can split the input list in a single pass:

    (define (split lst)
      (let-values (((odds evens) (partition odd? lst)))
        (list odds
              evens)))
    

    Be aware that the last two alternatives will be useful only if the input list contains exclusively integer numbers, for sorting lists of other data types with your own implementation of mergesort, you’re better off using my first version of split.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing a version of merge sort in c. For the first step
I am implementing the Merge sort algorithm. The problem is when I try to
While implementing this generic merge sort , as a kind of Code Kata ,
I have an unusual problem. I've been implementing Merge Sort and have encountered the
I am writing a c++ program implementing the Merge Sort iteratively. The main code
As a learning excercise, I've just had an attempt at implementing my own 'merge
I'm implementing a rudimentary version of LISP in Ruby just in order to familiarize
I have studied the theory of the merge sort but don't have any idea
I'm implementing a bitonic sort using intel TBB. When using the parallel_invoke method all
I'm implementing a document server. Currently, if two users open the same document, then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.