INF210 Lec2 Data Structures
INF210 Lec2 Data Structures
INF 210
Fall 2022-2023
Lecture 2
Introduction to Data Structures
INSTRUCTOR
DR/ AYMAN SOLIMAN & DR/ OSAMA FAROUK
Ø Contents
1) Measuring Efficiency with BigO Notation
3) Why BigO?
4) Quick Recap?
§ Searching through
§ Modifying
§ Accessing
§ BigO Notation
WHAT IS IT?
HOW DO WE
MEASURE IT?
10/12/22 Dr/ Ayman Soliman 4
1) Measuring Efficiency with BigO Notation
Ø BigO Notation
§ The most common functions you might want from a data structure
q Accessing elements
q Inserting an element
q Deleting an element
N = 10
Accessing Searching Inserting Deleting
Equation Equation Equation Equation
8 Operations
2 Operations
50 Operations
42 Operations
1898 Operations
O of 2
Random
Function() O(2)
10/12/22 Dr/ Ayman Soliman 10
2) Measuring Efficiency with BigO Notation - Time Complexity Equations
Ø It’s called BigO notation because the syntax for the Time Complexity
equations includes a BigO and then a set of parentheses
Constant Time
A Function Time Complexity
O of 5
Random
Function() O(5)
10/12/22 Dr/ Ayman Soliman 11
2) Measuring Efficiency with BigO Notation - Time Complexity Equations
Ø It’s called BigO notation because the syntax for the Time Complexity
equations includes a BigO and then a set of parentheses
Constant Time
A Function Time Complexity
O(5)
O of 5
Random
Function()
O(5)
O of 5
Random
Function()
Ø Most of the time, our integer n, is going to have some adverse-effect on how
many operations it takes
10/12/22 Dr/ Ayman Soliman 13
2) Measuring Efficiency with BigO Notation - Time Complexity Equations
Ø It’s called BigO notation because the syntax for the Time Complexity
equations includes a BigO and then a set of parentheses
Ø Most of the time, our integer n, is going to have some adverse-effect on how
many operations it takes
>
Speed
Laptop
Super-computer
10/12/22 Dr/ Ayman Soliman 15
4) Measuring Efficiency with BigO Notation - Quick Recap?
What the data structure is good at, and what the data structure is bad at
§ No matter what the size of your data set is, the task will be completed in a
single instruction
1 1, 100,
1000000,..
10/12/22 Dr/ Ayman Soliman 19
5) Types of Time Complexity Equations
Ø The absolute best a data structure can “score” on each criteria is O(1)
§ No matter what the size of your data set is, the task will be completed in a
single instruction
Number of Operations
When we graph volume of data vs # of instructions required
Number of Operations
Number of Operations
Slower Than Faster Than
Number of Operations
Number of Operations
Skyrockets Increases More Slowly Increases Way More Slowly
10 10
10/12/22 Dr/ Ayman Soliman 25
5) Types of Time Complexity Equations
Ø The next common time complexity efficiency equation type that’s going to
come up is O(n)
50 50
10/12/22 Dr/ Ayman Soliman 26
5) Types of Time Complexity Equations
Ø The next common time complexity efficiency equation type that’s going to
come up is O(n)
1000 1000
10/12/22 Dr/ Ayman Soliman 27
5) Types of Time Complexity Equations
Ø The next type of equation that will come up is O(n log n)
Number of Operations
Number of Operations
Low slope
Number of Operations
Slope Increases
§ Exponential in structure
Number of Operations
Number of Operations
O(n )
2 O(2 )
n
e s s i ng Search
ing
A c c O
O(n) (log n)
Some Data
Other Functionality
Structure
Inserting Deleting
O(n2) O(n2 )