SlideShare uma empresa Scribd logo
1 de 34
1
Data Structures and Algorithm Analysis
Dr. Nagwa Badr
2
The Need for Data Structures
Data structures organize data
⇒ more efficient programs.
More powerful computers ⇒ more complex
applications.
More complex applications demand more
calculations.
Complex computing tasks are unlike our
everyday experience.
3
What is a data structure?
 In a general sense, any data
representation is a data structure.
Example: An integer
 More typically, a data structure is meant
to be an organization for a collection of
data items.
4
Organizing Data
Any organization for a collection of records
can be searched, processed in any order,
or modified.
The choice of data structure and algorithm
can make the difference between a
program running in a few seconds or
many days.
5
Efficiency
A solution is said to be efficient if it solves
the problem within its resource
constraints.
 Space
 Time
 The cost of a solution is the amount of
resources that the solution consumes.
6
Costs and Benefits
 A data structure requires a certain
amount of:
 space for each data item it stores
 time to perform a single basic operation
 programming effort.
7
Example: Banking Application
 Operations are (typically):
 Open accounts
 Close accounts
 Access account to Add money
 Access account to Withdraw money
8
Example: Banking Application
 Teller and ATM transactions are
expected to take little time.
 Opening or closing an account can
take much longer (perhaps up to an
hour).
9
Example: Banking Application
 When considering the choice of data
structure to use in the database system
that manages the accounts, we are
looking for a data structure that:
 Is inefficient for deletion
 Highly efficient for search
 Moderately efficient for insertion
10
Example: Banking Application
 One data structure that meets these requirements is
the hash table (chapter 9).
 Records are accessible by account number (called
an exact-match query)
 Hash tables allow for extremely fast exact-match
search.
 Hash tables also support efficient insertion of new
records.
 Deletions can also be supported efficiently (but too
many deletions lead to some degradation in
performance – requiring the hash table to be
reorganized).
11
Example: City Database
 Database system for cities and towns.
 Users find information about a particular
place by name (exact-match query)
 Users also find all places that match a
particular value (or range of values),
such as location or population size
(called a range query).
12
Example: City Database
 The database must answer queries quickly
enough to satisfy the patience of a typical
user.
 For an exact-match query, a few seconds is
satisfactory
 For a range queries, the entire operation
may be allowed to take longer, perhaps on
the order of a minute.
13
Example: City Database
 The hash table is inappropriate for
implementing the city database because:
 It cannot perform efficient range queries
 The B+ tree (section 10) supports large
databases:
 Insertion
 Deletion
 Range queries
 If the database is created once and then
never changed, a simple linear index would
be more appropriate.
14
Selecting a Data Structure
Select a data structure as follows:
1. Analyze the problem to determine the resource
constraints a solution must meet.
2. Determine the basic operations that must be
supported. Quantify the resource constraints
for each operation.
3. Select the data structure that best meets these
requirements.
15
Some Questions to Ask
 Are all data inserted into the data structure
at the beginning, or are insertions
intersparsed with other operations?
 Can data be deleted?
 Are all data processed in some well-
defined order, or is random access
allowed?
16
Data Structure Philosophy
Each data structure has costs and benefits.
Rarely is one data structure better than
another in all situations.
A data structure requires:
 space for each data item it stores,
 time to perform each basic operation,
 programming effort.
17
Data Structure Philosophy
Each problem has constraints on available space
and time.
Only after a careful analysis of problem
characteristics can we know the best data
structure for the task.
Bank example:
 Start account: a few minutes
 Transactions: a few seconds
 Close account: overnight
continued
18
Goals of this Course
1. Reinforce the concept that costs and benefits
exist for every data structure.
1. Learn the commonly used data structures.
 These form a programmer's basic data structure
``toolkit.'‘
1. Understand how to measure the cost of a data
structure or program.
 These techniques also allow you to judge the merits
of new data structures that you or others might
invent.
19
Abstract Data Types
Abstract Data Type (ADT): a definition for a
data type solely in terms of a set of values
and a set of operations on that data type.
Each ADT operation is defined by its inputs
and outputs.
Encapsulation: Hide implementation details.
20
Data Structure
 A data structure is the physical implementation of an
