SlideShare a Scribd company logo
1 of 50
Lecture No.01
Data Structures
Dr. Sohail Aslam
Data Structures
 Prepares the students for (and is a
prerequisite for) the more advanced
material students will encounter in later
courses.
 Cover well-known data structures such as
dynamic arrays, linked lists, stacks,
queues, tree and graphs.
 Implement data structures in C++
Data Structures
 Prepares the students for (and is a
prerequisite for) the more advanced
material students will encounter in later
courses.
 Cover well-known data structures such as
dynamic arrays, linked lists, stacks,
queues, tree and graphs.
 Implement data structures in C++
Data Structures
 Prepares the students for (and is a
prerequisite for) the more advanced
material students will encounter in later
courses.
 Cover well-known data structures such as
dynamic arrays, linked lists, stacks,
queues, tree and graphs.
 Implement data structures in C++
Grading
 Term Exam 1 20%
 Term Exam 2 20%
 Final 35%
 8 Programming Assignments 25%
 Schedule of Topics:
http://www.vu.edu.pk/ds
Instructor
Sohail Aslam
 1998-Present: V.P. Software
Development, Techlogix Pakistan Limited
 1993-1998: Associate Professor,
Department of Computer Science, LUMS
 1990-1992: CSRD, University of Illinois
 1990: Ph.D, Computer Science, University
of Illinois
Need for Data Structures
 Data structures organize data ⇒ more
efficient programs.
 More powerful computers ⇒ more
complex applications.
 More complex applications demand more
calculations.
Need for Data Structures
 Data structures organize data ⇒ more
efficient programs.
 More powerful computers ⇒ more
complex applications.
 More complex applications demand more
calculations.
Need for Data Structures
 Data structures organize data ⇒ more
efficient programs.
 More powerful computers ⇒ more
complex applications.
 More complex applications demand more
calculations.
Organizing Data
 Any organization for a collection of records
that 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.
Organizing Data
 Any organization for a collection of records
that 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.
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.
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.
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.
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.
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.
Some Questions to Ask
• Are all data inserted into the data structure
at the beginning, or are insertions
interspersed with other operations?
• Can data be deleted?
• Are all data processed in some well-
defined order, or is random access
allowed?
Some Questions to Ask
• Are all data inserted into the data structure
at the beginning, or are insertions
interspersed with other operations?
• Can data be deleted?
• Are all data processed in some well-
defined order, or is random access
allowed?
Some Questions to Ask
• Are all data inserted into the data structure
at the beginning, or are insertions
interspersed with other operations?
• Can data be deleted?
• Are all data processed in some well-
defined order, or is random access
allowed?
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.
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.
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.
Goals of this Course
1. Reinforce the concept that costs and benefits
exist for every data structure.
2. Learn the commonly used data structures.
– These form a programmer's basic data structure
“toolkit.”
3. 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.
Goals of this Course
1. Reinforce the concept that costs and benefits
exist for every data structure.
2. Learn the commonly used data structures.
– These form a programmer's basic data structure
“toolkit”.
3. 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.
Goals of this Course
1. Reinforce the concept that costs and benefits
exist for every data structure.
2. Learn the commonly used data structures.
– These form a programmer's basic data structure
“toolkit”.
3. 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.
Arrays
 Elementary data structure that exists as built-in
in most programming languages.
main( int argc, char** argv )
{
int x[6];
int j;
for(j=0; j < 6; j++)
x[j] = 2*j;
}
Arrays
 Array declaration: int x[6];
 An array is collection of cells of the same type.
 The collection has the name ‘x’.
 The cells are numbered with consecutive
integers.
 To access a cell, use the array name and an
index:
x[0], x[1], x[2], x[3], x[4], x[5]
Array Layout
x[1]
x[2]
x[3]
x[4]
x[5]
x[0]
Array cells are
contiguous in
computer memory
The memory can be
thought of as an
array
What is Array Name?
 ‘x’ is an array name but there is no variable x. ‘x’ is not an lvalue.
 For example, if we have the code
int a, b;
then we can write
b = 2;
a = b;
a = 5;
But we cannot write
2 = a;
What is Array Name?
 ‘x’ is an array name but there is no variable x. ‘x’ is not an lvalue.
 For example, if we have the code
