SlideShare uma empresa Scribd logo
1 de 31
1
Confidential
2
Confidential
Computational complexity of the algorithm:
When time fades away
Oleksandr Basalkevych
Senior Software Developer
3
Confidential
Agenda
1. Why can't we use the common concept of time?
2. The asymptotic complexity of algorithm.
3. A story about monkey, who can sort an array.
4. Comparison of elementary algorithms, determination of complexity.
5. Q&A.
6. Quiz
4
Confidential
Gifts
5
Confidential
Algorithm evaluation criteria
• Execution time
• Used memory
6
Confidential
6
Why can't we use the common
concept of time?
7
Confidential
Execution time
We cannot use usual concept of “time” (like milliseconds, seconds) because
different CPUs have different clock frequency.
CPU1
2 x 10 op/s
7
CPU2
5 x 10 op/s
8
To complete, algorithm A needs to execute 10 elementary operations
8
THEN
T = 5s
CPU1
T = 0.2s
CPU2
But we are talking about the same algorithm…
8
Confidential
8
The asymptotic complexity of
algorithm
9
Confidential
Computational Complexity of an algorithm is the
amount of resources required for running it.
• O-notation (big O notation)
𝑂 𝑔 𝑛 = { 𝑓 𝑛 : 𝑡ℎ𝑒𝑟𝑒 𝑒𝑥𝑖𝑠𝑡
𝑝𝑜𝑠𝑖𝑡𝑖𝑣𝑒 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡𝑠 𝒄 𝑎𝑛𝑑 𝒏𝟎
𝑠𝑢𝑐ℎ 𝑡ℎ𝑎𝑡
0 ≤ 𝑓 𝑛 ≤ 𝒄𝑔 𝑛 𝑓𝑜𝑟 𝑎𝑙𝑙 𝑛 ≥ 𝒏𝟎 }
10
Confidential
Computational Complexity
11
Confidential
Computational Complexity
12
Confidential
Computational Complexity
Let’s assume that the CPU performs approximately 10 elementary operations per
second.
6
13
Confidential
13
A story about monkey, who can sort
an array.
14
Confidential
Monkey with cards
Even monkey can sort an array… with O(N!) complexity.
15
Confidential
15
Comparison of elementary algorithms,
determination of complexity.
16
Confidential
O-notation expression simplification
• Ignore constants
• Greater power has much greater contribution
So,
𝑂 2𝑁 + 10 = 𝑂(𝑁)
𝑂(
𝑁
2
) = 𝑂(𝑁)
𝑂 𝑁2
+ 𝑁 = 𝑂(𝑁2
)
𝑂
𝑁3
2
+ 5𝑁2 +
𝑁
3
+ 1 = ?
𝑂(𝑁3)
17
Confidential
Let’s practice: Reverse array
A: 3 18 1 21 48 26 reverse A: 26 48 21 1 18 3
N = length(A)
for i : [0 … N/2 - 1]
left = i
right = N – i - 1
temp = A[left]
A[left] = A[right]
A[right] = temp
2
N/2 times:
1
3
2
3
2
𝑂 2 +
𝑁
2
1 + 3 + 2 + 3 + 2 = 𝑂
11
2
𝑁 + 2 = 𝑶(𝑵)
18
Confidential
Let’s practice: Element search
A: 3 18 1 21 48 26
res = -1
N = length(A)
for i : [0 … N-1]
if A[i] is equal to <Element>
res = i
break
1
2
N times in the worst case:
2
1
𝑂 1 + 2 + 2𝑁 + 1 = 𝑂 2𝑁 + 4 = 𝑶(𝑵)
19
Confidential
Binary search
A: 4 5 10 15 20 25
• The array must be sorted
30 35 40 45 50 58 65 80 98
• Lets find 20 using binary search algorithm
20
Confidential
Binary search: Searching for 20
A: 4 5 10 15 20 25 30 35 40 45 50 58 65 80 98
left(0) middle(7) right(14)
A: 4 5 10 15 20 25 30 35 40 45 50 58 65 80 98
left(0) middle(3) right(7)
A: 4 5 10 15 20 25 30 35 40 45 50 58 65 80 98
left(3) middle(5) right(7)
A: 4 5 10 15 20 25 30 35 40 45 50 58 65 80 98
left middle right
21
Confidential
Binary search: Searching for 38
A: 4 5 10 15 20 25 30 35 40 45 50 58 65 80 98
left(0) middle(7) right(14)
A: 4 5 10 15 20 25 30 35 40 45 50 58 65 80 98
left(7) middle(10) right(14)
A: 4 5 10 15 20 25 30 35 40 45 50 58 65 80 98
left(7) middle right(10)
A: 4 5 10 15 20 25 30 35 40 45 50 58 65 80 98
left(7) right(8) Not found: right – left = 1
22
Confidential
Binary search: Complexity
• Informal explanation. Each time we reduce the array search area by 2
times and perform some O(1) operations. E.g. having array of 16 elements,
we reduce the problem to 8, 4, 2, 1 elements step by step. Assume the
length of array is N. How many steps are we going to have?
𝑂(log2 𝑁)
• For formal proof refer to Cormen T., Leiserson C., Rivest R., Stein C.
“Introduction to Algorithms”
23
Confidential
23
It’s Quiz Time!
24
Confidential
It’s Quiz Time!
Join at: www.kahoot.it
Game PIN: XXXXXXX
25
Confidential
Example 1
𝑂(𝑁)
N = array.length
26
Confidential
Example 2
𝑂(𝑁2
)
N = array.length
27
Confidential
Example 3
𝑂(𝑁2
)
N = array.length
• • • • •
• • • •
• • •
• •
•
28
Confidential
Example 4
𝑂(𝑁𝑀)
N = arrayA.length
M = arrayB.length
29
Confidential
Example 5
𝑂(𝑁𝑀)
N = arrayA.length
M = arrayB.length
30
Confidential
Example 6
𝑂(𝑁2
+ 𝑀)
N = arrayA.length
M = arrayB.length
31
Thank You

