def serialize_tree(root):
    """ Given a tree root node (some object with a 'data' attribute and a 'children'
    attribute which is a list of child nodes), serialize it to a list, each element of
    which is either a pair (data, has_children_flag), or None (which signals an end of a
    sibling chain).
    """
    lst = []
    def serialize_aux(node):
        # Recursive visitor function
        if len(node.children) > 0:
            # The node has children, so:
            #  1. add it to the list & mark that it has children
            #  2. recursively serialize its children
            #  3. finally add a "null" entry to signal this node has no children
            lst.append((node.data, True))
            for child in node.children:
                serialize_aux(child)
            lst.append(None)
        else:
            # The node is child-less, so simply add it to
            # the list & mark that it has no children:
            lst.append((node.data, False))
    serialize_aux(root)
    return lst