CSCI 260 Fall 2026 Homework Questions Bank
Questions: This is a bank of questions. The list may contain some
that require material we have not yet covered, perhaps that we will not cover
in this course. I will try to keep it listed so that any that I believe you
may not have the suitable preparation for are BELOW the line that says, Future
Questions
-
Give an appropriate loop invariant for the correctness of Kruskal's algorithm. You don't have to prove it holds, but you do have to demonstrate that it is a "good" loop invariant.
-
[Tricky!]
When an adjacency-matrix representation is used, most graph algorithms require time
Θ(V2), but there are some exceptions. Show that determining whether a
directed graph contains a sink -- a vertex with in-degree |V|-1 and
out-degree 0-- can be determind in time O(v), even if the adjacency matrix
representation is used.
-
[4 marks] Give the DFS tree that results from running Depth First Traversal on the following graph
with source vertex 1.
-
Explain the difference between linear probing and double hashing.
-
Show the table that results when the table size m is 11,
and the following is the primary hash function:
h10(k)=(10*k mod 23) mod 11
h is an example of prime multiplicative hashing, and such
functions (used with larger primes, and appropriate factors) are pretty
good at distributing in a way that looks random. The value factor here is called
the seed. This class of hash functions was explored in the 1970's.
-
Use Double Hashing with Chaining on the following sequence of inserts
and show the resulting table:
90, 14, 30, 56, 12, 9, 100, 60, 3, 20, 1
| 90 |
14 |
7 |
56 |
12 |
35 |
100 |
60 |
3 |
20 |
1 |
| 3 |
2 |
1 |
8 |
5 |
5 |
0 |
2 |
7 |
5 |
10 |
| 2 |
6 |
7 |
0 |
4 |
3 |
4 |
4 |
3 |
4 |
1 |
-
Do the same but using closed hashing, with a
secondary hash function of:
h2(k)=k mod 8
-
Why store things in a linked list to handle collisions?
Would it be useful to make a little AVL tree in each
slot? What would that do to the running time of
the algorithm? (Trick question. Do we mean the
expected running time or the worst case?)
-
Now execute, on the closed hashing example (2) above,
delete(20), delete(35), delete(3), ins(21)
- AVL trees: Show the result of the following set of insertions
and deletions from an initially empty tree.
insert: 1,3,5,7,9,11, 13,15,17, 19, 21 in that order
then delete: 11, 17
-
B-tree of order m under Knuth's definition (what we studied in class)
has:
1. Every node has at most m children.
2. Every node, except for the root and the leaves, has at
least ⌈m/2⌉ children.
3. The root node has at least two children unless it is a leaf.
4. All leaves appear on the same level.
5. A non-leaf node with k children has k-1 keys.
Draw a B-tree of order 3 that contains the keys
15, 22, 24, 35, 36, 100, 112, 200, 235, 237, 290, 300
-
Find some coin denominations such that the greedy algorithm for
change-making is not always optimal, and give an example amount
for which greed does not give the optimal number of coins.
-
Write the pseudocode for Strassen's Algorithm when the matrices are
square and n is a power of 2. How would you change the
algorithm so that it can multiply an m by w matrix
with a w by n matrix, yielding a m by
n matrix?
-
[10 marks]
Give pseudocode for an O(n2) algorithm that will compute the length of the
longest monotonically non-decreasing subsequence of a sequence of integers. The subsequence need not be contiguous.
The input is an array A[0..n-1] of integers. The algorithm should also construct
an array S[0..n-1] of the integers in the non-decreasing subsequence. Assume all the
values in
array S are already initialized to a given value NO_VALUE that does not appear in the
sequence A; your algorithm will populate it with the values of the solution.
-
For each i, 1 ≤ i &le 10, give the value of
LIS(i)=
length of the longest monotonically non-decreasing subsequence of
that starts at i (and includes A[i].
A = [20, 14, 3, 30, 40, 6, 19, 28, 22, 17, 89, 13, 21, 55, 43, 12, 13, 31]
Future Questions