Data Structures Flashcards

1
Q

What are data structures?

A

the elementary particles of algorithms, data structures are woven into the fabric of computer science and are essential building blocks of many coding solutions.

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

True or False

Data structures can be boiled down to the manipulation of data

A

True

manipulating data involves structuring that data.

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

What is complexity analysis?

A

A single coding problem may have multiple solutions using different data structures, they are not all equal (ie time vs space)

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

During a coding interview, when asked (about your code) “can you improve it and do better” is usually referring to?

A

complexity analysis

Did you choose the most efficient data structure (nested for loop over a hash table) or did the question place more emphasis on space vs execution time?

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

What is space-time complexity?

A

time: how fast algorithm runs
space: how much memory an algorithm is utilizing

all depends on the use-case

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

True or False

Memory is a bounded type of storage

A

True

memory is finite (limited)

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

bits are?

8 bits is a?

A

binary 0 and 1’s (base 2)

byte

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

True or False

pointers can be allocated in memory as well

A

True

and pointers aren’t memory intensive and don’t have to be in continuous memory.

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

True or False

Accessing a memory address is just about instantaneous?

A

True

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

True or False

32bit (fixed-width) is 4 bytes memory

A

True

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

True or False

64bit (fixed-width) is 8 bytes memory

A

True

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

A single byte can represent up to ___ data values

A

256

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

Constant time is represent as?

A

O(1)

if the value of T(n) is bounded by a value that does not depend on the size of the input. ie, accessing any single element in an array takes constant time as only one operation has to be performed to locate it.

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

Logarithmic time is represented as?

A

O(log(n))

Algorithms taking logarithmic time are commonly found in operations on binary trees or when using binary search.

An O(log n) algorithm is considered highly efficient, as the ratio of the number of operations to the size of the input decreases and tends to zero when n increases.

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

Linear time is represented as?

A

O(n)

the running time increases at most linearly with the size of the input.

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

Log-Linear time is represented as?

A

O(nlog(n))

gives us a means of notating the rate of growth of an algorithm that performs better than O(n2) but not as well as O(n).

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

Quadratic time is represented as?

A

O(n2)

represents an algorithm whose performance is directly proportional to the squared size of the input data set (think of Linear, but squared). … In doing so, we are passing over the same array twice with each search.

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

Cubic time is represented as?

A

O(n3)

An algorithm is said to run in cubic time if the running time of the three loops is proportional to the cube of N. When N triples, the running time increases by N * N * N. Time Complexity of a loop is said as O(log N) if the loop variables is divided / multiplied by a constant amount.

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

Exponential time is represented as?

A

O(2n)

denotes an algorithm whose growth doubles with each additon to the input data set. If you know of other exponential growth patterns, this works in much the same way. The time complexity starts off very shallow, rising at an ever-increasing rate until the end.

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

Factorial time is represented as?

A

O(n!)

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

True or False

In terms on Big O Notation, it’s always in the context of the worst case senario?

A

True

Big O defines addresses when a function performs it’s worst in time complexity, when sh!t goes sideways!

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

In Big O Notation, which has a better time complexity? O(n) or O(1)

A

O(1) constant time

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

In Big O Notation, which has a better time complexity? O(n) or O(log n)

A

O(log n) logarithmic time

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

In Big O Notation, which has a better time complexity? O(n3) or O(n!)

A

