SlideShare a Scribd company logo
1 of 34
CS 6212 –
Design and
Analysis of
Algorithms
ASYMPTOTIC NOTATION
AND DATA STRUCTURES
 Instructor
Prof. Amrinder Arora
amrinder@gwu.edu
Please copy TA on emails
Please feel free to call as well

 Available for study sessions
Science and Engineering Hall
GWU
Algorithms Asymptotic Notation and Data Structures 2
LOGISTICS
 Asymptotic Notation
 Big Oh
 Small Oh
 Big Omega
 Small Omega
 Theta
Algorithms Asymptotic Notation and Data Structures 3
RECAP
 Big O notation
 f(n) = O(g(n)) if there exist constants n0 and c such that f(n) ≤ c g(n) for all n ≥ n0.
For example, n = O(2n) and 2n = O(n)
If f(n) = a0 n0 + a1 n1 + … + am nm,
then f(n) = O (nm)
 Big Omega notation
 f(n) = Ω(g(n)) if there exist constants n0 and c such that f(n) ≥ c g(n) for all n ≥ n0.
 Small o notation
 f(n) = o(g(n)) if for any constant c > 0, there exists n0 such that 0 ≤ f(n) < c g(n)
for all n ≥ n0.
For example, n = o(n2)
 Small omega () notation
 f(n) = (g(n)) if for any constant c > 0, there exists n0 such that f(n) ≥ c g(n) ≥ 0,
for all n ≥ n0
For example, n3 = (n2)
 Theta ( or ) notation
 If f(n) = O(g(n)) and g(n) = O(f(n)), then f(n) = (g(n))
4
ASYMPTOTIC NOTATIONS
Algorithms Asymptotic Notation and Data Structures
 Transpose symmetry
 f(n) = O(g(n)) if and only if g(n) = Ω(f(n))
 f(n) = o(g(n)) if and only if g(n) = (f(n))
 Limit method
 f(n) = o(g(n)) implies limnf(n)/g(n) = 0
 Using L’Hopital’s rule is common when using this method.
5
ASYMPTOTIC NOTATIONS (CONT.)
Algorithms Asymptotic Notation and Data Structures
O o   Ω
≤ < = > ≥
6
ASYMPTOTIC NOTATIONS (CONT.)
Analogy with real numbers
Algorithms Asymptotic Notation and Data Structures
Which properties apply to which (of
5) asymptotic notations?
 Transitivity
 Reflexivity
 Symmetry
 Transpose Symmetry
 Trichotomy
7
ASYMPTOTIC NOTATIONS (CONT.)
Algorithms Asymptotic Notation and Data Structures
Which properties apply to which (of
5) asymptotic notations?
 Transitivity: O, o, , , Ω
 Reflexivity: O, , Ω
 Symmetry: 
 Transpose Symmetry: (O with Ω, o with )
 Trichotomy: Does not hold. For real numbers x
and y, we can always say that either x < y or x =
y or x > y. For functions, we may not be able to
say that. For example if f(n) = sin(n) and
g(n)=cos(n)
8
ASYMPTOTIC NOTATIONS (CONT.)
Algorithms Asymptotic Notation and Data Structures
O o   Ω
≤ < = > ≥
Algorithms Asymptotic Notation and Data Structures 9
ASYMPTOTIC NOTATIONS (CONT.)
Analogy with real numbers
Question: Does it still not hold if we limit ourselves to
functions that are positive, always increasing with n, and
are not trigonometric?
Special Functions
 Polynomial vs. exponential
 Polynomial vs. logs
 Factorial / Combinatorial
 Trigonometric Functions
 Floors and Ceilings
Algorithms Asymptotic Notation and Data Structures 10
ASYMPTOTIC NOTATIONS (CONT.)
How do we prove that
2^n = omega (n^k)?
We want to prove that
for any given c, there
exists n0, such that
2^n > c * n^k, for all n
> n0.
 Divide and Conquer
 Greedy Method
 Dynamic Programming
 Graph search methods
 Backtracking
 Branch and bound
