DATA STRUCTURES AND ALGORITHM
Mobile: +92-312-7070895
Instructor: Dr. M. Usman Ashraf
Email: usman.ashraf@gcwus.edu.pk
Web:
https://sites.google.com/site/musmanashrafpk/teaching
Books to Follow
2
Some General Comments
3
Introduction to Data Structure
4
A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently
Need for Data Structures
Organizing Data
What is Data Structure?
7
Fundamental Data Structures
8
Hash Tables
Basic Data Structures
Linear Data Structures
Non-Linear Data Structures
Linked Lists
Stacks
Queues
Trees
Graphs
Arrays
array
Linked list
tree
queue
stack
Linear Data Structures
10
Non-Linear Data Structures
11
Operations on Data Structures
12
Linear Data Structures
13
Arrays
14
a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9]
1 2 3 4 5 6 7 8 9 10
Array a with 10 integer elements
Linked List
15
Stacks
16
Queues
17
20 30 10 60 57 29
Front
Back
Non-Linear Data Structures
18
Graphs
19
Undirected Graph
Directed Graph
Trees
20
Unordered Tree
Binary Tree
Hash Tables
21
Summary
22
Selecting a Data Structure
Select a data structure as follows:
Data Structure Philosophy
Introduction to Algorithms
A precise rule (or set of rules) specifying how to solve some problem.
25
What is an Algorithm?
26
What is an Algorithm?
27
Why Study Algorithms?
28
Notion of Algorithm and Problem
29
“Computer”
Problem
Algorithm
Input
Output
Representation of an Algorithms
30
Basic Issues Related to Algorithms
31
Analysis of Algorithms
32
Algorithm Efficiency
33
Best, Worst and Average Cases
34
Example: Best, Worst and Average Cases
35
Algorithm Analysis
We analyse algorithms, rather than problems. A problem can be solved with several algorithms, some are more efficient than others.
36
Quiz-1 Time: 15 Minutes
Write a program in C++, where user get input array arr of length 10 and another input in a variable x.
Define a class named “SearchOpr” containing function named “searchVal”. searchVal takes two parameters including an integer array localArr and integer ‘val’. searchVal will return 0 if localArr contains val.
You are supposed to search input value x from arr by utilizing class SearchOpr.
37
Why need algorithm analysis?
How to Analyse an Algorithm?
39
Analysis of Algorithms
Analysis of Algorithms
Any Query?
42
Assignment-1 (Secured Zero marks who ‘ven’t submitted)
What are the ways to measure the Time and space complexity of particular scenarios?
Explain each scenario with example code and find its complexity (time and space).
Handwritten.
With cover page.
Deadline: Next class.
43