Skip to main content

All Questions

Tagged with
0 votes
1 answer
177 views

Implement add-leaf, a Scheme procedure that takes in a tree instance t and a number x

Implement add-leaf, a Scheme procedure that takes in a tree instance t and a number x. This procedure will return a new tree where for each non-leaf node in the tree, append a new leaf with the label ...
Proteus Yi's user avatar
0 votes
1 answer
175 views

SCHEME Preorder/Postorder/Inorder Traversal of a binary search tree

Trying to traverse a tree in scheme and I keep getting an error when I try to actually call/run the function. (define (make-tree value left right) (list left value right)) (define (root tree) (...
virtuallyalike's user avatar
0 votes
0 answers
401 views

Find total number of leaves of a tree LISP

The following is a procedure that returns the total number of leaves of a tree. for example (count-leaves '((1 2) () (3) (4 5 6))) returns 6 this is code so far i found is there any other way to ...
mp96's user avatar
  • 53
2 votes
1 answer
159 views

Scheme equal-tree procedure

Given a new implementation of tree in Scheme using list: (define make-tree list) (define add-subtree cons) (define make-leaf (lambda (x) x)) (define empty-tree? empty?) (define first-subtree car) (...
Tariq Ganem's user avatar
0 votes
2 answers
617 views

Racket Tree Depth function (tree recursion) (No Structure Nodes!)

I'm trying to write a procedure (depth tree) that takes a tree as input and return an integer indicating the maximum level of the tree using Racket/Scheme Example: (depth '()) => 0 (depth '(1 2 3)) ...
Ptechnic's user avatar
2 votes
0 answers
333 views

Get a subtree by breadth-first index using continuation-passing style

This question is a follow-up on How do I get a subtree by index?. That question deals with depth-first indexing (for which I have provided a depth-first continuation-passing style solution). This ...
Flux's user avatar
  • 10.8k
2 votes
1 answer
423 views

How do I replace part of a tree with another tree at the specified index?

Suppose I have two trees: Tree A — '(+ (* 5 6) (sqrt 3)): Tree B — '(- 4 2): Goal: replace one of tree A's subtrees with tree B at a specified tree A index position. The index position starts at 0 ...
Flux's user avatar
  • 10.8k
2 votes
4 answers
459 views

How do I get a subtree by index?

Suppose I have the following tree: In my program, this tree is represented using a list: '(+ (* 5 6) (sqrt 3)). How do I get a subtree by its index? The index should start from 0 and be depth-first. ...
Flux's user avatar
  • 10.8k
1 vote
1 answer
138 views

Scheme Binary Search Tree Adding Elements

To begin, I wanted to write a function that: Takes in: A list of natural numbers, (list 2 6 1 23...) that could have repeating elements called "lst" A random binary search tree called &...
user avatar
2 votes
2 answers
461 views

Apply function to tree structure in racket

I'm trying to apply a function to a tree in the form of a Map but not sure how to exactly go about it. Here's my attempt.. (define-struct node (value left middle right)#:transparent) (struct ...
Electronic_Tear's user avatar
0 votes
2 answers
530 views

Scheme find far left node of a tree recursively

I am writing a function that finds the farthest left node in any tree. The function does not traverse the tree or give the farthest left node but just gives the left most child of the first node. (...
Ben's user avatar
  • 38
0 votes
1 answer
45 views

How do I modify every leaf value in a Leaf Labelled Tree by a function

I'm currently trying to modify a LLT(leaf labelled tree) by a function. Essentially I want the leaf values(L) to be modified by the function(fn) Here's my code so far (define (llt-map fn T) (cond ...
CanadianBeaver's user avatar
0 votes
1 answer
129 views

Maximum sum of a tree in Scheme

I am having troubles with an exercise I am trying to do because I'm new to this language and to think in a recursive way is kind of hard to me. I have a tree (not neccesary binary) and I need to find ...
B. A. C. A.'s user avatar
0 votes
0 answers
21 views

Scheme altering tree values [duplicate]

I receive a tree and suppose to output the same tree with the values negated: 1 becomes -1, -2 becomes 2, #t becomes #f and the opposite way. The tree is flexible - each can have multiple sons, one ...
Adam Morad's user avatar
0 votes
4 answers
930 views

Scheme changing tree values

I need to implement a procedure called inverse-tree that receives a tree whose nodes data values are numbers and booleans and returns the equivalent tree whose nodes satisfy the following: If the ...
Adam Morad's user avatar

15 30 50 per page
1
2 3 4 5