Algorithms Asymptotic Notation and Data Structures 11
DESIGNING AN ALGORITHM – TECHNIQUES
 Define the problem
 Find a working solution
 Fast enough?
 If not, you may have two options:
 Consider a different technique
 Consider a different data structure
 Iterate until satisfied.
Algorithms Asymptotic Notation and Data Structures 12
HOW TO DESIGN A FAST ALGORITHM?
 A data structure is a structure to hold the data, that allows
several interesting operations to be performed on the data
set.
 The data structure is designed with those specific operations
in mind.
 General problem:
 Given a data set and the operations that need to be supported, come
up with a data structure (organization) that allows those operations
to be done in an efficient manner.
Algorithms Asymptotic Notation and Data Structures 13
DATA STRUCTURES
 Last In First Out (LIFO)
 Allows 3 operations:
 Push (a)
 Pop()
 Top()
Algorithms Asymptotic Notation and Data Structures 14
STACK
 Using an array
 Use an array S[1:N], and use a special pointer to the “top” of the
stack.
 When pushing something on the stack, increment the pointer
 When popping, decrement the pointer
 Using a linked list
 Use a special pointer to the “top” of the stack
 When pushing something on the stack, advance the “top” pointer
 When popping, move the “top” pointer back one step – this suggests
that the linked list must be a doubly linked list
Algorithms Asymptotic Notation and Data Structures 15
IMPLEMENTATION OF STACKS
 First In First Out (FIFO)
 Allows 2 operations:
 dequeue(): Returns the first element
 enqueue(a): Adds an element a to the end of the queue
Algorithms Asymptotic Notation and Data Structures 16
QUEUE
tail -> …… -> head
 Using an array
 Keep “head” and “tail” indexes
 Using a linked list
 Keep “head” and “tail” pointers
 Handling operations
 When enqueuing an item, move tail one step to the left.
 When dequeuing an item, move head one step to the left
Algorithms Asymptotic Notation and Data Structures 17
QUEUE – IMPLEMENTATION
 A record is a built-in structure data type, that allows the
packaging of several elements (called fields)
 Every high level language allows the user to define
customized records.
 In C#/Java, this is called “class”.
 In C, this is called “struct”.
Algorithms Asymptotic Notation and Data Structures 18
RECORD STRUCT OBJECT CLASS
TEMPLATE
 Singly Linked
 A singly linked list is a sequence of records, where every record has a
field that points to the next record
 A special pointer called “first” has the reference to the first record
 Doubly Linked
 A doubly linked list is a sequence of records, where every record has
a field that points to the next record, and a field that points to the
previous record
 Special pointers called “first” and “last” with references to the first
and the last records
Algorithms Asymptotic Notation and Data Structures 19
LINKED LISTS
 A graph G=(V,E) consists of a finite set V, which is the set of
vertices, and set E, which is the set of edges. Each edge in E
connects two vertices v1 and v2, which are in V.
 Can be directed or undirected
Algorithms Asymptotic Notation and Data Structures 20
GRAPH
 If (x,y) is an edge, then x is said to be adjacent to y, and y is adjacent
from x.
 In the case of undirected graphs, if (x,y) is an edge, we just say that x
and y are adjacent (or x is adjacent to y, or y is adjacent to x). Also, we
say that x is the neighbor of y.
 The indegree of a node x is the number of nodes adjacent to x
 The outdegree of a node x is the number of nodes adjacent from x
 The degree of a node x in an undirected graph is the number of
neighbors of x
 A path from a node x to a node y in a graph is a sequence of node x,
x1,x2,...,xn,y, such that x is adjacent to x1, x1 is adjacent to x2, ..., and xn
is adjacent to y.
 The length of a path is the number of its edges.
 A cycle is a path that begins and ends at the same node
 The distance from node x to node y is the length of the shortest path
