SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
Lecture 4:
  Elementary Data Structures
         Steven Skiena

Department of Computer Science
 State University of New York
 Stony Brook, NY 11794–4400

http://www.cs.sunysb.edu/∼skiena
Problem of the Day
True or False?
1. 2n2 + 1 = O(n2 )
   √
2. n = O(log n)
             √
3. log n = O( n)
          √
4. n2 (1 + n) = O(n2 log n)
          √
      2
5. 3n + n = O(n2 )
   √
6. n log n = O(n)
7. log n = O(n−1/2 )
The Base is not Asymptotically Important

Recall the definition, clogc x = x and that
                                  logc a
                        logb a =
                                  log c b
Thus log 2 n = (1/ log 100 2) × log 100 n. Since 1/ log 100 2 =
6.643 is just a constant, it does not matter in the Big Oh.
Federal Sentencing Guidelines
2F1.1. Fraud and Deceit; Forgery; Offenses Involving Altered or Counterfeit Instruments other than Counterfeit Bearer Obligations of the United States.
(a) Base offense Level: 6
(b) Specific offense Characteristics


(1) If the loss exceeded $2,000, increase the offense level as follows:

                                                        Loss(Apply the Greatest)     Increase in Level
                                                        (A) $2,000 or less                 no increase
                                                        (B) More than $2,000                     add 1
                                                        (C) More than $5,000                     add 2
                                                        (D) More than $10,000                    add 3
                                                        (E) More than $20,000                    add 4
                                                        (F) More than $40,000                    add 5
                                                        (G) More than $70,000                    add 6
                                                        (H) More than $120,000                   add 7
                                                        (I) More than $200,000                   add 8
                                                        (J) More than $350,000                   add 9
                                                        (K) More than $500,000                  add 10
                                                        (L) More than $800,000                  add 11
                                                        (M) More than $1,500,000                add 12
                                                        (N) More than $2,500,000                add 13
                                                        (O) More than $5,000,000                add 14
                                                        (P) More than $10,000,000               add 15
                                                        (Q) More than $20,000,000               add 16
                                                        (R) More than $40,000,000               add 17
                                                        (Q) More than $80,000,000               add 18
Make the Crime Worth the Time
The increase in punishment level grows logarithmically in the
amount of money stolen.
Thus it pays to commit one big crime rather than many small
crimes totalling the same amount.
Elementary Data Structures
“Mankind’s progress is measured by the number of things we
can do without thinking.”
Elementary data structures such as stacks, queues, lists,
and heaps are the “off-the-shelf” components we build our
algorithm from.
There are two aspects to any data structure:
 • The abstract operations which it supports.
 • The implementation of these operations.
Data Abstraction
That we can describe the behavior of our data structures in
terms of abstract operations is why we can use them without
thinking.
That there are different implementations of the same abstract
operations enables us to optimize performance.
Contiguous vs. Linked Data Structures
Data structures can be neatly classified as either contiguous
or linked depending upon whether they are based on arrays or
pointers:
 • Contiguously-allocated structures are composed of single
   slabs of memory, and include arrays, matrices, heaps, and
   hash tables.
 • Linked data structures are composed of multiple distinct
   chunks of memory bound together by pointers, and
   include lists, trees, and graph adjacency lists.
Arrays
An array is a structure of fixed-size data records such that
each element can be efficiently located by its index or
(equivalently) address.
Advantages of contiguously-allocated arrays include:
 • Constant-time access given the index.
 • Arrays consist purely of data, so no space is wasted with
   links or other formatting information.
 • Physical continuity (memory locality) between successive
   data accesses helps exploit the high-speed cache memory
   on modern computer architectures.
Dynamic Arrays
Unfortunately we cannot adjust the size of simple arrays in
the middle of a program’s execution.
Compensating by allocating extremely large arrays can waste
a lot of space.
With dynamic arrays we start with an array of size 1, and
double its size from m to 2m each time we run out of space.
How many times will we double for n elements? Only
 log 2 n .
How Much Total Work?
The apparent waste in this procedure involves the recopying
of the old contents on each expansion.
If half the elements move once, a quarter of the elements
twice, and so on, the total number of movements M is given
by
             lg n                 lg n             ∞
                          i                i
       M=           i · n/2 = n          i/2 ≤ n         i/2i = 2n
             i=1                  i=1              i=1