O(n3) cubic time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Cite the time complexity O(1)
constant time
26
Cite the time complexity O(log n)
logarithmic time
27
Cite the time complexity O(n)
linear time
28
Cite the time complexity O(n \* log n)
log linear time
29
Cite the time complexity O(n2)
quadratic time
30
Cite the time complexity O(n3)
cubic
31
Cite the time complexity O(2n)
exponential
32
Cite the time complexity O(n!)
factorial
33
what is log(n) complexity analysis? ## Footnote *logb(x)=y iif by=x*
log of the num x, given a base b, is equal to y, if and only if, base to the power of y is equal to x
34
True or False In **log(n)** the base is assumed to be base 2(binary)? *logb(x)=y iif by=x*
True
35
True or False *logb(n)=y iif by=n* **or** *log(n)=y iif 2y=n* are one in the same
True This is just log(n)
36
True or False Computer science deals with log base 10?
False Computer science uses log base 2, dealing with binary values.
37
*log(1) = ?*
0 ## Footnote *20 = 1*
38
*log(4) = ?*
2 ## Footnote * 2? = 4* * 2 \* 2 = 4*
39
*log(16) = ?*
4 2? = 16 2 \* 2 \* 2 \* 2 = 16
40
How would you find the log of *(n)*?
*2? = (n)* the ? is the log of n
41
True or False *2? = n* when you double *n* you're increasing ? by 1
True
42
*2? = n* when you increase *? by one,* you're _______ *n*
doubling
43
*24 = 16* What is ? in *2? = 32*
? is increased by 1 to 25 ## Footnote *25 = 32*
44
logarithmic time *O(log N)* is particular efficient because?
It's increases by 1 when the input *(n)* doubles! ## Footnote * log(n) = y* * y is the ? in **n?***
45
Array - Cite the time complexity Accessing a value at a given index?
*O(1)* constant time
46
Array - Cite the time complexity Updating a value at a given index?
*O(1)* constant time
47
Array - Cite the time complexity Inserting a value at the begining?
*O(n)* linear time
48
Array - Cite the time complexity Inserting a value in the middle?
*O(n)* linear time
49
Array - Cite the time complexity Inserting a value at the end (dynamic array)?
amoritized *O(1)* contstant time
50
Array - Cite the time complexity Inserting a value at the end (static array)?
*O(n)* linear time
51
Array - Cite the time complexity Removing a value at the begining?
*O(n)* linear time
52
Array - Cite the time complexity Removing a value in the middle?
*O(n)* linear time
53
Array - Cite the time complexity Removing a value at the end?
*O(1)* constant time
54
Array - Cite the time complexity Copying an array?
*O(n)* linear time
55
A func that runs at constant time *O(1)* means what exactly?
That the time does NOT change based on the len of the input or *(n)* usually a basic operation like looking up an array/list value via it's index
56
What is the time complexity of \_\_init\_\_ of an array object?
*O(n)* linear time
57
What is the time complexity when traversing an array?
* O(n) linear time* * O(1)* *space*
58
What is the time complexity when copying an array?
* O(n) linear time* * O(n) space*
59
What is amortized analysis?
a method for analyzing a given algorithm's complexity, or how much of a resource, especially time or memory, it takes to execute.
60
What is the time complexity of using the built-in pop() method to remove and element from the end of an array?
constant time *O(1)*
61
What is the time complexity of using the built-in pop(34) method to remove and element from the all but the end of an array?
linear time *O(n)*
62
True or False Like an array, linked lists are stored in continuous memory locations?
False Linked lists use pointers in memory
63
What is this? [1, 2, 3, 4, 5]
an array
64
What is this? [1-\>, 2-\>, 3-\>, 4-\>, 5]
linked list
65
A listed list has what time complexity?
*O(i) time* must traverse through *i* nodes
66
Linked list - time complexity Accessing the head?
*O(1)* constant time
67
Linked list - time complexity Accessing the tail?
*O(n)* linear time
68
Linked list - time complexity Accessing the middle node?
*O(n)* linear time
69
Linked list - time complexity Inserting / removing the head?
*O(1)* constant time
70
Linked list - time complexity Inserting / removing the tail?
*O(n)* to access + *O(1)*
71
Linked list - time complexity Inserting / removing the middle node?
*O(n)* to access + *O(1)*
72
Linked list - time complexity Searching for a value?
*O(n)* linear time
73
Doubly linked list - time complexity Accessing the head?
*O(1)* constant time
74
Doubly linked list - time complexity Accessing the tail?
*O(1)* constant time
75
Doubly linked list - time complexity Accessing a middle node?
*O(n)* linear time
76
Doubly linked list - time complexity Inserting / removing the head?
*O(1)* constant time
77
Doubly linked list - time complexity Searching for a value?
*O(n)* linear time complexity
78
Doubly linked list - time complexity Inserting / removing the tail?
*O(1)* constant time
79
Doubly linked list - time complexity Inserting / removing a middel node?
*O(n)* to access *+ O(1)*
80
True or False Like an array a link-list can be indexed
False Linked lists have nodes that don't function like an arrays idx
81
True or False The space time for both the \_\_init\_\_ of an array and linked list is *O(n)* linear time
True
82
True or False In a Python dict (hash table) inserting, deleting, and searching all have a time complexity of *O(1)* constant time!
True on average **but** *O(n)* linear time in worst case senario, collisions and having to rely on a linked-list data structure underneath.
83
True or False Hash tables can have different data types as *keys,* these keys are subjected to a hash function underneath that allows for *O(1)* time interactions, this hash value is equilivent to an array's index?
True
84
Describe how a hash function operates.
For a key of a str data type *'foo'* Is transposed to its askey numerical value 102 ascii these key values are summed and the modulus operator based on the length of the hash table (underlying array) is used to calculate the index to store the key-value pair
85
True or False A hash table in which two keys equal the same index or hash value is then subjected to a linked-list data structure.
True
86
What is a collison when describing a hash table?
When more than a single *key* is assigned (hashed to) indentical values.
87
True or False In a hash table keys can be described as the *heap* when collisions are involved and a linked list data structure is being implemented on a hash table.
True
88
True or False hashing keys are *O(1)* constant time operations?
True
89
What is an array-like structure that follows the **LIFO**: Last In First Out rule?
a stack
90
Pushing an element on a stack is what time complex?
*O(1)* constant time
91
Popping or removing an element from a stack is what time complexity?
*O(1)* constant time
92
Peeking at the top element of a stack is accomplished in what time complexity?
*O(1)* constant time
93
Searching for an element in a stack has what time complexity?
*O(n)* linear time
94
An array-like data structure that implements the **FIFO**: First In First Out rule?
a Queue
95
*Enqueuing* a queue has ___ time complexity.
*O(1)* constant time
96
*Dequeuing* a queue takes ____ time complexity
*O(1)* constant time
97
Peeking a the first element in a queue is perform in ____ time
*O(1)* constant
98
Searching for an queue element is performed in _____ time
*O(n)* linear
99
True or False A stack is usually implemented with a dynamic-array or a singly-linked list
True
100
True or False A queue is implemented with a doubly linked-list
True
101
True or False strings are stored in memory as arrays of integers
True
102
True or False strings are mutable
True
103
What is the time complexity of the string code? ## Footnote ``` string = 'this is a string object' newString = "" ``` for character in string: newString += character
*O(n2)* because each addition of a char to newString creates an entirely new string and is itself *O(n)* operation
104
Traversing a str has what time complexity?
* O(n)* time identical to an array * O(1)* space
105
The complexity of copying a string?
*O(n)* time and space
106
The complexity of getting a string?
*O(1)* constant time and space
107
True or False strings are immutable
True The go around is to create a new string objec and thus a O(n2) time and space complexity or split the string into a appendable list
108
Define a collection of nodes or values called **vertices** that may be related; relations between vertices are called **edges**
graph
109
a ______ cycle occurs in a ______ when three of more vertices are connected so as to form a closed loop
graph
110
a graph that has no cycles
acyclic graph
111
a graph that has at least one cycle
cyclic graph
112
a graph whose edges are directed, meaning that they can only traverse in one direction, which is specified.
directed graph
113
a graph whose edges are undirected, meaning they can traverse in both directions
undirected graph
114
if for every pair of vertices in the graph there's a path of one or more edges connection the given vertices
connected graph
115
Cite two attributes of a direct graph
**strongly connected** - bidirectional **weakly connected** - not bidirectional
116
What is a graph in space complexity?
***O(v+e)*** *vertices + edges*
117
What are the two ways to traverse a graph?
* breath* first search * depth* first search
118
What is a graph in time complexity?
* O(v+e)* * vertices + edges*
119
A data structure that consists of nodes, each with some value and pointers to child-nodes, which recursively form _____ in the tree
*subtrees*
120
The first node in a tree is referred to as the _____ while the nodes at the bottom of a tree (nodes with no child-nodes) are referred to as ____ \_\_\_\_ or simply \_\_\_\_\_\_.
*root leaf nodes, leaves*
121
The paths between the root of a tree and its leaves are called _______ and the _____ of a tree is the length of its longest branch.
*branches, height*
122
A tree is effectively a \_\_\_\_\_\_
*graph*
123
A tree is effectively a graph that's \_\_\_\_\_\_, \_\_\_\_\_\_\_, and _______ that has an explicit root node, and whose nodes all have a single \_\_\_\_\_\_\_
*connected, directed, acyclic, parent*
124
There are many types of trees and tree-like structures, including
*binary trees, heaps, and tries* (**pronounced** *trees*)
125
A tree whose nodes have up to two child-nodes
binary tree
126
A tree whose nodes have up to ***k*** child nodes
**K-ary** tree A binary tree is a *k*-ary tree where *k* == 2
127
A binary tree whose interior nodes all have two child-nodes and whose leaf nodes all have the same depth is a?
**perfect** binary tree
128
A binary tree that's *almost* perfect; itls interior nodes all have two child-nodes, but its leaf nodes don't necessarily all have the same depth. Futhermore, the nodes in the last level of a _________ are as far left as possible.
*complete binary tree*
129
A binary tree whose nodes all have left and right subtress whose heights differ by no more than 1
balanced binary tree
130
A binary tree whose nodes all have either two child-nodes or zero child-nodes
full binary tree