[Palindrome Partitioning]

https://leetcode.com/problems/palindrome-partitioning/


def dfs(sublist, str)

if not str

ret += sublist

else

for str의 0번 인덱스 시작 길이가 1부터 len(str)까지의 모든 substring

if substring is palindrome

dfs(sublist += substring, str에서 substring을 제외한 나머지)



[Binary Tree Preorder, Inorder, Postorder]


https://leetcode.com/problems/binary-tree-preorder-traversal/

https://leetcode.com/problems/binary-tree-inorder-traversal/

https://leetcode.com/problems/binary-tree-postorder-traversal/


stack, hash

reverse(preorder) = postorder

'컴퓨터공학 > Program Solving' 카테고리의 다른 글

[Leetcode] 160302  (0) 2016.03.02
[Leetcode] 160301  (0) 2016.03.02
[leetcode] 160229  (0) 2016.02.29
[leetcode]160225  (0) 2016.02.25
[leetcode.com] 160224  (0) 2016.02.24
  • Preorder

  • Postorder

  • Level order

• NOTE :The inorder traversal is the special case for binary trees.

(another definition possible) 


- inorder는 binary-tree에서만 존재한다.


 preorder traversal

– To move down the tree to the left until a null node is reached

– The null node’s parent is then “visited”, and the traversal continues with the node that is one to the right

– If there is no move to the right, the traversal continues with the last unvisited node at the next higher level of the tree 




• Vertex -> Left subtree -> Right subtree 

– Root : 1st position in traversal
– Bottom right child: latest position 










 postorder traversal

– To move down the tree to the left until a null node is reached

– The traversal continues with the null node’s parent and then to the right

– If there is no move to the right (null node), the null node’s parent is then “visited”, and the traversal continues with the node at the next higher level of tree 





• Left subtree -> Right subtree -> Vertex 

– Root: latest position in traversal
– Bottom left child: 1
st position 

- EX) % rm -r /user/bit 







inorder traversal of a binary tree

– In an inorder traversal a node is visited after its left subtree and before its right subtree 







• Left subtree -> Vertex -> Right subtree
– Bottom left child : 1st position
– Bottom right child :latest position in traversal 








'컴퓨터공학 > Data structure' 카테고리의 다른 글

HashTable by Java  (0) 2016.01.26
Heap  (0) 2013.01.08
Balance? - Tree  (0) 2013.01.07

+ Recent posts