from x to y.
Algorithms Asymptotic Notation and Data Structures 21
GRAPH DEFINITIONS
 Using a matrix A[1..n,1..n] where A[i,j] = 1 if (i,j) is an edge,
and is 0 otherwise. This representation is called the
adjacency matrix representation. If the graph is undirected,
then the adjacency matrix is symmetric about the main
diagonal.
 Using an array Adj[1..n] of pointers, which Adj[i] is a linked
list of nodes which are adjacent to i.
 The matrix representation requires more memory, since it has
a matrix cell for each possible edge, whether that edge exists
or not. In adjacency list representation, the space used is
directly proportional to the number of edges.
 If the graph is sparse (very few edges), then adjacency list
may be a more efficient choice.
Algorithms Asymptotic Notation and Data Structures 22
GRAPH REPRESENTATIONS
 A tree is a connected acyclic graph (i.e., it has no cycles)
 Rooted tree: A tree in which one node is designated as a
root (the top node)
Algorithms Asymptotic Notation and Data Structures 23
TREE
Example:
Node A is root node
F and D are child nodes of A.
P and Q are child nodes of J.
Etc.
 Definitions
 Leaf is a node that has no children
 Ancestors of a node x are all the nodes on the path from x to the root,
including x and the root
 Subtree rooted at x is the tree consisting of x, its children and their
children, and so on and so forth all the way down
 Height of a tree is the maximum distance from the root to any node
Algorithms Asymptotic Notation and Data Structures 24
TREE
 A tree where every node has at most two children
 Binary Search Tree (BST): BST is a binary search tree where
every node contains a value, and for every node x, all the
nodes of the left subtree of x have values <= x, and all nodes
in the right subtree of x have values >= x.
 BST supports 3 operations: insert(x), delete(x) and search(x)
 It is more interesting (and efficient) if the BST is “height
balanced”. Red Black and AVL trees are interesting
implementations of height balanced BSTs.
Algorithms Asymptotic Notation and Data Structures 25
BINARY TREE
 Also known as priority queues
 Very efficient data structure to enforce priority, although do
not enforce complete sorting
 Can be max heap or min heap
 Commonly represented using a heap tree (although, can also
be a forest)
Algorithms Asymptotic Notation and Data Structures 26
HEAPS
 Flexible data structure, where a node has a variable number
of children (say between 2 and 4, both including, or between
50 and 100 both including)
 This variable number allows us to leave some “holes” in the
tree to fill as insertions happen, thereby allowing insertions
without changing the structure of the tree entirely.
 The variable number also allows us to treat deletions without
changing the structure.
 2-3 tree is a specific kind of BTree where each node can have
2 or 3 children.
http://www.slideshare.net/amrinderarora/btrees-great-
alternative-to-red-black-avl-and-other-bsts
Algorithms Asymptotic Notation and Data Structures 27
BTREE, 2-3 TREE
 Also called “Disjoint Set” data structure
 How to maintain sets dynamically – sets can be merged
(union), and we want to see which set a particular element is
in.
 find(x)  Identifies the set that element x belongs to
 Union (S1, S2)  Combines these two sets
Algorithms Asymptotic Notation and Data Structures 28
UNION FIND
Each set is marked by a leader
When calling “find” on a set’s member, it
returns the leader
Leader maintains a rank (or height)
When doing a union, make the tree with
smaller height (or rank) to be a child of the
tree with the larger height
Note that this is NOT a binary tree.
Algorithms Asymptotic Notation and Data Structures 29
UNION FIND DATA STRUCTURE
 When doing a find, follow that up by compressing the path to
the root, by making every node (along the way) point to the
root.
 This is not easy to prove, but Union Find with Path
compression, when starting with n nodes and m operations,
takes O(m log*(n)) time instead of O(m log n) time, where the
log* function is the iterated logarithm (also called the super
logarithm) and is an extremely slow growing function.
 log*(n) is defined as follows:
 0, if n <= 1
 1 + log*(log n) if n > 1