int a, b;
then we can write
b = 2;
a = b;
a = 5;
But we cannot write
2 = a;
What is Array Name?
 ‘x’ is an array name but there is no variable x. ‘x’ is not an lvalue.
 For example, if we have the code
int a, b;
then we can write
b = 2;
a = b;
a = 5;
But we cannot write
2 = a;
Array Name
 ‘x’ is not an lvalue
int x[6];
int n;
x[0] = 5;
x[1] = 2;
x = 3; // not allowed
x = a + b; // not allowed
x = &n; // not allowed
Array Name
 ‘x’ is not an lvalue
int x[6];
int n;
x[0] = 5;
x[1] = 2;
x = 3; // not allowed
x = a + b; // not allowed
x = &n; // not allowed
Dynamic Arrays
 You would like to use an array data structure
but you do not know the size of the array at
compile time.
 You find out when the program executes that
you need an integer array of size n=20.
 Allocate an array using the new operator:
int* y = new int[20]; // or int* y = new int[n]
y[0] = 10;
y[1] = 15; // use is the same
Dynamic Arrays
 You would like to use an array data structure
but you do not know the size of the array at
compile time.
 You find out when the program executes that
you need an integer array of size n=20.
 Allocate an array using the new operator:
int* y = new int[20]; // or int* y = new int[n]
y[0] = 10;
y[1] = 15; // use is the same
Dynamic Arrays
 You would like to use an array data structure
but you do not know the size of the array at
compile time.
 You find out when the program executes that
you need an integer array of size n=20.
 Allocate an array using the new operator:
int* y = new int[20]; // or int* y = new int[n]
y[0] = 10;
y[1] = 15; // use is the same
Dynamic Arrays
 ‘y’ is a lvalue; it is a pointer that holds the
address of 20 consecutive cells in memory.
 It can be assigned a value. The new operator
returns as address that is stored in y.
 We can write:
y = &x[0];
y = x; // x can appear on the right
// y gets the address of the
// first cell of the x array
Dynamic Arrays
 ‘y’ is a lvalue; it is a pointer that holds the
address of 20 consecutive cells in memory.
 It can be assigned a value. The new operator
returns as address that is stored in y.
 We can write:
y = &x[0];
y = x; // x can appear on the right
// y gets the address of the
// first cell of the x array
Dynamic Arrays
 ‘y’ is a lvalue; it is a pointer that holds the
address of 20 consecutive cells in memory.
 It can be assigned a value. The new operator
returns as address that is stored in y.
 We can write:
y = &x[0];
y = x; // x can appear on the right
// y gets the address of the
// first cell of the x array
Dynamic Arrays
 We must free the memory we got using the new
operator once we are done with the y array.
delete[ ] y;
 We would not do this to the x array because we
did not use new to create it.
The LIST Data Structure
 The List is among the most generic of data
structures.
 Real life:
a. shopping list,
b. groceries list,
c. list of people to invite to dinner
d. List of presents to get
Lists
 A list is collection of items that are all of the
same type (grocery items, integers, names)
 The items, or elements of the list, are stored in
some particular order
 It is possible to insert new elements into various
positions in the list and remove any element of
the list
Lists
 A list is collection of items that are all of the
same type (grocery items, integers, names)
 The items, or elements of the list, are stored in
some particular order
 It is possible to insert new elements into various
positions in the list and remove any element of
the list
Lists
 A list is collection of items that are all of the
same type (grocery items, integers, names)
 The items, or elements of the list, are stored in
some particular order
 It is possible to insert new elements into various
positions in the list and remove any element of
the list
Lists
 List is a set of elements in a linear order.
For example, data values a1, a2, a3, a4 can be
arranged in a list:
(a3, a1, a2, a4)
In this list, a3, is the first element, a1 is the
second element, and so on
 The order is important here; this is not just a
random collection of elements, it is an ordered
collection
Lists
 List is a set of elements in a linear order.
For example, data values a1, a2, a3, a4 can be
arranged in a list:
(a3, a1, a2, a4)
In this list, a3, is the first element, a1 is the
second element, and so on
 The order is important here; this is not just a
