Fall 2014, CMPSC 465
Homework #1 Solutions
1. Proving correctness
Consider the following algorithm called KMSort.
KMSort(A, n)
for i = n downto 2 do
for j = i downto 2 do
if A[j] A[j 1] then
exchange A[j] and A[j 1];
Is this a valid sorting algorithm? Sh

Fall 2014, CMPSC 465
Homework Assignment #5
Last updated: October 20
Homework is due October 23, 6.40 pm. Please submit this homework in two parts:
Problem 1 is a programming question. There is a separate Angel Drop box for this problem,
so please use th

Fall 2014, CMPSC 465
Homework Assignment #1
Instructions
Homework is due September 11. Please submit either via Angel or in class, but not both.
Submissions emailed to course sta or late submissions will not be accepted. On the rst page,
please indicate y

CMPSC 465
Data Structures and Algorithms
Course Logistics
Last updated August 29, 2014
Kamesh Madduri
Welcome to the class!
Lectures will be in 113 IST Building
TR 6.30 7.45 PM
Dont use computers at the desk, actively take
notes during class
Recitati

CMPSC 465
Data Structures and Algorithms
Lecture 1
August 26, 2014
Kamesh Madduri
Lecture Outline
Introduction
The Sorting problem, Insertion sort algorithm
Writing pseudocode
2
What is an algorithm?
Well-defined computational procedure
Takes input,

CMPSC 465
Data Structures and Algorithms
Lecture 6
September 11, 2014
Kamesh Madduri
Announcements
HW2 due Thursday Sep 18, 6.40 pm
Problem overview
2
Lecture Outline
Elementary data structures
Linked lists (last class)
Stacks and queues
Dynamic Programmi

CMPSC 465
Data Structures and Algorithms
Lecture 3
September 2, 2014
Kamesh Madduri
Announcements
Assessment 1 due 6.30 pm on Thursday (Sep 4).
TAs will be conducting class on Thursday, Python
tutorial. Kamesh on travel.
Thursdays lecture notes + audio

CMPSC 465
Data Structures and Algorithms
Lecture 5
September 9, 2014
Kamesh Madduri
Last weeks review
Asymptotic notation
Big-Oh, Big-Omega
Growth of functions
Divide-and-conquer
Strassens algorithm
FFT
Alg for maximum subarray problem (recording)
Sol

Fall 2016, CMPSC 465
Homework Assignment #7 solutions
1
Suppose G is a weighted, connected, undirected graph and e is a smallest-weight edge in G. Show
that there is a minimum spanning tree of G that contains e.
Solution:
Let edge e connect vertices u an

CMPSC 465
Data Structures and Algorithms
Lecture 2
August 28, 2014
Kamesh Madduri
Review of last class
Class logistics
Why take this class?
Programming Language: how to say
Algorithm: what to say
Insertion sort algorithm
Pseudocode conventions
2
Ins

CMPSC 465
Data Structures and Algorithms
Lecture 8
September 18, 2014
Kamesh Madduri
Announcements
HW3 due Thursday Sep 25, 6.40 pm
Overview of problems
2
Review of previous lecture
Dynamic Programming
Computing the nth value in the Fibonacci sequence

CMPSC 465
Data Structures and Algorithms
Lecture 7
September 16, 2014
Kamesh Madduri
Announcements
HW2 due Thursday Sep 18, 6.40 pm
Keep checking Piazza for related discussion, hints
2
Review of previous lecture
Elementary data structures
Dynamic set

CMPSC 465
Data Structures and Algorithms
Lecture 10
September 25, 2014
Kamesh Madduri
Lecture Outline
Dynamic programming review
Homework 3 solutions
2
Q. Show greedy rod-cutting
doesnt work
Exercise 15.1-2
Define density di of a rod of length i to be

CMPSC 465
Data Structures and Algorithms
Lecture 13
October 9, 2014
Kamesh Madduri
Lecture Outline
Review: Interval partitioning problem, demo of
greedy earliest-start-time-first algorithm; Fractional
knapsack problem
Problem statements for
Scheduling

