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.
Answer:
The Haskell function that generates all binary trees with empty leaves is given as below:
generateAllTrees input = do
(left, value : right) <- splits input
Node <$> generateAllTrees left <*> pure value <*>
generateAllTrees right
HASKELL TREE QUESTION: write and test a function sizeTree :: Tree a b -> Int that...
Hi everyone, I need help in Haskell, please. Write a Haskell function that takes an Int i as its only parameter and uses a list comprehension to caclulate m(i) = 1 + 1/2 + 1/3, ... + 1/i
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...
Write a function that takes an int as an argument and returns true if the int is an even number and false if not. In any case change the value of the original argument to twice its value. Use the integers 0 through 4 as test cases. Do not use any arrays.
IN HASKELL func5 :: (Int -> Int) -> Int -> (Int, Int) func5 f x = (x, f x) Using map and the function above, write a function that takes a list of Ints and a function (Int -> Int) and returns a new list of tuples, with the first element being the original element, and the second being the result of the transformation. e.g. [1,2,3] becomes [(1,1), (2, 4), (3, 9)] if the function passed in returns the square...
C++ Write a function, singleParent, that returns the number of nodes in a binary tree that have only one child. Add this function to the class binaryTreeType and create a program to test this function. (Note: First create a binary search tree.)
code in haskell Write a function morerecent that takes two dates and returns whichever one is more recent. morerecent :: (Int, Int, Int) -> (Int, Int, Int) -> (Int, Int, Int)
Write a recursive function that compares two given binary trees. It returns 1 if the two trees are different, and it returns 0 otherwise. The function signature is: int treeDiff (node "a, node *b); Write a recursive function that counts how many nodes in a tree have a single child. The function signature is: int countoneChild(node "root);
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) countNodes BTree a -> Integer
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) countNodes BTree a -> Integer
**Bonus Question Write a C function with signature bt' bstree (int' post, int size) that gets the post-order traversal of a binary search tree in the form of an int array,reconstructs the tree and returns a pointer to the tree root as output (The second input parameter size specifies the number of elements in the tree). Note: Type bt is defined in the following way: typedef struct btreenodel struct btreenode *left; int data; struct btreenode *right; }bt; 12pt Paragraph B...
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;...