General Data Structures Flashcards

1
Q

What is the toString() method?

A

A special method that returns a string representation of an object

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

How to use the toString() method in our classes?

A

public String toString(){
return constructor1 + “ “ + data1;

}

Must include the method toString to our class object and edit how we want it to act

Include an @Override before the method

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

Why do we use toString()?

A

So we can print out an object in the form of a string rather than the address of the object

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

What is an Array?

A

A fixed size that stores elements in a linear set

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

What is a Dynamic Array? Array Lists

A

Resizeable Array

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

What is a linked list?

A

Nodes linked via pointers

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

What is a Stack?

A

LIFO, think of a stack of books

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

What is deque? queue

A

Double-ended queue

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

What is a Queue?

A

FIFO, think of a line

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

What is a Hash Table?

A

Stores key-value pairs

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

What is a Hash Set?

A

Unordered set, unique elements

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

What is a Binary Tree?

A

Each node has ≤2 children

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

What is a Binary Search Tree BST?

A

Ordered binary tree

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

What is an AVL Tree?

A

Self-balancing BST

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

What is a Red-Black tree?

A

Balanced BST used in TreeSet, TreeMap

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

What is a Segment Tree?

A

Used for range queries

16
Q

What is a Fenwick Tree?

A

Efficient prefix sum computation

17
Q

What is a Trie?

A

Used for string prefix searches

18
Q

What is a Min Heap?

A

Smallest element at the root

19
Q

What is a Max Heap?

A

Largest element at the root

20
Q

What is a priority Queue?

A

Supports Efficient Retrieval of min/max

21
Q

What is an Adjacency Matrix?

A

Graphs as a 2D Array

22
Q

What is an Adjacency List?

A

Graph as a list of lists

23
Q

How to implement basic Array?

A

int[] array = new int[10];

24
How to implement an Array List?
List arrayList = new ArrayList<>();
25
How to implement a Linked List?
LinkedList linkedList = new LinkedList<>();
26
How to implement a Stack?
Stack stack = new Stack<>();
27
How to implement a Queue?
Queue queue = new LinkedList<>();
28
How to implement a Deque?
Deque deque = new ArrayDeque<>();
29
How to implement a HashMap?
Map hashMap = new HashMap<>();
30
How to implement a HashSet?
Set hashSet = new HashSet<>();
31
How to implement a LinkedHashMap?
Map linkedHashMap = new LinkedHashMap<>();
32
How to implement a LinkedHashSet?
Set linkedHashSet = new LinkedHashSet<>();
33
How to implement a TreeSet?
TreeSet treeSet = new TreeSet<>();
34
How to implement a TreeMap?
TreeMap treeMap = new TreeMap<>();
35
How to implement a Min Heap?
PriorityQueue minHeap = new PriorityQueue<>();
36
How to implement a Max Heap?
PriorityQueue maxHeap = new PriorityQueue<>(Collections.reverseOrder());
37
How to implement a Adjacency List?
Map> graph = new HashMap<>();
38
How to implement a Adjacency Matrix?
int[][] adjMatrix = new int[10][10];