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 9227843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:10:48+00:00 2026-06-18T05:10:48+00:00

I am writing a function that takes 2 binary trees (t1 and t2) and

  • 0

I am writing a function that takes 2 binary trees (t1 and t2) and generates a new tree that places t2 at the bottom right of t1. t2 is attached to the first node whose right child is empty, even if the node is not a leaf.

let rec adjoin_right (t1: 'a tree) (t2: 'a tree) : 'a tree

test case:

let test () : bool =
adjoin_right (Node (Empty, 1, Empty)) (Node (Empty, 2, Empty)) = 
Node(Empty, 1, Node (Empty, 2, Empty))
;; run_test "adjoin_right leaf" test

Can somebody steer me in the right direction for this problem? I know that I’ll probably have to write a helper function.

  • 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-18T05:10:49+00:00Added an answer on June 18, 2026 at 5:10 am

    To make recursion work you just have to think about two questions:

    • What’s the result supposed to be if t1 is Empty?

    • If t1 isn’t empty, but you had a function that worked properly when applied to the subtrees of t1, how would you use this function to get the result?

    If you can figure these out, then you do have a function that works properly for subtrees.

    Edit

    Consider the recursive case. You have l (your left subtree), r (your right subtree), and v (the value in the node). In FP you’re not going to change any of these values. What you want to do is to construct a new tree with the correct contents. So, how would you use your function recursively to make the new tree from these three ingredients? It’s not hard–really just one line of code.

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

Sidebar

Related Questions

I'm writing a function that takes two parameters, the first being the id of
I'm writing a trimming function that takes a string and finds the first newline
Suppose I'm writing a function that takes a list of integers and returns only
I am writing a function that takes in a output target file and a
I am writing a function that takes a string, string pointer and an int.
I am writing a function that takes in an argument. From that argument, I
I'm writing a wrapper to a function that takes varargin as its inputs. I
I'm writing a function that returns the first n ( n <= strlen(src) )
I am writing a Haskell function that takes a list of strings and returns
I have am writing a Python function that takes a timeout value as a

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.