SlideShare a Scribd company logo
Lecture 1: Introduction to data structures and
algorithms
University of Technology and Engineering
Vietnam National University Hanoi
Outline
➢Data structures and algorithms
➢Industrial problems
➢Data types
➢Abstract data structures
➢Problem description
Data Structures and Algorithms 2
Computer programs
➢ What is a computer program?
A computer program is a set of instructions that perform
specific tasks when executed by computers.
➢ What is a good computer program?
❖Correctness
❖Efficiency
❖Simple/Understandable
❖Easy to change/maintain and upgrade
“Program = Algorithms + Data structures”
N. Wirth
Data Structures and Algorithms 3
Data structures?
➢ What is a data structure?
A data structure is a particular way of storing and organizing data
so that they can be used efficiently.
➢ What is a good data structure?
❖ Correctness (satisfy requirements)
❖ Memory efficiency
❖ Simple/understandable
❖ Implementable
➢ Standard data structures
❖ Array
❖ Set
❖ Map/Dictionary
Data Structures and Algorithms 4
Algorithms?
➢ What is an algorithm?
An algorithm is a step by step procedure to solve a problem. An algorithm can be
described by nature languages (English, Vietnamese...) or programming languages
(C++, Java, Python…)
Example: How to cook rice?
❖ Step 1: Get rice
❖ Step 2: Rinse the rice
❖ Step 3: Put the rice and water into a rice cooker
❖ Step 4: Turn on the rice cooker
❖ Step 5: Check the rice when the rice cooker turns off
➢ What is a good algorithm?
❖ Correctness
❖ Efficiency
❖ Simple/understandable
❖ Implementable
Data Structures and Algorithms 5
Example: Searching problem
Problem: Given a list of numbers sorted increasingly, describe
an algorithm to check if a number k is in the list.
➢ Naïve searching algorithm
Moving from the begin to the end of the list to check if k is in
the list.
➢ Binary search algorithm
Compare k to the number at the middle of the list:
❖if they are equal, finish the searching process.
❖if k is smaller, perform the search in the first half of the list
❖if k is greater, perform the search in the last half of the list
Data Structures and Algorithms 6
Google search
Data Structures and Algorithms 7
Find the shortest path (Google
map)
Data Structures and Algorithms 8
Traveling salesman problem
(TSP)
A salesman needs to visit n customers at n different
locations. Find the shortest path for the salesman such
as he visits each location exactly once and finally
returns to the start location.
Data Structures and Algorithms 9
Quiz 1: The roles of data
structures and algorithms
Data Structures and Algorithms 10
Quiz 2: The roles of data structures
and algorithms
Data Structures and Algorithms 11
Data types
➢A data type is specified by:
❖The range of values or the values it can
hold.
❖Operations on values
Data Structures and Algorithms 12
type range operations
bool true / false and, or, not,
char [-127, 127] ‘<‘, ‘>’, ‘=’, ‘+’, ‘-’, ‘*’, ‘/’
int -32,767 -> 32,767 ‘<‘, ‘>’, ‘=’, ‘+’, ‘-’, ‘*’, ‘/’
float ~1E-37 -> ~1E+37 ‘<‘, ‘>’, ‘=’, ‘+’, ‘-’, ‘*’, ‘/’
double ~1.7E-308 -> ~1.7E+308 ‘<‘, ‘>’, ‘=’, ‘+’, ‘-’, ‘*’, ‘/’
Structured data types
➢ Question: What data type to present a point on the
plane?
➢ Solution: Programming languages provide rules to
define a new data type T from defined data types
Example in C++:
struct PersonType {
string name;
int age;
bool gender;
};
Data Structures and Algorithms 13
Structured data types
➢ How to present a point on the plane?
struct PointType {
double x;
double y;
};
➢ How to present a line on the plane?
struct LineType {
PointType start;
PointType end;
};
Data Structures and Algorithms 14
Structured data types
➢ Define a data structure to present student information
struct StudentType {
string name;
int age;
bool gender;
}
➢ Define a data structure to present our class information
struct ClassType{
string className;
int numberStudents;
StudentType students[100];
}
Data Structures and Algorithms 15
Range of structured data types
➢ The range of a structured data type T is determined by
the ranges of data types that are used to construct T.
Example:
struct ComplexType {
double real;
double image;
};
➢The range of ComplextType:
❖ real: The range of ‘double’ type
❖ image: The range of ‘double’ type
Data Structures and Algorithms 16
Operations on structured data types
Operations on a structured data type of a program are defined by the program.
Example:
struct ComplexType {
double real;
double image;
};
ComplexType add (const ComplexType &c1, const ComplextType &c2) {
ComplexType sum;
sum.real = c1.real + c2.real;
sumimage = c1.image + c2.image;
return sum;
}
ComplexType multiply (const ComplexType &c1, const ComplextType &c2) {
ComplexType product;
product.real = (c1.real * c2.real) – (c1.image * c2.image);
product.image = (c1.real * c2.image) + (c1.image * c2.real);
return product;
}
Data Structures and Algorithms 17
Abstract data types
➢ Abstract components of a structured data type
Example: ComplexType
❖ real //the real component of complex number
❖ image //the image component of complex number
➢ Abstract operations of a structured data type
Example: ComplexType
❖ add (c1, c2): Add two complex numbers c1 and c2
and return their sum.
❖ multiply (c1, c2): Multiply two complex numbers c1
and c2 and return their product.
Data Structures and Algorithms 18
Abstract data types
➢ Abstract Student data type
❖ Abstract data type components
» ID
» Name
» DOB
» Address
❖Abstract operations
» initializeStudent (ID, Name, DOB, Address)
» compareStudents (student1, student2)
» getID (student)
» getName (student)
» getDOB (student)
» getAddress (student)
Data Structures and Algorithms 19
Quiz 3
➢Abstract TEACHER data type
➢Abstract COMPUTER data type
➢Abstract RECTANGLE data type
Data Structures and Algorithms 20
Problem description
➢ Description:
❖What is the nature of problem?
❖What questions need to be solved?
❖What data and constrains are given?
❖What results are expected?
❖Examples
➢ Input: Describe the input and their specific
constrains
➢ Output: Describe the output and their
specific requirements
Data Structures and Algorithms 21
Birthday cake selection
➢ Problem: Today is Anna’s birthday and she is going to buy a birthday cake.
The cake shop has many birthday cakes with different sizes. As a kid, Anna
wants to pick the largest one. For example, if there are 4 birthday cakes
with sizes 1, 5, 3, and 7, Anna will pick the cake with size 7. Your task is to
write a program to find the largest birthday cake for Anna.
➢ Input: Data come from file BirthdayCakes.txt as following:
❖ The first line contains a single integer number n, denoting the
number of birthday cakes at the shop (0 < n < 10000).
❖ The second line contains n space-separated integer numbers each
describes the size of one cake.
➢ Output: Write to file BirthdayCakes.out an integer number which is the
size of the largest birthday cake.
Example:
BirthdayCakes.txt BirthdayCakes.out
4 7
1 5 3 7
Data Structures and Algorithms 22
Quiz 4
➢Describe the problem of finding the
product of two big integer numbers
➢Describe the problem of sorting
students according to their final
examinations
➢Describe the problem of finding the
shortest path between two locations
Data Structures and Algorithms 23