random collection of elements, it is an ordered
collection
List Operations
Useful operations
• createList(): create a new list (presumably empty)
• copy(): set one list to be a copy of another
• clear(); clear a list (remove all elments)
• insert(X, ?): Insert element X at a particular position
in the list
• remove(?): Remove element at some position in
the list
• get(?): Get element at a given position
• update(X, ?): replace the element at a given position
with X
• find(X): determine if the element X is in the list
• length(): return the length of the list.
List Operations
 We need to decide what is meant by “particular
position”; we have used “?” for this.
 There are two possibilities:
1. Use the actual index of element: insert after element
3, get element number 6. This approach is taken by
arrays
2. Use a “current” marker or pointer to refer to a
particular position in the list.
List Operations
 We need to decide what is meant by “particular
position”; we have used “?” for this.
 There are two possibilities:
1. Use the actual index of element: insert after element
3, get element number 6. This approach is taken by
arrays
2. Use a “current” marker or pointer to refer to a
particular position in the list.
List Operations
 If we use the “current” marker, the following four
methods would be useful:
 start(): moves to “current” pointer to the very first
element.
 tail(): moves to “current” pointer to the very last
element.
 next(): move the current position forward one
element
 back(): move the current position backward one
element

More Related Content

What's hot

Comments in C Programming
Comments in C ProgrammingComments in C Programming
Comments in C Programmingprogramming9
 
Software engineering principles in system software design
Software engineering principles in system software designSoftware engineering principles in system software design
Software engineering principles in system software designTech_MX
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++Shyam Gupta
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patternsAmit Kabra
 
Dynamic Binding in C# 4.0
Dynamic Binding in C# 4.0Dynamic Binding in C# 4.0
Dynamic Binding in C# 4.0Buu Nguyen
 
Software engineering introduction
Software engineering introductionSoftware engineering introduction
Software engineering introductionVishal Singh
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1REHAN IJAZ
 
Programming Languages / Translators
Programming Languages / TranslatorsProgramming Languages / Translators
Programming Languages / TranslatorsProject Student
 
Software Engineering- Crisis and Process Models
Software Engineering- Crisis and Process ModelsSoftware Engineering- Crisis and Process Models
Software Engineering- Crisis and Process ModelsNishu Rastogi
 
software development and programming languages
software development and programming languages software development and programming languages
software development and programming languages PraShant Kumar
 
Characteristics of Software
Characteristics of SoftwareCharacteristics of Software
Characteristics of SoftwareUpekha Vandebona
 

What's hot (20)

System testing
System testingSystem testing
System testing
 
