DS: Misc Flashcards

1
Q

What is a Circular List?

A

A list that does not have a clear “head” or “tail”, because “tail” points to “head” effectively creating a closed loop.

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

HashMap Complexity

A

On AVERAGE:
Insert: O(1)
Deleting: O(1)
Search: O(1)

In Worst Case: Above 3 are O(n).

This is wrt to Collision of Keys, all based on hashing function. Hashing key.

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

Java TreeMap - when would you use it?

A

Java TreeMap is an implementation of Red-Black tree.

Map is sorted in the natural ordering of keys or the Comparator provided.

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

How are Strings stored and their memory layout?

A

In memory, everything is stored in bits 0 or 1.
When using ASCII encoding, which covers all the english alphabets - we can map every character to a number and store them in 1 byte.
ASCII mapping is 0-255 (2^8).
So a string is stored as array of ASCII encoded numbers. Each character is 1 byte.

If using another encoding, then depending on number of bytes to store them.

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

What is a “sub-sequence of an array”?

A

A sub-sequence of an array is a set of numbers that aren’t necessarily adjacent in the array - BUT - that are in the same order as they appear in the array.

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

Binary Tree vs BST

A

Binary Tree: A tree in which, every node has at max 2 child nodes.

Binary Search Tree: A Binary Tree in which all the nodes in the left sub-tree is less than or equal to value of node itself. And all the nodes in the right sub-tree is greater than node.

                                   Node X
                                         /\
                                        /  \
                                       /    \
                             Node Y  Subtree 3
                                   /\
                                  /  \
                                 /    \
                   Subtree 1   Subtree 2

BST: Subtree 1 < Node Y < Subtree 2 < Node X < Subtree 3

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