CS251 Homework 2
Final Exam Review
Answer the following questions in preparation of the final exam. Write the questions and
the answers neatly and turn them in during the final exam. I will post the solutions one
day before the final exam but I encourage
CS251 Homework 2
Due date: Wednesday April 27, 11:59pm in Blackboard, submit PDF les only.
This is a rm deadline: no extensions or late submissions will be
accepted, since solutions will be released immediately after the deadline.
True/False Questions (20
CS251 Homework 1
Due date: Monday March 7, 11:59pm in Blackboard, submit PDF les only.
This is a rm deadline: no extensions or late submissions will be
accepted, since solutions will be released immediately after the deadline.
True/False Questions
1. In a
CS251 Homework 1
Due date: Monday April 7, 11:59pm in Blackboard, submit PDF les only.
This is a rm deadline: no extensions or late submissions will be
accepted, since solutions will be released immediately after the deadline.
True/False Questions
1. In a
CS251 Homework 2
Due date: Wednesday April 27, 11:59pm in Blackboard, submit PDF les only.
This is a rm deadline: no extensions or late submissions will be
accepted, since solutions will be released immediately after the deadline.
True/False Questions (20
CS 25100
Fall 2013
Written Assignment 1
Due in class: 1:30pm, Monday, Sept. 30
Note: The midterm exam will be on Wednesday, October 16, 8:00pm-10:00pm in
CL50 room 224.
Write legibly or type your answers to the following questions, using an appropriate
ps
CS 25100
Fall 2013
Written Assignment 2
Due in class: 1:30pm, Friday, Oct. 11
Note: The midterm exam will be on Wednesday, October 16, 8:00pm-10:00pm in
CL50 room 224.
Write legibly or type your answers to the following questions.
1. We are given seven ch
Setting Up Deletion
Deletion from Red-Black
Trees
As with binary search trees, we can always
delete a node that has at least one external child
If the key to be deleted is stored at a node that
has no external children, we move there the key
of its inorde
SEARCHING
The Dictionary ADT
a dictionary is an abstract model of a database
the dictionary ADT
binary search
like a priority queue, a dictionary stores key-element
pairs
binary search trees
the main operation supported by a dictionary is
searching
PRIORITY QUEUES
Stock Trading
We focus on the trading of a single security, say
Akamai Technologies, founded in 1998 by CS
professors and students at MIT (200 employees,
$20B market cap)
Stock trading (motivation)
The priority queue ADT
Investors plac
QUEUES AND LINKED
LISTS
Queues
A queue differs from a stack in that its insertion and
removal routines follows the rst-in-rst-out (FIFO)
principle.
Queues
Elements may be inserted at any time, but only the
element which has been in the queue the longes
CS 25100
Fall 2013
Programming Assignment 3
Due time: 11:59pm, Monday, Nov. 26
Your assignment is to code up a java procedure named bip m that, given an undirected
bipartite graph, will output a maximum-size matching for that graph. Your code
should use m
MINIMUM SPANNING TREE
Prim-Jarnik algorithm
Kruskal algorithm
Weighted Graphs
(weight of subgraph G') =
(sum of weights of edges of G')
weight(G') =
Thats a very nice hat.
weight(e)
(e G')
G'
Thats not a hat!
Thats my head!
Im Tree Head!
1500
SEA
MSN
80
CS 251 Data Structure & Algorithm
Instructor: Prof. Greg N. Frederickson
Homework 1 Sample Solution
Problem 1 (10 points)
(3 points) Insert: First search the tree to check if it already has this value or not. If it does not
have this value, then insert it
CS 251 Data Structure & Algorithm
Instructor: Prof. Greg N. Frederickson
Homework assignment 2 Sample Solution
Problem 1 (10 points)
Grader: Chenyun Dai
Problem 2a (10 points)
Grader: Wei-Yen Day
1
For M (1) = 3: for any node in 2-3-4 trees, the maximum n
9/21/2016
CS 251, LE 2
Clicker Questions
Week 5.2
45
Tree 1
47
84
53
99
64
14
12
Tree 2
Tree 3
14
84
Which are a min-heaps?
A.All are min-heaps
B.1 and 2
C.2 and 3
D.2 only
80
25
52
52
53
83
18
45
81
77
1
9/21/2016
After an extract-min operation, element
CS 251, LE 2
Clicker Questions
Week 4
How many cells can an earliest
flow path (EFP) have?
Given is a 4 x10 flow grid containing 0s and 1s.
Which statements are true?
1. The EFP can contain 11 cells.
2. The EFP can contain 24 cells.
3. The EFP can contain
10/12/2016
CS 251, LE 2
Clicker Questions
Week 8
25 is deleted (with successor replacement)
What does not hold after the deletion?
A. The node holding 25 is spliced out
B. After the deletion, 30 is a child of 10
C. After the deletion, the root holds 30
D.
MORE MERGE SORT
Java Implementation of
Merge-Sort
Java implementation
Interface SortObject
Time complexity
public interface SortObject cfw_
/sort sequence S in nondecreasing order
using compartor c
public void sort (Sequence S, Comparator c);
Generic
SHORTEST PATHS
Weighted Graphs
Weighted Digraphs
weights on the edges of a graph represent distances,
costs, etc.
Shortest paths
An example of an undirected weighted graph:
2704
2704
1846
1846
740
1464
JFK
187
SFO
740
1464
1090
LAX
1090
LAX
1235
1235
Sorting Algorithms
MERGE SORT
Selection Sort uses a priority queue P implemented
with an unsorted sequence:
- Phase 1: the insertion of an item into P takes O(1)
time; overall O(n)
- Phase 2: removing an item takes time proportional
to the number of elem
SEQUENCES
The Vector ADT
A sequence S (with n elements) that supports the
following methods:
Vectors
Positions
- elemAtRank(r):
Return the element of S with rank r; an
error occurs if r < 0 or r > n -1
Lists
General Sequences
- replaceAtRank(r,e):
Re
Quick-Sort
Quicksort
To understand quick-sort, lets look at a high-level
description of the algorithm
1) Divide : If the sequence S has 2 or more elements,
select an element x from S to be your pivot. Any
arbitrary element, like the last, will do. Remov
STRINGS AND PATTERN
MATCHING
String Searching
The previous slide is not a great example of what is
meant by String Searching. Nor is it meant to
ridicule people without eyes.
Brute Force,Rabin-Karp, Knuth-Morris-Pratt
The object of string searching is
Radix Sort
More Sorting
Unlike other sorting methods, radix sort
considers the structure of the keys
Assume keys are represented in a base M
number system (M = radix), i.e., if M = 2,
the keys are represented in binary
radix sort
bucket sort
in-place so
STACKS
Abstract Data Types (ADTs)
An Abstract Data Type is an abstraction of a data
structure: no coding is involved.
Abstract Data Types (ADTs)
The ADT species:
- what can be stored in the ADT
- what operations can be done on/by the ADT
Stacks
Appli
TREES
Trees
a tree represents a hierarchy
- organization structure of a corporation
trees
Electronics RUs
binary trees
traversals of trees
R&D
Sales
Purchasing
Manufacturing
template method pattern
Domestic
data structures for trees
Canada
Internati
TRIES
Text Processing
We have seen that preprocessing the pattern speeds
up pattern matching queries
Standard Tries
After preprocessing the pattern in time proportional
to the pattern length, the Boyer-Moore algorithm
searches an arbitrary English text
/*
* Compilation: javac Accumulator.java
* Execution:
java Accumulator < input.txt
* Dependencies: StdOut.java StdIn.java
*
* Mutable data type that calculates the mean, sample standard
* deviation, and sample variance of a stream of real numbers
* use a
Sorting
Radix sort (LSD)
o Time: O(W(N + R)
o N: number of words
o W: word size
o R: R-character alphabet
Hashing
Linear probing
1
1
(1+
)
o Search: successful:
2
1
o Search: unsuccessful:
1
1
(1+
)
2
( 1 )2
o Performance degrades quickly after
1
>
2
D
CS 251, Fall 2017
Data Structures and Algorithms
Professor Mike Atallah (LE 2)
Professor Xavier Tricoche (LE 1)
Overview
Course overview
Introductory example:
Union find
Algorithms, 4th Edition
Robert Sedgewick and Kevin Wayne
Copyright 20022010
August
2.1 Elementary Sorts
Algorithms, 4th Edition
Robert Sedgewick and Kevin Wayne
rules of the game
selection sort
insertion sort
sorting challenges
shellsort
Copyright 20022010
August 14, 2017 1:23:11 PM
Sorting problem
Ex. Student record in a university.
So
Binary Trees
Introduction
We extend the concept of linked data structures to structure containing nodes with more than
one self-referenced field.
Definition
A tree is either empty or consists of one node called the root and zero or more subtrees.
Every no