[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOP[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOP
 
Comments in C Programming
Comments in C ProgrammingComments in C Programming
Comments in C Programming
 
Ch17 distributed software engineering
Ch17 distributed software engineeringCh17 distributed software engineering
Ch17 distributed software engineering
 
Language processor
Language processorLanguage processor
Language processor
 
Software engineering principles in system software design
Software engineering principles in system software designSoftware engineering principles in system software design
Software engineering principles in system software design
 
Intro to assembly language
Intro to assembly languageIntro to assembly language
Intro to assembly language
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
 
Dynamic Binding in C# 4.0
Dynamic Binding in C# 4.0Dynamic Binding in C# 4.0
Dynamic Binding in C# 4.0
 
Software engineering introduction
Software engineering introductionSoftware engineering introduction
Software engineering introduction
 
Software Development Process
Software Development ProcessSoftware Development Process
Software Development Process
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer Programming
 
Programming Languages / Translators
Programming Languages / TranslatorsProgramming Languages / Translators
Programming Languages / Translators
 
Presentation compiler design
Presentation compiler designPresentation compiler design
Presentation compiler design
 
Software Engineering- Crisis and Process Models
Software Engineering- Crisis and Process ModelsSoftware Engineering- Crisis and Process Models
Software Engineering- Crisis and Process Models
 
software development and programming languages
software development and programming languages software development and programming languages
software development and programming languages
 
Characteristics of Software
Characteristics of SoftwareCharacteristics of Software
Characteristics of Software
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
 

Similar to Data structures cs301 power point slides lecture 01

CS301-lec01.ppt
CS301-lec01.pptCS301-lec01.ppt
CS301-lec01.pptomair31
 
computer notes - Data Structures - 1
computer notes - Data Structures - 1computer notes - Data Structures - 1
computer notes - Data Structures - 1ecomputernotes
 
Computer notes - data structures
Computer notes - data structuresComputer notes - data structures
Computer notes - data structuresecomputernotes
 
Data structure and algorithm.
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm. Abdul salam
 
DSA 1- Introduction.pdf
DSA 1- Introduction.pdfDSA 1- Introduction.pdf
DSA 1- Introduction.pdfAliyanAbbas1
 
Unit 2 - Data Manipulation with R.pptx
Unit 2 - Data Manipulation with R.pptxUnit 2 - Data Manipulation with R.pptx
Unit 2 - Data Manipulation with R.pptxMalla Reddy University
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptxSajalFayyaz
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R langsenthil0809
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureRai University
 
Bsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureBsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureRai University
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureRai University
 
EE-232-LEC-01 Data_structures.pptx
EE-232-LEC-01 Data_structures.pptxEE-232-LEC-01 Data_structures.pptx
EE-232-LEC-01 Data_structures.pptxiamultapromax
 
Introduction to Data Science With R Notes
Introduction to Data Science With R NotesIntroduction to Data Science With R Notes
Introduction to Data Science With R NotesLakshmiSarvani6
 
Bca2020 data structure and algorithm
Bca2020   data structure and algorithmBca2020   data structure and algorithm
Bca2020 data structure and algorithmsmumbahelp
 

Similar to Data structures cs301 power point slides lecture 01 (20)

Data Structure Lec #1
Data Structure Lec #1Data Structure Lec #1
Data Structure Lec #1
 
CS301-lec01.ppt
CS301-lec01.pptCS301-lec01.ppt
CS301-lec01.ppt
 
computer notes - Data Structures - 1
computer notes - Data Structures - 1computer notes - Data Structures - 1
computer notes - Data Structures - 1
 
Computer notes - data structures
Computer notes - data structuresComputer notes - data structures
Computer notes - data structures
 
Data structure and algorithm.
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm.
 
DSA 1- Introduction.pdf
DSA 1- Introduction.pdfDSA 1- Introduction.pdf
DSA 1- Introduction.pdf
 
algo 1.ppt
algo 1.pptalgo 1.ppt
algo 1.ppt
 
Unit 2 - Data Manipulation with R.pptx
Unit 2 - Data Manipulation with R.pptxUnit 2 - Data Manipulation with R.pptx
Unit 2 - Data Manipulation with R.pptx
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R lang
 
Lec1
Lec1Lec1
Lec1
 
Lec1
Lec1Lec1
Lec1
 
Lect1.pptx
Lect1.pptxLect1.pptx
Lect1.pptx
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
 
Bsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureBsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structure
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structure
 
EE-232-LEC-01 Data_structures.pptx
EE-232-LEC-01 Data_structures.pptxEE-232-LEC-01 Data_structures.pptx
EE-232-LEC-01 Data_structures.pptx
 
Introduction to Data Science With R Notes
Introduction to Data Science With R NotesIntroduction to Data Science With R Notes
Introduction to Data Science With R Notes
 
Bca2020 data structure and algorithm
Bca2020   data structure and algorithmBca2020   data structure and algorithm
Bca2020 data structure and algorithm
 
Numerical data.
Numerical data.Numerical data.
Numerical data.
 

Recently uploaded

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 

Data structures cs301 power point slides lecture 01

  • 2. Data Structures  Prepares the students for (and is a prerequisite for) the more advanced material students will encounter in later courses.  Cover well-known data structures such as dynamic arrays, linked lists, stacks, queues, tree and graphs.  Implement data structures in C++
  • 3. Data Structures  Prepares the students for (and is a prerequisite for) the more advanced material students will encounter in later courses.  Cover well-known data structures such as dynamic arrays, linked lists, stacks, queues, tree and graphs.  Implement data structures in C++
  • 4. Data Structures  Prepares the students for (and is a prerequisite for) the more advanced material students will encounter in later courses.  Cover well-known data structures such as dynamic arrays, linked lists, stacks, queues, tree and graphs.  Implement data structures in C++
  • 5. Grading  Term Exam 1 20%  Term Exam 2 20%  Final 35%  8 Programming Assignments 25%  Schedule of Topics: http://www.vu.edu.pk/ds
  • 6. Instructor Sohail Aslam  1998-Present: V.P. Software Development, Techlogix Pakistan Limited  1993-1998: Associate Professor, Department of Computer Science, LUMS  1990-1992: CSRD, University of Illinois  1990: Ph.D, Computer Science, University of Illinois
  • 7. Need for Data Structures  Data structures organize data ⇒ more efficient programs.  More powerful computers ⇒ more complex applications.  More complex applications demand more calculations.
  • 8. Need for Data Structures  Data structures organize data ⇒ more efficient programs.  More powerful computers ⇒ more complex applications.  More complex applications demand more calculations.
  • 9. Need for Data Structures  Data structures organize data ⇒ more efficient programs.  More powerful computers ⇒ more complex applications.  More complex applications demand more calculations.
  • 10. Organizing Data  Any organization for a collection of records that 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.
  • 11. Organizing Data  Any organization for a collection of records that 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.
  • 12. 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.
  • 13. 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.
  • 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. 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.
  • 16. 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.
  • 17. Some Questions to Ask • Are all data inserted into the data structure at the beginning, or are insertions interspersed with other operations? • Can data be deleted? • Are all data processed in some well- defined order, or is random access allowed?
  • 18. Some Questions to Ask • Are all data inserted into the data structure at the beginning, or are insertions interspersed with other operations? • Can data be deleted? • Are all data processed in some well- defined order, or is random access allowed?
  • 19. Some Questions to Ask • Are all data inserted into the data structure at the beginning, or are insertions interspersed with other operations? • Can data be deleted? • Are all data processed in some well- defined order, or is random access allowed?
  • 20. 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.
  • 21. 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.
  • 22. 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.
  • 23. Goals of this Course 1. Reinforce the concept that costs and benefits exist for every data structure. 2. Learn the commonly used data structures. – These form a programmer's basic data structure “toolkit.” 3. 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.
  • 24. Goals of this Course 1. Reinforce the concept that costs and benefits exist for every data structure. 2. Learn the commonly used data structures. – These form a programmer's basic data structure “toolkit”. 3. 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.
  • 25. Goals of this Course 1. Reinforce the concept that costs and benefits exist for every data structure. 2. Learn the commonly used data structures. – These form a programmer's basic data structure “toolkit”. 3. 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.
  • 26. Arrays  Elementary data structure that exists as built-in in most programming languages. main( int argc, char** argv ) { int x[6]; int j; for(j=0; j < 6; j++) x[j] = 2*j; }
  • 27. Arrays  Array declaration: int x[6];  An array is collection of cells of the same type.  The collection has the name ‘x’.  The cells are numbered with consecutive integers.  To access a cell, use the array name and an index: x[0], x[1], x[2], x[3], x[4], x[5]
  • 28. Array Layout x[1] x[2] x[3] x[4] x[5] x[0] Array cells are contiguous in computer memory The memory can be thought of as an array
  • 29. What is Array Name?  ‘x’ is an array name but there is no variable x. ‘x’ is not an lvalue.  For example, if we have the code int a, b; then we can write b = 2; a = b; a = 5; But we cannot write 2 = a;
  • 30. What is Array Name?  ‘x’ is an array name but there is no variable x. ‘x’ is not an lvalue.  For example, if we have the code int a, b; then we can write b = 2; a = b; a = 5; But we cannot write 2 = a;
  • 31. What is Array Name?  ‘x’ is an array name but there is no variable x. ‘x’ is not an lvalue.  For example, if we have the code int a, b; then we can write b = 2; a = b; a = 5; But we cannot write 2 = a;
  • 32. Array Name  ‘x’ is not an lvalue int x[6]; int n; x[0] = 5; x[1] = 2; x = 3; // not allowed x = a + b; // not allowed x = &n; // not allowed
  • 33. Array Name  ‘x’ is not an lvalue int x[6]; int n; x[0] = 5; x[1] = 2; x = 3; // not allowed x = a + b; // not allowed x = &n; // not allowed
  • 34. Dynamic Arrays  You would like to use an array data structure but you do not know the size of the array at compile time.  You find out when the program executes that you need an integer array of size n=20.  Allocate an array using the new operator: int* y = new int[20]; // or int* y = new int[n] y[0] = 10; y[1] = 15; // use is the same
  • 35. Dynamic Arrays  You would like to use an array data structure but you do not know the size of the array at compile time.  You find out when the program executes that you need an integer array of size n=20.  Allocate an array using the new operator: int* y = new int[20]; // or int* y = new int[n] y[0] = 10; y[1] = 15; // use is the same
  • 36. Dynamic Arrays  You would like to use an array data structure but you do not know the size of the array at compile time.  You find out when the program executes that you need an integer array of size n=20.  Allocate an array using the new operator: int* y = new int[20]; // or int* y = new int[n] y[0] = 10; y[1] = 15; // use is the same
  • 37. Dynamic Arrays  ‘y’ is a lvalue; it is a pointer that holds the address of 20 consecutive cells in memory.  It can be assigned a value. The new operator returns as address that is stored in y.  We can write: y = &x[0]; y = x; // x can appear on the right // y gets the address of the // first cell of the x array
  • 38. Dynamic Arrays  ‘y’ is a lvalue; it is a pointer that holds the address of 20 consecutive cells in memory.  It can be assigned a value. The new operator returns as address that is stored in y.  We can write: y = &x[0]; y = x; // x can appear on the right // y gets the address of the // first cell of the x array
  • 39. Dynamic Arrays  ‘y’ is a lvalue; it is a pointer that holds the address of 20 consecutive cells in memory.  It can be assigned a value. The new operator returns as address that is stored in y.  We can write: y = &x[0]; y = x; // x can appear on the right // y gets the address of the // first cell of the x array
  • 40. Dynamic Arrays  We must free the memory we got using the new operator once we are done with the y array. delete[ ] y;  We would not do this to the x array because we did not use new to create it.
  • 41. The LIST Data Structure  The List is among the most generic of data structures.  Real life: a. shopping list, b. groceries list, c. list of people to invite to dinner d. List of presents to get
  • 42. Lists  A list is collection of items that are all of the same type (grocery items, integers, names)  The items, or elements of the list, are stored in some particular order  It is possible to insert new elements into various positions in the list and remove any element of the list
  • 43. Lists  A list is collection of items that are all of the same type (grocery items, integers, names)  The items, or elements of the list, are stored in some particular order  It is possible to insert new elements into various positions in the list and remove any element of the list
  • 44. Lists  A list is collection of items that are all of the same type (grocery items, integers, names)  The items, or elements of the list, are stored in some particular order  It is possible to insert new elements into various positions in the list and remove any element of the list
  • 45. Lists  List is a set of elements in a linear order. For example, data values a1, a2, a3, a4 can be arranged in a list: (a3, a1, a2, a4) In this list, a3, is the first element, a1 is the second element, and so on  The order is important here; this is not just a random collection of elements, it is an ordered collection
  • 46. Lists  List is a set of elements in a linear order. For example, data values a1, a2, a3, a4 can be arranged in a list: (a3, a1, a2, a4) In this list, a3, is the first element, a1 is the second element, and so on  The order is important here; this is not just a random collection of elements, it is an ordered collection
  • 47. List Operations Useful operations • createList(): create a new list (presumably empty) • copy(): set one list to be a copy of another • clear(); clear a list (remove all elments) • insert(X, ?): Insert element X at a particular position in the list • remove(?): Remove element at some position in the list • get(?): Get element at a given position • update(X, ?): replace the element at a given position with X • find(X): determine if the element X is in the list • length(): return the length of the list.
  • 48. List Operations  We need to decide what is meant by “particular position”; we have used “?” for this.  There are two possibilities: 1. Use the actual index of element: insert after element 3, get element number 6. This approach is taken by arrays 2. Use a “current” marker or pointer to refer to a particular position in the list.
  • 49. List Operations  We need to decide what is meant by “particular position”; we have used “?” for this.  There are two possibilities: 1. Use the actual index of element: insert after element 3, get element number 6. This approach is taken by arrays 2. Use a “current” marker or pointer to refer to a particular position in the list.
  • 50. List Operations  If we use the “current” marker, the following four methods would be useful:  start(): moves to “current” pointer to the very first element.  tail(): moves to “current” pointer to the very last element.  next(): move the current position forward one element  back(): move the current position backward one element