Data Structures Flashcards

1
Q

Time Complexity

A

Amount of time it takes to run an algorithm

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

Space Complexity

A

Amount of memory taken up by a program to run

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

Asymptotic Analysis

A

Evaluating performance of an algorithm in terms of input size and its increase
- We don’t actually see how fast it can run but rather how it increases with different inputs

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

Big O

A

Upper bound of the algoirthm (worst case)

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

Omega

A

Lower bound of the Algorithm
Best case

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

Theta

A

Average case

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

Rules of Big O
- Execution time of statements

A
  • Return statement takes 1 unit of time
  • Assignment operation/arithmetical operation all take 1 unit of time
  • Drop lower order terms/constants
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

O(1)

A

Constant Time
- Simple instructions

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

O(n)

A

Linear Time
- if input is based on n

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

O(n^2)

A

Polynomial Time
- When an algorithm is n*n = n^2

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

Why use a linked list?

A
  • For fast insertion, deletion, espeically in the middle
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

When use a hashmap?

A

When you want key-value pairs
- Fast lookups by key
- Caching or memoization
- Counting occurrences of elements

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

When use a HashSet?

A

Ensuring uniqueness
- fast checking
- removing dups
- set operations like union/intersection

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

When use a regular set?

A

When you want flexibility, can switch between hashset and treeset
- When defining APIs

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

When to use regular arrays?

A

Fixed size, better performance than primitive types
- multi-dimensional

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

When to use Arraylists?

A

When you don’t know the size
- when yolu need fasat random access
When you frequently add/remove elements at the end

17
Q

How to create a new set?

A

Set<String> bookCategories = new HashSet<>();</String>

18
Q

How to create a new LinkedList?

A

LinkedList<String> issuedBooks = new LinkedList<>();</String>

19
Q

How to create a new ArrayList?

A

ArrayList<String> availableBooks = new ArrayList<>();</String>

20
Q

How to create a new hashmap?

A

HashMap<String, Boolean> bookAvailability = new HashMap<>();

21
Q

How to create a new HashSet?

A

HashSet<String> borrowers = new HashSet<>();</String>