SlideShare a Scribd company logo
Introduction:
Basic Concepts and Notations
Complexity analysis: time space tradeoff
Algorithmic notations, Big O notation
Introduction to omega, theta and little o
notation
Basic Concepts and Notations
 Algorithm: Outline, the essence of a
computational procedure, step-by-step
instructions
 Program: an implementation of an algorithm in
some programming language
 Data Structure: Organization of data needed to
solve the problem
Classification of Data Structures
Data Structures
Primitive
Data Structures
Non-Primitive
Data Structures
Linear
Data Structures
Non-Linear
Data Structures
• Integer
• Real
• Character
• Boolean
• Array
• Stack
• Queue
• Linked List
• Tree
• Graph
Data Structure Operations
Data Structures are processed by using certain operations.
1.Traversing: Accessing each record exactly once so that certain
items in the record may be processed.
2.Searching: Finding the location of the record with a given key
value, or finding the location of all the records that satisfy one or
more conditions.
3.Inserting: Adding a new record to the structure.
4.Deleting: Removing a record from the structure.
Special Data Structure-
Operations
• Sorting: Arranging the records in some logical order
(Alphabetical or numerical order).
• Merging: Combining the records in two different sorted
files into a single sorted file.
Algorithmic Problem
 Infinite number of input instances satisfying the
specification. For example: A sorted, non-
decreasing sequence of natural numbers of non-
zero, finite length:
 1, 20, 908, 909, 100000, 1000000000.
 3.
Specification
of input ?
Specification
of output as a
function of
input
Algorithmic Solution
 Algorithm describes actions on the input
instance
 Infinitely many correct algorithms for the same
algorithmic problem
Specification
of input
Algorithm
Specification
of output as a
function of
input
What is a Good Algorithm?
 Efficient:
 Running time
 Space used
 Efficiency as a function of input size:
 The number of bits in an input number
 Number of data elements(numbers, points)
Complexity analysis
 Why we should analyze algorithms?
 Predict the resources that the algorithm requires
 Computational time (CPU consumption)
 Memory space (RAM consumption)
 Communication bandwidth consumption
 The running time of an algorithm is:
 The total number of primitive operations executed
(machine independent steps)
 It is a determination of order of magnitude of statement.
 Also known as algorithm complexity
Time Complexity
 Worst-case
 An upper bound on the running time for any input
of given size
 Average-case
 Assume all inputs of a given size are equally likely
 Best-case
 The lower bound on the running time
Time Complexity – Example
 Sequential search in a list of size n
 Worst-case:
 n comparisons
 Best-case:
 1 comparison
 Average-case:
 n/2 comparisons
time space tradeoff
 A time space tradeoff is a situation where the
memory use can be reduced at the cost of slower
program execution (and, conversely, the
computation time can be reduced at the cost of
increased memory use).
 A space-time or time-memory tradeoff is a way of
solving a problem or calculation in less time by using
more storage space (or memory), or by solving a
problem in very little space by spending a long time.
time space tradeoff
 As the relative costs of CPU cycles, RAM space, and
hard drive space change—hard drive space has for
some time been getting cheaper at a much faster rate
than other components of computers—the
appropriate choices for time space tradeoff have
changed radically.
 Often, by exploiting a time space tradeoff, a program
can be made to run much faster.
Asymptotic notations
 Algorithm complexity is rough estimation of
the number of steps performed by given
computation depending on the size of the
input data
 Measured through asymptotic notation
 O(g) where g is a function of the input data
size
 Examples:
 Linear complexity O(n) – all elements are processed once
(or constant number of times)
 Quadratic complexity O(n2
) – each of the elements is
processed n times
Big-O Notation (O)
Asymptotic Upper Bound
Basics of data structure types of data structures
Basics of data structure types of data structures
Omega Notation (Ω)
Asymptotic Lower Bound
Basics of data structure types of data structures
Theta Notation (Θ)
g(n) is an asymptotically tight bound of f(n)
Basics of data structure types of data structures
Basics of data structure types of data structures
little o notation
ω-notation
Big O notation
 f(n)=O(g(n)) iff there exist a positive constant c
and non-negative integer n0 such that
f(n)  cg(n) for all nn0.
 g(n) is said to be an upper bound of f(n).
Basic rules
1. Nested loops are multiplied together.
2. Sequential loops are added.
3. Only the largest term is kept, all others are
dropped.
4. Constants are dropped.
5. Conditional checks are constant (i.e. 1).
Example 1
 //linear
 for(int i = 0; i < n; i++) {
 cout << i << endl;
 }
 Ans: O(n)