More Related Content

PPTX
EE-232-LEC-01 Data_structures.pptx
PPT
Intro.ppt
PPT
Intro.ppt
PPT
Intro_2.ppt
PPTX
DSA - Lesson 1-1Introductio to data struct.pptx
PPTX
DSA - Lesson 1 INtroduction to database.pptx
PDF
Data structure and Alogorithm analysis unit one
PDF
01VD062009003760042.pdf
EE-232-LEC-01 Data_structures.pptx
Intro.ppt
Intro.ppt
Intro_2.ppt
DSA - Lesson 1-1Introductio to data struct.pptx
DSA - Lesson 1 INtroduction to database.pptx
Data structure and Alogorithm analysis unit one
01VD062009003760042.pdf

Similar to Lec1_introductionLec1_introductionokkokokok (20)

PDF
Lesson 1 - Data Structures and Algorithms Overview.pdf
PPTX
1-Introduction to Data Structures beginner.pptx
PDF
Iare ds lecture_notes_2
PPTX
1. Introduction to Data Structure.pptx
PPTX
Chapter 1 _edited.pptx.software engineering
PPTX
Chapter 1 _edited.pptx.software engineering
PPTX
Data_structures_and_algorithm_Lec_1.pptx
PPTX
Data_structures_and_algorithm_Lec_1.pptx
PPTX
Data structures lectures no 1
PDF
Unit I Data structure and algorithms notes
PPTX
Data Structures and Algorithm - Module 1.pptx
PPT
PPTX
datastructuresandalgorithm-module1-230307012644-4c895c84.pptx
PPTX
data structures and its importance
PDF
PDF
Data Structure and its Fundamentals
PPTX
DS Module 1.pptx
PDF
MCA_Data Structure_Notes_of_UNIT_I & II.pdf
PPT
Introduction To Data Structures.ppt
PDF
Data structures
Lesson 1 - Data Structures and Algorithms Overview.pdf
1-Introduction to Data Structures beginner.pptx
Iare ds lecture_notes_2
1. Introduction to Data Structure.pptx
Chapter 1 _edited.pptx.software engineering
Chapter 1 _edited.pptx.software engineering
Data_structures_and_algorithm_Lec_1.pptx
Data_structures_and_algorithm_Lec_1.pptx
Data structures lectures no 1
Unit I Data structure and algorithms notes
Data Structures and Algorithm - Module 1.pptx
datastructuresandalgorithm-module1-230307012644-4c895c84.pptx
data structures and its importance
Data Structure and its Fundamentals
DS Module 1.pptx
MCA_Data Structure_Notes_of_UNIT_I & II.pdf
Introduction To Data Structures.ppt
Data structures
Ad

