Python solutions (recursively and iteratively).
    \n    # recursively\n    def preorderTraversal1(self, root):\n        res = []\n        self.dfs(root, res)\n        return res\n        \n    def dfs(self,
        \n    # recursively\n    def preorderTraversal1(self, root):\n        res = []\n        self.dfs(root, res)\n        return res\n        \n    def dfs(self, root, res):\n        if root:\n            res.append(root.val)\n            self.dfs(root.left, res)\n            self.dfs(root.right, res)\n    \n    # iteratively\n    def preorderTraversal(self, root):\n        stack, res = [root], []\n        while stack:\n            node = stack.pop()\n            if node:\n                res.append(node.val)\n                stack.append(node.right)\n                stack.append(node.left)\n        return res
['Recursion', 'Python']