ADT.
 Each operation associated with the ADT is implemented by one
or more subroutines in the implementation.
 In a OO language such as C++, an ADT and its
implementation together make up a class.
 Data structure usually refers to an organization for data
in main memory.
 File structure: an organization for data on peripheral
storage, such as a disk drive.
21
Labeling collections of objects
Humans deal with complexity by assigning a
label to an assembly of objects. An ADT
manages complexity through abstraction.
 Hierarchies of labels
Ex1: transistors ⇒ gates ⇒ CPU.
In a program, implement an ADT, then think only
about the ADT, not its implementation.
22
Logical vs. Physical Form
Data items have both a logical and a physical form.
Logical form: definition of the data item within an
ADT.
 Ex: Integers in mathematical sense: +, -
Physical form: implementation of the data item
within a data structure.
 Ex: 16/32 bit integers, overflow.
23
Data Type
ADT:
Type
Operations
Data Items:
Logical Form
Data Items:
Physical Form
Data Structure:
Storage Space
Subroutines
24
Problems, Algorithms and
Programs
 Programmers deal with:
 problems,
 algorithms and
 computer programs.
These are distinct concepts…
25
Problems
 Problem: a task to be performed.
 Best thought of as inputs and matching
outputs.
 Problem definition should include constraints
on the resources that may be consumed by
any acceptable solution.
26
Problems (cont)
 Problems ⇔ mathematical functions
 A function is a matching between inputs (the domain)
and outputs (the range).
 An input to a function may be single number, or a
collection of information.
 The values making up an input are called the
parameters of the function.
 A particular input must always result in the same
output every time the function is computed.
27
Algorithms and Programs
Algorithm: a method or a process followed to solve
a problem.
 A recipe: The algorithm gives us a “recipe” for solving
the problem by performing a series of steps, where
each step is completely understood and doable.
An algorithm takes the input to a problem (function)
and transforms it to the output.
 A mapping of input to output.
A problem can be solved by many algorithms.
28
A problem can have many
algorithms
For example, the problem of sorting can be
solved by the following algorithms:
 Insertion sort
 Bubble sort
 Selection sort
 Shellsort
 Mergesort
 Others
29
Algorithm Properties
An algorithm possesses the following properties:
 It must be correct.
 It must be composed of a series of concrete steps.
 There can be no ambiguity as to which step will be performed
next.
 It must be composed of a finite number of steps.
 It must terminate.
A computer program is an instance, or concrete
representation, for an algorithm in some
programming language.
30
Programs
 A computer program is a concrete
representation of an algorithm in some
programming language.
 Naturally, there are many programs that
are instances of the same algorithms,
since any modern programming
language can be used to implement any
algorithm.
31
To Summarize:
 A problem is a function or a mapping of
inputs to outputs.
 An algorithm is a recipe for solving a
problem whose steps are concrete and
ambiguous.
 A program is an instantiation of an
algorithm in a computer programming
language.
32
Example
 Problem: find y = x to the power of 2
 Algorithm1: Multiply X by X
 Algorithm2: Add X to itself X times
 Program1: for (int i = 0; i<x; i++)
y +=x;
33
Example (cont.)
Program2: (Assembly Intel 8086)
mov bl,x // read x
mov al,bl // store x
mov cl,bl // int counter
loop: add al,bl // al = al + x
dec cl // decrement loop ctr
jnz loop
34
In class exercises
 Think of a program you have used that is
unacceptably slow. Identify other basic operations
that the program performs quickly enough.
 Imagine that you are a shipping clerk for a large
company. You have just been handed about 1000
invoices, each of which is a single sheet of paper with
a large number in the upper right corner. The
invoices must be sorted by this number, in order from
lowest to highest. Write down as many different
approaches to sorting the invoices as you can think
of.

Mais conteúdo relacionado

Mais procurados

DMDW Lesson 04 - Data Mining Theory
DMDW Lesson 04 - Data Mining TheoryDMDW Lesson 04 - Data Mining Theory
DMDW Lesson 04 - Data Mining TheoryJohannes Hoppe
 
International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)ijceronline
 
Introduction to Machine Learning with SciKit-Learn
Introduction to Machine Learning with SciKit-LearnIntroduction to Machine Learning with SciKit-Learn
Introduction to Machine Learning with SciKit-LearnBenjamin Bengfort
 
