Data Structures Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Arrays

A

Collection of elements stored in memory locations through which each element can be accessed by its index

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

Accessing an element in array: time complexity

A

O(1)

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

Deleting elements in the middle of an array: time complexity

A

O(n), because it may require shifting elements

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

Linked Lists

A

Linked lists are a sequence of nodes where each node contains data and a reference to the next node

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

There are two types of linked lists:

A
  • Single linked lists (one-way links)
  • Double linked lists (two-way links)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

For Linked Lists: insertion and deletion can be (enter time complexity) at head or end of tail

A

O(1)

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

For linked lists: searching takes (enter time complexity) as you need to traverse the list

A

O(n)

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

Stacks

A

A stack is a collection of elements that follows the Last-In, First-Out principle (LIFO). You can only insert (push) or remove (pop) elements from the top of the stack

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

Stacks: push and pop operations both run in (insert time complexity)

A

O(1)

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

Queues

A

A queue is a collection of elements that follows the First-In, First-Out (FIFO) principal. Elements are inserted at the back (enqueue) and removed from the front (dequeue). Therefore, the first element is pulled out by dequeue.

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

Queues: both enqueue and dequeue run in (insert time complexity) in implementations like linked lists

A

O(1)

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

Trees

A

A tree is a hierarchical data structure with nodes connected by edges. The top node is called the root, and each node may have children. It is non-linear compared to arrays and linked lists.

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

Binary Trees

A

Binary Trees are trees in which each node has at most two children, referred to as the left child and the right child.

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

Binary Search Trees

A

Binary Search Trees (BST) is a type of binary tree in which the left child of a node contains values less than the node, and the right child contains values greater than the node. This allows for efficient searching, insertion, and deletion.

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

Binary trees have traversal operations with time complexity ____ (inorder, preorder, postorder)

A

O(n)

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

Binary Search Trees: - In the AVG case, search, insert and delete operations run in ____, but the worst case (unbalanced tree) can lead to O(n)

A

O(log n)

17
Q

AVL Trees

A

AVL Tree is a self-balancing binary search tree. It ensures the height difference between the left and right subtrees (balance factor) is at most 1

18
Q

AVL Trees: - Insertions, deletions, and lookups all run in ____, as the tree remains balanced

A

O(log n)

19
Q

Hash Tables (DataFrames in Pandas)

A

Hash tables store key-value pairs and use hash functions to map keys to their values. Python’s dict and set use hash tables internally. In Pandas, DataFrames behave like a table where rows and columns are labeled and can hold heterogenous data

20
Q

Hash tables: Insertion, deletion, and lookup operations run in average-case O(1), though collisions can degrade performance to ___ in the worst case.

A

O(n)

21
Q

Hash tables are ideal for ____

A

fast lookups by key