Divide and Conquer
examples of D&C
merge sort, binary search, an,
matrix multiplication, polynomial multiplication
Divide the problem into a number of subproblems
Conquer the subprobl
25. All-Pairs Shortest Paths
Shortest Paths and Matrix Multiplication
Johnsons Algorithm for Sparse Graphs
Problem: To find the shortest route between every pair of
points on a ma
Elementary Graph Algorithms
Strongly Connected Components
Graphs (Appendix B.4, B.5)
A graph is a nonempty finite set V along with
Disjoint Sets Data Structures
& Minimum Spanning Trees
Growing a Minimum Spanning Tree
Data Structures for Disjoint Sets
Problem: A town has a set o
Properties of red-black trees
A variation of binary search trees with one extra bit of
storage per node: its color (RED or BLACK)
Each node contains 4 fields: co
Binary Search Trees
What is a binary search tree?
Querying a binary search tree
Insertion and deletion
Randomly built binary search trees (*)
Data structures that support many dynamic-set operations
Elementary Data Structures
Stacks & Queues
Implementing Pointers and Objects
Representing Rooted Trees
A data structure is a way to store and organize data in order to
facilitate access and
Medians and Order Statistics
Minimum and Maximum
Selection in Expected Linear Time
Selection in Worst-Case Linear Time
ith order statistic is the ith smallest element of a set of n elements.
The minimum is
Sorting in Linear Time
Lower bounds for sorting
How fast can we sort?
We will prove a lower bound (nlgn) , then beat it by
playing a different game.
Maintaining the heap property
Building a heap
Heap Data Structure
Heap A is a nearly complete binary tree.
Height of node = # of edges on a longest simple path
the hiring problem
indicator random variables
The Hiring Problem
You are using an employment agency to hire a new office assistant.
You interview the candidate a
The substitution method
The recursion-tree method
The master method
What is a recurrence?
A recurrence is an equality or inequality that
describes a function in terms of its value on smaller
Growth of Functions
standard notation and common functions
(g(n) = cfw_ f(n): there exist positive constants c1, c2,
and n0 such that
0 c1 g(n) f(n) c2 g(n), n n0
(g(n) = cfw
We will first introduce foundations of data structures such as the linked lists, stacks, queues, trees, heaps,...etc. Fundamental issues about algorithms, such as how to measure algorithmic efficiency, recurrence and functions
A form of software reuse in which a new class is created by
absorbing an existing classs members and embellishing them
with new or modified capabilities.
Can save time during program development by basing new
Covered in this chapter
double primitive type
Analogy to help you understand classes and their
Suppose you want to drive a car and make it go faster by
pressing down on its accelerator ped
Java application programming
Use tools from the JDK to compile and run programs.
Videos at www.deitel.com/books/jhtp8/
Help you get started with Eclipse and NetBeans integrated
Enables you to program in the general rather than program
in the specific.
Polymorphism enables you to write programs that process
objects that share the same superclass as if theyre all objects
of the superclass; this
Deeper look at building classes, controlling access to
members of a class and creating constructors.
Compositiona capability that allows a class to have
references to objects of other classes as members.
More details on enum types.
Collections of related data items.
Discussed in depth in Chapters 2022.
Data structures consisting of related data items of the same type.
Make it convenient to process related groups of values.
Best way to develop and maintain a large program is to
construct it from small, simple pieces, or modules.
divide and conquer.
Topics in this chapter
Declare a method with more than one parameter