Lec 1 - Basics (DS and Algo)
Lec 1 - Basics (DS and Algo)
CSC – 1204
Email: [email protected]
2
Grading Policy
3
Data Structure and Algorithms
Why to study ?
Data Structure and Algorithms
•Data Structure
How to organize data ? (processing or storing in computer)
e.g., Arrays
•Algorithm
A step-by-step procedure for solving a problem
e.g., how to travel from one point to other ?
Data Structure and Algorithms
Design Issue:
select and design appropriate data types
(This is the main motivation to learn and understand data
structures)
Why Study Data
Linked List
Queue Stack
Tree
• Searching
Finding the location of the data element (key) in the structure
• Insertion
Adding a new data element to the structure
• Deletion
Removing a data element from the structure
• Sorting
Arrange the data elements in a logical order (ascending/descending)
• Merging
Combining data elements from two or more data structures into one
Problem Solving
(Baqala, Home)
School
Masjid (Home , Masjid)
Baqala
(Masjid, Home)
(Home , Intersection)
(Baqala , Masjid)
(Masjid, School)
Hash Table
Or
Hash Map
Algorithm to Solve Problem
School
Masjid
Baqala Problem ?
Finding Shortest Path from (Home to School)
Home Intersection
problem
algorithm
Input range
for num←0; num<=range; num←num+1 do
if num % 2 = 0 then
print num is even
else
print num is odd
endif
endfor
What is a Good Algorithm?
It must be correct
It must be finite (in terms of time and size)
It must terminate
It must be unambiguous
Which step is next?
It must be space and time efficient
• Abstract Data Type (ADT) is the logical picture of the data and the
operations to manipulate the component elements of the data
• A definition for a data type solely in terms of a set of
values and a set of operations on that data type.
(Mathematical/logical views only).
• ADTs are entities that are definitions of data and
operations, but don’t have implementation details
• Each ADT operation is defined by its inputs and outputs.
•Basic definitions
Type: a set of objects.
ADT:
Data Items:
Type
Logical Form
Operations
38
Data Structure Philosophy
• programming effort.
Data Structure Philosophy
(cont.)
• Each problem has constraints on available space and
time.
• Only after a careful analysis of problem characteristics,
we can know the best data structure for the task.
• Bank example:
Queue(Sequential Access)
Hierarchical
Collections
49
Group
Collections
• Examples:
Sets.
Graphs.
Graph Collection
Networks.
Sets Collection
Network Collection
Some Questions to Ask