Clustbigfim frequent itemset mining of
Clustbigfim frequent itemset mining ofClustbigfim frequent itemset mining of
Clustbigfim frequent itemset mining ofijfcstjournal
 
Vol 16 No 2 - July-December 2016
Vol 16 No 2 - July-December 2016Vol 16 No 2 - July-December 2016
Vol 16 No 2 - July-December 2016ijcsbi
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdNimmi Weeraddana
 
An Improved Differential Evolution Algorithm for Data Stream Clustering
An Improved Differential Evolution Algorithm for Data Stream ClusteringAn Improved Differential Evolution Algorithm for Data Stream Clustering
An Improved Differential Evolution Algorithm for Data Stream ClusteringIJECEIAES
 
Session 06 machine learning.pptx
Session 06 machine learning.pptxSession 06 machine learning.pptx
Session 06 machine learning.pptxbodaceacat
 
Big Data Analytics(Intro,Hadoop Map Reduce,Mahout,K-means clustering,H-base)
Big Data Analytics(Intro,Hadoop Map Reduce,Mahout,K-means clustering,H-base)Big Data Analytics(Intro,Hadoop Map Reduce,Mahout,K-means clustering,H-base)
Big Data Analytics(Intro,Hadoop Map Reduce,Mahout,K-means clustering,H-base)MIT College Of Engineering,Pune
 
Scalable Distributed Real-Time Clustering for Big Data Streams
Scalable Distributed Real-Time Clustering for Big Data StreamsScalable Distributed Real-Time Clustering for Big Data Streams
Scalable Distributed Real-Time Clustering for Big Data StreamsAntonio Severien
 
Analysis of computational
Analysis of computationalAnalysis of computational
Analysis of computationalcsandit
 
Data Mining: Mining stream time series and sequence data
Data Mining: Mining stream time series and sequence dataData Mining: Mining stream time series and sequence data
Data Mining: Mining stream time series and sequence dataDataminingTools Inc
 
FPGA Implementation of High Speed 8bit Vedic Multiplier using Barrel Shifter
FPGA Implementation of High Speed 8bit Vedic Multiplier using Barrel ShifterFPGA Implementation of High Speed 8bit Vedic Multiplier using Barrel Shifter
FPGA Implementation of High Speed 8bit Vedic Multiplier using Barrel Shifterdbpublications
 

Mais procurados (20)

DMDW Lesson 04 - Data Mining Theory
DMDW Lesson 04 - Data Mining TheoryDMDW Lesson 04 - Data Mining Theory
DMDW Lesson 04 - Data Mining Theory
 
International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)
 
Introduction to Machine Learning with SciKit-Learn
Introduction to Machine Learning with SciKit-LearnIntroduction to Machine Learning with SciKit-Learn
Introduction to Machine Learning with SciKit-Learn
 
An Approach of Improvisation in Efficiency of Apriori Algorithm
An Approach of Improvisation in Efficiency of Apriori AlgorithmAn Approach of Improvisation in Efficiency of Apriori Algorithm
An Approach of Improvisation in Efficiency of Apriori Algorithm
 
Clustbigfim frequent itemset mining of
Clustbigfim frequent itemset mining ofClustbigfim frequent itemset mining of
Clustbigfim frequent itemset mining of
 
Vol 16 No 2 - July-December 2016
Vol 16 No 2 - July-December 2016Vol 16 No 2 - July-December 2016
Vol 16 No 2 - July-December 2016
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
An Improved Differential Evolution Algorithm for Data Stream Clustering
An Improved Differential Evolution Algorithm for Data Stream ClusteringAn Improved Differential Evolution Algorithm for Data Stream Clustering
An Improved Differential Evolution Algorithm for Data Stream Clustering
 
Session 06 machine learning.pptx
Session 06 machine learning.pptxSession 06 machine learning.pptx
Session 06 machine learning.pptx
 
F011123134
F011123134F011123134
F011123134
 