Example 2
 //quadratic
 for(int i = 0; i < n; i++) {
 for(int j = 0; j < n; j++){
 //do swap stuff, constant time
 }
 }
 Ans O(n^2)
Example 3
 for(int i = 0; i < 2*n; i++) {
 cout << i << endl;
 }
 At first you might say that the upper bound is
O(2n); however, we drop constants so it becomes
O(n)
Example 4
 //linear
 for(int i = 0; i < n; i++) {
 cout << i << endl;
 }

 //quadratic
 for(int i = 0; i < n; i++) {
 for(int j = 0; j < n; j++){
 //do constant time stuff
 }
 }
 Ans : In this case we add each loop's Big O, in this
case n+n^2. O(n^2+n) is not an acceptable
answer since we must drop the lowest term. The
upper bound is O(n^2). Why? Because it has the
largest growth rate
Example 5
 for(int i = 0; i < n; i++) {
 for(int j = 0; j < 2; j++){
 //do stuff
 }
 }
 Ans: Outer loop is 'n', inner loop is 2, this we
have 2n, dropped constant gives up O(n)
Example 6
x=y+z;
for(i=1; i<= n; i++)
x=y+z;
for(i=1; i<=n/2; i++)
for(j=1; j<=n; j++)
x=y+z;
Example 7
x=y+z;
for(i=1; i<= n; i++)
x=y+z;
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
x=y+z;
a=b+c;
Example 8
while(n>1)
{
n=n-1;
a=b+c;
}
Example 10
while(n>=1)
{
n=n-20;
n=n-5;
n=n-2;
}
Example 11
while(n>=1)
{
n=n-20;
n=n+5;
n=n-30;
}
Example 12
while(n>=1)
{
n=n/2;
}
Example 13
while(n>=1)
{
n=n/2;
n=n/3;
}
Example 14
while(n>=1)
{
n=n-2;
n=n/2;
}
Example 15
 for(int i = 1; i < n; i *= 2) {
 cout << i << endl;
 }
 There are n iterations, however, instead of
simply incrementing, 'i' is increased by 2*itself
each run. Thus the loop is log(n).
Example 16
 for(int i = 0; i < n; i++) { //linear
 for(int j = 1; j < n; j *= 2){ // log (n)
 //do constant time stuff
 }
 }
 Ans: n*log(n)
Example 17
while(n>2)
{
n=√n;
}
Example 18
while(n>2)
{
n=n2;
n=√n;
n=n-2;
}
Example 19
x=y+z;
for(i=1; i<= n; i++)
{
j=2;
while(j<=n)
{
j=j2;
}
}
Comp 122
Thank You

More Related Content

PPT
Data Structure and Algorithms
PPTX
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
PPTX
Data Structure Algorithm -Algorithm Complexity
PPTX
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
PDF
Data Structure - Lecture 1 - Introduction.pdf
PDF
Data Structure & Algorithms - Mathematical
PPTX
Searching Algorithms
PPTX
Introduction to data structures and complexity.pptx
Data Structure and Algorithms
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
Data Structure Algorithm -Algorithm Complexity
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
Data Structure - Lecture 1 - Introduction.pdf
Data Structure & Algorithms - Mathematical
Searching Algorithms
Introduction to data structures and complexity.pptx

Similar to Basics of data structure types of data structures (20)

PDF
ESINF03-AlgAnalis.pdfESINF03-AlgAnalis.pdf
PPTX
Analysis of algorithms
DOCX
Data structure notes for introduction, complexity
PPT
Data Structures- Part2 analysis tools
PPT
Lecture 1 and 2 of Data Structures & Algorithms
PPTX
complexity big oh notation notation.pptx
PPTX
Design and Analysis of Algorithms Lecture Notes
PPTX
Data Structures and Algorithms for placements
PDF
Data Structures and Algorithms - Lec 02.pdf
PPT
Chapter 1 & 2 - Introduction dhjgsdkjfsaf.ppt
PPTX
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
PPTX
Algorithm for the DAA agscsnak javausmagagah
PPTX
Module 1 notes of data warehousing and data
PPTX
DS Unit-1.pptx very easy to understand..
PDF
Design Analysis and Algorithm Module1.pdf
DOCX
Basic Computer Engineering Unit II as per RGPV Syllabus
PPTX
Unit ii algorithm
PPTX
asymptotic analysis and insertion sort analysis
PPTX
19. algorithms and-complexity
ESINF03-AlgAnalis.pdfESINF03-AlgAnalis.pdf
Analysis of algorithms
Data structure notes for introduction, complexity
Data Structures- Part2 analysis tools
Lecture 1 and 2 of Data Structures & Algorithms
complexity big oh notation notation.pptx
Design and Analysis of Algorithms Lecture Notes
Data Structures and Algorithms for placements
Data Structures and Algorithms - Lec 02.pdf
Chapter 1 & 2 - Introduction dhjgsdkjfsaf.ppt
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
Algorithm for the DAA agscsnak javausmagagah
Module 1 notes of data warehousing and data
DS Unit-1.pptx very easy to understand..
Design Analysis and Algorithm Module1.pdf
Basic Computer Engineering Unit II as per RGPV Syllabus
Unit ii algorithm
asymptotic analysis and insertion sort analysis
19. algorithms and-complexity
Ad