Mais conteúdo relacionado

Mais de GlobalLogic Ukraine

GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Ukraine
 

Mais de GlobalLogic Ukraine (20)

GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
 
Страх і сила помилок - IT Inside від GlobalLogic Education
Страх і сила помилок - IT Inside від GlobalLogic EducationСтрах і сила помилок - IT Inside від GlobalLogic Education
Страх і сила помилок - IT Inside від GlobalLogic Education
 
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
 
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic QA Webinar “What does it take to become a Test Engineer”GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
 
“How to Secure Your Applications With a Keycloak?
“How to Secure Your Applications With a Keycloak?“How to Secure Your Applications With a Keycloak?
“How to Secure Your Applications With a Keycloak?
 
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
 
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
 
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
 
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
 
GlobalLogic Webinar "Introduction to Embedded QA"
GlobalLogic Webinar "Introduction to Embedded QA"GlobalLogic Webinar "Introduction to Embedded QA"
GlobalLogic Webinar "Introduction to Embedded QA"
 
C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"
 
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
 
GlobalLogic Azure TechTalk ONLINE “Marketing Data Lake in Azure”
GlobalLogic Azure TechTalk ONLINE “Marketing Data Lake in Azure”GlobalLogic Azure TechTalk ONLINE “Marketing Data Lake in Azure”
GlobalLogic Azure TechTalk ONLINE “Marketing Data Lake in Azure”
 
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
 
Java Webinar #13 “Where Is My Development Zone?”
Java Webinar #13 “Where Is My Development Zone?”Java Webinar #13 “Where Is My Development Zone?”
Java Webinar #13 “Where Is My Development Zone?”
 
NET Webinar #1 "Is There a Life Outside the Entity Framework"
NET Webinar #1 "Is There a Life Outside the Entity Framework"NET Webinar #1 "Is There a Life Outside the Entity Framework"
NET Webinar #1 "Is There a Life Outside the Entity Framework"
 
GlobalLogic С/C++/Embedded Live Coding Challenge. Basic graph algorithms
GlobalLogic С/C++/Embedded Live Coding Challenge. Basic graph algorithmsGlobalLogic С/C++/Embedded Live Coding Challenge. Basic graph algorithms
GlobalLogic С/C++/Embedded Live Coding Challenge. Basic graph algorithms
 
Online TechTalk “Flutter Mobile Development”
Online TechTalk “Flutter Mobile Development”Online TechTalk “Flutter Mobile Development”
Online TechTalk “Flutter Mobile Development”
 
Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"
 

Último

Último (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Computational Complexity of the Algorithm: When Time Fades Away