Lecture # 0 Data - Structures - and - Algorithm
Lecture # 0 Data - Structures - and - Algorithm
Store
Organize
Access
Manipulate
11/19/2024 07:36 AM
3
Another Example: Library
11/19/2024 07:36 AM
4
Introduction to Data
Structure
A data structure is a particular way of
storing and organizing data in a
computer so that it can be used
efficiently
11/19/2024 07:36 AM
Google Map
6
11/19/2024 07:36 AM
Excel Sheet
7
11/19/2024 07:36 AM
Family Tree
8
11/19/2024 07:36 AM
Basic DS Example: Arrays
11/19/2024 07:36 AM
Arrays (cont.)
10
11/19/2024 07:36 AM
Discussion : variable vs
11
Array
Your are suppose to store marks of 100
students.
Think of as many ways as possible.
11/19/2024 07:36 AM
Classification of Data Structure
13
A data structure is a particular way of
organizing data in computer memory so
that it can be used efficiently.
Non-Linear
11/19/2024 07:36 AM
Non-Primitive data structure
15
11/19/2024 07:36 AM
Comparison:
17
11/19/2024 07:36 AM
18 Introduction to Algorithms
A precise rule (or set of rules) specifying how
to solve some problem.
11/19/2024 07:36 AM
Algorithms
19
Step2:
…
11/19/2024 07:36 AM
Example # 1
22
Step 1 – START
Step 2 – declare three integers a, b & c
Step 3 – define values of a & b
Step 4 – add values of a & b
Step 5 – store output of Step 4 to c
Step 6 – print c
Step 7 – STOP
11/19/2024 07:36 AM
Example # 2
23
Good choice:
more efficient programs
Bad choice:
poor programs performance
11/19/2024 07:36 AM
Example:
25
Example:
Problem: Find the largest element ‘k’ out of ‘N’
integers
Proble
m
Algorithm
11/19/2024 07:36 AM
Role of Data Structure
27
Proble
m
program
11/19/2024 07:36 AM
Representation of an
28
Algorithms
An algorithm may be represented in
different forms:
A description using English/other languages
A real computer program, e.g. C++ or java
A pseudo-code, C-like program, program-
language-like program.
11/19/2024 07:36 AM
Algorithm Efficiency
29
11/19/2024 07:36 AM
How to measure the efficiency?
30
11/19/2024 07:36 AM
Best, Worst and Average
31
Cases
Not all inputs of a given size take the
same time.
Each algorithm has three cases:
Best case:
Worst Case:
Average Case:
11/19/2024 07:36 AM
Example: Best, Worst and Average Cases
32
11/19/2024 07:36 AM
Types of ADTs:
36
11/19/2024 07:36 AM
Terms in Data Structures
37
Interface
Each data structure has an interface. Interface
represents the set of operations that a data
structure supports. An interface only provides
the list of supported operations, type of
parameters they can accept and return type of
these operations.
Implementation
Implementation provides the internal
representation of a data structure. It also
provides the definition of algorithms used in
the operation of data structure.
11/19/2024 07:36 AM
Characteristics of Data Structure
38
Correctness
Data structure implementation should
implement its interface correctly.
Time Complexity
Running time or the execution time of
operations of data structure must be as
small as possible.
Space Complexity
Memory usage of a data structure
operation should be as little as possible.
11/19/2024 07:36 AM
Selecting a Data Structure
39
11/19/2024 07:36 AM
Fundamental Data
40
Structures
Basic Data
Structures
11/19/2024 07:36 AM
41
array
Linked list
queue
tree stack
11/19/2024 07:36 AM
Linear Data Structures
42
11/19/2024 07:36 AM
Non-Linear Data Structures
43
Front 20 30 10 60 57 Back
11/19/2024 07:36 AM
29
48
Non-Linear Data
Structures
Graphs
Trees
Hash Tables
11/19/2024 07:36 AM
Graphs
49
11/19/2024 07:36 AM
Undirected Graph Directed Graph
Trees
50
A Tree is a way of
representing the hierarchical
nature of a structure in a
graphical form.
Properties of trees
Root Node
Child Node Unordered Tree
Parent Node
Leaf Node
Types
Unordered Tree
Binary Tree is an ordered tree
data structure in which each node
has at most two children.
Binary07:36
11/19/2024 TreeAM
Examples:
51
11/19/2024 07:36 AM
Activity:
52
11/19/2024 07:36 AM
Summary
53