Week 7-11 Flashcards

(195 cards)

1
Q

3 advantages of Functions are:
1. Helps ________ code into blocks.
2. Makes program more ______________ and easier to update.
3. Can be reused, preventing _____________.

A

organize; readble; redundancy

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

____________ are written to complete a specific task.

A

Functions

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

What describes taking a complex set of instructions and packaging them together inside a block of code?

A

Functions

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

When using ‘def’ function, parentheses may contain optional ____________.

A

parameters

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

Is there a limit on the amount of lines of code that are in a function?

A

No

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

T/F: Functions can contain ANY valid python code.

A

T

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

“name” refers to the __________(parameter/argument) and “Taylor” refers to the ____________(parameter/argument).

A

parameter; argument

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

What is: the name of the data that we use inside of the function?

A

Parameter

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

Are there a limit of the number of parameters that can be used?

A

No

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

What is: data that is being passed to the function?

A

Argument

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

It is important to order the 2 ___________ the same as the 2 ________________.

A

arguments; parameters

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

In which type of argument does order matter?

A

Positional

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

Which argument does order not matter?

A

Keyword

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

What is the most basic type of argument in python?

A

Positional arguments

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

Positional arguments are passed to a function based on their ______________.

A

position/order

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

Keyword arguments allow you to pass arguments to a function using their _______________ __________.

A

Parameter names

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

Which argument is specified by key-value pairs and are separated by commas?

A

Keyword Arguments

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

Which argument makes code more self-explanatory?

A

Keyword arguments

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

Which argument is the longest?

A

Keyword

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

my_first_function(a=1, b=2, c=3) is an example of what?

A

Keyword Argument

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

Where is a local scope defined?

A

Inside a function

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

Which scope cannot be accessed outside of a function?

A

Local scope

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

Def greet():
-message = “Hello World!”
-Print(message)

What is the local variable?

A

Hello World!

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

What would be printed in the following:

Def funcB(a,b):
-A = 2
-B = 3
-Print(“Inside funcB a,b = “, a,b)

A

