/* NinePuzzle.java
CSC 225 - Fall 2015
Assignment 5 - Template for the 9-puzzle
This template includes some testing code to help verify the implementation.
Input boards can be provided with standard input or read from a file.
To provide test inputs with s
CSC 225 - Summer 2015
Connectivity
Bill Bird
Department of Computer Science
University of Victoria
July 22, 2015
University of Victoria - CSC 225 - Summer 2015
1
Review of Paths (1)
v3
v4
v2
v5
v6
v1
w
v7
u
I
For two vertices u, w V (G ), a path between u
Bucket, Bin, Radix and
Lexicographic Sort
Sorting under assumptions
CSC 225Spring 2016
443
Linear Sorting
If you know something about the values of
the input set, you can potentially do better
than the (n log n) sorting lower bound
For example, if the v
Structure of a Recursive Algorithm
Algorithm recursiveMax(A,n):
Input: An array A storing n 1 integers.
Output: The maximum element in A.
if n = 1 then return A[0] end
return max(recursiveMax(A,n-1),A[n-1])
Base case: 3 operations (n=1, A[0], return)
In
Priority Queues
A priority queue (PQ) is a container of elements,
each having an associated key
The keys determine the priority used to remove
elements (i.e., deleteMin or deleteMax)
The keys of the elements in a PQ must satisfy the
total order propert
CSC 225 - Summer 2015
Topological Sorting
Bill Bird
Department of Computer Science
University of Victoria
July 21, 2015
University of Victoria - CSC 225 - Summer 2015
1
Directed Acyclic Graphs (1)
I
A directed acyclic graph (DAG) is a directed graph with
Trees
A (rooted) tree T is a set of nodes in a
parent-child relationship with the following
properties:
T has a special node r, called the root of T
Each node v of T different from r has a parent
node u
CSC 225Spring 2016
303
Trees
x
node x
v and y are s
Chapter 5. Fundamental Techniq,
The Master Method
Each of the methods described above for solving recurrence equations is ad 1*,
and requires mathematical sophistication in order to be used effectively. There:
nevertheless, one method for solving dividean
CSC 225 - Spring 2016
Introduction to Graphs
Bill Bird
Department of Computer Science
University of Victoria
March 3, 2016
University of Victoria - CSC 225 - Spring 2016
1
Graphs (1)
I
A graph is a collection of vertices and edges.
I
Formally, a graph G i
, Divide-and-Conquer 269
We illustrate the usage of the master method with a few examples (with each
taking the assumption that T(n) : c for n < d, for constants c 2 l and d 2 1).
Example 5.7: Consider the recurrence
T(n) 2- 4T(n/2) +n.
In this case, nlog
CSC 225 - Summer 2015
Transitive Closure
Bill Bird
Department of Computer Science
University of Victoria
July 27, 2015
University of Victoria - CSC 225 - Summer 2015
1
Transitive Closure (1)
0
0
5
1
5
1
4
2
4
2
3
I
3
G
C
The transitive closure of a graph
CSC 225 - Summer 2015
Graphs II
Bill Bird
Department of Computer Science
University of Victoria
July 7, 2015
University of Victoria - CSC 225 - Summer 2015
1
Bipartite Graphs (1)
.
.
.
.
X
Y
I
A graph is bipartite if the vertices of G can be partitioned
i
Basic Data Structures
Stacks
Queues
Lists
X
12
3
7
24
4
1
1
A
12
7.5
7.3
11.5
10
8.5
7.4
CSC 225Spring 2016
147
Abstract Data Type (ADT)
An abstract data type (ADT) is an
abstraction of a data structure
An ADT specifies:
Data stored
Operations on the
CSC 225 - Summer 2015
Hashing I
Bill Bird
Department of Computer Science
University of Victoria
June 26, 2015
University of Victoria - CSC 225 - Summer 2015
1
The Pigeonhole Principle (1)
Exercise: Prove that in any group of 8 people, there must be at
lea
CSC 225 - Spring 2016
Radix Sort
Bill Bird
Department of Computer Science
University of Victoria
February 5, 2016
University of Victoria - CSC 225 - Spring 2016
1
Comparison Sorting (1)
I
I
I
I
General sorting algorithms cannot make any assumptions
about
CSC 225 - Summer 2015
Minimum Weight Spanning Trees
Bill Bird
Department of Computer Science
University of Victoria
July 27, 2015
University of Victoria - CSC 225 - Summer 2015
1
Edge-Weighted Graphs (1)
b
a
1
d
1
10
2
5
1
-1
I
e
6
g
.1
h
1
c
0
f
An edge-
CSC 225 - Summer 2015
Traversals I
Bill Bird
Department of Computer Science
University of Victoria
July 14, 2015
University of Victoria - CSC 225 - Summer 2015
1
Path Finding (1)
u
w
I
Problem: Design an algorithm to find a path from u to w in
the graph a
Algorithm Design Technique
Divide and Conquer: Quicksort
Mergesort divides the input set according to
the position of the elements (i.e., first and
second part of sequence)
Quicksort divides the input set according to
the value of the elements
http:/en.
CSC 225 - SPRING 2016
ALGORITHMS AND DATA STRUCTURES I
PROGRAMMING ASSIGNMENT 2
UNIVERSITY OF VICTORIA
1
Programming Assignment
The assignment is to implement the merge sort algorithm with the following input and output
specifications:
Input:
Output:
A li
/* PairSum.java
CSC 225 - Summer 2015
Template for the PairSum225 problem, which takes an array A and returns
- true if there are two elements of A which add to 225
- false otherwise
The provided code for the problem (in the PairSum225 function below)
imp
/* HeapSort.java
CSC 225 - Fall 2015
Assignment 3 - Template for Heap Sort
This template includes some testing code to help verify the implementation.
To interactively provide test inputs, run the program with
java HeapSort
To conveniently test the algori
abstract class TreeAndRepresentation cfw_
int N;
/ number of nodes in the binary tree t.
int M;
/ number of entries in the sequence representation;
int[] a; / a sequence representation of a tree.
BT t;
/ a binary tree;
TreeAndRepresentation( int N, BT t )
import java.util.*;
public class linklistcfw_
public static void main(String[] args)cfw_
/Creating a LinkedList array, one LinkedList for each vertex.
LinkedList[] vertex = new LinkedList[362880]; / The number of
vertices in your graph should be 9! which
/* TripleSum.java
CSC 225 - Spring 2016
Programming Assignment 1 - Template for TripleSum
This template includes some testing code to help verify the implementation.
To interactively provide test inputs, run the program with
java TripleSum
To conveniently
CSC 225 Spring 2016
ALGORITHMS AND DATA STRUCTURES I
ASSIGNMENT 4
UNIVERSITY OF VICTORIA
1. Let G be a graph whose vertices are integers 1 through 8, and let the adjacent vertices of
each vertex be given by the table below:
vertex
Adjacent vertices
1
(2,
CSC 225 SPRING 2016
ALGORITHMS AND DATA STRUCTURES I
ASSIGNMENT 3
UNIVERSITY OF VICTORIA
1. Suppose that we are given a sequence S of n elements, each of which is an integer in the
range [0, n2 1]. Describe a simple method for sorting S in O(n) time. (Hin
/* HashTable.java
CSC 225 - Spring 2016
Template for string hashing
=
Modify the code below to use quadratic probing to resolve collisions.
Your task is implement the insert, find, remove, and resize methods for the
hash table.
The load factor should alwa
Assignment 3 - Solution
CSC 225 Assignment 3
Ian Drummond
V00734569
Question 1:
Every number in the unsorted sequence is of the form
1 2 . , =
Radix sort takes the first number of each digit and places it into a bucket, with the number of buckets
equalin
CSC 225 - SPRING 2017
ALGORITHMS AND DATA STRUCTURES I
PROGRAMMING ASSIGNMENT 2
UNIVERSITY OF VICTORIA
Due: Friday, February 17th, 2017 at 11:30pm.
1
Programming Assignment
The assignment is to implement an array-based heap sort algorithm with the followi