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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:16:38+00:00 2026-06-17T21:16:38+00:00

How do you delete the minimum in BST? I can’t seem to find a

  • 0

How do you delete the minimum in BST? I can’t seem to find a way to keep the tree

data BST = EmptyT
         | Node Float BST BST
           deriving (Eq, Show, Read)

deleteMin :: BST -> Maybe BST
deleteMin EmptyT  = Nothing
deleteMin (Node x left right)
    |left == EmptyT = ? 
    |otherwise = ?

do i need getters and setters?

  • 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-17T21:16:39+00:00Added an answer on June 17, 2026 at 9:16 pm

    Haskell does not have “getters and setter” in the OOP sense, though you can
    come up with similar concepts. If you wish to delete a value in your binary
    tree, you have to construct a new tree with the value missing. That is how you
    “keep the tree.”

    Assuming you are using a standard BST, then the leftmost node in the tree will
    contain the minimum element. So, by traversing your tree towards the left,
    you should eventually run into a situation that looks like Node x EmptyT r.
    Any other node, you just recursively call deleteMin on the left branch.

    This gives a function that looks like

    deleteMin :: BST -> Maybe BST
    deleteMin EmptyT                = Nothing
    deleteMin (Node x EmptyT right) = Just right
    deleteMin (Node x left right)   =
        case deleteMin left of
             Nothing -> Nothing
             Just nl -> Just $ Node x nl right
    

    You have to check the result of each call to deleteMin to check for
    Nothing. I don’t think you really need to return a Maybe BST, unless you
    really need to indicate that there is no element to delete. It makes more
    sense (to me at least) to just return an empty tree if there is nothing to
    delete.

    I think most would also consider the use of pattern matching preferable over using guards with an equality check.

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

Sidebar

Related Questions

I can't seem to figure out how to delete an element from the BST.
$(.delete).click( function() { var thesender = this; $(thesender).text(Del...); $.getJSON(ajax.php, {}, function(data) { if (data[result])
How I can delete an object which I had added before with this code.
I'm breeding over this problem now for a while and I can not find
The following is the best minimum working example I can construct for now. I
Is there a way I can get a blank MVC template for VS2008? Like
http://en.wikipedia.org/wiki/Minimum_spanning_tree I'm looking to benchmark my minimum spanning tree algorithm against the best of
I was wondering if we can use a binary search tree to simulate heap
Delete the records that have the minimum of records, I have 2 tables person
How can I implement a function to delete an element in a binary search

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.