CMPSC 465
Data Structures and Algorithms
Lecture 14
October 14, 2014
Kamesh Madduri
Todays lecture
The slides are a summary of the handwritten notes
in class.
In future, I might post notes instead and point you
to slides from other sources.
2
Why heaps?

Chris Kramer
CMPSC 465: HW 2 Q2
Collaborators: Quinn Burke
2. Asymptotic Analysis
a. f(n) + g(n) = (max(f(n), g(n)
Given that f and g are asymptotically nonnegative functions and that there is a
function h(n) (max(f(n), g(n) then:
For all n>n0 and c1 =
0

P9 mule oracle, . AngHQ WWW-W A memtm
FLEDWCL Seq/WuliWW O,!,\,Z,3,S,.a
F :
o , 4), Two
Fib- WW (arm? (wwsk ("m 001? 01/), POW/3r Glr 2-7.!
003 70 LEWW' Fuse?
Ganotamm,choskaw:
l. 39 11' gourmet? A
2. How W Hme doc/3 DC W7
2. cm M M mum? "'
Lot m) M 3% W

on ms : 53+ 3n+\ : 934%;ch W ,
m1+3VLJr\ Is cfw_14 5LYL) Jgaz' Am 301,) 99C)
0 ms: 1 +96): 905) '> Walk W
3%) e 9C) , M mats o. W 39,.) 590:)
1 M 34*" C) 5 36%).
W beta y),
:3 3'1) Q Ck (M9) .
ALSO W 501 O 1 a. I O I b3 .
W51 9%) = GUM)
Also Jpx 0,1. 5m i

Fall 2016, CMPSC 465
Homework Assignment #6 solutions
1
The Hadamard matrices H0 , H1 , H2 , . . . are defined as follows:
H0 is the 1 1 matrix [1]
Hk1 Hk1
k
k
For k > 0, Hk is the 2 2 matrix Hk =
Hk1 Hk1
Show that if v is a column vector of length n =

CMPSC 465
Data Structures and Algorithms
Kamesh Madduri
What are data structures?
A higher-level abstraction used in algorithms.
A concrete implementation of an abstract data type
(ADT).
Two types of operations defined on ADTs: queries,
modifying opera

Sample Chapter
grokking
algorithms
An illustrated guide for
programmers and other curious people
Aditya Y. Bhargava
MANNING
S helter I sl and
Grokking Algorithms
by Aditya Y. Bhargava
Chapter 2
Copyright 2016 Manning Publications
vii
contents
preface
xii

Chris Kramer
CMPSC 465: HW 3 Q1
Collaborators: Quinn Burke
1. (Carpets)
a. The inputs of this divide-and-conquer algorithm are, n = 2k which determines the size of
the room and coordinates of the only carpet piece, (x, y) cfw_1, ., n cfw_1, ., n . When
k

Chris Kramer
CMPSC 465: HW 2 Q1
Collaborators: Quinn Burke
1. (Finding similar pizzas)
a. Description
My algorithm will take the difference in diameters between both the first and
40
middle and middle and last pizzas in the stack. If the either difference

Algorithms
R OBERT S EDGEWICK | K EVIN W AYNE
1.5 U NION -F IND
dynamic connectivity
quick find
Algorithms
F O U R T H
E D I T I O N
R OBERT S EDGEWICK | K EVIN W AYNE
http:/algs4.cs.princeton.edu
quick union
improvements
applications
1.5 U NION -F I

Grub; : TWMLogA-j E< Mama/W
A camp in gm. (xi/E), M
V: swwormw
E:setakcdam,.\nxcl.grgia Fabuww
VuuhmZxWWnvlaWW.
31W #130; O .JEOCL" 017 WCM,V> '
4,ch mm cfw_0 am m. oW/lm
5% 10min in and m DRAW
IDmhxkgmp: all lav weedm/ckd
Fov (H/7, Valium LL auvaV m M mg