Recently uploaded (20)

PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
PPT on Performance Review to get promotions
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
web development for engineering and engineering
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
OOP with Java - Java Introduction (Basics)
Model Code of Practice - Construction Work - 21102022 .pdf
Arduino robotics embedded978-1-4302-3184-4.pdf
UNIT-1 - COAL BASED THERMAL POWER PLANTS
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPT on Performance Review to get promotions
bas. eng. economics group 4 presentation 1.pptx
Lecture Notes Electrical Wiring System Components
Foundation to blockchain - A guide to Blockchain Tech
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
web development for engineering and engineering
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Mechanical Engineering MATERIALS Selection
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Lesson 3_Tessellation.pptx finite Mathematics
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
OOP with Java - Java Introduction (Basics)
Ad

Basics of data structure types of data structures

  • 1. Introduction: Basic Concepts and Notations Complexity analysis: time space tradeoff Algorithmic notations, Big O notation Introduction to omega, theta and little o notation
  • 2. Basic Concepts and Notations  Algorithm: Outline, the essence of a computational procedure, step-by-step instructions  Program: an implementation of an algorithm in some programming language  Data Structure: Organization of data needed to solve the problem
  • 3. Classification of Data Structures Data Structures Primitive Data Structures Non-Primitive Data Structures Linear Data Structures Non-Linear Data Structures • Integer • Real • Character • Boolean • Array • Stack • Queue • Linked List • Tree • Graph
  • 4. Data Structure Operations Data Structures are processed by using certain operations. 1.Traversing: Accessing each record exactly once so that certain items in the record may be processed. 2.Searching: Finding the location of the record with a given key value, or finding the location of all the records that satisfy one or more conditions. 3.Inserting: Adding a new record to the structure. 4.Deleting: Removing a record from the structure.
  • 5. Special Data Structure- Operations • Sorting: Arranging the records in some logical order (Alphabetical or numerical order). • Merging: Combining the records in two different sorted files into a single sorted file.
  • 6. Algorithmic Problem  Infinite number of input instances satisfying the specification. For example: A sorted, non- decreasing sequence of natural numbers of non- zero, finite length:  1, 20, 908, 909, 100000, 1000000000.  3. Specification of input ? Specification of output as a function of input
  • 7. Algorithmic Solution  Algorithm describes actions on the input instance  Infinitely many correct algorithms for the same algorithmic problem Specification of input Algorithm Specification of output as a function of input
  • 8. What is a Good Algorithm?  Efficient:  Running time  Space used  Efficiency as a function of input size:  The number of bits in an input number  Number of data elements(numbers, points)
  • 9. Complexity analysis  Why we should analyze algorithms?  Predict the resources that the algorithm requires  Computational time (CPU consumption)  Memory space (RAM consumption)  Communication bandwidth consumption  The running time of an algorithm is:  The total number of primitive operations executed (machine independent steps)  It is a determination of order of magnitude of statement.  Also known as algorithm complexity
  • 10. Time Complexity  Worst-case  An upper bound on the running time for any input of given size  Average-case  Assume all inputs of a given size are equally likely  Best-case  The lower bound on the running time
  • 11. Time Complexity – Example  Sequential search in a list of size n  Worst-case:  n comparisons  Best-case:  1 comparison  Average-case:  n/2 comparisons
  • 12. time space tradeoff  A time space tradeoff is a situation where the memory use can be reduced at the cost of slower program execution (and, conversely, the computation time can be reduced at the cost of increased memory use).  A space-time or time-memory tradeoff is a way of solving a problem or calculation in less time by using more storage space (or memory), or by solving a problem in very little space by spending a long time.
  • 13. time space tradeoff  As the relative costs of CPU cycles, RAM space, and hard drive space change—hard drive space has for some time been getting cheaper at a much faster rate than other components of computers—the appropriate choices for time space tradeoff have changed radically.  Often, by exploiting a time space tradeoff, a program can be made to run much faster.
  • 14. Asymptotic notations  Algorithm complexity is rough estimation of the number of steps performed by given computation depending on the size of the input data  Measured through asymptotic notation  O(g) where g is a function of the input data size  Examples:  Linear complexity O(n) – all elements are processed once (or constant number of times)  Quadratic complexity O(n2 ) – each of the elements is processed n times
  • 20. Theta Notation (Θ) g(n) is an asymptotically tight bound of f(n)
  • 25. Big O notation  f(n)=O(g(n)) iff there exist a positive constant c and non-negative integer n0 such that f(n)  cg(n) for all nn0.  g(n) is said to be an upper bound of f(n).
  • 26. Basic rules 1. Nested loops are multiplied together. 2. Sequential loops are added. 3. Only the largest term is kept, all others are dropped. 4. Constants are dropped. 5. Conditional checks are constant (i.e. 1).
  • 27. Example 1  //linear  for(int i = 0; i < n; i++) {  cout << i << endl;  }
  • 29. Example 2  //quadratic  for(int i = 0; i < n; i++) {  for(int j = 0; j < n; j++){  //do swap stuff, constant time  }  }
  • 31. Example 3  for(int i = 0; i < 2*n; i++) {  cout << i << endl;  }
  • 32.  At first you might say that the upper bound is O(2n); however, we drop constants so it becomes O(n)
  • 33. Example 4  //linear  for(int i = 0; i < n; i++) {  cout << i << endl;  }   //quadratic  for(int i = 0; i < n; i++) {  for(int j = 0; j < n; j++){  //do constant time stuff  }  }
  • 34.  Ans : In this case we add each loop's Big O, in this case n+n^2. O(n^2+n) is not an acceptable answer since we must drop the lowest term. The upper bound is O(n^2). Why? Because it has the largest growth rate
  • 35. Example 5  for(int i = 0; i < n; i++) {  for(int j = 0; j < 2; j++){  //do stuff  }  }
  • 36.  Ans: Outer loop is 'n', inner loop is 2, this we have 2n, dropped constant gives up O(n)
  • 37. Example 6 x=y+z; for(i=1; i<= n; i++) x=y+z; for(i=1; i<=n/2; i++) for(j=1; j<=n; j++) x=y+z;
  • 38. Example 7 x=y+z; for(i=1; i<= n; i++) x=y+z; for(i=1; i<=n; i++) for(j=1; j<=n; j++) x=y+z; a=b+c;
  • 45. Example 15  for(int i = 1; i < n; i *= 2) {  cout << i << endl;  }
  • 46.  There are n iterations, however, instead of simply incrementing, 'i' is increased by 2*itself each run. Thus the loop is log(n).
  • 47. Example 16  for(int i = 0; i < n; i++) { //linear  for(int j = 1; j < n; j *= 2){ // log (n)  //do constant time stuff  }  }
  • 51. Example 19 x=y+z; for(i=1; i<= n; i++) { j=2; while(j<=n) { j=j2; } }

Editor's Notes

  • #3: PRIMITIVE DATATYPE       The primitive data types are the basic data types that are available in most of the programming languages. The primitive data types are used to represent single values.  NON PRIMITIVE DATATYPES               The data types that are derived from primary data types are known as non-Primitive data types. These datatypes are used to store group of values.  
  • #4: 목차 자바의 생성배경 자바를 사용하는 이유 과거, 현재, 미래의 자바 자바의 발전과정 버전별 JDK에 대한 설명 자바와 C++의 차이점 자바의 성능 자바 관련 산업(?)의 경향
  • #5: 목차 자바의 생성배경 자바를 사용하는 이유 과거, 현재, 미래의 자바 자바의 발전과정 버전별 JDK에 대한 설명 자바와 C++의 차이점 자바의 성능 자바 관련 산업(?)의 경향
  • #8: Refer the notes.
  • #9: Refer the Notes
  • #15: Where, C>0 & n0>=1 Also Known as Worst Case Complexity
  • #18: Where, C>0 & n0>=1 Also Known as Best Case Complexity
  • #20: C1>0, C2>0, N0>=1 Also Known as Average Time Complexity
  • #37: O(n2
  • #38: O(n2
  • #39: O(n)
  • #40: n/27 O(n)
  • #41: n/45 O(n)
  • #42: log2n
  • #43: O(log6n)
  • #44: O(log2n)
  • #49: O(log logn)
  • #50: O(n)
  • #51: O(n.log(log2n))