Thus each of the n elements move an average of only twice,
and the total work of managing the dynamic array is the same
O(n) as a simple array.
Pointers and Linked Structures
Pointers represent the address of a location in memory.
A cell-phone number can be thought of as a pointer to its
owner as they move about the planet.
In C, *p denotes the item pointed to by p, and &x denotes the
address (i.e. pointer) of a particular variable x.
A special NULL pointer value is used to denote structure-
terminating or unassigned pointers.
Linked List Structures

typedef struct list {
      item type item;
      struct list *next;
} list;

             Lincoln     Jefferson   Clinton   NIL
Searching a List
Searching in a linked list can be done iteratively or
recursively.
list *search list(list *l, item type x)
{
      if (l == NULL) return(NULL);

      if (l− >item == x)
            return(l);
      else
            return( search list(l− >next, x) );
}
Insertion into a List
Since we have no need to maintain the list in any particular
order, we might as well insert each new item at the head.
void insert list(list **l, item type x)
{
      list *p;

      p = malloc( sizeof(list) );
      p− >item = x;
      p− >next = *l;
      *l = p;
}


Note the **l, since the head element of the list changes.
Deleting from a List

delete list(list **l, item type x)
{
      list *p; (* item pointer *)
      list *last = NULL; (* predecessor pointer *)

      p = *l;
      while (p− >item != x) { (* find item to delete *)
            last = p;
            p = p− >next;
      }

      if (last == NULL) (* splice out of the list *)
            *l = p− >next;
      else
            last− >next = p− >next;

      free(p); (* return memory used by the node *)
}
Advantages of Linked Lists
The relative advantages of linked lists over static arrays
include:
1. Overflow on linked structures can never occur unless the
   memory is actually full.
2. Insertions and deletions are simpler than for contiguous
   (array) lists.
3. With large records, moving pointers is easier and faster
   than moving the items themselves.
Dynamic memory allocation provides us with flexibility on
how and where we use our limited storage resources.
Stacks and Queues
Sometimes, the order in which we retrieve data is independent
of its content, being only a function of when it arrived.
A stack supports last-in, first-out operations: push and pop.
A queue supports first-in, first-out operations: enqueue and
dequeue.
Lines in banks are based on queues, while food in my
refrigerator is treated as a stack.
Impact on Tree Traversal
Both can be used to store nodes to visit in a tree, but the order
of traversal is completely different.
                            1                            1




                  2                 3           5                2




              4       5         6       7   7       6        4       3

                          Queue                         Stack



Which order is friendlier for WWW crawler robots?
Dictonary / Dynamic Set Operations
Perhaps the most important class of data structures maintain
a set of items, indexed by keys.
 • Search(S,k) – A query that, given a set S and a key value
   k, returns a pointer x to an element in S such that key[x]
   = k, or nil if no such element belongs to S.
 • Insert(S,x) – A modifying operation that augments the set
   S with the element x.
 • Delete(S,x) – Given a pointer x to an element in the set S,
   remove x from S. Observe we are given a pointer to an
   element x, not a key value.
• Min(S), Max(S) – Returns the element of the totally
   ordered set S which has the smallest (largest) key.
 • Next(S,x), Previous(S,x) – Given an element x whose key
   is from a totally ordered set S, returns the next largest
   (smallest) element in S, or NIL if x is the maximum
   (minimum) element.
There are a variety of implementations of these dictionary
operations, each of which yield different time bounds for
various operations.
Array Based Sets: Unsorted Arrays

 • Search(S,k) - sequential search, O(n)
 • Insert(S,x) - place in first empty spot, O(1)
 • Delete(S,x) - copy nth item to the xth spot, O(1)
 • Min(S,x), Max(S,x) - sequential search, O(n)
 • Successor(S,x), Predecessor(S,x) - sequential search,
   O(n)
