CSCE 310: Data Structures &
CSCE
Algorithms
Algorithms
Brute Force *
Dr. Byrav Ramamurthy
byrav@cse.unl.edu
Chapter 3
Design and Analysis of Algorithms Chapter 3
1
Brute force
a A straightforward approach usually based on problem
straightforward
statement
Graphs
By Prof. Samuel J.
By
Lomonaco , Jr.
CMSC 203 - Discrete Structures
1
IntroductiontoGraphs
Definition: Asimple graphG=(V,E)consistsofV,a
Definition: A
nonemptysetofvertices,andE,asetofunordered pairsof
distinctelementsofVcallededges.
ForeacheE,e=cf
Graphs
Chapter 9, Section 9.1
Introduction to Graphs
Dr. Gene Boggess
These class notes are based on material from our
textbook, Discrete Mathematics and Its
Applications, 6th ed., by Kenneth H. Rosen,
published by McGraw Hill, Boston, MA, 2006. They
are
Hashing
Byrav Ramamurthy
byrav@cse.unl.edu
Giving credit where credit is due:
Most of the slides are based on the lecture
note by Dr. David Matuszek, University of
Pennsylvania
Further edits by Prof. Ying Lu (UNL)
2
Example Problem
Assume that you are
CSCE 310
Fall 2012
Homework 1
Due: Friday 9/21/2012
(100 points)
Instructions
1. Read all of these instructions before solving the problems. Following all of these instructions is
part of the assignment.
2. Use webhandin (http:/cse.unl.edu/~cse310/handin/
CSCE 310
Fall 2012
Homework 2
Due: Monday 10/8/2012 at 11:59 PM
(100 points)
Instructions
1. Read all of these instructions before solving the problems. Following all of these instructions is
part of the assignment.
2. Use webhandin (http:/cse.unl.edu/~cs
CSCE 310
Fall 2012
Homework 3
Due: Friday 11/16/2012 at 11:59 PM
(100 points)
Instructions
1. Read all of these instructions before solving the problems. Following all of these instructions is
part of the assignment.
2. Use webhandin (http:/cse.unl.edu/~c
CSCE 310
Data Structures & Algorithms
P, NP, and NP-Complete
Byrav Ramamurthy
byrav@cse.unl.edu
1
CSCE 310
Data Structures & Algorithms
x Giving credit where credit is due:
Most of the lecture notes are based on slides
created by Dr. Cusack and Dr. Leubk
CSE 310 Spring 2001
Solutions to Homework 1
Gennette Gill ggill@cse.unl.edu and Joel Gompert jgompert@cse.unl.edu
Acknowledgments and disclaimer:
Some material is taken from notes given by Dr. Cusack and Dr. Skiena. These notes are made available as a
cou
CSCE310 Spring 2001
Solutions to Homework 2
Gennette Gill ggill@cse.unl.edu and Joel Gompert jgompert@cse.unl.edu
Acknowledgments and disclaimer:
Some material is taken from notes given by Dr. Cusack. These notes are made available
as a courtesy of the TA
CSCE310 Spring 2001
Solutions to Homework 4
Acknowledgments and disclaimer: These notes are made available as a courtesy of the
TAs and instructor. They are not guaranteed to be error-free or the most accurate,
efficient or detailed. Feel free to notify t
CSCE 310
Data Structures & Algorithms
Greedy Algorithms
and MST
Byrav Ramamurthy
1
CSCE 310
Data Structures & Algorithms
Giving credit where credit is due:
Most of slides for this lecture are based on slides
created by Dr. David Luebke, University of
Vir
CSCE 310: Data Structures & Algorithms
Transform and Conquer
Byrav Ramamurthy
byrav@cse.unl.edu
Design and Analysis of Algorithms Chapter 6
1
Transform and Conquer
Solve problem by transforming into:
a more convenient instance of the same problem (instanc
CSCE 310: Data Structures & Algorithms
Transform and Conquer
(Heaps and Heapsort)
Byrav Ramamurthy
byrav@cse.unl.edu
Design and Analysis of Algorithms Chapter 6
1
Heapsort
Definition:
A heap is a binary tree with the following conditions:
it is essentiall
CSCE 310: Data Structures &
CSCE
Algorithms
Algorithms
Analysis of Algorithms
Byrav Ramamurthy
byrav@cse.unl.edu
Design and Analysis of Algorithms Chapter 2
1
The Time Complexity of an
Algorithm
Algorithm
Specifies how the running time depends
on the size
CSCE 310: Data Structures &
CSCE
Algorithms
Algorithms
Nonrecursive Algorithm Analysis *
Dr. Byrav Ramamurthy
byrav@cse.unl.edu
Design and Analysis of Algorithms Chapter 2
1
Time efficiency of nonrecursive
Time
algorithms
algorithms
a Steps in mathematica
CSCE 310: Data Structures &
Algorithms
Algorithms
Recursive Algorithm Analysis
Dr. Byrav Ramamurthy
byrav@cse.unl.edu
Design and Analysis of Algorithms Chapter 2
1
Example: recursive evaluation of
Example:
n!
a
Definition: n ! = 1*2*(n-1)*n
1*2
a
Recursiv
CSCE 310: Data Structures &
CSCE
Algorithms
Algorithms
Graph Traversals
DFS and BFS
Chapter 3
Dr. Byrav Ramamurthy
byrav@cse.unl.edu
Design and Analysis of Algorithms Chapter 5
1
Graph Traversal
a Many problems require processing all graph
Many
vertices i
CSCE 310: Data Structures &
CSCE
Algorithms
Algorithms
Decrease and Conquer
Dr. Byrav Ramamurthy
byrav@cse.unl.edu
Design and Analysis of Algorithms Chapter 5
1
Decrease and Conquer
1.
Reduce a problem instance to a smaller instance
Reduce
of the same pro
CSCE 310: Data Structures &
CSCE
Algorithms
Algorithms
Decrease-by-a-Constant-Factor Algorithms
Dr. Byrav Ramamurthy
byrav@cse.unl.edu
Design and Analysis of Algorithms Chapter 5
Design
1
Decrease by a constant factor
a Binary search
Binary
a Fake-coin pr
CSCE 310: Data Structures &
CSCE
Algorithms
Algorithms
Variable-Size-Decrease Algorithms
Byrav Ramamurthy
byrav@cse.unl.edu
Design and Analysis of Algorithms Chapter 5
1
Examples of Decrease and
Examples
Conquer
Conquer
a Decrease by one:
Insertion sort
G
CSCE 310: Data Structures &
CSCE
Algorithms
Algorithms
Divide and Conquer (I)
Byrav Ramamurthy
byrav@cse.unl.edu
Design and Analysis of Algorithms Chapter 4
1
Divide and Conquer
The most well known algorithm design strategy:
1. Divide instance of problem
CSCE 310: Data Structures &
CSCE
Algorithms
Algorithms
Divide and Conquer (II)*
Dr. Byrav Ramamurthy
byrav@cse.unl.edu
Design and Analysis of Algorithms Chapter 4
1
In-class exercises
In-class
a 4.2.1 Apply quicksort to sort the list E, X, A,
4.2.1
M, P,
CSCE 310: Data Structures &
CSCE
Algorithms
Algorithms
Divide and Conquer (III)*
Dr. Byrav Ramamurthy
byrav@cse.unl.edu
Design and Analysis of Algorithms Chapter 4
1
Divide and conquer examples
a Closest-pair problem
a Convex-hull problem
Design and Analy
CSCE310 Spring 2001
Solutions to Homework 5
Acknowledgments and disclaimer:
Some material is taken from notes by Dr. Cusack. These notes are made available as a
courtesy of the TAs and instructor. They are not guaranteed to be error-free or the most
accur