Big Data Analytics(Intro,Hadoop Map Reduce,Mahout,K-means clustering,H-base)
Big Data Analytics(Intro,Hadoop Map Reduce,Mahout,K-means clustering,H-base)Big Data Analytics(Intro,Hadoop Map Reduce,Mahout,K-means clustering,H-base)
Big Data Analytics(Intro,Hadoop Map Reduce,Mahout,K-means clustering,H-base)
 
Scalable Distributed Real-Time Clustering for Big Data Streams
Scalable Distributed Real-Time Clustering for Big Data StreamsScalable Distributed Real-Time Clustering for Big Data Streams
Scalable Distributed Real-Time Clustering for Big Data Streams
 
Analysis of computational
Analysis of computationalAnalysis of computational
Analysis of computational
 
Week 1 - Data Structures and Algorithms
Week 1 - Data Structures and AlgorithmsWeek 1 - Data Structures and Algorithms
Week 1 - Data Structures and Algorithms
 
Aa31163168
Aa31163168Aa31163168
Aa31163168
 
Icbai 2018 ver_1
Icbai 2018 ver_1Icbai 2018 ver_1
Icbai 2018 ver_1
 
Harvard poster
Harvard posterHarvard poster
Harvard poster
 
Data Mining: Mining stream time series and sequence data
Data Mining: Mining stream time series and sequence dataData Mining: Mining stream time series and sequence data
Data Mining: Mining stream time series and sequence data
 
Unit 1 dsa
Unit 1 dsaUnit 1 dsa
Unit 1 dsa
 
FPGA Implementation of High Speed 8bit Vedic Multiplier using Barrel Shifter
FPGA Implementation of High Speed 8bit Vedic Multiplier using Barrel ShifterFPGA Implementation of High Speed 8bit Vedic Multiplier using Barrel Shifter
FPGA Implementation of High Speed 8bit Vedic Multiplier using Barrel Shifter
 

Destaque

Chapter 5 interests groups (1)
Chapter 5 interests groups (1)Chapter 5 interests groups (1)
Chapter 5 interests groups (1)dhohnhol
 
What's in Store for Solar in the 2015 Texas Legislative Session?
What's in Store for Solar in the 2015 Texas Legislative Session? What's in Store for Solar in the 2015 Texas Legislative Session?
What's in Store for Solar in the 2015 Texas Legislative Session? Rick Borry
 
10 incredibly ironic flaws you can find in our constitution
10 incredibly ironic flaws you can find in our constitution10 incredibly ironic flaws you can find in our constitution
10 incredibly ironic flaws you can find in our constitutionohjhaly
 
Govt 2306 ch_7
Govt 2306 ch_7Govt 2306 ch_7
Govt 2306 ch_7Rick Fair
 
The New Age of Renewable Energy in Texas
The New Age of Renewable Energy in TexasThe New Age of Renewable Energy in Texas
The New Age of Renewable Energy in TexasBounce Energy
 
Govt 2306 ch_6
Govt 2306 ch_6Govt 2306 ch_6
Govt 2306 ch_6Rick Fair
 
Texas Tomorrow: The Future of Texas by Raul Torres CPA
Texas Tomorrow: The Future of Texas  by Raul Torres CPATexas Tomorrow: The Future of Texas  by Raul Torres CPA
Texas Tomorrow: The Future of Texas by Raul Torres CPARaul Torres, CPA
 
The Legislative Branch
The Legislative BranchThe Legislative Branch
The Legislative Branchitutor
 
Legislative Branch Notes
Legislative Branch NotesLegislative Branch Notes
Legislative Branch NotesTimothy Smith
 
Article VI - Legislative Department
Article VI - Legislative DepartmentArticle VI - Legislative Department
Article VI - Legislative DepartmentChristian Almazon
 
Writing a conceptual framework
Writing a conceptual frameworkWriting a conceptual framework
Writing a conceptual frameworkwtidwell
 

Destaque (15)

Chapter 5 interests groups (1)
Chapter 5 interests groups (1)Chapter 5 interests groups (1)
Chapter 5 interests groups (1)
 
What's in Store for Solar in the 2015 Texas Legislative Session?
What's in Store for Solar in the 2015 Texas Legislative Session? What's in Store for Solar in the 2015 Texas Legislative Session?
What's in Store for Solar in the 2015 Texas Legislative Session?
 