Array Based Sets: Sorted Arrays

 • Search(S,k) - binary search, O(lg n)
 • Insert(S,x) - search, then move to make space, O(n)
 • Delete(S,x) - move to fill up the hole, O(n)
 • Min(S,x), Max(S,x) - first or last element, O(1)
 • Successor(S,x), Predecessor(S,x) - Add or subtract 1 from
   pointer, O(1)
Pointer Based Implementation
We can maintain a dictionary in either a singly or doubly
linked list.
            L
                A    B    C    D   E    F




            L   A    B    C    D   E    F
Doubly Linked Lists
We gain extra flexibility on predecessor queries at a cost of
doubling the number of pointers by using doubly-linked lists.
Since the extra big-Oh costs of doubly-linkly lists is zero,
we will usually assume they are, although it might not be
necessary.
Singly linked to doubly-linked list is as a Conga line is to a
Can-Can line.

Más contenido relacionado

La actualidad más candente

Calculus Cheat Sheet All
Calculus Cheat Sheet AllCalculus Cheat Sheet All
Calculus Cheat Sheet AllMoe Han
 
Introduction to inverse problems
Introduction to inverse problemsIntroduction to inverse problems
Introduction to inverse problemsDelta Pi Systems
 
Succinct Data Structure for Analyzing Document Collection
Succinct Data Structure for Analyzing Document CollectionSuccinct Data Structure for Analyzing Document Collection
Succinct Data Structure for Analyzing Document CollectionPreferred Networks
 
Homomorphism and Anti-homomorphism of Multi-Fuzzy Ideal and Multi-Anti Fuzzy ...
Homomorphism and Anti-homomorphism of Multi-Fuzzy Ideal and Multi-Anti Fuzzy ...Homomorphism and Anti-homomorphism of Multi-Fuzzy Ideal and Multi-Anti Fuzzy ...
Homomorphism and Anti-homomorphism of Multi-Fuzzy Ideal and Multi-Anti Fuzzy ...iosrjce
 
Linear regression with R 1
Linear regression with R 1Linear regression with R 1
Linear regression with R 1Kazuki Yoshida
 
Chapter 1 functions
Chapter 1  functionsChapter 1  functions
Chapter 1 functionsUmair Pearl
 
The multilayer perceptron
The multilayer perceptronThe multilayer perceptron
The multilayer perceptronESCOM
 
Some fixed point theorems in generalised dislocated metric spaces
Some fixed point theorems in generalised dislocated metric spacesSome fixed point theorems in generalised dislocated metric spaces
Some fixed point theorems in generalised dislocated metric spacesAlexander Decker
 
11.some fixed point theorems in generalised dislocated metric spaces
11.some fixed point theorems in generalised dislocated metric spaces11.some fixed point theorems in generalised dislocated metric spaces
11.some fixed point theorems in generalised dislocated metric spacesAlexander Decker
 
237654933 mathematics-t-form-6
237654933 mathematics-t-form-6237654933 mathematics-t-form-6
237654933 mathematics-t-form-6homeworkping3
 
Concept map function
Concept map functionConcept map function
Concept map functionzabidah awang
 
Calculus First Test 2011/10/20
Calculus First Test 2011/10/20Calculus First Test 2011/10/20
Calculus First Test 2011/10/20Kuan-Lun Wang
 
Change of variables in double integrals
Change of variables in double integralsChange of variables in double integrals
Change of variables in double integralsTarun Gehlot
 
Sienna 7 heaps
Sienna 7 heapsSienna 7 heaps
Sienna 7 heapschidabdu
 
Cea0001 ppt project
Cea0001 ppt projectCea0001 ppt project
Cea0001 ppt projectcea0001
 
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups mathsjournal
 

La actualidad más candente (20)

Calculus Cheat Sheet All
Calculus Cheat Sheet AllCalculus Cheat Sheet All
Calculus Cheat Sheet All
 
Introduction to inverse problems
Introduction to inverse problemsIntroduction to inverse problems
Introduction to inverse problems
 
Succinct Data Structure for Analyzing Document Collection
Succinct Data Structure for Analyzing Document CollectionSuccinct Data Structure for Analyzing Document Collection
Succinct Data Structure for Analyzing Document Collection
 
Analysis Solutions CVI
Analysis Solutions CVIAnalysis Solutions CVI
Analysis Solutions CVI
 
