Recent questions tagged goclasses-da-dpp

0 0 votes
2 2 answers
130
130 views
What is the order of growth of $\texttt{foo}$ in terms of $\texttt{n}$, where $\texttt{n}$ is the length of $\texttt{lst}$?Assume that slicing a list and calling $\texttt...
1 1 vote
2 2 answers
116
116 views
Select all sorting algorithms that run in worst-case cost $\text{Θ(n log n)}$.HeapSortInsertionSortMergeSortQuickSort
2 2 votes
2 2 answers
122
122 views
Selection sort works in a series of passes over an array. Choose the answer that shows how this array will appear after the first two passes of selection sort.Original ar...
1 1 vote
2 2 answers
114
114 views
How many comparisons will binary search be expected to perform to find one member of a list of $1000$ sorted numbers?$999$Approximately $20$Approximately $30$Approximatel...
1 1 vote
2 2 answers
146
146 views
A grid contains '$\texttt{s}$' for sand, '$\texttt{r}$' for rock, and $\texttt{None}$ for empty.The operation $\texttt{jumpdown(grid, x, n)}$ works on one column $\texttt...
1 1 vote
2 2 answers
123
123 views
Suppose $\texttt{zeroArray(3, 4)}$ creates a $2$D array with $3$ rows and $4$ columns, filled with zeros.Now consider:v = zeroArray(3, 4)Which expression correctly change...
2 2 votes
2 2 answers
126
126 views
Consider the following Python code:def group_by(s, fn): grouped = {} for x in s: key = fn(x) if key in grouped: grouped[key].append(x) else: grouped[key] = [x] return gro...
2 2 votes
2 2 answers
129
129 views
Consider the following Python code:def insert_items(s, before, after): index = 0 while index < len(s): if s[index] == before: s.insert(index + 1, after) index += 1 index ...
2 2 votes
3 3 answers
143
143 views
Consider the following Python code:def remove_dups(L1, L2): for e in L1: if e in L2: L1.remove(e) L1 = [1, 2, 3, 4] L2 = [1, 2, 5, 6] remove_dups(L1, L2) print(L1)What is...
2 2 votes
2 2 answers
237
237 views
A function $\texttt{deep_map(f, s)}$ replaces every non-list element $\texttt{x}$ inside a nested list $\texttt{​​​​​​​s}$ with $\texttt{f(x)}$.It modifies $\texttt{​​​​​...
2 2 votes
3 3 answers
220
220 views
A function $\texttt{shuffle(s)}$ takes a sequence $\texttt{s}$ with an even number of elements. It returns a new list by interleaving the first half of $\texttt{s}$ with ...
2 2 votes
3 3 answers
174
174 views
Consider the following Python code:s = [3] s.extend([4, 5]) s.extend([s.append(9), s.append(10)]) print(s)What is the output of the code above?[3, 4, 5, 9, 10][3, 4, 5, N...
2 2 votes
3 3 answers
195
195 views
Consider the following Python code:s = [9, 7, 8] a, b = s, s[:] print(a is s, b == s, b is s) print(a.pop()) print(a + b)What is the output of the code above?True True Tr...
2 2 votes
3 3 answers
236
236 views
Consider the following Python code:s = [6, 7, 8] print(s.append(6)) s.insert(0, 9) x = s.pop(1) s.remove(x) print(s)What is the output of the code above?None [9, 7, 8]Non...
6 6 votes
1 1 answer
414
414 views
Consider the following Python code:def virfib_sq(n): print(n) if n <= 1: return n return (virfib_sq(n - 1) + virfib_sq(n - 2)) 2 r4 = virfib_sq(4)What would be the outp...
4 4 votes
1 1 answer
238
238 views
Consider the following Python code:def virfib_sq(n): print(n) if n <= 1: return n return (virfib_sq(n - 1) + virfib_sq(n - 2)) 2 r3 = virfib_sq(3)What would Python disp...
3 3 votes
1 1 answer
203
203 views
Consider the following Python code:def virfib_sq(n): print(n) if n <= 1: return n return (virfib_sq(n - 1) + virfib_sq(n - 2)) 2 r2 = virfib_sq(2)What would be the outp...
3 3 votes
1 1 answer
199
199 views
Consider the following Python code:def virfib_sq(n): print(n) if n <= 1: return n return (virfib_sq(n - 1) + virfib_sq(n - 2)) 2 r1 = virfib_sq(1)What would be the outp...
2 2 votes
1 1 answer
226
226 views
Consider the following Python code:def virfib_sq(n): print(n) if n <= 1: return n return (virfib_sq(n - 1) + virfib_sq(n - 2)) 2 r0 = virfib_sq(0)What would be the outp...
2 2 votes
1 1 answer
224
224 views
Consider the following Python code:def total_first(t): if not t: return 0 return t[0][0] + total_first(t[1:]) data = [[2, 7], [5, 1], [3, 8], [4, 9]] print(total_first(da...
2 2 votes
1 1 answer
178
178 views
Consider the following Python code:def show(lst, i=0): if i == len(lst): return show(lst, i + 1) if lst[i] % 2 != 0: print(lst[i], end="") show([1, 2, 3, 4, 5])What is th...
2 2 votes
1 1 answer
163
163 views
Consider the following Python code:def count_greater(lst, v): if not lst: return 0 count = 1 if lst[0] v else 0 return count + count_greater(lst[1:], v) print(count_grea...
2 2 votes
1 1 answer
162
162 views
Consider the following Python code:def mystery(n): if n < 10: return n a = n // 10 b = n % 10 return mystery(a + b) print(mystery(678))What is the output of the code abov...
2 2 votes
1 1 answer
165
165 views
Consider the following Python code:def solve(n): if n <= 0: return 0 return n + solve(n - 2) print(solve(6), solve(5))What is the output of the code above?9 1212 912 12Re...
3 3 votes
1 1 answer
170
170 views
Consider the following Python code:class Node: def __init__(self, data): self.data = data self.next = None a = Node("A") b = Node("B") c = Node("C") d = Node("D") a.next ...
3 3 votes
1 1 answer
147
147 views
Consider the following Python code:class Node: def __init__(self, data): self.data = data self.next = None head = Node(20) tail = head new_first = Node(10) new_first.next...
3 3 votes
1 1 answer
134
134 views
Consider the following Python code:class Node: def __init__(self, data): self.data = data self.next = None n1 = Node(5) n2 = Node(10) n3 = Node(15) n4 = Node(20) n1.next ...
3 3 votes
2 2 answers
195
195 views
Consider the following Python code:class Node: def __init__(self, data): self.data = data self.next = None a = Node("A") b = Node("B") c = Node("C") a.next = b b.next = c...
4 4 votes
2 2 answers
178
178 views
Consider the following Python code:class Node: def __init__(self, value): self.value = value self.next = None n1 = Node(10) n2 = Node(20) print(n1.value, n1.next, n2.valu...
3 3 votes
1 1 answer
138
138 views
Consider the following Python code:class Node: def __init__(self, data): self.data = data self.next = None n1 = Node(10) n2 = Node(20) n3 = Node(30) n1.next = n2 n2.next ...