10 incredibly ironic flaws you can find in our constitution
10 incredibly ironic flaws you can find in our constitution10 incredibly ironic flaws you can find in our constitution
10 incredibly ironic flaws you can find in our constitution
 
Govt 2306 ch_7
Govt 2306 ch_7Govt 2306 ch_7
Govt 2306 ch_7
 
Chapter 11 & 4
Chapter 11 & 4Chapter 11 & 4
Chapter 11 & 4
 
The New Age of Renewable Energy in Texas
The New Age of Renewable Energy in TexasThe New Age of Renewable Energy in Texas
The New Age of Renewable Energy in Texas
 
The Power of 3 Notes
The Power of 3 NotesThe Power of 3 Notes
The Power of 3 Notes
 
Govt 2306 ch_6
Govt 2306 ch_6Govt 2306 ch_6
Govt 2306 ch_6
 
Texas Tomorrow: The Future of Texas by Raul Torres CPA
Texas Tomorrow: The Future of Texas  by Raul Torres CPATexas Tomorrow: The Future of Texas  by Raul Torres CPA
Texas Tomorrow: The Future of Texas by Raul Torres CPA
 
The Legislative Branch
The Legislative BranchThe Legislative Branch
The Legislative Branch
 
Legislative Branch Notes
Legislative Branch NotesLegislative Branch Notes
Legislative Branch Notes
 
Article VI Legislative
Article VI LegislativeArticle VI Legislative
Article VI Legislative
 
The legislative department
The legislative departmentThe legislative department
The legislative department
 
Article VI - Legislative Department
Article VI - Legislative DepartmentArticle VI - Legislative Department
Article VI - Legislative Department
 
Writing a conceptual framework
Writing a conceptual frameworkWriting a conceptual framework
Writing a conceptual framework
 

Semelhante a Data Structures and Algorithm Analysis

Chapter 1 Data structure.pptx
Chapter 1 Data structure.pptxChapter 1 Data structure.pptx
Chapter 1 Data structure.pptxwondmhunegn
 
Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01Prashanth Shivakumar
 
Lecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptLecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptMuhammadTalhaAwan1
 
Introduction to Data Structure and algorithm.pptx
Introduction to Data Structure and algorithm.pptxIntroduction to Data Structure and algorithm.pptx
Introduction to Data Structure and algorithm.pptxesuEthopi
 
CS3114_09212011.ppt
CS3114_09212011.pptCS3114_09212011.ppt
CS3114_09212011.pptArumugam90
 
Introduction to Data structure and algorithm.pptx
Introduction to Data structure and algorithm.pptxIntroduction to Data structure and algorithm.pptx
Introduction to Data structure and algorithm.pptxline24arts
 
Data Structure and Algorithm chapter two, This material is for Data Structure...
Data Structure and Algorithm chapter two, This material is for Data Structure...Data Structure and Algorithm chapter two, This material is for Data Structure...
Data Structure and Algorithm chapter two, This material is for Data Structure...bekidea
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure Prof Ansari
 
Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)MUHAMMAD AAMIR
 
Trivento summercamp masterclass 9/9/2016
Trivento summercamp masterclass 9/9/2016Trivento summercamp masterclass 9/9/2016
Trivento summercamp masterclass 9/9/2016Stavros Kontopoulos
 
Data Engineer's Lunch #85: Designing a Modern Data Stack
Data Engineer's Lunch #85: Designing a Modern Data StackData Engineer's Lunch #85: Designing a Modern Data Stack
Data Engineer's Lunch #85: Designing a Modern Data StackAnant Corporation
 
Big Data Hadoop (Overview)
Big Data Hadoop (Overview)Big Data Hadoop (Overview)
Big Data Hadoop (Overview)Rohit Srivastava
 
Simplified Data Processing On Large Cluster
Simplified Data Processing On Large ClusterSimplified Data Processing On Large Cluster
Simplified Data Processing On Large ClusterHarsh Kevadia
 

Semelhante a Data Structures and Algorithm Analysis (20)

Lect1.pptx
Lect1.pptxLect1.pptx
Lect1.pptx
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
algo 1.ppt
algo 1.pptalgo 1.ppt
algo 1.ppt
 
