tmuecksch
BASIC-Programmierer
Beiträge: 123
Registriert: 19. Apr 2013 10:51

Hey there,

I got some questions:

In the task description we are asked to implement a function which computes a sublist.
Implement the function sublists which takes a list xs and computes the set X of all lists such that for all ys in X, ys is the result of removing some (or no) elements from xs. Implement sublists with some flavor of fold.
I don't exactly get how these sublists are supposed to be assembled. The description doesn't answer some questions. It says "[...] ys is the result of remove some (or no) elements from xs." This doesn't specify if all permutations have to be in the list, or just one we can randomly pick.

In the fourth task we have to implement a fold function on a binary tree. It is not specified how a fold function would work on binary trees and I was not able to find any hints on the internet. Could you please specify this function or refer to an adequate source?

Talaron
Mausschubser
Beiträge: 85
Registriert: 26. Apr 2012 11:34

Not official, but as the tests are passed I guess I got the tasks right:

Task 2: What we are supposed to implement is comparable to the power set of a mathematical set, except that the original order of the remaining elements has to be retained.

An example would be: sublists((1,2,3)) = {(), (1), (2), (3), (1,2), (1,3), (2,3), (1,2,3)}

Task 4: Here it helped me a lot to look at the function's signature: "fold[T,R](tree: Tree[T])(init: R)(f : (T, R, R) => R): R"

The function given as parameter takes a tree node and two already computed results to create a new result. I can see only one logical way/direction to apply such a function in a binary tree that ends in a single result created from the tree.
Zuletzt geändert von Talaron am 6. Mai 2014 21:36, insgesamt 1-mal geändert.

Dennis Albrecht
Sonntagsinformatiker
Beiträge: 222
Registriert: 4. Okt 2010 18:15