Homomorphism and Anti-homomorphism of Multi-Fuzzy Ideal and Multi-Anti Fuzzy ...
Homomorphism and Anti-homomorphism of Multi-Fuzzy Ideal and Multi-Anti Fuzzy ...Homomorphism and Anti-homomorphism of Multi-Fuzzy Ideal and Multi-Anti Fuzzy ...
Homomorphism and Anti-homomorphism of Multi-Fuzzy Ideal and Multi-Anti Fuzzy ...
 
Semantic Data Box
Semantic Data BoxSemantic Data Box
Semantic Data Box
 
Linear regression with R 1
Linear regression with R 1Linear regression with R 1
Linear regression with R 1
 
Chapter 1 functions
Chapter 1  functionsChapter 1  functions
Chapter 1 functions
 
The multilayer perceptron
The multilayer perceptronThe multilayer perceptron
The multilayer perceptron
 
Some fixed point theorems in generalised dislocated metric spaces
Some fixed point theorems in generalised dislocated metric spacesSome fixed point theorems in generalised dislocated metric spaces
Some fixed point theorems in generalised dislocated metric spaces
 
11.some fixed point theorems in generalised dislocated metric spaces
11.some fixed point theorems in generalised dislocated metric spaces11.some fixed point theorems in generalised dislocated metric spaces
11.some fixed point theorems in generalised dislocated metric spaces
 
237654933 mathematics-t-form-6
237654933 mathematics-t-form-6237654933 mathematics-t-form-6
237654933 mathematics-t-form-6
 
Claire98
Claire98Claire98
Claire98
 
Ex algebra (5)
Ex algebra  (5)Ex algebra  (5)
Ex algebra (5)
 
Concept map function
Concept map functionConcept map function
Concept map function
 
Calculus First Test 2011/10/20
Calculus First Test 2011/10/20Calculus First Test 2011/10/20
Calculus First Test 2011/10/20
 
Change of variables in double integrals
Change of variables in double integralsChange of variables in double integrals
Change of variables in double integrals
 
Sienna 7 heaps
Sienna 7 heapsSienna 7 heaps
Sienna 7 heaps
 
Cea0001 ppt project
Cea0001 ppt projectCea0001 ppt project
Cea0001 ppt project
 
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
A Study on Intuitionistic Multi-Anti Fuzzy Subgroups
 

Destacado

02 cv mil_intro_to_probability
02 cv mil_intro_to_probability02 cv mil_intro_to_probability
02 cv mil_intro_to_probabilityzukun
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structuresKuber Chandra
 
ETHZ CV2012: Information
ETHZ CV2012: InformationETHZ CV2012: Information
ETHZ CV2012: Informationzukun
 
ETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVzukun
 
My lyn tutorial 2009
My lyn tutorial 2009My lyn tutorial 2009
My lyn tutorial 2009zukun
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++Ngeam Soly
 

Destacado (10)

02 cv mil_intro_to_probability
02 cv mil_intro_to_probability02 cv mil_intro_to_probability
02 cv mil_intro_to_probability
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
 
ETHZ CV2012: Information
ETHZ CV2012: InformationETHZ CV2012: Information
ETHZ CV2012: Information
 
ETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCV
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
 
My lyn tutorial 2009
My lyn tutorial 2009My lyn tutorial 2009
My lyn tutorial 2009
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 

Similar a Skiena algorithm 2007 lecture04 elementary data structures

Types Working for You, Not Against You
Types Working for You, Not Against YouTypes Working for You, Not Against You
Types Working for You, Not Against YouC4Media
 
Extracting Executable Transformations from Distilled Code Changes
Extracting Executable Transformations from Distilled Code ChangesExtracting Executable Transformations from Distilled Code Changes
Extracting Executable Transformations from Distilled Code Changesstevensreinout
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systemsleague
 
Mining Functional Patterns
Mining Functional PatternsMining Functional Patterns
Mining Functional PatternsDebasish Ghosh
 
Building a Functional Stream in Scala
Building a Functional Stream in ScalaBuilding a Functional Stream in Scala
Building a Functional Stream in ScalaDerek Wyatt
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structuresMohd Arif
 
