SlideShare a Scribd company logo
Introduction to Data Structures
Introduction
• Data means value or set of values . Data items refers to a single unit of values.
• Data is represented in the from of text/numbers/figures/ tables/graphs/pictures etc.
A computer Language is incomplete without data.
• Information is derived from data, such as:
per capita income, Average Population of the states , price index ,etc.
Data
Method to
Process data
I
N
F
O
R
M
A
T
I
O
N
Introduction
• In a month we everyday get the newspaper then at the end we can calculate the
bill from the data of the cost of newspaper we daily receive.
• Data about some persons in a group:
• Distance between the two stations:
A 100 km B
Information Details Data
Name Satish
Gender Male
Age 32
Phone 987680987
Introduction
• From the score of an individual cricket player we can draw following information:
• Total Runs Scored
• Highest score
• Average
• Strike rate
• No. of Sixes
• No. of fours
• This information helps the planners/analysts/to make decisions.
• Info. In Computer: A computer is an electronic device that manipulates the
information presented in the form of data.
• Data: Data is nothing but a collection of numbers, alphabets and symbols
combined to represent information.
• Entity: An entity possesses some attributes and some values can be allocated to it.
E.g. student entity in a college.
Overview of Data Structures
• Data Structures are a method of representing of logical relationships between
individual data elements related to the solution of a given problem.
• A data structure is a structured set of variables associated with one another in
different ways, co-operatively defining the components in the system and capable
of being operated upon in the program.
• Data structures are the basis of the programming tools. The choice of data
structures should provide the following:
1. The data structure should satisfactorily represent the relationship between the
data elements.
2. The data structure should be easy so that the programmer can easily process the
data.
Classification of Data Structures
• Linear: The values are arranged in a linear fashion. E.g. Arrays, Linked Lists, Stacks,
Queues etc.
• Non-Linear: The values are not arranged in an order. E.g. Tree, Graph, Table etc.
• Homogeneous: Here all the values stored are of same type e.g. arrays
• Non- Homogeneous: Here all the values stored are of different type e.g. structures and
classes.
• Dynamic:A dynamic data structure is one that can grow or shrink as needed to contain
the data you want stored. That is, you can allocate new storage when it's needed and
discard that storage when you're done with it. E.g. pointers, or references
• Static:They're essentially fixed-size and often use much space E.g. Array
Basic Notations
• Mathematical Notations and Functions:
1. Floor and Ceiling
2. Remainder Function
3. Integer and Absolute Value
4. Summation Symbol
5. Factorial Function
6. Permutations
7. Exponents and Logarithms:
am =a.a.a…a (m times) a0 =1
C++ Program of sum of two numbers
#include<iostream>
Using namespace std;
Main()
{
int a,b,sum;
cout<<“enter a and b”;
cin>> a>>b;
sum=a+b;
cout<<“sum of a and b is “;
cout<<sum;
}
Sum of N numbers
Part 1
#include<iostream>
Using namespace std;
Main()
{
int sum=0;
For(int i=0;i<n;i++)
{
Part 2
cin>>i;
sum=sum +i;
cout<<“sum of n numbers is “;
cout<<sum;
}
Basic Notations
Algorithmic Notations:
Finite step by step list of well-defined instructions for solving a particular problem.
Formal presentation of the Algorithm consists of two parts:
1. A paragraph that tells the purpose of an algorithm. Identifies the variables which occur in the algorithm
and lists the input data.
2. The list of the steps that is to be executed.
Some conventions used in Algorithms:
 Identifying Number (Algorithm 2: )
 Steps, Control and Exit ( All statements are numbered, Go to and Exit)
 Comments (The comments are to be given to understand the meaning)
 Variable Names (capital letters are used for variable names)
 Assignment Statement (Max:=DATA[1])
 Input and output (Read: variable names, Write: Messages and/or variable names)
 Procedure
Basic Notations
Control Structures:
1. Sequential Logic or Sequential Flow
2. Selection Logic or Conditional Flow
• If (condition) , then:
-----
[Endif]
• If (condition) , then:
-----
Else :
-------
[ Endif]
• Multiple If (condition), then : -----
Elseif : -----
Else :
------
[Endif]
3. Iteration Logic (Repetitive Flow)
• for loop =>
Repeat for K=I to N:
[Module] [End of Loop]
• While loop=>
Repeat while K<= N:
(logic)
[end of while loop]
Types of Data Structures
• Arrays:
1. Linear data Structure
2. All elements stored at contiguous memory locations
3. Every element is identified by an index (Logical Address)
4. At the same time every element is identified by a physical address (Physical
Address)
5. We can have 2 D and 3D arrays also but stored in memory in a linear way.
Types of Data Structures
• Stack:
– Only the top item can be accessed
– Can only extract one item at a time
• A stack is a data structure with the property that only the top element of the stack
is accessible
• The stack’s storage policy is Last-In, First-Out
• Only the top element of a stack is visible, therefore the number of operations
performed by a stack are few
• Need the ability to
– Inspect the top element
– Retrieve the top element
– Push a new element on the stack
– Test for an empty stack
Types of Data Structures
• Queue:
• Stores a set of elements in a particular order
• Stack principle: FIRST IN FIRST OUT
• = FIFO
• It means: the first element inserted is the first one to be removed
• Real life examples
– Waiting in line
– Waiting on hold for tech support
• Applications related to Computer Science
– Threads
– Job scheduling (e.g. Round-Robin algorithm for CPU allocation)
Linked Lists
• A linked list is a series of connected nodes
• Each node contains at least
– A piece of data (any type)
– Pointer to the next node in the list
• Head: pointer to the first node
• The last node points to NULL
A 
Head
B C
A
data pointer
node
Types of Data Structures
• Linked List:
1. Linear data structure.
2. Primarily used when the elements are to stored at non-contiguous locations.
1. Linked list is able to grow in size as needed.
2. Does not require the shifting of items during insertions and deletions.
Terminology for a Tree
• Tree: A collection of data whose entries have a hierarchical organization
• Node: An entry in a tree
• Root node: The node at the top
• Terminal or leaf node: A node at the bottom
• Parent: The node immediately above a specified node
• Child: A node immediately below a specified node
• Ancestor: Parent, parent of parent, etc.
• Descendent: Child, child of child, etc.
• Siblings: Nodes sharing a common parent
• Binary tree: A tree in which every node has at most two children
• Depth: The number of nodes in longest path from root to leaf
Tree Terminology
Graph
• A graph is a pair (V, E), where
– V is a set of nodes, called vertices
– E is a collection of pairs of vertices, called edges
– Vertices and edges are positions and store elements
• Example:
– A vertex represents an airport and stores the three-letter airport code
– An edge represents a flight route between two airports and stores the
mileage of the route
21
Graphs
ORD
PVD
MIA
DFW
SFO
LAX
LGA
HNL
Edge Types
• Directed edge
– ordered pair of vertices (u,v)
– first vertex u is the origin
– second vertex v is the destination
– e.g., a flight
• Undirected edge
– unordered pair of vertices (u,v)
– e.g., a flight route
• Directed graph
– all the edges are directed
– e.g., route network
• Undirected graph
– all the edges are undirected
– e.g., flight network
22
Graphs
ORD PVD
flight
AA 1206
ORD PVD
849
miles
Applications
• Electronic circuits
– Printed circuit board
– Integrated circuit
• Transportation networks
– Highway network
– Flight network
• Computer networks
– Local area network
– Internet
– Web
• Databases
– Entity-relationship diagram
23
Graphs
John
David
Paul
brown.edu
cox.net
cs.brown.edu
att.net
qwest.net
math.brown.edu
cslab1b
cslab1a
Complexity Analysis
and
Time Space Trade-off
Algorithm
• A clearly specified set of instructions to solve a problem.
• Characteristics:
– Input: Zero or more quantities are externally supplied
– Definiteness: Each instruction is clear and unambiguous
– Finiteness: The algorithm terminates in a finite number of steps.
– Effectiveness: Each instruction must be primitive and feasible
– Output: At least one quantity is produced
Algorithm
Need for analysis
• To determine resource consumption
– CPU time
– Memory space
• Compare different methods for solving the same problem
before actually implementing them and running the
programs.
• To find an efficient algorithm
Complexity
• A measure of the performance of an algorithm
• An algorithm’s performance depends on
– internal factors
– external factors
External Factors
• Speed of the computer on which it is run
• Quality of the compiler
• Size of the input to the algorithm
Internal Factor
30
The algorithm’s efficiency, in terms of:
• Time required to run
• Space (memory storage)required to run
Note:
Complexity measures the internal factors (usually more interested in time than
space)
Two ways of finding complexity
• Experimental study
• Theoretical Analysis
Experimental study
• Write a program implementing the algorithm
• Run the program with inputs of varying size and
composition
• Get an accurate measure of the actual running time
Use a method like System.currentTimeMillis()
• Plot the results
Example
 a. Sum=0;
for(i=0;i<N;i++)
for(j=0;j<i;j++)
Sum++;
Example graph
Time in millisec
Limitations of Experiments
• It is necessary to implement the algorithm, which may be
difficult
• Results may not be indicative of the running time on other
inputs not included in the experiment.
• In order to compare two algorithms, the same hardware and
software environments must be used
• Experimental data though important is not sufficient
Theoretical Analysis
• Uses a high-level description of the algorithm instead of an
implementation
• Characterizes running time as a function of the input size, n.
• Takes into account all possible inputs
• Allows us to evaluate the speed of an algorithm independent of
the hardware/software environment
Space Complexity
• The space needed by an algorithm is the sum of a fixed part and
a variable part
• The fixed part includes space for
– Instructions
– Simple variables
– Fixed size component variables
– Space for constants
– Etc..
Cont…
• The variable part includes space for
– Component variables whose size is dependant on the
particular problem instance being solved
– Recursion stack space
– Etc..
Time Complexity
• The time complexity of a problem is
– the number of steps that it takes to solve an instance of the problem as a
function of the size of the input (usually measured in bits), using the most
efficient algorithm.
• The exact number of steps will depend on exactly what machine or language
is being used.
• To avoid that problem, the Asymptotic notation is generally used.
Time Space Trade-off
• In computer science, a space-time or time-memory trade off is a situation
where the memory use can be reduced at the cost of slower program
execution (or, vice versa, the computation time can be reduced at the cost of
increased memory use). 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 space-time tradeoffs have changed radically. Often,
by exploiting a space-time tradeoff, a program can be made to run much
faster.
Types of Time Space Trade-off
• Lookup tables v. recalculation
The most common situation is an algorithm involving a lookup table: an
implementation can include the entire table, which reduces computing time,
but increases the amount of memory needed, or it can compute table entries
as needed, increasing computing time, but reducing memory requirements.
• Compressed v. uncompressed data
A space-time trade off can be applied to the problem of data storage. If data is
stored uncompressed, it takes more space but less time than if the data were
stored compressed (since compressing the data reduces the amount of space it
takes, but it takes time to run the decompression algorithm). Depending on
the particular instance of the problem, either way is practical.

More Related Content

Similar to ds 1 Introduction to Data Structures.ppt (20)

PDF
Lec01-Algorithems - Introduction and Overview.pdf
MAJDABDALLAH3
 
PPTX
Unit 1 dsuc
Sweta Singh
 
PPTX
Data Structures unit I Introduction - data types
AmirthaVarshini80
 
PPT
algo 1.ppt
example43
 
PPTX
Data structure &amp; algorithms introduction
Sugandh Wafai
 
PDF
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Axmedcarb
 
PPT
Introduction of C++ Text book UNIT-1 .ppt
akulaaruna81
 
PPTX
DSA Ch1(Introduction) [Recovered].pptx
HOWoTO79
 
PDF
Unit I Data structure and algorithms notes
FIONACHATOLA
 
PPTX
Data Structures and Algorithm - Module 1.pptx
EllenGrace9
 
PPTX
Unit 1 Data Structures Introduction L1.pptx
dummysharma1
 
PDF
MCA_Data Structure_Notes_of_UNIT_I & II.pdf
pankajsharmamca
 
PPTX
project on data structures and algorithm
AnujKumar566766
 
PPT
DATA STRUCTURE AND ALGORITHMS
removed_8057d320f6c8601c14a895598b86eacb
 
DOCX
3rd-Sem_CSE_Data-Structures and Applications.docx
harshavardhan543715
 
PPTX
1-Introduction to Data Structures beginner.pptx
231b209
 
PPTX
Lect1.pptx
muhammadRamzan816406
 
PPTX
8.unit-1-fds-2022-23.pptx
RavishankarBhaganaga
 
PPTX
EE-232-LEC-01 Data_structures.pptx
iamultapromax
 
PDF
Data Structure Introduction.pdfssssssssssss
parwarsmko98
 
Lec01-Algorithems - Introduction and Overview.pdf
MAJDABDALLAH3
 
Unit 1 dsuc
Sweta Singh
 
Data Structures unit I Introduction - data types
AmirthaVarshini80
 
algo 1.ppt
example43
 
Data structure &amp; algorithms introduction
Sugandh Wafai
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Axmedcarb
 
Introduction of C++ Text book UNIT-1 .ppt
akulaaruna81
 
DSA Ch1(Introduction) [Recovered].pptx
HOWoTO79
 
Unit I Data structure and algorithms notes
FIONACHATOLA
 
Data Structures and Algorithm - Module 1.pptx
EllenGrace9
 
Unit 1 Data Structures Introduction L1.pptx
dummysharma1
 
MCA_Data Structure_Notes_of_UNIT_I & II.pdf
pankajsharmamca
 
project on data structures and algorithm
AnujKumar566766
 
DATA STRUCTURE AND ALGORITHMS
removed_8057d320f6c8601c14a895598b86eacb
 
3rd-Sem_CSE_Data-Structures and Applications.docx
harshavardhan543715
 
1-Introduction to Data Structures beginner.pptx
231b209
 
8.unit-1-fds-2022-23.pptx
RavishankarBhaganaga
 
EE-232-LEC-01 Data_structures.pptx
iamultapromax
 
Data Structure Introduction.pdfssssssssssss
parwarsmko98
 

Recently uploaded (20)

PPTX
Server Side Web Development Unit 1 of Nodejs.pptx
sneha852132
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
Depth First Search Algorithm in 🧠 DFS in Artificial Intelligence (AI)
rafeeqshaik212002
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
PPTX
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
Day2 B2 Best.pptx
helenjenefa1
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PPT
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
PPTX
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PDF
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
Server Side Web Development Unit 1 of Nodejs.pptx
sneha852132
 
MRRS Strength and Durability of Concrete
CivilMythili
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Depth First Search Algorithm in 🧠 DFS in Artificial Intelligence (AI)
rafeeqshaik212002
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
Day2 B2 Best.pptx
helenjenefa1
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
Ad

ds 1 Introduction to Data Structures.ppt

  • 1. Introduction to Data Structures
  • 2. Introduction • Data means value or set of values . Data items refers to a single unit of values. • Data is represented in the from of text/numbers/figures/ tables/graphs/pictures etc. A computer Language is incomplete without data. • Information is derived from data, such as: per capita income, Average Population of the states , price index ,etc. Data Method to Process data I N F O R M A T I O N
  • 3. Introduction • In a month we everyday get the newspaper then at the end we can calculate the bill from the data of the cost of newspaper we daily receive. • Data about some persons in a group: • Distance between the two stations: A 100 km B Information Details Data Name Satish Gender Male Age 32 Phone 987680987
  • 4. Introduction • From the score of an individual cricket player we can draw following information: • Total Runs Scored • Highest score • Average • Strike rate • No. of Sixes • No. of fours • This information helps the planners/analysts/to make decisions. • Info. In Computer: A computer is an electronic device that manipulates the information presented in the form of data. • Data: Data is nothing but a collection of numbers, alphabets and symbols combined to represent information. • Entity: An entity possesses some attributes and some values can be allocated to it. E.g. student entity in a college.
  • 5. Overview of Data Structures • Data Structures are a method of representing of logical relationships between individual data elements related to the solution of a given problem. • A data structure is a structured set of variables associated with one another in different ways, co-operatively defining the components in the system and capable of being operated upon in the program. • Data structures are the basis of the programming tools. The choice of data structures should provide the following: 1. The data structure should satisfactorily represent the relationship between the data elements. 2. The data structure should be easy so that the programmer can easily process the data.
  • 6. Classification of Data Structures • Linear: The values are arranged in a linear fashion. E.g. Arrays, Linked Lists, Stacks, Queues etc. • Non-Linear: The values are not arranged in an order. E.g. Tree, Graph, Table etc. • Homogeneous: Here all the values stored are of same type e.g. arrays • Non- Homogeneous: Here all the values stored are of different type e.g. structures and classes. • Dynamic:A dynamic data structure is one that can grow or shrink as needed to contain the data you want stored. That is, you can allocate new storage when it's needed and discard that storage when you're done with it. E.g. pointers, or references • Static:They're essentially fixed-size and often use much space E.g. Array
  • 7. Basic Notations • Mathematical Notations and Functions: 1. Floor and Ceiling 2. Remainder Function 3. Integer and Absolute Value 4. Summation Symbol 5. Factorial Function 6. Permutations 7. Exponents and Logarithms: am =a.a.a…a (m times) a0 =1
  • 8. C++ Program of sum of two numbers #include<iostream> Using namespace std; Main() { int a,b,sum; cout<<“enter a and b”; cin>> a>>b; sum=a+b; cout<<“sum of a and b is “; cout<<sum; }
  • 9. Sum of N numbers Part 1 #include<iostream> Using namespace std; Main() { int sum=0; For(int i=0;i<n;i++) { Part 2 cin>>i; sum=sum +i; cout<<“sum of n numbers is “; cout<<sum; }
  • 10. Basic Notations Algorithmic Notations: Finite step by step list of well-defined instructions for solving a particular problem. Formal presentation of the Algorithm consists of two parts: 1. A paragraph that tells the purpose of an algorithm. Identifies the variables which occur in the algorithm and lists the input data. 2. The list of the steps that is to be executed. Some conventions used in Algorithms:  Identifying Number (Algorithm 2: )  Steps, Control and Exit ( All statements are numbered, Go to and Exit)  Comments (The comments are to be given to understand the meaning)  Variable Names (capital letters are used for variable names)  Assignment Statement (Max:=DATA[1])  Input and output (Read: variable names, Write: Messages and/or variable names)  Procedure
  • 11. Basic Notations Control Structures: 1. Sequential Logic or Sequential Flow 2. Selection Logic or Conditional Flow • If (condition) , then: ----- [Endif] • If (condition) , then: ----- Else : ------- [ Endif]
  • 12. • Multiple If (condition), then : ----- Elseif : ----- Else : ------ [Endif] 3. Iteration Logic (Repetitive Flow) • for loop => Repeat for K=I to N: [Module] [End of Loop]
  • 13. • While loop=> Repeat while K<= N: (logic) [end of while loop]
  • 14. Types of Data Structures • Arrays: 1. Linear data Structure 2. All elements stored at contiguous memory locations 3. Every element is identified by an index (Logical Address) 4. At the same time every element is identified by a physical address (Physical Address) 5. We can have 2 D and 3D arrays also but stored in memory in a linear way.
  • 15. Types of Data Structures • Stack: – Only the top item can be accessed – Can only extract one item at a time • A stack is a data structure with the property that only the top element of the stack is accessible • The stack’s storage policy is Last-In, First-Out • Only the top element of a stack is visible, therefore the number of operations performed by a stack are few • Need the ability to – Inspect the top element – Retrieve the top element – Push a new element on the stack – Test for an empty stack
  • 16. Types of Data Structures • Queue: • Stores a set of elements in a particular order • Stack principle: FIRST IN FIRST OUT • = FIFO • It means: the first element inserted is the first one to be removed • Real life examples – Waiting in line – Waiting on hold for tech support • Applications related to Computer Science – Threads – Job scheduling (e.g. Round-Robin algorithm for CPU allocation)
  • 17. Linked Lists • A linked list is a series of connected nodes • Each node contains at least – A piece of data (any type) – Pointer to the next node in the list • Head: pointer to the first node • The last node points to NULL A  Head B C A data pointer node
  • 18. Types of Data Structures • Linked List: 1. Linear data structure. 2. Primarily used when the elements are to stored at non-contiguous locations. 1. Linked list is able to grow in size as needed. 2. Does not require the shifting of items during insertions and deletions.
  • 19. Terminology for a Tree • Tree: A collection of data whose entries have a hierarchical organization • Node: An entry in a tree • Root node: The node at the top • Terminal or leaf node: A node at the bottom • Parent: The node immediately above a specified node • Child: A node immediately below a specified node • Ancestor: Parent, parent of parent, etc. • Descendent: Child, child of child, etc. • Siblings: Nodes sharing a common parent • Binary tree: A tree in which every node has at most two children • Depth: The number of nodes in longest path from root to leaf
  • 21. Graph • A graph is a pair (V, E), where – V is a set of nodes, called vertices – E is a collection of pairs of vertices, called edges – Vertices and edges are positions and store elements • Example: – A vertex represents an airport and stores the three-letter airport code – An edge represents a flight route between two airports and stores the mileage of the route 21 Graphs ORD PVD MIA DFW SFO LAX LGA HNL
  • 22. Edge Types • Directed edge – ordered pair of vertices (u,v) – first vertex u is the origin – second vertex v is the destination – e.g., a flight • Undirected edge – unordered pair of vertices (u,v) – e.g., a flight route • Directed graph – all the edges are directed – e.g., route network • Undirected graph – all the edges are undirected – e.g., flight network 22 Graphs ORD PVD flight AA 1206 ORD PVD 849 miles
  • 23. Applications • Electronic circuits – Printed circuit board – Integrated circuit • Transportation networks – Highway network – Flight network • Computer networks – Local area network – Internet – Web • Databases – Entity-relationship diagram 23 Graphs John David Paul brown.edu cox.net cs.brown.edu att.net qwest.net math.brown.edu cslab1b cslab1a
  • 25. Algorithm • A clearly specified set of instructions to solve a problem. • Characteristics: – Input: Zero or more quantities are externally supplied – Definiteness: Each instruction is clear and unambiguous – Finiteness: The algorithm terminates in a finite number of steps. – Effectiveness: Each instruction must be primitive and feasible – Output: At least one quantity is produced
  • 27. Need for analysis • To determine resource consumption – CPU time – Memory space • Compare different methods for solving the same problem before actually implementing them and running the programs. • To find an efficient algorithm
  • 28. Complexity • A measure of the performance of an algorithm • An algorithm’s performance depends on – internal factors – external factors
  • 29. External Factors • Speed of the computer on which it is run • Quality of the compiler • Size of the input to the algorithm
  • 30. Internal Factor 30 The algorithm’s efficiency, in terms of: • Time required to run • Space (memory storage)required to run Note: Complexity measures the internal factors (usually more interested in time than space)
  • 31. Two ways of finding complexity • Experimental study • Theoretical Analysis
  • 32. Experimental study • Write a program implementing the algorithm • Run the program with inputs of varying size and composition • Get an accurate measure of the actual running time Use a method like System.currentTimeMillis() • Plot the results
  • 35. Limitations of Experiments • It is necessary to implement the algorithm, which may be difficult • Results may not be indicative of the running time on other inputs not included in the experiment. • In order to compare two algorithms, the same hardware and software environments must be used • Experimental data though important is not sufficient
  • 36. Theoretical Analysis • Uses a high-level description of the algorithm instead of an implementation • Characterizes running time as a function of the input size, n. • Takes into account all possible inputs • Allows us to evaluate the speed of an algorithm independent of the hardware/software environment
  • 37. Space Complexity • The space needed by an algorithm is the sum of a fixed part and a variable part • The fixed part includes space for – Instructions – Simple variables – Fixed size component variables – Space for constants – Etc..
  • 38. Cont… • The variable part includes space for – Component variables whose size is dependant on the particular problem instance being solved – Recursion stack space – Etc..
  • 39. Time Complexity • The time complexity of a problem is – the number of steps that it takes to solve an instance of the problem as a function of the size of the input (usually measured in bits), using the most efficient algorithm. • The exact number of steps will depend on exactly what machine or language is being used. • To avoid that problem, the Asymptotic notation is generally used.
  • 40. Time Space Trade-off • In computer science, a space-time or time-memory trade off is a situation where the memory use can be reduced at the cost of slower program execution (or, vice versa, the computation time can be reduced at the cost of increased memory use). 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 space-time tradeoffs have changed radically. Often, by exploiting a space-time tradeoff, a program can be made to run much faster.
  • 41. Types of Time Space Trade-off • Lookup tables v. recalculation The most common situation is an algorithm involving a lookup table: an implementation can include the entire table, which reduces computing time, but increases the amount of memory needed, or it can compute table entries as needed, increasing computing time, but reducing memory requirements. • Compressed v. uncompressed data A space-time trade off can be applied to the problem of data storage. If data is stored uncompressed, it takes more space but less time than if the data were stored compressed (since compressing the data reduces the amount of space it takes, but it takes time to run the decompression algorithm). Depending on the particular instance of the problem, either way is practical.