Programming Questions Flashcards

1
Q

What is a set in Python

A

Set is a collection of Unique Elements.
They are mutable = > add or remove elements
IF you add duplicate element it will be ignored

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Create a set in python

A

set1 = set([1,2,3])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Time complexity to search for an element in SET in python and Why?

A

O(1) since underlying is hashtable. Python calculates the hashvalue and find the memory address directly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Inorder traversal Use

A

used for binary search trees to get nodes in sorted order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Preorder traversal Use

A

1) useful for creating a copy of the tree.
2) create a copy of the tree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Postorder traversal Use

A

1) used in expression trees to evaluate expressions.
2) used to delete the tree
3) Garbage collections

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Level order traversal Use

A

1) search or process nodes level-by-level.
2) finding the shortest path between nodes.
3) Tree Serialization and Deserialization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Inorder

A

Left -> Root -> Right

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Preorder

A

Root -> Left -> Right

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Post Order

A

Left -> Right -> Root

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly