Prep Flashcards

1
Q

In-order traversal

A

Left -> Root -> Righ

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

Pre-order traversal

A

Root -> Left -> Righ

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

Post-order traversal

A

Left -> Right -> Root

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

Tree

A

A tree is a widely used abstract data type that represents a hierarchical structure with a set of connected nodes. Each node in the tree can be connected to many children, but must be connected to exactly one parent, except for the root node, which has no parent.

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

Complete binary tree

A

A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible.

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

Balanced binary tree

A

A binary tree structure in which the left and right subtrees of every node differ in height by no more than 1.

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

Graph

A

A graph is a structure containing a set of objects (nodes or vertices) where there can be edges between these nodes/vertices. Edges can be directed or undirected and can optionally have values (a weighted graph). Trees are undirected graphs in which any two vertices are connected by exactly one edge and there can be no cycles in the graph.

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

Depth-first search

A

Depth-first search is a graph traversal algorithm which explores as far as possible along each branch before backtracking. A stack is usually used to keep track of the nodes that are on the current search path. This can be done either by an implicit recursion stack, or an actual stack data structure.

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

Breadth-first search

A

Breadth-first search is a graph traversal algorithm which starts at a node and explores all nodes at the present depth, before moving on to the nodes at the next depth level. A queue is usually used to keep track of the nodes that were encountered but not yet explored.

A similar template for doing breadth-first searches on the matrix goes like this. It is important to use double-ended queues and not arrays/Python lists as enqueuing for double-ended queues is O(1) but it’s O(n) for arrays.

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

Heap

A

A heap is a specialized tree-based data structure which is a complete tree that satisfies the heap property.

Max heap - In a max heap the value of a node must be greatest among the node values in its entire subtree. The same property must be recursively true for all nodes in the tree.
Min heap - In a min heap the value of a node must be smallest among the node values in its entire subtree. The same property must be recursively true for all nodes in the tree.

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

Hash table

A

A hash table (commonly referred to as hash map) is a data structure that implements an associative array abstract data type, a structure that can map keys to values. A hash table uses a hash function on an element to compute an index, also called a hash code, into an array of buckets or slots, from which the desired value can be found. During lookup, the key is hashed and the resulting hash indicates where the corresponding value is stored.

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

Separate chaining

A

A linked list is used for each value, so that it stores all the collided items.

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

Open addressing

A

All entry records are stored in the bucket array itself. When a new entry has to be inserted, the buckets are examined, starting with the hashed-to slot and proceeding in some probe sequence, until an unoccupied slot is found.

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

Linked list

A

Like arrays, a linked list is used to represent sequential data. It is a linear collection of data elements whose order is not given by their physical placement in memory, as opposed to arrays, where data is stored in sequential blocks of memory. Instead, each element contains an address of the next element. It is a data structure consisting of a collection of nodes which together represent a sequence.

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

Doubly linked list

A

A linked list where each node has two pointers, next which points to the next node and prev which points to the previous node. The prev pointer of the first node and the next pointer of the last node point to null.

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

Circular linked list

A

A singly linked list where the last node points back to the first node. There is a circular doubly linked list variant where the prev pointer of the first node points to the last node and the next pointer of the last node points to the first node.

17
Q

Array

A

Arrays hold values of the same type at contiguous memory locations. In an array, we’re usually concerned about two things - the position/index of an element and the element itself. Different programming languages implement arrays under the hood differently and can affect the time complexity of operations you make to the array. In some languages like Python, JavaScript, Ruby, PHP, the array (or list in Python) size is dynamic and you do not need to have a size defined beforehand when creating the array. As a result, people usually have an easier time using these languages for interviews.

18
Q

Subarray

A

A range of contiguous values within an array.
Example: given an array [2, 3, 6, 1, 5, 4], [3, 6, 1] is a subarray while [3, 1, 5] is not a subarray.

19
Q

Subsequence

A

A sequence that can be derived from the given sequence by deleting some or no elements without changing the order of the remaining elements.