Algorithms Asymptotic Notation and Data Structures 30
UNION FIND – PATH COMPRESSION
Algorithms Asymptotic Notation and Data Structures 31
SOME PRACTICAL PROBLEMS
 Terrorism, insider trading, financial fraud analysis
 Are two people connected given millions of “x knows y” statements?
 Vulnerability Assessment
 Are two computers in a network connected?
 IC Design
 Are two points shot circuited on this mother board?
 Click Fraud Analysis, Page Ranking
 Are two web pages connected (indirectly)?
 Abstractions
 Given a graph, is there a path connecting one node to another?
 How can we organize a given universe of objects into sets?
Algorithms Asymptotic Notation and Data Structures 32
EXAMPLE
Algorithms Asymptotic Notation and Data Structures 33
EXAMPLE (CONT.)
 Divide and Conquer
 http://www.cs.cmu.edu/afs/cs/academic/class/15210-
f11/www/lectures/03/lecture03.pdf
 http://en.wikipedia.org/wiki/Divide_and_conquer_algorithm
 Recursive Algorithm
http://en.wikipedia.org/wiki/Recursion_(computer_science)
 Tail Recursion
http://en.wikipedia.org/wiki/Tail_call
 Recurrence Relations
http://en.wikipedia.org/wiki/Recurrence_relation
Algorithms Asymptotic Notation and Data Structures 34
READING ASSIGNMENT

More Related Content

What's hot (20)

Linear Search & Binary Search
Linear Search & Binary SearchLinear Search & Binary Search
Linear Search & Binary Search
 
Quick Sort
Quick SortQuick Sort
Quick Sort
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
 
Hashing
HashingHashing
Hashing
 
asymptotic notation
asymptotic notationasymptotic notation
asymptotic notation
 
Tree and graph
Tree and graphTree and graph
Tree and graph
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
stack presentation
stack presentationstack presentation
stack presentation
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Sorting
SortingSorting
Sorting
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
 
Linked List
Linked ListLinked List
Linked List
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Hash table in data structure and algorithm
Hash table in data structure and algorithmHash table in data structure and algorithm
Hash table in data structure and algorithm
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 

Similar to Asymptotic Notation and Data Structures

for sbi so Ds c c++ unix rdbms sql cn os
for sbi so   Ds c c++ unix rdbms sql cn osfor sbi so   Ds c c++ unix rdbms sql cn os
for sbi so Ds c c++ unix rdbms sql cn osalisha230390
 
19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm ComplexityIntro C# Book
 
Stack squeues lists
Stack squeues listsStack squeues lists
Stack squeues listsJames Wong
 
Stacksqueueslists
StacksqueueslistsStacksqueueslists
StacksqueueslistsFraboni Ec
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues listsTony Nguyen
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues listsHarry Potter
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues listsYoung Alista
 
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRYON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRYFransiskeran
 
19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexityIntro C# Book
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to MatlabAmr Rashed
 
presentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptxpresentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptxjainaaru59
 