Dancing Links: an educational pearl
Dancing Links: an educational pearlDancing Links: an educational pearl
Dancing Links: an educational pearlESUG
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structuresNiraj Agarwal
 
Review session2
Review session2Review session2
Review session2NEEDY12345
 
Quantitative Methods for Lawyers - Class #21 - Regression Analysis - Part 4
Quantitative Methods for Lawyers - Class #21 - Regression Analysis - Part 4Quantitative Methods for Lawyers - Class #21 - Regression Analysis - Part 4
Quantitative Methods for Lawyers - Class #21 - Regression Analysis - Part 4Daniel Katz
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed worldDebasish Ghosh
 
Applicationof datastructures
Applicationof datastructuresApplicationof datastructures
Applicationof datastructuresHitesh Wagle
 
Applicationof datastructures
Applicationof datastructuresApplicationof datastructures
Applicationof datastructuresHitesh Wagle
 
Lec 03 - Combinational Logic Design
Lec 03 - Combinational Logic DesignLec 03 - Combinational Logic Design
Lec 03 - Combinational Logic DesignVajira Thambawita
 

Similar a Skiena algorithm 2007 lecture04 elementary data structures (20)

Types Working for You, Not Against You
Types Working for You, Not Against YouTypes Working for You, Not Against You
Types Working for You, Not Against You
 
2 depth first
2 depth first2 depth first
2 depth first
 
Extracting Executable Transformations from Distilled Code Changes
Extracting Executable Transformations from Distilled Code ChangesExtracting Executable Transformations from Distilled Code Changes
Extracting Executable Transformations from Distilled Code Changes
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systems
 
Mining Functional Patterns
Mining Functional PatternsMining Functional Patterns
Mining Functional Patterns
 
Building a Functional Stream in Scala
Building a Functional Stream in ScalaBuilding a Functional Stream in Scala
Building a Functional Stream in Scala
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structures
 
Hprec5.2
Hprec5.2Hprec5.2
Hprec5.2
 
Q
QQ
Q
 
Dancing Links: an educational pearl
Dancing Links: an educational pearlDancing Links: an educational pearl
Dancing Links: an educational pearl
 
Zippers
ZippersZippers
Zippers
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
Review session2
Review session2Review session2
Review session2
 
Quantitative Methods for Lawyers - Class #21 - Regression Analysis - Part 4
Quantitative Methods for Lawyers - Class #21 - Regression Analysis - Part 4Quantitative Methods for Lawyers - Class #21 - Regression Analysis - Part 4
Quantitative Methods for Lawyers - Class #21 - Regression Analysis - Part 4
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
 
Applicationof datastructures
Applicationof datastructuresApplicationof datastructures
Applicationof datastructures
 
Applicationof datastructures
Applicationof datastructuresApplicationof datastructures
Applicationof datastructures
 
Libretto
LibrettoLibretto
Libretto
 
Lec 03 - Combinational Logic Design
Lec 03 - Combinational Logic DesignLec 03 - Combinational Logic Design
Lec 03 - Combinational Logic Design
 
An Introduction to RxJava
An Introduction to RxJavaAn Introduction to RxJava
An Introduction to RxJava
 

Más de zukun

Siwei lyu: natural image statistics
Siwei lyu: natural image statisticsSiwei lyu: natural image statistics
Siwei lyu: natural image statisticszukun
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibrationzukun
 
Brunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionBrunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionzukun
 
Modern features-part-4-evaluation
Modern features-part-4-evaluationModern features-part-4-evaluation
Modern features-part-4-evaluationzukun
 
Modern features-part-3-software
Modern features-part-3-softwareModern features-part-3-software
Modern features-part-3-softwarezukun
 
Modern features-part-2-descriptors
Modern features-part-2-descriptorsModern features-part-2-descriptors
Modern features-part-2-descriptorszukun
 
Modern features-part-1-detectors
Modern features-part-1-detectorsModern features-part-1-detectors
Modern features-part-1-detectorszukun
 
Modern features-part-0-intro
Modern features-part-0-introModern features-part-0-intro
Modern features-part-0-introzukun
 
Lecture 02 internet video search
Lecture 02 internet video searchLecture 02 internet video search
Lecture 02 internet video searchzukun
 