Chapter 1 Data structure.pptx
Chapter 1 Data structure.pptxChapter 1 Data structure.pptx
Chapter 1 Data structure.pptx
 
Chapter 1- IT.pptx
Chapter 1- IT.pptxChapter 1- IT.pptx
Chapter 1- IT.pptx
 
Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01
 
Lecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptLecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).ppt
 
Introduction to Data Structure and algorithm.pptx
Introduction to Data Structure and algorithm.pptxIntroduction to Data Structure and algorithm.pptx
Introduction to Data Structure and algorithm.pptx
 
CS3114_09212011.ppt
CS3114_09212011.pptCS3114_09212011.ppt
CS3114_09212011.ppt
 
Introduction to Data structure and algorithm.pptx
Introduction to Data structure and algorithm.pptxIntroduction to Data structure and algorithm.pptx
Introduction to Data structure and algorithm.pptx
 
Data Structure and Algorithm chapter two, This material is for Data Structure...
Data Structure and Algorithm chapter two, This material is for Data Structure...Data Structure and Algorithm chapter two, This material is for Data Structure...
Data Structure and Algorithm chapter two, This material is for Data Structure...
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure
 
Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)
 
251 - Alogarithms Lects.pdf
251 - Alogarithms Lects.pdf251 - Alogarithms Lects.pdf
251 - Alogarithms Lects.pdf
 
Trivento summercamp masterclass 9/9/2016
Trivento summercamp masterclass 9/9/2016Trivento summercamp masterclass 9/9/2016
Trivento summercamp masterclass 9/9/2016
 
Data Engineer's Lunch #85: Designing a Modern Data Stack
Data Engineer's Lunch #85: Designing a Modern Data StackData Engineer's Lunch #85: Designing a Modern Data Stack
Data Engineer's Lunch #85: Designing a Modern Data Stack
 
8.unit-1-fds-2022-23.pptx
8.unit-1-fds-2022-23.pptx8.unit-1-fds-2022-23.pptx
8.unit-1-fds-2022-23.pptx
 
Big Data
Big DataBig Data
Big Data
 
Big Data Hadoop (Overview)
Big Data Hadoop (Overview)Big Data Hadoop (Overview)
Big Data Hadoop (Overview)
 
Simplified Data Processing On Large Cluster
Simplified Data Processing On Large ClusterSimplified Data Processing On Large Cluster
Simplified Data Processing On Large Cluster
 

Mais de Ibrahim El-Torbany (15)

Idea2
Idea2Idea2
Idea2
 
Cpp lernaufgabe linked_list
Cpp lernaufgabe linked_listCpp lernaufgabe linked_list
Cpp lernaufgabe linked_list
 
C++ examples &revisions
C++ examples &revisionsC++ examples &revisions
C++ examples &revisions
 
Lec6 mod linked list
Lec6 mod linked listLec6 mod linked list
Lec6 mod linked list
 
Lec5
Lec5Lec5
Lec5
 
Lec3
Lec3Lec3
Lec3
 
Lec2
Lec2Lec2
Lec2
 
Lec2&3 data structure
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structure
 
Lec4
Lec4Lec4
Lec4
 
Ass logic
Ass logicAss logic
Ass logic
 
Math lecture 4 Part 1
Math lecture 4 Part 1Math lecture 4 Part 1
Math lecture 4 Part 1
 
Tutorial 1
Tutorial 1Tutorial 1
Tutorial 1
 
Lec2&3_DataStructure
Lec2&3_DataStructureLec2&3_DataStructure
Lec2&3_DataStructure
 
Lecture 2 math 2
Lecture 2 math 2Lecture 2 math 2
Lecture 2 math 2
 
Chapter 1 what is statistics
Chapter 1 what is statisticsChapter 1 what is statistics
Chapter 1 what is statistics
 

