Midterm Exam Flashcards

(34 cards)

1
Q

What is a priority queue?

A

An abstract data type similar to a queue but each element has a priority

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

What operations does a priority queue have?

A
  • insert - Inserts an item with a given priority
  • extractMax - Removes and returns the item with the highest priority
  • peek - returns the item with the highest priority without removing it
  • isEmpty - Checks if the queue is empty
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Operation times for priority queue in unsorted array or list

A
  • insert - O(1)

*extractMax - O(n) - must search for highest priority

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

Operation times for priority queue in sorted arrays or lists

A
  • insert - O(n) - has to search to insert in correct position

*extractMax - O(1)

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

Operation times for priority queues in Binary Heaps

A

-Most efficient and commonly used

  • insert - O(log n)
    -extractMax / extractMin - O(log n)
    -peek - O(1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a job scheduler?

A
  • A system that manages a queue of jobs (tasks / processes) and determines which to run based on priority.

-Operating Systems, printer queues
-A priority queue

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

What is a singly linked list?

A

A linear data structure where each element (nodes) points to the next node in the list.

Memory is not contiguous.
Can be dynamically grown / shrank.
Random access is not possible.

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

What is a doubly linked list?

A
  • A data structure where nodes point both forward and backward
  • Allows for traversal in both directions for easier deletions
  • Slightly more complex to implement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is hashing?

A

The process of converting input data into a fixed-size string of characters.

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

Explain how to hash

A
  • Done using a hash function
  • Always produces the same output for the same input.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a block chain?

A

A chain of ‘blocks’ (like nodes) that are linked together with a key (hash of previous node). If a block is altered, it invalidates the chain. This makes it extremely hard to commit fraud.

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

What does every block of a blockchain contain?

A
  • Data
  • Timestamp
  • Previous block’s hash
  • Current block’s hash
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is Big-Omega time complexity?

A
  • Gives the best-case lower bound of an algorithm’s runtime or growth
  • “This algorithm will take at least this long”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is big-theta time complexity?

A
  • Gives the exact or tight bound of an algorithm’s runtime.

-Best case, worst case, always the same.

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

What is little-Omega time complexity?

A
  • Describes a strict lower bound - meaning this function will ALWAYS take at least this much time.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a hash table?

A
  • A key-value data structure that lets you store data for very fast access.
  • You provide a key, and the hash table gives you back the value.
  • Under the hood, it uses a hash function to map the key to an index in an array
17
Q

Real world applications of hash tables

A
  • Dictionaries
    -Data base indexing
  • Caching
    -Password storage
18
Q

What is chaining?

A
  • A method of handling collisions in hash tables where each index of the hash table is a linked list of entries that hash to the same index
19
Q

Open Addressing - Solving Collisions

A
  • Handles collisions by finding another open slot in the hash table.
20
Q

What is asymptotic analysis

A

A way of describing the behavior of an algorithm as the input size becomes very large.

  • Running time depends on the size of the input
21
Q

What is merge sort?

A

Divides the array into two halves, then sorts each halve recursively, then merges the sorted halves into one array

22
Q

What is insertion sort?

A
  • Goes through each element and compares it to the elements before it. Shifts the larger values to the right and inserts the current value into its correct position.
23
Q

Heap Sort

A
  • Comparison-based sorting algorithm that uses binary heap data structure
  • Sort into a max or min heap and then swap the root node with the most or least node. Then heapify. Repeat this cycle until sorted.
24
Q

What is quick sort?

A
  • Picks a pivot and all elements less than the pivot go to the left of the array and all elements more than go to the right
25
What is a data structure?
- They are used to organize additional data.
26
What is augmenting a data structure?
- Adding extra information to the nodes or elements to support additional operations efficiently.
27
What is an Order Statistic Tree?
An augmented Binary Search tree where each node stores the size of its subtree
28
What is a Red-Black binary search tree?
Maintains balance by enforcing the red-black properties to ensure the tree's height stays logarithmic
29
four properties of a red black binary search tree
- Every node is either red or black - The root is always black - Red nodes cannot have red children - The path from every node to its descendent NULL nodes must have the same number of black nodes.
30
Time complexity of all operations regarding red black trees
O(log n)
31
What is recursion?
When a function calls itself to solve smaller instances of the same problem
32
What is the Master Method
- Gives a shortcut to find the asymptotic time complexity of recursive algorithms - T(n) = a x T(n/b) + f(n)
33
When to use the Master Method?
When an algorithm splits a problem into smaller subproblems.
34
What is the utility of the Master Method?
It's a fast way to find the Big O of recursive algorithms by plugging values into a standard form and comparing the work at each level of recursion