Recently uploaded (20)

PDF
plating appetizers and hors d'oeuvres...
PPTX
HEALTHY EATING HABITS A BRIEF PRESENTATION
PPTX
TLE 10 - LESSON 3 MARKET FORM OF EGGS BY GROUP 5 .pptx
PPT
Food Chain and Food Web in the world.ppt
PPTX
SEAFOOD IRRADIATION – TECHNOLOGY AND APPLICATION.pptx
DOC
IC毕业证学历认证,白金汉郡新大学毕业证留学生文凭
PDF
PROMO FUNCTIONAL BEVERAGES MARKET, USA, MAY-JUNE 2025
PDF
Understanding the Appeal and Cultural Influence of Burgers Around the World
PDF
Marinate Container for Effortless Meal Preparation
PDF
Microwaving Fish: The best way to cook a fish!
PPTX
BARTENDING-03-Cocktail-Recipesqq(1).pptx
PDF
Wendy’s Menu Canada – Complete Guide 2025
PPTX
FST-401 lecture # 10 food chemistry.pptx
PPTX
หลักสูตร Standard Barista for IPC barista
PPTX
students copy Fundamendals of Cookery final.pptx
PDF
Ecosure Passing Score with eAuditor Audits & Inspections
PDF
PREPARE SALAD & SALD DRESSING cookery 1.
PDF
08_Mango_Dis_PARTIALSTEMPARASITE.pdf -farmers
PPTX
pu te ripptx characteristics discription and
PPTX
1. CLEAN AND MAINTAIN KITCHEN PREMISES.pptx
plating appetizers and hors d'oeuvres...
HEALTHY EATING HABITS A BRIEF PRESENTATION
TLE 10 - LESSON 3 MARKET FORM OF EGGS BY GROUP 5 .pptx
Food Chain and Food Web in the world.ppt
SEAFOOD IRRADIATION – TECHNOLOGY AND APPLICATION.pptx
IC毕业证学历认证,白金汉郡新大学毕业证留学生文凭
PROMO FUNCTIONAL BEVERAGES MARKET, USA, MAY-JUNE 2025
Understanding the Appeal and Cultural Influence of Burgers Around the World
Marinate Container for Effortless Meal Preparation
Microwaving Fish: The best way to cook a fish!
BARTENDING-03-Cocktail-Recipesqq(1).pptx
Wendy’s Menu Canada – Complete Guide 2025
FST-401 lecture # 10 food chemistry.pptx
หลักสูตร Standard Barista for IPC barista
students copy Fundamendals of Cookery final.pptx
Ecosure Passing Score with eAuditor Audits & Inspections
PREPARE SALAD & SALD DRESSING cookery 1.
08_Mango_Dis_PARTIALSTEMPARASITE.pdf -farmers
pu te ripptx characteristics discription and
1. CLEAN AND MAINTAIN KITCHEN PREMISES.pptx
Ad

