Question
haskell
6. (10 points) For this definition of BTree, write the definition of the function that counts the number of Nodes in a BTree
0 0
Add a comment Improve this question Transcribed image text
Answer #1

countNodes :: Integral n => BTree a -> n
countNodes Empty = 0
countNodes (Node _ l r) = succ $ countNodes l + countNodes r

Add a comment
Know the answer?
Add Answer to:
haskell 6. (10 points) For this definition of BTree, write the definition of the function that counts the number of Node's in a BTree. data BTree a-Empty | Node a (BTree a) (BTree a) countNode...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • By definition, the height of a node in a binary tree is the number of edges...

    By definition, the height of a node in a binary tree is the number of edges along the longest path from the node to any leaf. Assume the following node structure struct TreeNode! int data; node Type right; // points to right child node Type "left; // points to left child }; Write a recursive function that takes a pointer to a node in a binary tree and returns its height. Note: the height of a leaf node is o...

  • By definition, the height of a node in a binary tree is the number of edges...

    By definition, the height of a node in a binary tree is the number of edges along the longest path from the node to any leaf. Assume the following node structure struct TreeNode int data; node Type right; // points to right child node Type "Left; // points to left child ) Write a recursive function that takes a pointer to a node in a binary tree and returns its height. Note: the height of a leaf node is 0...

  • 1) (10 pts) Write a recursive function that counts and returns the number of nodes in...

    1) (10 pts) Write a recursive function that counts and returns the number of nodes in a binary tree with the root root, that store an even value. Please use the struct shown and function prototype shown below. (For example, if the tree rooted at root stored 2, 3, 4, 8, 13, 18 and 20, the function should return 5, since there are five even values [2,4,8,18,20] stored in the tree. typedef struct node { int data; struct node* left;...

  • Use Haskell for the above problems. Unless stated otherwise do not use library functions that are...

    Use Haskell for the above problems. Unless stated otherwise do not use library functions that are not in the Haskell standard prelude. 5. Consider the following definition for a binary tree. data Tree a Empty l Leaf a l Node a (Tree a) (Tree a) A binary tree is balanced if, at every node, the difference between the height the left and right subtree is at most one Height is defined as follows: height of an Empty node is 0...

  • HASKELL TREE QUESTION: write and test a function sizeTree :: Tree a b -> Int that...

    HASKELL TREE QUESTION: write and test a function sizeTree :: Tree a b -> Int that counts the total number of nodes and leaves in its argument.

  • In Haskell: Write a recursive function fibonacci that computes the n-th Fibonacci number. fibonacci :: Int...

    In Haskell: Write a recursive function fibonacci that computes the n-th Fibonacci number. fibonacci :: Int -> Int Write a recursive function myProduct that multiplies all the numbers in a list. myProduct :: [Integer] -> Integer Using the technique of List Comprehension write a function that would remove even numbers from a list of lists. For Example: given input: [[1,2,3,4], [6,3,45,8], [4,9,23,8]] expected output: [[1,3], [3,45],[9,23]]. Show how the library function replicate :: Int -> a-> [a] that produces a...

  • Exercise-2: 15 points Develop a node class and a doubly list class. The node class should have tw...

    Exercise-2: 15 points Develop a node class and a doubly list class. The node class should have two state variables namely data and nextNode. The doubly list class should contain the following methods: Middlelnsert- insert a node somewhere in the middle of the list Startinsert-insert a node at start of the Linked list Endinsert- insert a node at the end of the Linked list Delete-delete a node Traverse-prints all the node's data Reverse-reverses the linked list . . Note: Choose...

  • Exercise-1:15 points Develop a node class and a singly list class. The node class should have two...

    Exercise-1:15 points Develop a node class and a singly list class. The node class should have two state variables namely data and nextNode. The singly list class should contain the following methods . Middlelnsert-insert a node somewhere in the middle of the list . Startinsert-insert a node at start of the Linked list Endinsert-insert a node at the end of the Linked list . Delete-delete a node Traverse-prints all the node's data Reverse -reverses the linked list Note: Choose appropriate...

  • For this lab, you will need to write the following functions in table.cpp, and add function...

    For this lab, you will need to write the following functions in table.cpp, and add function prototypes for them to table.h and invoke the functions in main.cpp. * int countNodes(node * root) Recursively count the number of the nodes in the tree. * int sumLeaves(node * root) Recursively sum all of the leaf nodes in the tree. You must use the functions with these exact function prototypes. ****************************************************************************** main.cpp #include "table.h" #include <iostream> using namespace std; int main() { node...

  • Recall from Assignment 2 the definition of a binary tree data structure: either an empty tree,...

    Recall from Assignment 2 the definition of a binary tree data structure: either an empty tree, or a node with two children that are trees. Let T(n) denote the number of binary trees with n nodes. For example T(3) 5 because there are five binary trees with three nodes: (a) Using the recursive definition of a binary tree structure, or otherwise, derive a recurrence equation for T(n). (8 marks) A full binary tree is a non-empty binary tree where every...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT