树
Data Structures & Algorithms · 15 notes
- Postorder Traversal Sequence of a Binary Search Treehistorical
Given an integer array, determine whether it is the postorder traversal result of a binary search tree. Return true if it is, otherwise return false. Assume that any two numbers in the input array are distinct.
- Next Node in a Binary Treehistorical
Given a binary tree and one of its nodes, find and return the next node in inorder traversal order. Note that each tree node contains not only left and right child pointers, but also a pointer to its parent.
- Binary Search Tree and Doubly Linked Listhistorical
Given a binary search tree, convert it into a sorted doubly linked list. No new nodes may be created; only the pointers between existing tree nodes may be adjusted.
- Kth Node in a Binary Search Treehistorical
Given a binary search tree, find its kth smallest node. For example, in (5, 3, 7, 2, 4, 6, 8), the value of the third smallest node is 4.
- Depth of a Binary Treehistorical
Given a binary tree, find its depth. A path is formed by the nodes traversed from the root to a leaf, including both the root and the leaf. The length of the longest path is the depth of the tree.
- Print a Binary Tree from Top to Bottomhistorical
Print every node of a binary tree from top to bottom, with nodes on the same level printed from left to right.
- Symmetric Binary Treehistorical
Implement a function to determine whether a binary tree is symmetric. A binary tree is defined as symmetric if it is identical to its mirror image.
- Mirror of a Binary Treehistorical
Transform a binary tree into its mirror by swapping the left and right subtrees at every node.
- Print a Binary Tree in Multiple Lineshistorical
Print a binary tree level by level from top to bottom, with nodes on the same level output from left to right. Output each level on a separate line.
- Print a Binary Tree in Zigzag Orderhistorical
Implement a function that prints a binary tree in zigzag order: the first row from left to right, the second level from right to left, the third row from left to right, and so on.
- Substructure of a Treehistorical
Given two binary trees A and B, determine whether B is a substructure of A. (ps: an empty tree is not considered a substructure of any tree.).
- Reconstruct Binary Treehistorical
Given the preorder traversal and inorder traversal results of a binary tree, reconstruct the binary tree. Assume that the input preorder traversal and inorder traversal results contain no duplicate numbers.
- Paths in a Binary Tree With a Given Sumhistorical
Given the root node of a binary tree and an integer, print all paths in the binary tree whose node values sum to the given integer. A path is defined as the nodes traversed from the root node of the tree downward to a leaf node.
- Serialize a Binary Treehistorical
Implement two functions to serialize and deserialize a binary tree respectively.