The Last Algorithm Course Flashcards

1
Q

What is the simplest Data Structure?

A

An array

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

What is Big O?

A

It is a way to categorize an algorithms time or memory requirements based on input

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

Why do we use Big O?

A

It will help us make decisions about what data structures and Algorithms to use. Knowing how they perform can help us make the best possible program.

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

What is the running time of this algorithm?

function sum_char_codes (n: string): number {
let sum = 0;
for (let i = 0; i < n.length; ++i) {
sum += n. charCodeAt (i) ;
}
return sum;
}

A

O(N)

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

What are the 3 concepts for time and space complexity?

A

1.Growth with respect to input
2.Constants are always dropped
3.Worst case is usually the way we measure

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

What is the running time of this algorithm?

function sum_ char_ codes (n: string) : number {
let sum = 0;
for (let i = 0; i < n.length; ++i) {
sum += n. charCodeAt (i) ;
}
for (let i = 0; i < n.length; ++i) {
sum += n. charCodeAt (i) ;
}
return sum;

}

A

O(N)

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

What is the running time of this algorithm?

function sum_ char_ codes (n: string) : number {
let sum = 0;
for (let i = 0; i < n.length; ++i) {
const charCode = n. charCodeAt (i) ;
// Capital E
if (charCode === 69) {
return sum;
}
sum += charCode;
}
return sum;
}

A

O(N)
(O of N)

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

What is the running time of this algorithm?

function sum char codes (n: string): number {
let sum = 0;
for (let i = 0; i < n. length; ++i) {
for (let j = 0; j < n.length; ++j) {
sum += charCode;
}
}
return sum;
}

A

O(N^2)

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

What is the running time of this algorithm?

function sum char_codes (n: string): number {
let sum = 0;
for (let i = 0; i < n. length; ++i) {
for (let j = 0; j < n.length; ++j) {
for (let k = 0; k < n. length; ++k) {
sum += charCode;
}
}
}
return sum;
}

A

O(N^3)

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

An example of O(n log n)

A

Quicksort

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

An example of O(log n)

A

Binary search trees

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

This is an example of what?

export default function bs_list(haystack: number[], needle: number): boolean
{

6 }
let 10 = 0;
let hi = haystack. length;
do {
const m = Math. floor(lo + (hi - 10) / 2);
const v = haystack[m];
if (v === needle) {
return true;
7 else if (v > needle) §
hi = m;
† else {
10 = m + 1;

} while (lo < hi);
return false;

A

Binary Search

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

What is the running time of Bubble Sort?

A

O(n^2)

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

What sucks about an array?

A

Deletion ( you can’t delete but can zero out something)
Insertion (you can’t insert, but you can write)
It’s Ungrowable

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

What is the running time from deleting or inserting in a linked list?

A

O(1)

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

What kind of structure is a queue?

A

FIFO (First In First Out)

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

What is the opposite of a Queue?

A

A Stack

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

For a linked list, what’s the only way you’re able to search for an item?

A

Using linear search

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

TRUE or FALSE:
There is no such thing as a binary search on a linked list

A

True

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

Which one is better? An array list or linked list?

A

It depends on the situation. If you are popping or pushing from the end, then any can work well.
There’s a trade off
Getting sucks on linked list. Removing from the front sucks on array list because then you have to move all the other values to the left by one.

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

What is Recursion?

A

The simplest way to think of recursion is a function that calls itself until the problem is solved

22
Q

What is a Base Case?

A

A base case is the point in which the problem is solved at.

23
Q

When do you use recursion?

A

When you can’t use a for loop

24
Q

What is bubble sort?

A

It is a sorting algorithm that works by comparing the two elements next to each other and swapping them if they are not in order.
It goes back and repeats until it’s all sorted.

25
Q

What is QuickSort?

A
26
Q

What is Divide and Conquer?

A

Is to be able to split your input into 2 chunks, 3 chunks, or whatever the splitting is and be able to go over those smaller subsets and solve things faster and be able re split it again and again

27
Q

What is the running time of QuickSort?

A

O(nlogn)

28
Q

What running time can QuickSort also be besides O(nlogn)?

A

O(n^2)

29
Q

What is a doubly linked list?

A
30
Q

In a tree, what is a root?

A

The most parent node. The first

31
Q

In a tree, what is the height?

A

The longest path from the root to the most child node

32
Q

What is the running time of a tree?

A

O(n)
(O of n)

33
Q

Where is the root in a pre order?

A

In the beginning

34
Q

Where is the root in an in order?

A

The beginning

35
Q

Where is the root in a post order?

A

The end

36
Q

What is the Depth First Search data structure?

A

Stack

37
Q

What is a Breadth First Search data structure?

A

Queue

38
Q

What is the running time of a Breadth-First Search?

A

O(n) but with JavaScript it’s an O(n^2)

39
Q

What is the running time of the find() algorithm?

A

O(h) which is between O(logn) and O(n)
(O of height)

40
Q

What is a Heap data structure?

A

It is a binary tree where every child and grandchild is smaller (MaxHeap) or larger (MinHeap) than the current node.

41
Q

What is a Heap data structure also known as?

A

A priority queue

42
Q

Is a Heap always a full/complete tree?

A

Yes. It is always adding from left to right and never has an empty space/gap

43
Q

What is the running time of delete or insert in a Heap?

A

O(logn)

44
Q

What is a trie tree? (pronounced tree but people call them try trees)

A

Used for storing and searching a specific key from a set.

45
Q

TRUE OR FALSE:
All Trees are graphs

A

True

46
Q

What is the running time of BFS (Breadth First Search and DFS (Depth First Search) in a Graph?

A

O(V + E)
(O of vertex + edge)

47
Q

What is the run time of Dijkstra’s Sortest Path?

A

O(logV(V + E)

48
Q

What is the run time of search, insert, and delete in a hash table ?

A

O(1)

49
Q

What does LRU stand for?

A

Least Recently Used

50
Q

What is LRU?

A

It’s a cashing mechanism that we will evict the least recently used item