Improving circuit miniaturization and its efficiency using Rough Set Theory( ...
Improving circuit miniaturization and its efficiency using Rough Set Theory( ...Improving circuit miniaturization and its efficiency using Rough Set Theory( ...
Improving circuit miniaturization and its efficiency using Rough Set Theory( ...Sarvesh Singh
 
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEA NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEijscmcj
 
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEA NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEijscmc
 
On algorithmic problems concerning graphs of higher degree of symmetry
On algorithmic problems concerning graphs of higher degree of symmetryOn algorithmic problems concerning graphs of higher degree of symmetry
On algorithmic problems concerning graphs of higher degree of symmetrygraphhoc
 

Similar to Asymptotic Notation and Data Structures (20)

Q
QQ
Q
 
AlgorithmAnalysis2.ppt
AlgorithmAnalysis2.pptAlgorithmAnalysis2.ppt
AlgorithmAnalysis2.ppt
 
for sbi so Ds c c++ unix rdbms sql cn os
for sbi so   Ds c c++ unix rdbms sql cn osfor sbi so   Ds c c++ unix rdbms sql cn os
for sbi so Ds c c++ unix rdbms sql cn os
 
19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity
 
Stack squeues lists
Stack squeues listsStack squeues lists
Stack squeues lists
 
Stacksqueueslists
StacksqueueslistsStacksqueueslists
Stacksqueueslists
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues lists
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues lists
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues lists
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues lists
 
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRYON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
ON ALGORITHMIC PROBLEMS CONCERNING GRAPHS OF HIGHER DEGREE OF SYMMETRY
 
19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity19. Java data structures algorithms and complexity
19. Java data structures algorithms and complexity
 
Linear algebra havard university
Linear algebra havard universityLinear algebra havard university
Linear algebra havard university
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
presentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptxpresentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptx
 
Improving circuit miniaturization and its efficiency using Rough Set Theory( ...
Improving circuit miniaturization and its efficiency using Rough Set Theory( ...Improving circuit miniaturization and its efficiency using Rough Set Theory( ...
Improving circuit miniaturization and its efficiency using Rough Set Theory( ...
 
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEA NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
 
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREEA NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
A NEW PARALLEL ALGORITHM FOR COMPUTING MINIMUM SPANNING TREE
 
R for Statistical Computing
R for Statistical ComputingR for Statistical Computing
R for Statistical Computing
 
On algorithmic problems concerning graphs of higher degree of symmetry
On algorithmic problems concerning graphs of higher degree of symmetryOn algorithmic problems concerning graphs of higher degree of symmetry
On algorithmic problems concerning graphs of higher degree of symmetry
 

More from Amrinder Arora

Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Amrinder Arora
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchAmrinder Arora
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalAmrinder Arora
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Amrinder Arora
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaAmrinder Arora
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Amrinder Arora
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Amrinder Arora
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Amrinder Arora
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine LearningAmrinder Arora
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisAmrinder Arora
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part IIAmrinder Arora
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1Amrinder Arora
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsAmrinder Arora
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersAmrinder Arora
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsAmrinder Arora
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresAmrinder Arora
 
Tries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsTries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsAmrinder Arora
 

More from Amrinder Arora (20)

Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
 
NP-Completeness - II
NP-Completeness - IINP-Completeness - II
NP-Completeness - II
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine Learning
 
NP completeness
NP completenessNP completeness
NP completeness
 
Algorithmic Puzzles
Algorithmic PuzzlesAlgorithmic Puzzles
Algorithmic Puzzles
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
 
Tries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsTries - Tree Based Structures for Strings
Tries - Tree Based Structures for Strings
 

Recently uploaded

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 

Recently uploaded (20)

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 

Asymptotic Notation and Data Structures

  • 1. CS 6212 – Design and Analysis of Algorithms ASYMPTOTIC NOTATION AND DATA STRUCTURES
  • 2.  Instructor Prof. Amrinder Arora amrinder@gwu.edu Please copy TA on emails Please feel free to call as well   Available for study sessions Science and Engineering Hall GWU Algorithms Asymptotic Notation and Data Structures 2 LOGISTICS
  • 3.  Asymptotic Notation  Big Oh  Small Oh  Big Omega  Small Omega  Theta Algorithms Asymptotic Notation and Data Structures 3 RECAP
  • 4.  Big O notation  f(n) = O(g(n)) if there exist constants n0 and c such that f(n) ≤ c g(n) for all n ≥ n0. For example, n = O(2n) and 2n = O(n) If f(n) = a0 n0 + a1 n1 + … + am nm, then f(n) = O (nm)  Big Omega notation  f(n) = Ω(g(n)) if there exist constants n0 and c such that f(n) ≥ c g(n) for all n ≥ n0.  Small o notation  f(n) = o(g(n)) if for any constant c > 0, there exists n0 such that 0 ≤ f(n) < c g(n) for all n ≥ n0. For example, n = o(n2)  Small omega () notation  f(n) = (g(n)) if for any constant c > 0, there exists n0 such that f(n) ≥ c g(n) ≥ 0, for all n ≥ n0 For example, n3 = (n2)  Theta ( or ) notation  If f(n) = O(g(n)) and g(n) = O(f(n)), then f(n) = (g(n)) 4 ASYMPTOTIC NOTATIONS Algorithms Asymptotic Notation and Data Structures
  • 5.  Transpose symmetry  f(n) = O(g(n)) if and only if g(n) = Ω(f(n))  f(n) = o(g(n)) if and only if g(n) = (f(n))  Limit method  f(n) = o(g(n)) implies limnf(n)/g(n) = 0  Using L’Hopital’s rule is common when using this method. 5 ASYMPTOTIC NOTATIONS (CONT.) Algorithms Asymptotic Notation and Data Structures
  • 6. O o   Ω ≤ < = > ≥ 6 ASYMPTOTIC NOTATIONS (CONT.) Analogy with real numbers Algorithms Asymptotic Notation and Data Structures
  • 7. Which properties apply to which (of 5) asymptotic notations?  Transitivity  Reflexivity  Symmetry  Transpose Symmetry  Trichotomy 7 ASYMPTOTIC NOTATIONS (CONT.) Algorithms Asymptotic Notation and Data Structures
  • 8. Which properties apply to which (of 5) asymptotic notations?  Transitivity: O, o, , , Ω  Reflexivity: O, , Ω  Symmetry:   Transpose Symmetry: (O with Ω, o with )  Trichotomy: Does not hold. For real numbers x and y, we can always say that either x < y or x = y or x > y. For functions, we may not be able to say that. For example if f(n) = sin(n) and g(n)=cos(n) 8 ASYMPTOTIC NOTATIONS (CONT.) Algorithms Asymptotic Notation and Data Structures
  • 9. O o   Ω ≤ < = > ≥ Algorithms Asymptotic Notation and Data Structures 9 ASYMPTOTIC NOTATIONS (CONT.) Analogy with real numbers Question: Does it still not hold if we limit ourselves to functions that are positive, always increasing with n, and are not trigonometric?
  • 10. Special Functions  Polynomial vs. exponential  Polynomial vs. logs  Factorial / Combinatorial  Trigonometric Functions  Floors and Ceilings Algorithms Asymptotic Notation and Data Structures 10 ASYMPTOTIC NOTATIONS (CONT.) How do we prove that 2^n = omega (n^k)? We want to prove that for any given c, there exists n0, such that 2^n > c * n^k, for all n > n0.
  • 11.  Divide and Conquer  Greedy Method  Dynamic Programming  Graph search methods  Backtracking  Branch and bound Algorithms Asymptotic Notation and Data Structures 11 DESIGNING AN ALGORITHM – TECHNIQUES
  • 12.  Define the problem  Find a working solution  Fast enough?  If not, you may have two options:  Consider a different technique  Consider a different data structure  Iterate until satisfied. Algorithms Asymptotic Notation and Data Structures 12 HOW TO DESIGN A FAST ALGORITHM?
  • 13.  A data structure is a structure to hold the data, that allows several interesting operations to be performed on the data set.  The data structure is designed with those specific operations in mind.  General problem:  Given a data set and the operations that need to be supported, come up with a data structure (organization) that allows those operations to be done in an efficient manner. Algorithms Asymptotic Notation and Data Structures 13 DATA STRUCTURES
  • 14.  Last In First Out (LIFO)  Allows 3 operations:  Push (a)  Pop()  Top() Algorithms Asymptotic Notation and Data Structures 14 STACK
  • 15.  Using an array  Use an array S[1:N], and use a special pointer to the “top” of the stack.  When pushing something on the stack, increment the pointer  When popping, decrement the pointer  Using a linked list  Use a special pointer to the “top” of the stack  When pushing something on the stack, advance the “top” pointer  When popping, move the “top” pointer back one step – this suggests that the linked list must be a doubly linked list Algorithms Asymptotic Notation and Data Structures 15 IMPLEMENTATION OF STACKS
  • 16.  First In First Out (FIFO)  Allows 2 operations:  dequeue(): Returns the first element  enqueue(a): Adds an element a to the end of the queue Algorithms Asymptotic Notation and Data Structures 16 QUEUE
  • 17. tail -> …… -> head  Using an array  Keep “head” and “tail” indexes  Using a linked list  Keep “head” and “tail” pointers  Handling operations  When enqueuing an item, move tail one step to the left.  When dequeuing an item, move head one step to the left Algorithms Asymptotic Notation and Data Structures 17 QUEUE – IMPLEMENTATION
  • 18.  A record is a built-in structure data type, that allows the packaging of several elements (called fields)  Every high level language allows the user to define customized records.  In C#/Java, this is called “class”.  In C, this is called “struct”. Algorithms Asymptotic Notation and Data Structures 18 RECORD STRUCT OBJECT CLASS TEMPLATE
  • 19.  Singly Linked  A singly linked list is a sequence of records, where every record has a field that points to the next record  A special pointer called “first” has the reference to the first record  Doubly Linked  A doubly linked list is a sequence of records, where every record has a field that points to the next record, and a field that points to the previous record  Special pointers called “first” and “last” with references to the first and the last records Algorithms Asymptotic Notation and Data Structures 19 LINKED LISTS
  • 20.  A graph G=(V,E) consists of a finite set V, which is the set of vertices, and set E, which is the set of edges. Each edge in E connects two vertices v1 and v2, which are in V.  Can be directed or undirected Algorithms Asymptotic Notation and Data Structures 20 GRAPH
  • 21.  If (x,y) is an edge, then x is said to be adjacent to y, and y is adjacent from x.  In the case of undirected graphs, if (x,y) is an edge, we just say that x and y are adjacent (or x is adjacent to y, or y is adjacent to x). Also, we say that x is the neighbor of y.  The indegree of a node x is the number of nodes adjacent to x  The outdegree of a node x is the number of nodes adjacent from x  The degree of a node x in an undirected graph is the number of neighbors of x  A path from a node x to a node y in a graph is a sequence of node x, x1,x2,...,xn,y, such that x is adjacent to x1, x1 is adjacent to x2, ..., and xn is adjacent to y.  The length of a path is the number of its edges.  A cycle is a path that begins and ends at the same node  The distance from node x to node y is the length of the shortest path from x to y. Algorithms Asymptotic Notation and Data Structures 21 GRAPH DEFINITIONS
  • 22.  Using a matrix A[1..n,1..n] where A[i,j] = 1 if (i,j) is an edge, and is 0 otherwise. This representation is called the adjacency matrix representation. If the graph is undirected, then the adjacency matrix is symmetric about the main diagonal.  Using an array Adj[1..n] of pointers, which Adj[i] is a linked list of nodes which are adjacent to i.  The matrix representation requires more memory, since it has a matrix cell for each possible edge, whether that edge exists or not. In adjacency list representation, the space used is directly proportional to the number of edges.  If the graph is sparse (very few edges), then adjacency list may be a more efficient choice. Algorithms Asymptotic Notation and Data Structures 22 GRAPH REPRESENTATIONS
  • 23.  A tree is a connected acyclic graph (i.e., it has no cycles)  Rooted tree: A tree in which one node is designated as a root (the top node) Algorithms Asymptotic Notation and Data Structures 23 TREE Example: Node A is root node F and D are child nodes of A. P and Q are child nodes of J. Etc.
  • 24.  Definitions  Leaf is a node that has no children  Ancestors of a node x are all the nodes on the path from x to the root, including x and the root  Subtree rooted at x is the tree consisting of x, its children and their children, and so on and so forth all the way down  Height of a tree is the maximum distance from the root to any node Algorithms Asymptotic Notation and Data Structures 24 TREE
  • 25.  A tree where every node has at most two children  Binary Search Tree (BST): BST is a binary search tree where every node contains a value, and for every node x, all the nodes of the left subtree of x have values <= x, and all nodes in the right subtree of x have values >= x.  BST supports 3 operations: insert(x), delete(x) and search(x)  It is more interesting (and efficient) if the BST is “height balanced”. Red Black and AVL trees are interesting implementations of height balanced BSTs. Algorithms Asymptotic Notation and Data Structures 25 BINARY TREE
  • 26.  Also known as priority queues  Very efficient data structure to enforce priority, although do not enforce complete sorting  Can be max heap or min heap  Commonly represented using a heap tree (although, can also be a forest) Algorithms Asymptotic Notation and Data Structures 26 HEAPS
  • 27.  Flexible data structure, where a node has a variable number of children (say between 2 and 4, both including, or between 50 and 100 both including)  This variable number allows us to leave some “holes” in the tree to fill as insertions happen, thereby allowing insertions without changing the structure of the tree entirely.  The variable number also allows us to treat deletions without changing the structure.  2-3 tree is a specific kind of BTree where each node can have 2 or 3 children. http://www.slideshare.net/amrinderarora/btrees-great- alternative-to-red-black-avl-and-other-bsts Algorithms Asymptotic Notation and Data Structures 27 BTREE, 2-3 TREE
  • 28.  Also called “Disjoint Set” data structure  How to maintain sets dynamically – sets can be merged (union), and we want to see which set a particular element is in.  find(x)  Identifies the set that element x belongs to  Union (S1, S2)  Combines these two sets Algorithms Asymptotic Notation and Data Structures 28 UNION FIND
  • 29. Each set is marked by a leader When calling “find” on a set’s member, it returns the leader Leader maintains a rank (or height) When doing a union, make the tree with smaller height (or rank) to be a child of the tree with the larger height Note that this is NOT a binary tree. Algorithms Asymptotic Notation and Data Structures 29 UNION FIND DATA STRUCTURE
  • 30.  When doing a find, follow that up by compressing the path to the root, by making every node (along the way) point to the root.  This is not easy to prove, but Union Find with Path compression, when starting with n nodes and m operations, takes O(m log*(n)) time instead of O(m log n) time, where the log* function is the iterated logarithm (also called the super logarithm) and is an extremely slow growing function.  log*(n) is defined as follows:  0, if n <= 1  1 + log*(log n) if n > 1 Algorithms Asymptotic Notation and Data Structures 30 UNION FIND – PATH COMPRESSION
  • 31. Algorithms Asymptotic Notation and Data Structures 31 SOME PRACTICAL PROBLEMS  Terrorism, insider trading, financial fraud analysis  Are two people connected given millions of “x knows y” statements?  Vulnerability Assessment  Are two computers in a network connected?  IC Design  Are two points shot circuited on this mother board?  Click Fraud Analysis, Page Ranking  Are two web pages connected (indirectly)?  Abstractions  Given a graph, is there a path connecting one node to another?  How can we organize a given universe of objects into sets?
  • 32. Algorithms Asymptotic Notation and Data Structures 32 EXAMPLE
  • 33. Algorithms Asymptotic Notation and Data Structures 33 EXAMPLE (CONT.)
  • 34.  Divide and Conquer  http://www.cs.cmu.edu/afs/cs/academic/class/15210- f11/www/lectures/03/lecture03.pdf  http://en.wikipedia.org/wiki/Divide_and_conquer_algorithm  Recursive Algorithm http://en.wikipedia.org/wiki/Recursion_(computer_science)  Tail Recursion http://en.wikipedia.org/wiki/Tail_call  Recurrence Relations http://en.wikipedia.org/wiki/Recurrence_relation Algorithms Asymptotic Notation and Data Structures 34 READING ASSIGNMENT