Último

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
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
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Último (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
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
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Data Structures and Algorithm Analysis

  • 1. 1 Data Structures and Algorithm Analysis Dr. Nagwa Badr
  • 2. 2 The Need for Data Structures Data structures organize data ⇒ more efficient programs. More powerful computers ⇒ more complex applications. More complex applications demand more calculations. Complex computing tasks are unlike our everyday experience.
  • 3. 3 What is a data structure?  In a general sense, any data representation is a data structure. Example: An integer  More typically, a data structure is meant to be an organization for a collection of data items.
  • 4. 4 Organizing Data Any organization for a collection of records can be searched, processed in any order, or modified. The choice of data structure and algorithm can make the difference between a program running in a few seconds or many days.
  • 5. 5 Efficiency A solution is said to be efficient if it solves the problem within its resource constraints.  Space  Time  The cost of a solution is the amount of resources that the solution consumes.
  • 6. 6 Costs and Benefits  A data structure requires a certain amount of:  space for each data item it stores  time to perform a single basic operation  programming effort.
  • 7. 7 Example: Banking Application  Operations are (typically):  Open accounts  Close accounts  Access account to Add money  Access account to Withdraw money
  • 8. 8 Example: Banking Application  Teller and ATM transactions are expected to take little time.  Opening or closing an account can take much longer (perhaps up to an hour).
  • 9. 9 Example: Banking Application  When considering the choice of data structure to use in the database system that manages the accounts, we are looking for a data structure that:  Is inefficient for deletion  Highly efficient for search  Moderately efficient for insertion
  • 10. 10 Example: Banking Application  One data structure that meets these requirements is the hash table (chapter 9).  Records are accessible by account number (called an exact-match query)  Hash tables allow for extremely fast exact-match search.  Hash tables also support efficient insertion of new records.  Deletions can also be supported efficiently (but too many deletions lead to some degradation in performance – requiring the hash table to be reorganized).
  • 11. 11 Example: City Database  Database system for cities and towns.  Users find information about a particular place by name (exact-match query)  Users also find all places that match a particular value (or range of values), such as location or population size (called a range query).
  • 12. 12 Example: City Database  The database must answer queries quickly enough to satisfy the patience of a typical user.  For an exact-match query, a few seconds is satisfactory  For a range queries, the entire operation may be allowed to take longer, perhaps on the order of a minute.
  • 13. 13 Example: City Database  The hash table is inappropriate for implementing the city database because:  It cannot perform efficient range queries  The B+ tree (section 10) supports large databases:  Insertion  Deletion  Range queries  If the database is created once and then never changed, a simple linear index would be more appropriate.
  • 14. 14 Selecting a Data Structure Select a data structure as follows: 1. Analyze the problem to determine the resource constraints a solution must meet. 2. Determine the basic operations that must be supported. Quantify the resource constraints for each operation. 3. Select the data structure that best meets these requirements.
  • 15. 15 Some Questions to Ask  Are all data inserted into the data structure at the beginning, or are insertions intersparsed with other operations?  Can data be deleted?  Are all data processed in some well- defined order, or is random access allowed?
  • 16. 16 Data Structure Philosophy Each data structure has costs and benefits. Rarely is one data structure better than another in all situations. A data structure requires:  space for each data item it stores,  time to perform each basic operation,  programming effort.
  • 17. 17 Data Structure Philosophy Each problem has constraints on available space and time. Only after a careful analysis of problem characteristics can we know the best data structure for the task. Bank example:  Start account: a few minutes  Transactions: a few seconds  Close account: overnight continued
  • 18. 18 Goals of this Course 1. Reinforce the concept that costs and benefits exist for every data structure. 1. Learn the commonly used data structures.  These form a programmer's basic data structure ``toolkit.'‘ 1. Understand how to measure the cost of a data structure or program.  These techniques also allow you to judge the merits of new data structures that you or others might invent.
  • 19. 19 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely in terms of a set of values and a set of operations on that data type. Each ADT operation is defined by its inputs and outputs. Encapsulation: Hide implementation details.
  • 20. 20 Data Structure  A data structure is the physical implementation of an ADT.  Each operation associated with the ADT is implemented by one or more subroutines in the implementation.  In a OO language such as C++, an ADT and its implementation together make up a class.  Data structure usually refers to an organization for data in main memory.  File structure: an organization for data on peripheral storage, such as a disk drive.
  • 21. 21 Labeling collections of objects Humans deal with complexity by assigning a label to an assembly of objects. An ADT manages complexity through abstraction.  Hierarchies of labels Ex1: transistors ⇒ gates ⇒ CPU. In a program, implement an ADT, then think only about the ADT, not its implementation.
  • 22. 22 Logical vs. Physical Form Data items have both a logical and a physical form. Logical form: definition of the data item within an ADT.  Ex: Integers in mathematical sense: +, - Physical form: implementation of the data item within a data structure.  Ex: 16/32 bit integers, overflow.
  • 23. 23 Data Type ADT: Type Operations Data Items: Logical Form Data Items: Physical Form Data Structure: Storage Space Subroutines
  • 24. 24 Problems, Algorithms and Programs  Programmers deal with:  problems,  algorithms and  computer programs. These are distinct concepts…
  • 25. 25 Problems  Problem: a task to be performed.  Best thought of as inputs and matching outputs.  Problem definition should include constraints on the resources that may be consumed by any acceptable solution.
  • 26. 26 Problems (cont)  Problems ⇔ mathematical functions  A function is a matching between inputs (the domain) and outputs (the range).  An input to a function may be single number, or a collection of information.  The values making up an input are called the parameters of the function.  A particular input must always result in the same output every time the function is computed.
  • 27. 27 Algorithms and Programs Algorithm: a method or a process followed to solve a problem.  A recipe: The algorithm gives us a “recipe” for solving the problem by performing a series of steps, where each step is completely understood and doable. An algorithm takes the input to a problem (function) and transforms it to the output.  A mapping of input to output. A problem can be solved by many algorithms.
  • 28. 28 A problem can have many algorithms For example, the problem of sorting can be solved by the following algorithms:  Insertion sort  Bubble sort  Selection sort  Shellsort  Mergesort  Others
  • 29. 29 Algorithm Properties An algorithm possesses the following properties:  It must be correct.  It must be composed of a series of concrete steps.  There can be no ambiguity as to which step will be performed next.  It must be composed of a finite number of steps.  It must terminate. A computer program is an instance, or concrete representation, for an algorithm in some programming language.
  • 30. 30 Programs  A computer program is a concrete representation of an algorithm in some programming language.  Naturally, there are many programs that are instances of the same algorithms, since any modern programming language can be used to implement any algorithm.
  • 31. 31 To Summarize:  A problem is a function or a mapping of inputs to outputs.  An algorithm is a recipe for solving a problem whose steps are concrete and ambiguous.  A program is an instantiation of an algorithm in a computer programming language.
  • 32. 32 Example  Problem: find y = x to the power of 2  Algorithm1: Multiply X by X  Algorithm2: Add X to itself X times  Program1: for (int i = 0; i<x; i++) y +=x;
  • 33. 33 Example (cont.) Program2: (Assembly Intel 8086) mov bl,x // read x mov al,bl // store x mov cl,bl // int counter loop: add al,bl // al = al + x dec cl // decrement loop ctr jnz loop
  • 34. 34 In class exercises  Think of a program you have used that is unacceptably slow. Identify other basic operations that the program performs quickly enough.  Imagine that you are a shipping clerk for a large company. You have just been handed about 1000 invoices, each of which is a single sheet of paper with a large number in the upper right corner. The invoices must be sorted by this number, in order from lowest to highest. Write down as many different approaches to sorting the invoices as you can think of.

Notas do Editor

  1. A primary concern for this course is efficiency. You might believe that faster computers make it unnecessary to be concerned with efficiency. However… So we need special training.
  2. If you are willing to pay enough in time delay. Example: Simple unordered array of records.
  3. Alternate definition: Better than known alternatives (“relatively efficient”). Space and time are typical constraints for programs. This does not mean always strive for the most efficient program. If the program operates well within resource constraints, there is no benefit to making it faster or smaller.
  4. Typically want the “simplest” data structure that will meet the requirements.
  5. These questions often help to narrow the possibilities. If data can be deleted, a more complex representation is typically required.
  6. The space required includes data and overhead. Some data structures/algorithms are more complicated than others.
  7. The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  8. The concept of an ADT is one instance of an important principle that must be understood By any successful computer specialist: managing complexity through abstraction.
  9. In this class, we frequently move above and below “the line” separating logical and physical forms.
  10. But NO constraints on HOW the problem is solved
  11. “Correct” means computes the proper function. “Concrete steps” are executable by the machine in question. We frequently interchange use of “algorithm” and “program” though they are actually different concepts.