2,3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What would be printed in the following and why: Def funcB(a,b): -A = 2 -B = 3 Def funcA(): -A = 10 -B = 20 -FuncB(a,b) -Print("Inside funcA a,b = ",a,b)
10,20 2,3 are local to 'funcB' therefore, would not get printed in 'funcA'
26
What would be printed: Def greet(): -Print("Hello!") Def welcome(): -Greet() -Print("Welcome!") Welcome()
Hello! Welcome!
27
Function immediately exists when "__________" is used.
return
28
Which statement in python allows functions to send back a value as output?
Return
29
What is the output? Def add(a,b): -Return a+b Result = add(3,4) Print(result)
7
30
Can a function return multiple values?
Yes
31
If local variables have the same name as global variables, will there be conflict?
No
32
Local variables and global variables are considered separate ____________.
entities
33
When accessing a variable within a function, Python searches for a variable _____________ before checking the ___________ scope.
locally; global
34
What is the output and why? def foo(x): -y=1 -x += 5 -print("in foo() y=",y) -print("in foo() x=",x) x=10 foo(x) print("x=",x)
10; the variable in the main program cannot be overridden
35
If the variable is local, it can be ___________.
overridden
36
Can you override a variable in the main program?
No
37
What would be the output and why? def foo(x): -y=1 -x += 5 -print("in foo() y=",y) -print("in foo() x=",x) x=10 foo(x) print("y=",y)
Error; y is local to 'foo()'
38
__________ are step-by-step procedures used to solve specific problems or perform tasks.
Algorithms
39
Algorithms require careful ____________ and consideration.
planning
40
Computer science is REALLY about: ________________.
Algorithms
41
Algorithms force you to think of the _________ rather than just the solution.
process
42
What describes a way to design computer solutions to problems?
Algorithms
43
What is step one of constructing algorithms?
Define the problem
44
What step of constructing algorithms do you determine specific goals and objectives of the algorithm?
Step 2 - Analyze the problem
45
What do you do in step 3, design the algorithm?
develop high-level plan to solve
46
In which step do you want to ensure that each step of the algorithm is well-defined and unambiguous?
Step 4 - Break down the algorithm
47
When breaking down the algorithm, you want to divide into smaller, _____________ subproblems.
interconnected
48
Step 5 of constructing an algorithm is specifying _________ and __________.
inputs; outputs
49
Which type of algorithm is considered to be a visual representation?
Flowchart
50
Which type of algorithm is considered to be a language-like representation?
Pseudocode
51
What describes using symbols to depict the sequence of steps, decision points, loops, etc in order to understand an algorithm at a glance?
Flowchart
52
Pseudocodes use ___________ language and programming constructs.
Natural
53
What provides human-readable representations of algorithm steps?
Pseudocode
54
Step 7 of constructing an algorithm is to test and _________.
refine
55
In what stage of constructing an algorithm do you implement the algorithm in the programming language of your choice?
Step 7 - Test and Refine
56
In step 7, you want to add ________ statement to help track down problems.
Print
57
Debug your algorithm in step 7, which is?
Test and Refine
58
Which stage of constructing an algorithm do you not want to put a lot of focus on?
Step 8 - Analyze complexity and optimize
59
In step 8, you want to optimize algorithm by revising certain steps. What is this step called?
Analyze complexity and optimize
60
What is the very last step of constructing an algorithm?
Step 9 - document + maintain
61
In the last step of constructing an algorithm, you will want to consider ________ control to manage algorithm updates.
version
62
_____________ is a fundamental operation in computing.
Searching
63
What involves finding a specific item or value from collection of data?
Searching
64
What is searching essential for?
efficient data retrieval
65
What describes the process of locating particular elements or records within a dataset?
Searching
66
"Efficient" searching improves ________________ of systems.
performance
67
Searching is important in helping us make ____________.
decisions
68
Searching is crucial for what 2 things?
Finding info quickly + efficiently
69
__________ Search checkes each element until a match is found or the end of a collection is reached.
Linear
70
What is also known as "sequential search?"
Linear search
71
Which type of Algorithms search searches sequentially?
Linear search
72
In a Linear search for '5' what would be the output index of the following: [1, 11, 7, 8, 5, 3, 10, 9, 4]
4
73
Put in the #missingline: def linear_search(arr,target): -for i in range(len(arr)): --#missingline ---return i
if arr[i] == target:
74
How many loop iterations are needed to find the number 5 in this list: [1, 11, 7, 8, 5, 3, 10, 9, 4]
5 (index + 1)
75
In a linear search, searching backwards may be useful when:
- desired order is from last to first - expecting target value is near end of list
76
___________ Order ___________ describes when desired order of search results is from last occurrence to first.
Reverse; Requirement
77
When identifying the most recent entries in a log, what type of backwards search would you use?
Reverse Order Requirement
78
___________ Search is used when you have an expectation that the target value is more likely to be found towards the end of a list.
Optimized
79
When defining a linear search in a for loop, what is the line that ensures index 0 is included?
for i in range(len(arr) -1, -1, -1):
80
When defining a linear search in a while loop, what is the line that ensures index 0 is included?
while index >= 0:
81
In a linear search, for loops use _______ function and while loops use ________ function.
range; length
82
If we are wanting to find multiple occurrences in a linear search, what line of code needs to be included in a for loop?
occurrences.append(i)
83
If we are wanting to find multiple occurrences in a linear search, what line of code needs to be included in a while loop?
indexes.append(i)
84
When is a linear search NOT efficient to use?
Long lists
85
A benefit of linear searches is they are ___________________ to implement.
straightforward
86
What is the time complexity of a linear search in worst-case scenerio?
O(n)
87
O(n) represents what worst-case scenario time complexity?
Linear search
88
What is the worst-case scenario for linear searches? HINT: 2 parts
When target element is @ end of the list or is not present
89
In the time complexity 'O(n)' what does 'n' represent?
elements in the list
90
Linear searches are suitable for ________ lists.
small
91
Linear searches are suitable when the list is NOT ___________.
sorted
92
_________ Search serves as a basis for more advances search algorithms.
Linear
93
___________ and ________ searches are considered more advanced.
Linear; Binary
94
Binary searches repeatedly _____________ the search space in ________.
divide; half
95
Binary searches are ideal for large ___________ datasets.
sorted
96
What is the time complexity of a binary search?
O(log n)
97
In a binary search, the algorithm's execution time grows _____________ with input size.
logarithmically
98
Binary searches are highly efficient for __________ datasets.
large
99
___________ searches are ONLY efficient when you can guarantee the list is sorted.
Binary
100
In a binary search, if the middle element is larger than the target, what occurs?
repeat process on the left half of the list
101
In a binary search, if the middle element is less than the target, repeat the process on the _________ half of the list.
right
102
A binary searches reduces search space in half by each _____________.
iteration
103
What is one disadvantage of a binary search if the data set requires sorting prior to performing the search?
Upfront cost is expensive
104
Choosing the right sorting algorithm requires considering ___________ size.
input
105
Choosing the right sorting algorithm requires considering _________ requirements.
memory
106
Stability must be considered when choosing the right __________ algorithm.
sorting
107
___________ considerations must be considered when choosing the right sorting algorithm.
Performance
108
Which sorting algorithm repeatedly compares adjacent elements and swaps them if they're in the wrong order?
Bubble Sort
109
Which sorting algorithm gradually moves larger elements towards the end of the list?
Bubble Sort
110
In Bubble Sort, we need ________ passes over the list.
n-1
111
Does Bubble Sort detect if the list is sorted or when it becomes sorted?
No
112
What would happen to index zero in the following situation: list[0] = list[1] list[1] = list[2]
It would disappear
113
In Bubble Sorting, after each pass, 1 less ________ comparison is needed.
comparison
114
When writing a Bubble Sort, should the print statement be in line with the if statement?
Yes
114
What is the variation of Bubble Sort called?
Short Bubble Sort
115
Short Bubble Sort is also known as ____________ Bubble Sort.
Optimized
116
What type of sorting algorithm includes optimization to reduce the number of unnecessary comparisons?
Short Bubble Sort
117
Short Bubble Sort introduced a ____________ flag called "____________".
Boolean; "swapped"
118
What does the boolean flag called "swapped" track in a Short Bubble Sort?
whether any swaps were made in a pass
119
Short Bubble Sort continues until a pass completes without any __________. This indicates the list is __________.
swaps; sorted
120
Which type of sorting algorithm is useful for educational purposes?
Short Bubble Sort
121
What is the time complexity of a Short Bubble Sort?
O(n^2)
122
What will perform better for partially sorted lists, Bubble Sort or Short Bubble Sort?
Short Bubble Sort
123
Generally, Short Bubble Sort is less ____________ compared to more advanced sorting algorithms.
efficient
124
Which sorting algorithm is simple and intuitive?
Selection Sort
125
Which sorting algorithm works by finding the minimum element from the unsorted part of the list and places it at the beginning of the list?
Selection Sort
126
What is Selection Sort guaranteed to perform?
Only one swap per pass over any list
127
Selection Sort is beneficial when the ________ of swapping elements is high.
cost
128
Which 2 sorting algorithms have the same time complexity at the worst-case scenarios?
Bubble Sort and Selection Sort
129
Which sorting algorithm does the following describe: find minimum value, move to the left, repeat
Selection Sort
130
Which sorting algorithm uses "find_minimum()" ??
Selection Sort
131
Selection Sort returns the index of the ___________ element.
minimum
132
What describes the amount of time an algorithm takes to run as a function of the input size?
Time Complexity
133
What is the best-case scenario in a sequential search?
The target is the very first element
134
What is the most common analysis when considering time complexity?
Worst-case scenarios
135
Growth rate of a function is also known as _________ of the function.
Order
136
What is the KEY in determining an algorithm's computational time complexity?
Input size
137
What is the average-case scenario in a Linear search?
of items in list / 2
138
After the 3rd comparison in a Binary Search, there would be ________ n items left.
1/8
139
What describes the worst-case scenario in a Binary search?
n/2^k = 1
140
In Bubble Sort, outer loops control the _________ of passes through the list, while the inner loop compares adjacent ____________ and swaps if necessary.
number; elements
141
In Bubble Sort, which loop iterates n-1 times?
Outer
142
Which sorting algorithm(s) have the worst-case scenario of the # of swaps being equal to the number of comparisons? HINT: there are 2
Bubble and Short Bubble Sort
143
Selection Sort makes more/equal/less comparisons as Bubble Sort?
equal
144
T/F: Selection Sort requires different number of iterations, comparisons, adn swaps regardless of initial order of the list.
F
145
___________ Time Complexity has a fixed number of operations regardless of input size.
Constant
146
Which Time Complexity is the most efficient algorithm?
Constant
147
Accessing an element in a list by its index is an example of a ____________ Time Complexity.
Constant
148
_____________ Time Complexity divides the input size by a constant factor in each step.
Logarithmic
149
Binary searching in a sorted list is an example of what type of Time Complexity?
Logarithmic
150
Which type of Time Complexity performs a constant number of operations for each element in the input?
Linear Time Complexity
151
Traversing a list to find a specific element is an example of __________ Time Complexity.
Linear
152
When the running time is proportional to the input size we have a ____________ Time Complexity.
Linear
153
Selection Sort and Bubble Sorts are examples of ________________ Time Complexity.
Quadratic
154
When the running time is proportional to the square of the input size we have a __________________ Time Complexity.
Quadratic.
155
Quadratic Time Complexities perform ___________ iterations over input.
nested
156
List the best and worst-case scenarios for Linear Search.
Best = 1 Worst = n
157
List the best and worst-case scenarios for Binary Search.
Best = 1 Worst = log n
158
List the best and worst-case scenarios for Bubble Sort.
Best = n^2 Worst = n^2
159
List the best and worst-case scenarios for Short Bubble Sort.
Best = n Worst = n^2
160
List the best and worst-case scenarios for Selection Sort.
Best = n^2 Worst = n^2
161
Time Complexity provides a _______________ understanding of an algorithm's efficiency.
theoretical
162
What helps when selecting efficient algorithms for various computation problems?
Time Complexity
163
Other than Time Complexity, ______________ usage also impacts actual performance.
memory
164
The BEST algorithm choice depends on 2 things: 1. Specific ___________; 2. ________ constraints.
problem; time
165
What are the 3 key components of the Von Neumann computer architecture?
1. Central Processing Unit (CPU) 2. Memory Unit 3. Input/Output (I/O) Devices
166
In the Von Neumann computer architecture, the Memory Unit stores both...?
data + instructions
167
What architecture forms the basis of modern computing systems today?
Von Neumann
168
The Von Neumann computer architecture performs _____________ execution.
sequential
169
What type of communication pathway does the Von Neumann architecture use?
Single Bus
170
The number of Quantization levels represents ____________.
resolution
171
The greater the resolution, the more accurate representation of original ____________ signal.
analog
172
Quantization error is also known as ________.
noise
173
Sampling rate is also known as ___________.
frequency
174
What describes the number of samples taken per second from an analog signal during digitization? HINT: there are 2 words that could be right
Sampling Rate / frequency
175
If data changes every 10minutes, how often do you need to sample?
Every 5 minutes
176
The Nyquist-Shannon Theorem states that the sampling rate must be at least ___________ the highest frequency component.
twice
177
What sampling theorem describes that the sampling rate must be 2x the highest frequency?
Nyquist-Shannon
178
We want to sample an analog signal every 0.2 seconds. What would the sampling frequency be?
1/0.2 = 5Hz
179
_______ are a collection of logic gates.
Circuits
180
________ ________ are the fundamental building blocks of digital circuits.
Logic Gates
181
Which logic gates needs both A + B to be 1 for the output to be 1?
AND
182
Which gate needs @ least one input to be 1 in order for the output to be 1?
OR
183
In the ______ gate, if the input is 0, the output is 1.
NOT
184
Which logic gate has the highest precedence?
NOT
185
In the XOR gate, what happens when both inputs are 1?
output = 0
186
In the XOR gate, what happens if both inputs are 0?
output = 0
187
In an XOR gate, when is the output 1?
When the inputs are different from each other (ex. 0 and 1)
188
Is the XOR gate considered a fundamental gate?
No
189
How many bytes are in 16 bits?
2
190
Communativity means that the order of __________ DOES/DOES NOT affect the result.
DOES NOT
191
Communitivity refers to ________ while associative refers to ___________.
order; grouping
192
Is "A AND B" equal to "B AND A" ???
Yes
193
Which 2 logic gates meant he same thing when the order of inputs are changed?
AND + OR
194
What describes the following: A AND(B AND C) = B AND(A AND C)
associative