CSC148 Exam Study Questions 2024 with
Complete solutions (A Graded)
Huffman's algorithm - ANSWER used to organize the file compression by giving short codes to
frequent symbols and longer codes to infrequent symbols
byte - ANSWER an integer in the range 0-255
searching with sorted vs unsorted list - ANSWER unsorted : O(n)
sorted: log2(n) ( log(n)
general tree with n items insert, delete. - ANSWER insert can be fast, if you insert as a child of
the root - O(1), search and delete can be slow since you might need to check every item in the
tree - o(n) in the worst case
search efficiency in a BST: - ANSWER BST with n nodes has height logn and insert/delete/search
time of O(n) , if BST is balanced then it takes logn node accesses.
Python interpreter, java compiler, and pycharm and pythonTA - ANSWER -a program that
runs python code
-java compiler is a program that turns java code into a sequence of "Primitive instructions"
Pycharm and pythonTA are programs that analyze Python code and report potential problems
, Expressions vs statements - ANSWER Expression is a unit of code that, when evaluated
produces a single value, a statement is more general: evaluating a statement can produce a
value, or has some other effect.
EVERY expression is a statement, but not vice-versa!
Variable environment - ANSWER a map from variable names to values
Evaluating an Assign and consolidation - ANSWER name.evaluate-look up the variable name in
the current environment
evaluating an assign mutates the env
Assign.evaluate add a new variable binding to the current environment (mutates env)
Module - ANSWER a class that represents an entire Python program. Its
body is a list of statements
Sorting and the times, bubble, selection, insertion, quick, radix, merge? - ANSWER bubble ->
n^2, selection also n^2, insertion too, n^2
How does quicksort work? - ANSWER randomly select a pivot point, split list such that all
elements to the left are lower than P and all to the right are higher, then repeat the same
idea for the two partitions
Complexities of quicksort runtime - ANSWER If we always choose a pivot thats around median,
then the two partitians are about equal and the runtime is (nlog(n)), if we choose one that's
always min/max we get O(n^2),
Complete solutions (A Graded)
Huffman's algorithm - ANSWER used to organize the file compression by giving short codes to
frequent symbols and longer codes to infrequent symbols
byte - ANSWER an integer in the range 0-255
searching with sorted vs unsorted list - ANSWER unsorted : O(n)
sorted: log2(n) ( log(n)
general tree with n items insert, delete. - ANSWER insert can be fast, if you insert as a child of
the root - O(1), search and delete can be slow since you might need to check every item in the
tree - o(n) in the worst case
search efficiency in a BST: - ANSWER BST with n nodes has height logn and insert/delete/search
time of O(n) , if BST is balanced then it takes logn node accesses.
Python interpreter, java compiler, and pycharm and pythonTA - ANSWER -a program that
runs python code
-java compiler is a program that turns java code into a sequence of "Primitive instructions"
Pycharm and pythonTA are programs that analyze Python code and report potential problems
, Expressions vs statements - ANSWER Expression is a unit of code that, when evaluated
produces a single value, a statement is more general: evaluating a statement can produce a
value, or has some other effect.
EVERY expression is a statement, but not vice-versa!
Variable environment - ANSWER a map from variable names to values
Evaluating an Assign and consolidation - ANSWER name.evaluate-look up the variable name in
the current environment
evaluating an assign mutates the env
Assign.evaluate add a new variable binding to the current environment (mutates env)
Module - ANSWER a class that represents an entire Python program. Its
body is a list of statements
Sorting and the times, bubble, selection, insertion, quick, radix, merge? - ANSWER bubble ->
n^2, selection also n^2, insertion too, n^2
How does quicksort work? - ANSWER randomly select a pivot point, split list such that all
elements to the left are lower than P and all to the right are higher, then repeat the same
idea for the two partitions
Complexities of quicksort runtime - ANSWER If we always choose a pivot thats around median,
then the two partitians are about equal and the runtime is (nlog(n)), if we choose one that's
always min/max we get O(n^2),