01.Introduction to Data, Data Structure, Algortihm, Time and Space Complexity
01.Introduction to Data, Data Structure, Algortihm, Time and Space Complexity
Data Structures
3
Who I am :)
4
Who I am :)
❏ Collaboration with:
5
Who You are :)
❖ Name?
❖ Background?
❖ Expectations?
❖ Familiarity with the topics?
● Algorithms
● Programing
6
Course organization
8
Course organization
You can tap into slides, material and further information on Canvas.
9
Syllabus
10
Assessment Summary
11
Anything else?
12
Introduction
13
Questions
15
https://www.pinayhomeschoolershop.com/products/history-of-computers-timeline-and-ordering-activities
Features of Computers?
18
Similarity of human and computers
19
Computer Components
20
https://www.facebook.com/pg/Hardware-Software-267286954079644/groups/?ref=page_internal
Computer Hardware
https://www.tutorialspoint.com/computer_concepts/computer_concepts_components_of_computer_system.htm
21
CPU(Central Processing Unit)
https://medium.com/@nateshganesh/no-the-brain-is-not-a-computer-1c566d99318c
22
Arithmetic Logic Unit (ALU)
23
Control Unit
The brain communicates with the rest of the body via the
nervous system.
24
Memory (RAM) and Short-Term Memory
https://study.com/learn/lesson/video/random-access-memory-ram-concept-types-uses.html
https://app.uxcel.com/courses/ux-design-psychology/how-human-
memory-works-226/short-term-memory-3031
25
Software
26
https://xtendedview.com/technology/physical-storage-vs-digital-document/2146/
Software
https://www.researchgate.net/figure/Schematic-description-of-the-IPO-concept-
Through-defined-inputs-a-process-is_fig1_363819397
27
Fitness APP
29
Data at the Hardware Level
31
Importance of Data
32
https://stratoflow.com/amazon-recommendation-system/
Example of Data
33
Structured Data vs Unstructured Data
34
Structured Data vs Unstructured Data
35
What is a Data Structure?
❏ Definition:
○ A data structure is a way to organize and store data so that it is
easy to access and manipulate.
❏ Why Data Structures are Important
○ Just like bookshelves and categories help organize a library, data
structures help organize digital data in a meaningful way.
○ In Industry, efficient data structures speed up processes, save
storage, and improve performance in apps and software.
36
Types of Data Structure: simple
37
Types of Data Structure: complex
38
Types of Data Structure: complex
39
Types of Data Structure: complex
Binary image
Grayscale image
40
Exercise
41
Types of Data Structure: complex
42
Types of Data Structure
43
https://simplerize.com/data-structures/data-structure-introduction
Exercise
44
Common operations on Data Structure
adding an element
Traversing all elements
Looking for an element
removing an element
45
https://findtodaysnotes.wordpress.com/operations-of-data-structures/
What is Algorithm?
46
What is Algorithm?
● Definition:
❏ An algorithm is a sequence of instructions to complete a task.
47
Why Data Structures Need Algorithms
48
Why Data Structures Need Algorithms
50
Real-World Example – Building a Ride-Sharing App
51
Ways of algorithms expression
Flowchart
Pseudo Code
52
Flowchart
54
Example
Consider the example to add three numbers and print the sum
55
Example
56
Example
57
PSEUDO CODE
58
WHY USE PSEUDO CODE AT ALL?
60
The Main Constructs of Pseudocode
https://builtin.com/data-science/pseudocode 63
The Main Constructs of Pseudocode
https://builtin.com/data-science/pseudocode
● Exception handling is the process of responding to unwanted or unexpected events when a computer
program runs. Exception handling deals with these events to avoid the program or system crashing,
and without this process, exceptions would disrupt the normal operation of a program.
● Exceptions occur for numerous reasons, including invalid user input, code errors, device failure, the 64
loss of a network connection, insufficient memory to run an application, and so on.
Difference between CASE and IF
IF Statement:
● Primarily used when you need to evaluate a series of conditions that
may not be based on a single expression.
CASE Statement:
● Used when there is a single variable or expression with multiple
specific, distinct values.
65
PSEUDO CODE: IF-THE-ELSE
66
PSEUDO CODE: WHILE
67
PSEUDO CODE: CASE
Conditional branching
68
PSEUDO CODE: For
69
Example
Consider the example to add three numbers and print the sum
Step 1 : Start
Step 2 : Read A,B
Step 3 : Sum = A + B
Step 4 : Print Sum
Step 5: Stop
70
Example
71
Example
72
Example
73
Example
74
Time and Space Complexity
76
Problem: Calculate the Average Grade of Students
77
Problem: Calculate the Average Grade of Students
78
Problem: Calculate the Average Grade of Students
79
What is Time Complexity?
80
Best, Worst, and Average case
82
Notations
83
Notations
84
Notations
85
Notations
86
Notations
87
Notations
88
big O notation
89
big O notation
90
Exercise
Answer: O(n^2)
Explanation: The outer loop runs n times, and for each iteration of the
outer loop, the inner loop also runs n times. This results in n * n
= n^2 total operations.
92
Exercise
Answer: O(n^2)
Explanation: The inner loop's number of iterations decreases as i
increases, but overall, it still sums to approximately n * (n - 1)
/ 2, which simplifies to O(n^2).
93
Exercise
For i in range(n):
if i%2 == 0
print(i)
i = i /2
Answer: O(n)
Explanation: Although only half the values of i satisfy the condition i % 2 ==
0, the if check itself takes constant time. So, the overall complexity remains
O(n).
n+n/2 or 2n, it simplifies to O(n)
94
Exercise
What is the time complexity of this code? (If-Else Blocks with Loops)
Answer: O(n^2)
95
Exercise
What is the time complexity of this code? (If-Else Blocks with Loops)
Answer: O(n^2)
96
Exercise
What is the time complexity of this code? (If-Else Blocks with Loops)
Answer: O(n^2)
97
Exercise
What is the time complexity of this code? (If-Else Blocks with Loops)
Answer: O(n^2)
98
Exercise
99
What is Space Complexity?
100
Exercise
Answer: O(1)
Explanation: The function only
creates a single integer variable x,
which requires constant space. The
space complexity is independent of n.
101
Exercise
Answer: O(n)
Explanation: The function creates an
array of size n, requiring space
proportional to n.
102
Exercise
Answer: O(n)
103
Answers
104
Answers
105
Answers
106
Answers
107
Answers
108
Answers
❖ What is Algorithm?
✔ An algorithm is a sequence of instructions to complete a task.
109
Answers
110
References
111
THANKS!
112
113