Lec1_introductionLec1_introductionokkokokok

  • 1. Lecture 1: Introduction to data structures and algorithms University of Technology and Engineering Vietnam National University Hanoi
  • 2. Outline ➢Data structures and algorithms ➢Industrial problems ➢Data types ➢Abstract data structures ➢Problem description Data Structures and Algorithms 2
  • 3. Computer programs ➢ What is a computer program? A computer program is a set of instructions that perform specific tasks when executed by computers. ➢ What is a good computer program? ❖Correctness ❖Efficiency ❖Simple/Understandable ❖Easy to change/maintain and upgrade “Program = Algorithms + Data structures” N. Wirth Data Structures and Algorithms 3
  • 4. Data structures? ➢ What is a data structure? A data structure is a particular way of storing and organizing data so that they can be used efficiently. ➢ What is a good data structure? ❖ Correctness (satisfy requirements) ❖ Memory efficiency ❖ Simple/understandable ❖ Implementable ➢ Standard data structures ❖ Array ❖ Set ❖ Map/Dictionary Data Structures and Algorithms 4
  • 5. Algorithms? ➢ What is an algorithm? An algorithm is a step by step procedure to solve a problem. An algorithm can be described by nature languages (English, Vietnamese...) or programming languages (C++, Java, Python…) Example: How to cook rice? ❖ Step 1: Get rice ❖ Step 2: Rinse the rice ❖ Step 3: Put the rice and water into a rice cooker ❖ Step 4: Turn on the rice cooker ❖ Step 5: Check the rice when the rice cooker turns off ➢ What is a good algorithm? ❖ Correctness ❖ Efficiency ❖ Simple/understandable ❖ Implementable Data Structures and Algorithms 5
  • 6. Example: Searching problem Problem: Given a list of numbers sorted increasingly, describe an algorithm to check if a number k is in the list. ➢ Naïve searching algorithm Moving from the begin to the end of the list to check if k is in the list. ➢ Binary search algorithm Compare k to the number at the middle of the list: ❖if they are equal, finish the searching process. ❖if k is smaller, perform the search in the first half of the list ❖if k is greater, perform the search in the last half of the list Data Structures and Algorithms 6
  • 7. Google search Data Structures and Algorithms 7
  • 8. Find the shortest path (Google map) Data Structures and Algorithms 8
  • 9. Traveling salesman problem (TSP) A salesman needs to visit n customers at n different locations. Find the shortest path for the salesman such as he visits each location exactly once and finally returns to the start location. Data Structures and Algorithms 9
  • 10. Quiz 1: The roles of data structures and algorithms Data Structures and Algorithms 10
  • 11. Quiz 2: The roles of data structures and algorithms Data Structures and Algorithms 11
  • 12. Data types ➢A data type is specified by: ❖The range of values or the values it can hold. ❖Operations on values Data Structures and Algorithms 12 type range operations bool true / false and, or, not, char [-127, 127] ‘<‘, ‘>’, ‘=’, ‘+’, ‘-’, ‘*’, ‘/’ int -32,767 -> 32,767 ‘<‘, ‘>’, ‘=’, ‘+’, ‘-’, ‘*’, ‘/’ float ~1E-37 -> ~1E+37 ‘<‘, ‘>’, ‘=’, ‘+’, ‘-’, ‘*’, ‘/’ double ~1.7E-308 -> ~1.7E+308 ‘<‘, ‘>’, ‘=’, ‘+’, ‘-’, ‘*’, ‘/’
  • 13. Structured data types ➢ Question: What data type to present a point on the plane? ➢ Solution: Programming languages provide rules to define a new data type T from defined data types Example in C++: struct PersonType { string name; int age; bool gender; }; Data Structures and Algorithms 13
  • 14. Structured data types ➢ How to present a point on the plane? struct PointType { double x; double y; }; ➢ How to present a line on the plane? struct LineType { PointType start; PointType end; }; Data Structures and Algorithms 14
  • 15. Structured data types ➢ Define a data structure to present student information struct StudentType { string name; int age; bool gender; } ➢ Define a data structure to present our class information struct ClassType{ string className; int numberStudents; StudentType students[100]; } Data Structures and Algorithms 15
  • 16. Range of structured data types ➢ The range of a structured data type T is determined by the ranges of data types that are used to construct T. Example: struct ComplexType { double real; double image; }; ➢The range of ComplextType: ❖ real: The range of ‘double’ type ❖ image: The range of ‘double’ type Data Structures and Algorithms 16
  • 17. Operations on structured data types Operations on a structured data type of a program are defined by the program. Example: struct ComplexType { double real; double image; }; ComplexType add (const ComplexType &c1, const ComplextType &c2) { ComplexType sum; sum.real = c1.real + c2.real; sumimage = c1.image + c2.image; return sum; } ComplexType multiply (const ComplexType &c1, const ComplextType &c2) { ComplexType product; product.real = (c1.real * c2.real) – (c1.image * c2.image); product.image = (c1.real * c2.image) + (c1.image * c2.real); return product; } Data Structures and Algorithms 17
  • 18. Abstract data types ➢ Abstract components of a structured data type Example: ComplexType ❖ real //the real component of complex number ❖ image //the image component of complex number ➢ Abstract operations of a structured data type Example: ComplexType ❖ add (c1, c2): Add two complex numbers c1 and c2 and return their sum. ❖ multiply (c1, c2): Multiply two complex numbers c1 and c2 and return their product. Data Structures and Algorithms 18
  • 19. Abstract data types ➢ Abstract Student data type ❖ Abstract data type components » ID » Name » DOB » Address ❖Abstract operations » initializeStudent (ID, Name, DOB, Address) » compareStudents (student1, student2) » getID (student) » getName (student) » getDOB (student) » getAddress (student) Data Structures and Algorithms 19
  • 20. Quiz 3 ➢Abstract TEACHER data type ➢Abstract COMPUTER data type ➢Abstract RECTANGLE data type Data Structures and Algorithms 20
  • 21. Problem description ➢ Description: ❖What is the nature of problem? ❖What questions need to be solved? ❖What data and constrains are given? ❖What results are expected? ❖Examples ➢ Input: Describe the input and their specific constrains ➢ Output: Describe the output and their specific requirements Data Structures and Algorithms 21
  • 22. Birthday cake selection ➢ Problem: Today is Anna’s birthday and she is going to buy a birthday cake. The cake shop has many birthday cakes with different sizes. As a kid, Anna wants to pick the largest one. For example, if there are 4 birthday cakes with sizes 1, 5, 3, and 7, Anna will pick the cake with size 7. Your task is to write a program to find the largest birthday cake for Anna. ➢ Input: Data come from file BirthdayCakes.txt as following: ❖ The first line contains a single integer number n, denoting the number of birthday cakes at the shop (0 < n < 10000). ❖ The second line contains n space-separated integer numbers each describes the size of one cake. ➢ Output: Write to file BirthdayCakes.out an integer number which is the size of the largest birthday cake. Example: BirthdayCakes.txt BirthdayCakes.out 4 7 1 5 3 7 Data Structures and Algorithms 22
  • 23. Quiz 4 ➢Describe the problem of finding the product of two big integer numbers ➢Describe the problem of sorting students according to their final examinations ➢Describe the problem of finding the shortest path between two locations Data Structures and Algorithms 23