CPSC 331 Assignment #1
Instructions for Use of Test Files and Submission of
Assignments)
1
Instructions for Use of Test Files
1. If you have not already done so, please work through at the least of th
Question 1:
While it is not very explicitly documented, examination online material that discusses arrays in Java indicatesthat the
length of an array in Java must be small enough to be represented as
Question 1 (Background Check)
State the definition of each of the following:
Terminationof an algorithm for a given problem.
Loop variant.
Question 2 (Practise Proving Termination)
Consider the follow
CPSC 331, F15 (L01), Self-Study List #2 Computer Science, University of Calgary
Exercises 1-4: Selected Exercises from Textbook, Chapter 3 Growth of Functions
1. 3.1-1, p. 52
SOLUTION
2. 3.1-3, p. 53
CPSC 331, F15 (L01), Self-Study List #3: [2]: ANALYSIS & CORRECTNESS
1
1 Algorithm Analysis
1.
Suppose it is known that the running time of an algorithm is (1/3)n2 + 6n, and that the running time of a
Warmup Problems:
1. Consider the following array.
a.
Trace the execution of the Deterministic Partitioning algorithm on this input. That is,
trace the execution of the program after the call
DPartitio
Question 1
a.
b.
c.
Draw the binary search tree that results from a sequence of insert operations using the
following parameters: 5,6,3,1,11,9,7,8,2,4,6,12,10.
Draw a binary search tree of minimal hei
CPSC 331 L02
November 20, 2015
University of Calgary
Exercise Set #10
To be prepared for the tutorials on Nov 2326.
Exercise 10.1
(a) Draw an AVL Tree of height 4 that contains the minimum possible nu
Question 1:
Describe a data structure in pseudo-code that allows you to access array entries in constant time, and
to initialize a given array of size n in constant time. (I.e., after an initializatio
Question 1
Consider the universe U=cfw_0,.,999, a hash table of size m=59, and a hash function h:U->cfw_0,.,58,
where h(x)=x mod 59. Show the hash tables that result from inserting the keys
473, 418,
CPSC 331, F15 (L01), Self-Study List #5: [2]: ANALYSIS & CORRECTNESS
1
ALGORITHM ANALYSIS
What do the following algorithms (given in code or pseudo-code) do? For each one, analyze its recurrence, wors
CPSC 331, F15 (L01), Self-Study List #4: [2]: ANALYSIS & CORRECTNESS
1
ALGORITHM ANALYSIS
Problem 1
In the following, use either a direct proof (by giving values for c and n0 in the definition of bigO
Below you find Euclids famous algorithm that computes the greatest common divisor, gcd(x, y),
of two integers x and y.
Algorithm 1: Euclid
1
2
3
4
5
6
7
8
9
Input: X, Y
/* Precondition:
x := X; y := Y
CPSC 331 L02
September 23, 2015
University of Calgary
Exercise Set #3
To be prepared for the tutorials on Sep 28Oct 1.
Typically not all questions can be discussed in tutorials. This week, the tutoria
1
2
3
4
5
Input: x
/* Precondition:
y := x2
while y > 0 do
x := x 1
y := y 2x 1
end
xN
*/
(a) Prove that
x N cfw_0 and
y = x2
(L)
is a loop invariant for the algorithm above.
(b) Use a loop variant to
CPSC 331 Winter, 2014
Solutions for Assignment #3
1. You were rst asked to prove that si Fi+1 + Fi+2 1 for every integer i 1.
Proof: By induction on i. The strong form of mathematical induction will b
CPSC 331 Winter, 2014
Solutions for Assignment #1
1. In this rst equation, you were asked to give a (reasonably short) proof that the function
f (n) = n is a bound function for the recursive algorithm
CPSC 331 Winter, 2014
Solutions for Assignment #2
1. In this question you were asked to show that it would be very bad idea to require that a
remove operation should reduce the capacity of the array e
CPSC 331 Winter 2014
Solutions for Required Problems in Assignment #4
1. You were rst asked to complete the implementation of the method dQuickSort1 , that
implements the deterministic version of Quic
<html><head></head><body><pre style="word-wrap: break-word; white-space: prewrap;">package cpsc331.hogwarts;
public class CDumble cfw_
/*
*
* Computes the n<sup>th</sup> Fibonacci number o
<html><head></head><body><pre style="word-wrap: break-word; white-space: prewrap;">package cpsc331.hogwarts;
public class SDumble cfw_
/*
*
* Computes the n<sup>th</sup> Fibonacci number o
CPSC 331 Term Test #2
March 18, 2014
Name:
Please DO NOT write your ID number on this page.
Instructions:
Answer all questions in the space provided. Continue answers on page 10 if you need
more room.
CPSC 331 Supplement for Term Test #1
The Slytherin Series is the sequence of integers S0 , S1 , S2 , . . . such that, for n 0,
0
if n = 0,
Sn = 1
if n = 1,
2 Sn1 Sn2 if n 2.
Algorithms for the followi
CPSC 331 Winter, 2014
Solution for Question #1 on Term Test #2
This question concerned the stack and queue abstract data types.
(a) You were rst asked to describe how an array A can be used to impleme
I - Fundamental Concepts
1. State the definition of each of the following.
precondition
postcondition
correctness of an algorithm (for a given problem)
partial correctness of an algorithm (for a given
Question 1:
Show that Insertion Sort has best-case running time (n).
A common measure for how well an array A of length n is sorted, is the number of
its inversions, which is the number of index pairs