Data Structures Flashcards

1
Q

Are elements indexed in a Linked List

A

No

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

Advantages of Linked List

A

Insert/Delete are quick: Prepend O(1) Append O(n)

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

Implement a Linked List

A
class Node {
   constructor() {
       var data;
         Node.next() 
         Node (data) {
             this.data = data
          }
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Binary Search Tree Structure

A

left nodes < root nodes < right nodes

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

Balanced Binary Tree Method Complexity

A

insert & find: O(logn)

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

Proper way to Traverse a Binary Tree

A

Left then root then right

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

Heap Structure

A

Root is smaller than children(Min Binary Heap), Root is always larger (Max Binary Heap.
Priority Queue is a Min Binary Heap. (2n +1): 2 to get child index, Math.floor(n/2) to get parent index

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

Implement a counting function in a Linked List

A
function countNodes(Nodehead) {
   //assuming head !== null
   let count = 1
   Node.current = head
   while (current.next != null) {
   current = current.next;
   count += 1;
   }
   return count;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Hash Tables consist of

A

keys mapped to values stored as objects in an array

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

Hash Table Time complexity

A

Constant

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

How do hash table elements get sorted

A

A key is passed into a hashing function, and the result is the index the key, value pair is stored at

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

Hash function for integers

A

sum(integers) % array.size = index

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

Hash function for strings

A

sum(CharCode) % array.size = index

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

Open Addressing method for Collision Handling in Hash Tables

A

Linear Probing: takes linear time, decent in if the load factor is low. keep looking for the next open index (or plus 3, quadratic). Keys might bunch together

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

Load factor in a Hash Table

A

load factor = n / k where n is the number of entries and k is the number of buckets in the array

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

Closed Addressing method for Collision Handling in Hash Tables

A

Chaining: creating a linked list at indexes with more than one hash pointing to it. Search by stepping along the linked list. O(n)

17
Q

Objectives of a Hash function

A
  • minimize collisions
  • uniform distribution of hash values
  • easy to calculate
  • be able to resolve collisions
18
Q

Runtime of a hash function

A

O(1)

19
Q

Linked List

A

Data structure that represents a sequence of nodes. Single & double linked. Single only points one direction, double points both directions

20
Q

Linked List disadvantage

A

does not provide constant time access to look up an index. O(n) time

21
Q

Linked list advantage

A

add/remove items from the beginning of the list in constant time.

22
Q

Deleting node in linked list

A

given n, find prev. prev.next = n.next. Check for null pointers and reset the head/tail node as necessary

23
Q

linked list runner technique

A

iterate through the linked list with 2 pointers simultaneously, with one ahead of the other. the ‘fast’ node could be ahead by a fixed amount or could be hopping multiple nodes.

24
Q

Array advantages

A

Constant time for lookup

25
Q

Stacks

A

LIFO, O(1) time for add/remove

26
Q

Queue

A

FIFO O(1) time for add/remove

27
Q

When to use DFS

A

If we know the solution lies somewhere deep in a tree or far from the source vertex in graph, use DFS. If our tree is very wide, use DFS as BFS will take too much memory.

28
Q

When to use BFS

A

If we know the solution is not that far from the source vertex, use BFS. If our tree is very deep, choose BSF over DFS.