Strings, Sequences, and
Dynamic Programming
COMP 182: Algorithmic Thinking
Luay Nakhleh
Department of Computer Science
Rice University
Spring 2014
1
Strings
Strings play an important role in computer science.
Strings are defined over a given alphabet !.
F
Divide&Conquer, Transform&Conquer,
Recursion, and Recurrence:
The Case of MergeSort
COMP 182: Algorithmic Thinking
Luay Nakhleh
Department of Computer Science
Rice University
Spring 2014
1
Divide-and-Conquer Algorithms
Divide-and-conquer algorithms work a
COMP 182: Algorithmic Thinking
25 March 2014
Luay Nakhleh
When writing computer programs or mathematical expressions, we often make use of parentheses and want to
ensure that they are balanced. For example, () and ()()() are balanced strings of parenthese
Of Men and Mice.
and Rats and Chimps and Algorithmic Thinking
COMP 182: Algorithmic Thinking
Luay Nakhleh
Department of Computer Science
Rice University
Spring 2014
1
A biologist is interested in the evolutionary history of
humans, mice, rats, and chimps.
Mathematical Induction
COMP 182: Algorithmic Thinking
Luay Nakhleh
Department of Computer Science
Rice University
Spring 2014
1
[P (1) ^ 8k(P (k) ! P (k + 1)] ! 8nP (n)
2
To prove that P(n) is true for all positive integers n, where
P(n) is a propositiona
Heaps
COMP 182: Algorithmic Thinking
Luay Nakhleh
Department of Computer Science
Rice University
Spring 2014
1
Heaps
A heap can be dened as a binary tree with keys assigned to its nodes (one
key per node) provided the following two conditions are met:
1.
Graphs
COMP 182: Algorithmic Thinking
Luay Nakhleh
Department of Computer Science
Rice University
Spring 2014
1
Why Graphs?
2
Facebook Network
[Try www.touchgraph.com]
3
Road Map of Houston
4
The Internet
5
Programmed Cell Death
6
Protein-protein Interact
Conict and Fission:
Social Anthropology and Algorithmic
Thinking
COMP 182: Algorithmic Thinking
Luay Nakhleh
Department of Computer Science
Rice University
Spring 2014
1
The problem of how and why ssion takes place in
small bounded groups has long been a
Algorithm Efciency
COMP 182: Algorithmic Thinking
Luay Nakhleh
Department of Computer Science
Rice University
Spring 2014
1
All Correct Algorithms Are Not
Created Equal
When presented with a set of correct algorithms for a certain problem,
it is natural t
Algorithmic Thinking:
Why and What
COMP 182: Algorithmic Thinking
Luay Nakhleh
Department of Computer Science
Rice University
Spring 2014
1
A consensus is emerging that, this time around, throwing more differential equations
at the problem wont cut it. Ma
COMP 182 Algorithmic Thinking
Final Exam, Spring 2014
May 1, 2014
9:00 am - 12:00 pm
Solution sketches
Name: Luay Nakhleh
This is a three-hour exam.
Answer all questions. Please, give clear and rigorous answers.
You are allowed to use your solutions to
COMP 182: Algorithmic Thinking
Luay Nakhleh
Sets
Definition 1 A set is a collection of distinct items.
A set can be described explicitly, as in
A = cfw_a, b, c, d
or
B = cfw_0, 1.
Alternatively, a set can be described symbolically using certain rules. For
COMP 182: Algorithmic Thinking
Luay Nakhleh
Functions
Definition 1 Let A and B be nonempty sets. A function from A to B is an assignment of exactly one element of B
to each element of A. We write f (a) = b if b is the unique element of B assigned by the f
COMP 182: Algorithmic Thinking
4
Pseudo-code
Arrays, lists, and matrices
Let A be an array, L be a list, and M be a matrix.
A[0.n
1]: Array A has n elements indexed at 0, 1, . . . , n
L[0.n
1]: List L has n elements indexed at 0, 1, . . . , n
M [0.n 1,
Propositional Logic
COMP 182: Algorithmic Thinking
Luay Nakhleh
Department of Computer Science
Rice University
Spring 2014
1
The Need for Logic and Proofs
So far, we have seen several algorithms, and took their correctness for
granted.
In some cases, its
Weighted Graphs and
Greedy Algorithms
COMP 182: Algorithmic Thinking
Luay Nakhleh
Department of Computer Science
Rice University
Spring 2014
1
Weighted Graphs
In many real-world applications of graph theory, the edges in the
graph have weights associated
COMP 182: Algorithmic Thinking
Luay Nakhleh
The Number of Paths
A Quick Tour of Graphs, Matrix Multiplication/Power, Problem Reduction, and Mathematical Induction
In this handout, we will address the problem of finding the numbers of paths of a given leng
Brute Force Algorithms
COMP 182: Algorithmic Thinking
Luay Nakhleh
Department of Computer Science
Rice University
Spring 2014
1
Brute Force Algorithms
A brute force algorithm is a solution that is based directly on the
problem definition.
It is often easy
BIOINFORMATICS
Vol. 20 no. 11 2004, pages 17461758
doi:10.1093/bioinformatics/bth163
Efficient sampling algorithm for estimating
subgraph concentrations and detecting
network motifs
N. Kashtan1,3 , S. Itzkovitz1,2 , R. Milo1,2 and U. Alon1,2,
1 Departmen
COMP 182 Algorithmic Thinking
Mathematical
Induction
Luay Nakhleh
Computer Science
Rice University
Reading Material
Chapter 5, Section 1-4
[P (1) ^ 8k(P (k) ! P (k + 1)] ! 8nP (n)
Why Is It Valid?
The well-ordering property of positive integers:
Every non
Proofs
COMP182AlgorithmicThinking
LuayNakhleh,MichaelBurke
ComputerScience
RiceUniversity
Reading Material
Chapter1,Sections3,6,7,8
How to Succeed in this
Course
Think;donotmemorize
Readthebookanddoadditionalpracticeproblems
Mathematicsnotlearnedpassively
COMP 182 Algorithmic Thinking
Proofs
Luay Nakhleh
Computer Science
Rice University
Reading Material
Chapter 1, Section 3, 6, 7, 8
Propositional Equivalences
The compound propositions p and q are called logically
equivalent, denoted by pq, if pq is a tauto
COMP 182: Algorithmic Thinking
Week 7
Mathematical Induction: (P (1) (k 1, P (k) P (k + 1) n 1, P (n).
Strong Induction: (P (1) (k 1, (P (1) P (2) P (k) P (k + 1) n 1, P (n).
1. Use mathematical induction to prove that n3 + 2n is divisible by 3 for every
COMP 182: Algorithmic Thinking
Week 6 - Solutions
1.
(a) No change is necessary; Dijkstras algorithm just needs to make use of the edge direction when considering
neighbors.
(b) If we make no change to Dijkstras algorithm, it would compute the distance be
COMP 182: Algorithmic Thinking
Week 3
1. Find the least integer n such that f (x) is O(xn ) for each of these functions.
(a) f (x) = 2x3 + x2 log x.
(b) f (x) = 2x2 + x3 log x.
2. Is 4x = O(2x )? Justify your answer.
3. Let f and g be two functions over t
COMP 182: Algorithmic Thinking
Week 2
A matching on graph g = (V, E) is a subset of gs edges such that no two edges have a node in common. A perfect
matching is a matching where every node is incident with at least one edge in the matching. The size of a
COMP 182: Algorithmic Thinking
Week 2 - Solutions
A matching on graph g = (V, E) is a subset of gs edges such that no two edges have a node in common. A perfect
matching is a matching where every node is incident with at least one edge in the matching. Th