Lecture 01 internet video search
Lecture 01 internet video searchLecture 01 internet video search
Lecture 01 internet video searchzukun
 
Lecture 03 internet video search
Lecture 03 internet video searchLecture 03 internet video search
Lecture 03 internet video searchzukun
 
Icml2012 tutorial representation_learning
Icml2012 tutorial representation_learningIcml2012 tutorial representation_learning
Icml2012 tutorial representation_learningzukun
 
Advances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionAdvances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionzukun
 
Gephi tutorial: quick start
Gephi tutorial: quick startGephi tutorial: quick start
Gephi tutorial: quick startzukun
 
EM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysisEM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysiszukun
 
Object recognition with pictorial structures
Object recognition with pictorial structuresObject recognition with pictorial structures
Object recognition with pictorial structureszukun
 
Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities zukun
 
Icml2012 learning hierarchies of invariant features
Icml2012 learning hierarchies of invariant featuresIcml2012 learning hierarchies of invariant features
Icml2012 learning hierarchies of invariant featureszukun
 
ECCV2010: Modeling Temporal Structure of Decomposable Motion Segments for Act...
ECCV2010: Modeling Temporal Structure of Decomposable Motion Segments for Act...ECCV2010: Modeling Temporal Structure of Decomposable Motion Segments for Act...
ECCV2010: Modeling Temporal Structure of Decomposable Motion Segments for Act...zukun
 
Quoc le tera-scale deep learning
Quoc le   tera-scale deep learningQuoc le   tera-scale deep learning
Quoc le tera-scale deep learningzukun
 

Más de zukun (20)

Siwei lyu: natural image statistics
Siwei lyu: natural image statisticsSiwei lyu: natural image statistics
Siwei lyu: natural image statistics
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibration
 
Brunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionBrunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer vision
 
Modern features-part-4-evaluation
Modern features-part-4-evaluationModern features-part-4-evaluation
Modern features-part-4-evaluation
 
Modern features-part-3-software
Modern features-part-3-softwareModern features-part-3-software
Modern features-part-3-software
 
Modern features-part-2-descriptors
Modern features-part-2-descriptorsModern features-part-2-descriptors
Modern features-part-2-descriptors
 
Modern features-part-1-detectors
Modern features-part-1-detectorsModern features-part-1-detectors
Modern features-part-1-detectors
 
Modern features-part-0-intro
Modern features-part-0-introModern features-part-0-intro
Modern features-part-0-intro
 
Lecture 02 internet video search
Lecture 02 internet video searchLecture 02 internet video search
Lecture 02 internet video search
 
Lecture 01 internet video search
Lecture 01 internet video searchLecture 01 internet video search
Lecture 01 internet video search
 
Lecture 03 internet video search
Lecture 03 internet video searchLecture 03 internet video search
Lecture 03 internet video search
 
Icml2012 tutorial representation_learning
Icml2012 tutorial representation_learningIcml2012 tutorial representation_learning
Icml2012 tutorial representation_learning
 
Advances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionAdvances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer vision
 
Gephi tutorial: quick start
Gephi tutorial: quick startGephi tutorial: quick start
Gephi tutorial: quick start
 
EM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysisEM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysis
 
Object recognition with pictorial structures
Object recognition with pictorial structuresObject recognition with pictorial structures
Object recognition with pictorial structures
 
Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities
 
Icml2012 learning hierarchies of invariant features
Icml2012 learning hierarchies of invariant featuresIcml2012 learning hierarchies of invariant features
Icml2012 learning hierarchies of invariant features
 
ECCV2010: Modeling Temporal Structure of Decomposable Motion Segments for Act...
ECCV2010: Modeling Temporal Structure of Decomposable Motion Segments for Act...ECCV2010: Modeling Temporal Structure of Decomposable Motion Segments for Act...
ECCV2010: Modeling Temporal Structure of Decomposable Motion Segments for Act...
 
Quoc le tera-scale deep learning
Quoc le   tera-scale deep learningQuoc le   tera-scale deep learning
Quoc le tera-scale deep learning
 

