Programming Questions Flashcards
What is a set in Python
Set is a collection of Unique Elements.
They are mutable = > add or remove elements
IF you add duplicate element it will be ignored
Create a set in python
set1 = set([1,2,3])
What is Time complexity to search for an element in SET in python and Why?
O(1) since underlying is hashtable. Python calculates the hashvalue and find the memory address directly.
Inorder traversal Use
used for binary search trees to get nodes in sorted order.
Preorder traversal Use
1) useful for creating a copy of the tree.
2) create a copy of the tree.
Postorder traversal Use
1) used in expression trees to evaluate expressions.
2) used to delete the tree
3) Garbage collections
Level order traversal Use
1) search or process nodes level-by-level.
2) finding the shortest path between nodes.
3) Tree Serialization and Deserialization
Inorder
Left -> Root -> Right
Preorder
Root -> Left -> Right
Post Order
Left -> Right -> Root