0% found this document useful (0 votes)
30 views

Lecture 1 Introduction s2024

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Lecture 1 Introduction s2024

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Data structures and algorithms

Spring 2024
Lecture 1: Introduction to Data Structures and Algorithms
Lecturer: Do Thuy Duong
Outline
Basic course information
Introduction to Data structures and algorithms

2
Basic course information
Faculty: Information Technology
Unit code: 61FIT2DSA
Unit name: Data Structure and Algorithm
Level: Undergraduate
Units of credit: 5
Prerequisite: PR1
Suggested study: 5 hours per week
Year: Spring 2024

3
Basic course information
Lecturer: Ms. Do Thuy Duong
Email: [email protected]
Tutor: Ms. Do Thuy Duong & Mr. Giap Minh Hieu
Course homepage
https://lms.fit.hanu.vn/course/view.php?id=182
Check frequently for homework, assignments and announcements

4
Basic course information
Textbook:
Mark Allen Weiss, “Data Structures and algorithm analysis in Java”, 3 rd
edition, Pearson, 2012
Reference:
Thomas H. Cormen, “Introduction to Algorithms”, 3rd edition, The MIT Press,
2009

5
Assessments
Attendance: (attend at least 80% of classes)
Discussion: 10%
Answer questions in lecture & tutorial section
Midterm Exam: 30%
Final Exam: 60%

6
Basic course information
Lecture class focuses on theory
Tutorial class focuses on programming
Homework: solved by yourself to develop necessary skills
Programming language: Java. (Python for reference)

7
Course info: Resources
Check the website frequently for resources
Java IDE:
BlueJ
Netbeans
Eclipse (used in this course)

8
Introduction to DSA
a Computer Program = Data Structures + Algorithms
What is Data Structure?
What is Algorithm?

9
What is Data structures?
Definition: A data structure is a particular way of organizing data in a
computer so that we can perform operations on these data in an effective
way.
E.g: we can store a list of items having the same data type using the array
data structure.
int numbers[4] = {10, 20, 30, 40};

10
Types of data structures
Primitive (Built-in) data
structures:
predefined way of storing data
by the system. char, int, float,
double, …
And the set of operations that
can be performed on these data
are also predefined: addition,
subtraction, division,
multiplication, ...

11
Types of data structures
Non-primitive Data Structures
(User Defined Data Structures):
more complicated data
structures
derived from primitive data
structures.
used to store large and
connected data: Array, Linked
List, Tree, Graph, Stack, Queue,

12
What is an algorithm?
Algorithm is a step-by-step procedure for solving a
problem in a finite amount of time. An algorithm manipulates data.
Algorithm is not the complete code or program, it is just the core logic of a
problem.

13
What is an algorithm?
 An algorithm possesses the following properties:
• It must be correct.
• It must be composed of precisely defined steps.
• The order of the steps must be precisely defined.
• It must be composed of a finite number of steps.
• It must terminate for all inputs.
 A computer program is an instance or concrete representation, for an
algorithm in some programming language.

14
What is algorithm?
• Weiss’ Definition [Text book p.29]:
A clearly specified set of simple instructions to be followed to solve a problem

• Shampoo Algorithm
Step 1: Wet hair
Step 2: Lather
Step 3: Rinse
Step 4: Repeat
• Is this correct algorithm?

Which step will be repeated?

15
What is an algorithm?
• Shampoo Algorithm (Revision #1)
Step 1: Wet hair
Step 2: Lather
Step 3: Rinse
Step 4: Repeat Steps 1-4

How many times do we repeat step 1? Infinitely? Or at most 2


times?

16
What is an algorithm?
• Keep a count of the number of times to repeat the steps
• Repeat the algorithm at most 2 times

• Shampoo Algorithm (Revision #2)


Step 1: Set count = 0
Step 2: Wet hair
Step 3: Lather
Step 4: Rinse
Step 5: Increment count (increase its value by 1)
Step 6: If count < 2 repeat steps 2-6
Step 7: EXIT
• Will execute steps 2-6 two times

17
Why need DSA?
Requirements for a good software
 Clean Design
 Easy maintenance
 Reliable (no core dumps)
 Easy to use
 Fast

 Efficient data structures


 Efficient algorithms

18
Why need DSA?
DSA in our daily life:
 Facebook. Your friends on Facebook, friends of friends, mutual friends they
all can be represented easily by Graph.
 If you need to keep a deck of cards and arrange it properly, You will throw it
randomly or you will arrange the cards one over another and from a proper
deck. You can use Stack here to make a proper arrangement of cards one over
another.
 If you need to search a word in the dictionary? Do you go page by page or you
open some page and if the word is not found you open a page prior/later to one
opened depending upon the order of word to the current page (Binary
Search).

19
Why need DSA?
A Good programmer needs the right tools (algorithm and data structure) to
make the software run properly and efficiently (The main idea is to reduce
the space and time complexities of different tasks.).
If you know the characteristics of one data structure in contrast to another
you will be able to make the right decision in choosing the right data
structure to solve a problem.

20
Course contents
• Fundamentals of complexity analysis:
The running time of a program
Worst-case and expected time complexity.
• Data Structures:
ADT
List, Stack, Queue, Trees, heap.
Graph.
 Algorithms:
• Searching
• Sorting
• And some graph algorithms: DFS, BFS, Prim’s, Dijkstra’s.
• Divide and conquer, Dynamic programming technique.
21
Algorithm example
Maximum subsequence sum problem
• Maximum subsequence sum problem:
The problem is presented in textbook p.33
Given (possibly negative) integers A1, A2, A3, … AN.
The subsequence sum is:

(For convenience, the maximum subsequence sum is 0 if all the integers are
negative.)
Find the maximum value of Sij?
• Example:
A={-2, 11, -4, 13, -5, -2}
Sij can be: {-2+11}, {-2+11-4}, {-4+13-5} …
22
Maximum value of Sij is: {11 – 4 + 13}=20
Algorithm example
Maximum subsequence sum problem
There are 4
solutions in
textbook
(p.39)
1st
solution:

23
Algorithm example
Maximum subsequence sum problem
2nd solution: Improved brute force search

24
Algorithm example
Maximum subsequence
sum problem
3rd solution: Applied
divide and conquer
strategy

25
Algorithm example
Maximum subsequence
sum problem

3rd solution:

26
Algorithm example
Maximum subsequence sum problem
4th solution: Linear –
time version
Idea: The sub-array
with negative sum is
discarded (by
assigning thisSum =
0)

27
int maxSum = 0  int maxSum = INT_MIN

28
Tutorial and next topic
Prepare for the tutorial:
Download and install Eclipse
Practice Examples and Exercises in Week 1_Tutorial_Instruction
Read textbook section 2.4.3 (solution for the Maximum subsequence sum
problem)
Prepare for the next topic:
Read textbook chapter 2

29

You might also like