Último

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Último (20)

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
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...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Skiena algorithm 2007 lecture04 elementary data structures

  • 1. Lecture 4: Elementary Data Structures Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794–4400 http://www.cs.sunysb.edu/∼skiena
  • 2. Problem of the Day True or False? 1. 2n2 + 1 = O(n2 ) √ 2. n = O(log n) √ 3. log n = O( n) √ 4. n2 (1 + n) = O(n2 log n) √ 2 5. 3n + n = O(n2 ) √ 6. n log n = O(n) 7. log n = O(n−1/2 )
  • 3. The Base is not Asymptotically Important Recall the definition, clogc x = x and that logc a logb a = log c b Thus log 2 n = (1/ log 100 2) × log 100 n. Since 1/ log 100 2 = 6.643 is just a constant, it does not matter in the Big Oh.
  • 4. Federal Sentencing Guidelines 2F1.1. Fraud and Deceit; Forgery; Offenses Involving Altered or Counterfeit Instruments other than Counterfeit Bearer Obligations of the United States. (a) Base offense Level: 6 (b) Specific offense Characteristics (1) If the loss exceeded $2,000, increase the offense level as follows: Loss(Apply the Greatest) Increase in Level (A) $2,000 or less no increase (B) More than $2,000 add 1 (C) More than $5,000 add 2 (D) More than $10,000 add 3 (E) More than $20,000 add 4 (F) More than $40,000 add 5 (G) More than $70,000 add 6 (H) More than $120,000 add 7 (I) More than $200,000 add 8 (J) More than $350,000 add 9 (K) More than $500,000 add 10 (L) More than $800,000 add 11 (M) More than $1,500,000 add 12 (N) More than $2,500,000 add 13 (O) More than $5,000,000 add 14 (P) More than $10,000,000 add 15 (Q) More than $20,000,000 add 16 (R) More than $40,000,000 add 17 (Q) More than $80,000,000 add 18
  • 5. Make the Crime Worth the Time The increase in punishment level grows logarithmically in the amount of money stolen. Thus it pays to commit one big crime rather than many small crimes totalling the same amount.
  • 6. Elementary Data Structures “Mankind’s progress is measured by the number of things we can do without thinking.” Elementary data structures such as stacks, queues, lists, and heaps are the “off-the-shelf” components we build our algorithm from. There are two aspects to any data structure: • The abstract operations which it supports. • The implementation of these operations.
  • 7. Data Abstraction That we can describe the behavior of our data structures in terms of abstract operations is why we can use them without thinking. That there are different implementations of the same abstract operations enables us to optimize performance.
  • 8. Contiguous vs. Linked Data Structures Data structures can be neatly classified as either contiguous or linked depending upon whether they are based on arrays or pointers: • Contiguously-allocated structures are composed of single slabs of memory, and include arrays, matrices, heaps, and hash tables. • Linked data structures are composed of multiple distinct chunks of memory bound together by pointers, and include lists, trees, and graph adjacency lists.
  • 9. Arrays An array is a structure of fixed-size data records such that each element can be efficiently located by its index or (equivalently) address. Advantages of contiguously-allocated arrays include: • Constant-time access given the index. • Arrays consist purely of data, so no space is wasted with links or other formatting information. • Physical continuity (memory locality) between successive data accesses helps exploit the high-speed cache memory on modern computer architectures.
  • 10. Dynamic Arrays Unfortunately we cannot adjust the size of simple arrays in the middle of a program’s execution. Compensating by allocating extremely large arrays can waste a lot of space. With dynamic arrays we start with an array of size 1, and double its size from m to 2m each time we run out of space. How many times will we double for n elements? Only log 2 n .
  • 11. How Much Total Work? The apparent waste in this procedure involves the recopying of the old contents on each expansion. If half the elements move once, a quarter of the elements twice, and so on, the total number of movements M is given by lg n lg n ∞ i i M= i · n/2 = n i/2 ≤ n i/2i = 2n i=1 i=1 i=1 Thus each of the n elements move an average of only twice, and the total work of managing the dynamic array is the same O(n) as a simple array.
  • 12. Pointers and Linked Structures Pointers represent the address of a location in memory. A cell-phone number can be thought of as a pointer to its owner as they move about the planet. In C, *p denotes the item pointed to by p, and &x denotes the address (i.e. pointer) of a particular variable x. A special NULL pointer value is used to denote structure- terminating or unassigned pointers.
  • 13. Linked List Structures typedef struct list { item type item; struct list *next; } list; Lincoln Jefferson Clinton NIL
  • 14. Searching a List Searching in a linked list can be done iteratively or recursively. list *search list(list *l, item type x) { if (l == NULL) return(NULL); if (l− >item == x) return(l); else return( search list(l− >next, x) ); }
  • 15. Insertion into a List Since we have no need to maintain the list in any particular order, we might as well insert each new item at the head. void insert list(list **l, item type x) { list *p; p = malloc( sizeof(list) ); p− >item = x; p− >next = *l; *l = p; } Note the **l, since the head element of the list changes.
  • 16. Deleting from a List delete list(list **l, item type x) { list *p; (* item pointer *) list *last = NULL; (* predecessor pointer *) p = *l; while (p− >item != x) { (* find item to delete *) last = p; p = p− >next; } if (last == NULL) (* splice out of the list *) *l = p− >next; else last− >next = p− >next; free(p); (* return memory used by the node *) }
  • 17. Advantages of Linked Lists The relative advantages of linked lists over static arrays include: 1. Overflow on linked structures can never occur unless the memory is actually full. 2. Insertions and deletions are simpler than for contiguous (array) lists. 3. With large records, moving pointers is easier and faster than moving the items themselves. Dynamic memory allocation provides us with flexibility on how and where we use our limited storage resources.
  • 18. Stacks and Queues Sometimes, the order in which we retrieve data is independent of its content, being only a function of when it arrived. A stack supports last-in, first-out operations: push and pop. A queue supports first-in, first-out operations: enqueue and dequeue. Lines in banks are based on queues, while food in my refrigerator is treated as a stack.
  • 19. Impact on Tree Traversal Both can be used to store nodes to visit in a tree, but the order of traversal is completely different. 1 1 2 3 5 2 4 5 6 7 7 6 4 3 Queue Stack Which order is friendlier for WWW crawler robots?
  • 20. Dictonary / Dynamic Set Operations Perhaps the most important class of data structures maintain a set of items, indexed by keys. • Search(S,k) – A query that, given a set S and a key value k, returns a pointer x to an element in S such that key[x] = k, or nil if no such element belongs to S. • Insert(S,x) – A modifying operation that augments the set S with the element x. • Delete(S,x) – Given a pointer x to an element in the set S, remove x from S. Observe we are given a pointer to an element x, not a key value.
  • 21. • Min(S), Max(S) – Returns the element of the totally ordered set S which has the smallest (largest) key. • Next(S,x), Previous(S,x) – Given an element x whose key is from a totally ordered set S, returns the next largest (smallest) element in S, or NIL if x is the maximum (minimum) element. There are a variety of implementations of these dictionary operations, each of which yield different time bounds for various operations.
  • 22. Array Based Sets: Unsorted Arrays • Search(S,k) - sequential search, O(n) • Insert(S,x) - place in first empty spot, O(1) • Delete(S,x) - copy nth item to the xth spot, O(1) • Min(S,x), Max(S,x) - sequential search, O(n) • Successor(S,x), Predecessor(S,x) - sequential search, O(n)
  • 23. Array Based Sets: Sorted Arrays • Search(S,k) - binary search, O(lg n) • Insert(S,x) - search, then move to make space, O(n) • Delete(S,x) - move to fill up the hole, O(n) • Min(S,x), Max(S,x) - first or last element, O(1) • Successor(S,x), Predecessor(S,x) - Add or subtract 1 from pointer, O(1)
  • 24. Pointer Based Implementation We can maintain a dictionary in either a singly or doubly linked list. L A B C D E F L A B C D E F
  • 25. Doubly Linked Lists We gain extra flexibility on predecessor queries at a cost of doubling the number of pointers by using doubly-linked lists. Since the extra big-Oh costs of doubly-linkly lists is zero, we will usually assume they are, although it might not be necessary. Singly linked to doubly-linked list is as a Conga line is to a Can-Can line.