SlideShare a Scribd company logo
My 2 Cents of Preparing Coding Interview
Introduction 
ž In most experience of Coding Interview, 
we have noticed more and more 
interview questions are focusing on 
algorithms. 
ž To tell whether algorithms are better or 
worse, there is complexity BigO to 
measure the performance in theory. 
ž Today, I would like to introduce 
Algorithm Hierarchy to organize thinking 
way.
Not only Algorithm 
ž Remember: Not only is Algorithm one 
key part of coding interview, but also 
working attitude, communication skills, 
big picture thinking and so on are more 
considered etc.
Algorithm Hierarchy in thought 
ž 1. Basic Algorithm 
ž 2. Space–time tradeoff 
ž 3. Pruning Algorithm 
ž 4. Optimized Algorithm 
ž 5. Big data Algorithm 
ž Remember: As hierarchy is like pyramid, 
you would better working more on 
foundation then looking forward.
1. Basic Algorithm 
ž (completed and easy reading –cy) 
ž Recursion, Backtracking, Blind 
searching and sorting like DFS, BFS, 
merge sort and qsort etc.
2. Space–time tradeoff 
ž (completed and fast by additional space 
–cy) 
ž Iteration, Dynamic Programming, Hash, 
Priority queue etc.
3. Pruning Algorithm 
ž (completed and fast via shortcuts –cy) 
ž Binary search in rotated array, K largest, 
Single Linked List cycle detect, Matrix 
multiplication etc.
4. Optimized Algorithm 
ž (faster and almost completed –cy) 
ž Estimated value, Hill climbing, Greedy 
Heuristic search like A*, D* etc.
5. Big data Algorithm 
ž (fastest and almost completed –cy) 
ž Divide and Conquer (Cloud, Cluster) 
and Machine learning, (Genetic, Ant 
Colony), Artificial intelligence (Alpha- 
Beta, MCTS) etc.
Example of Algorithm Hierarchy 
ž Let me explain hierarchy by calculating 
Fibonacci sequence. 
ž 0, 1, 1, 2, 3, 5, 8, … 
ž Now we need to calculate nTh number 
in Fibonacci sequence.
Fibonacci sequence (1) 
ž 1. Basic Algorithm : Complexity O(n!) 
ž long long f1(int n) { 
ž return n < 2 ? n : (f1(n-1) + f1(n-2)); 
ž }
Fibonacci sequence (2) 
ž 2. Space–time tradeoff : Complexity O(n) 
ž long long f2(int n){ 
ž long long f[2] = {0, 1}; 
ž while (--n>=1) { 
ž f[0]=f[0]+f[1]; 
ž swap(f[0], f[1]); 
ž } 
ž return f[n+1]; 
ž }
Fibonacci sequence (3) 
ž 3. Probing Algorithm : Complexity O(log 
n) 
ž long long f3(int n){ 
ž return (n < 2)? n : 
MatrixPower(n-1).m_00; //power of 
matrix { {1,1}, {1, 0} } 
ž }
Fibonacci sequence (4) 
ž 4. Optimized Algorithm : Complexity 
O(1) 
ž const double sqrt5 =sqrt(5.0); 
ž long long f4 (int n){ 
ž return 0.5 + (pow((1+sqrt5)/2, n)) / 
sqrt5; 
ž }
Fibonacci sequence (5) 
ž 5. Big data Algorithm 
ž long long f5 (int n){ 
ž return f[n]; 
ž }
Fibonacci sequence (Output) 
ž f1(90) = timeout 
ž f2(90) = 2880067194370816120 
ž f3(90) = 2880067194370816120 
ž f4(90) = 2880067194370824704 
ž f5(90) = 2880067194370816120 
ž You may see f4(90) is slightly different 
because of double-precision, but it 
works for n<=70
No Recursion 
Remember: Don’t use Recursion for large 
scale problem, using Iteration instead at 
least, especially for graph problems like 
tree verify, sum and traversal etc.
Algorithm Hierarchy in Interview 
ž For Algorithm Hierarchy in Coding 
Interview, in my humble opinion, most 
Phone interview is on level 1, and most 
on-site interview is on level 2-3, 
however, you may asking about level 
4-5 algorithm.
Real Sample: Amazon’s most 
asked interview questions 
ž (source: geeksquiz.com) 
ž 1) K largest elements from a big file or array. 
ž 2) Find a triplet a, b, c such that a2 = b2 + c2. Variations of this problem like find 
a triplet with sum equal to 0. Find a pair with given sum. All such questions are 
efficiently solved using hashing. 
ž 3) Binary tree traversal questions like left view, right view, top view, bottom view, 
maximum of a level, minimum of a level, children sum property, diameter etc. 
ž 4) Convert a BST into a DLL and DLL to BST in place. 
ž 5) Vertical traversal of a Binary Tree. 
ž 6) Lowest Common ancestor in a Binary Search Tree and Binary Tree. 
ž 7) Implement a stack with push(), pop() and min() in O(1) time. 
ž 8) Reverse a linked list in groups of size k. 
ž 9) Given two numbers represented by two linked lists, write a function that 
returns sum list. 
ž 10) Rotate a matrix by 90 degree. 
ž 11) Some stack based questions like stock span problem, next greater element. 
ž 12) Some Dynamic Programming problems like maximum sum subarray, 
maximum sum subarray such that no elements are consecutive, edit distance, 
assembly line scheduling. 
ž You may easily find out there are 4 questions in each level 1-3, well balanced.
KISS in phone interview 
Think aloud face to face 
ž Remember: Don’t think too complex in 
phone interview, just clarify your idea 
and keep it stupid simple(KISS). 
ž For on-site interview, you would better to 
well prepare and think aloud.
oj.leetcode.com for preparing 
ž Last but not least, let me recommend 
oj.leetcode.com for preparing Coding 
Interview. 
ž After solving more than 140 problems in 
oj.leetcode.com in several days, I could 
summary out its Hierarchy: 49% level 1, 
28% level 2, 23% level 3. 
ž LeetCode is focusing on data structures 
and algorithms. It requires not only just 
workable, but also optimized code. So you 
need to program in strict time and space 
complexity.
Bottom line to pass interview 
ž Remember: In order to pass coding 
interview, you may need to solve 2-5 
problems per hour in oj.leetcode.com.
Thanks 
ž Thanks for watching. It is just my 
humble opinion, my 2 cents. 
ž Should you have any questions, please 
feel free to contact me. 
ž All rights reserved. Please contact 
changyu.yang for permission to copy, 
distribute or reprint.
Ad

More Related Content

What's hot (19)

Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
rajkumar1631010038
 
Algorithm defination, design & Implementation
Algorithm defination, design & ImplementationAlgorithm defination, design & Implementation
Algorithm defination, design & Implementation
Bilal Maqbool ツ
 
Algorithms and flowcharts ppt (seminar presentation)..
 Algorithms and flowcharts  ppt (seminar presentation).. Algorithms and flowcharts  ppt (seminar presentation)..
Algorithms and flowcharts ppt (seminar presentation)..
Nagendra N
 
2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem
Frankie Jones
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm design
Nahid Hasan
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computing
jayavignesh86
 
phases of algorithm
phases of algorithmphases of algorithm
phases of algorithm
sti meycauayan
 
flowchart & algorithms
flowchart & algorithmsflowchart & algorithms
flowchart & algorithms
Student
 
Algorithm and Programming (Introduction of Algorithms)
Algorithm and Programming (Introduction of Algorithms)Algorithm and Programming (Introduction of Algorithms)
Algorithm and Programming (Introduction of Algorithms)
Adam Mukharil Bachtiar
 
Programing Fundamental
Programing FundamentalPrograming Fundamental
Programing Fundamental
Qazi Shahzad Ali
 
Algorithm & flow chart
Algorithm & flow chartAlgorithm & flow chart
Algorithm & flow chart
baabtra.com - No. 1 supplier of quality freshers
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithm
DHANIK VIKRANT
 
Flowcharts and algorithms
Flowcharts and algorithmsFlowcharts and algorithms
Flowcharts and algorithms
Student
 
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision table
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision tableProgramming aids- Algorithm, Flowchart, Pseudocodes and Decision table
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision table
Anjali Technosoft
 
Introduction to Algorithms & flow charts
Introduction to Algorithms & flow chartsIntroduction to Algorithms & flow charts
Introduction to Algorithms & flow charts
Yash Gupta
 
Algorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo codeAlgorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo code
hamza javed
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
FellowBuddy.com
 
Algorithm and pseudocode conventions
Algorithm and pseudocode conventionsAlgorithm and pseudocode conventions
Algorithm and pseudocode conventions
saranyatdr
 
Writing algorithms
Writing algorithmsWriting algorithms
Writing algorithms
Krishna Chaytaniah
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
rajkumar1631010038
 
Algorithm defination, design & Implementation
Algorithm defination, design & ImplementationAlgorithm defination, design & Implementation
Algorithm defination, design & Implementation
Bilal Maqbool ツ
 
Algorithms and flowcharts ppt (seminar presentation)..
 Algorithms and flowcharts  ppt (seminar presentation).. Algorithms and flowcharts  ppt (seminar presentation)..
Algorithms and flowcharts ppt (seminar presentation)..
Nagendra N
 
2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem
Frankie Jones
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm design
Nahid Hasan
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computing
jayavignesh86
 
flowchart & algorithms
flowchart & algorithmsflowchart & algorithms
flowchart & algorithms
Student
 
Algorithm and Programming (Introduction of Algorithms)
Algorithm and Programming (Introduction of Algorithms)Algorithm and Programming (Introduction of Algorithms)
Algorithm and Programming (Introduction of Algorithms)
Adam Mukharil Bachtiar
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithm
DHANIK VIKRANT
 
Flowcharts and algorithms
Flowcharts and algorithmsFlowcharts and algorithms
Flowcharts and algorithms
Student
 
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision table
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision tableProgramming aids- Algorithm, Flowchart, Pseudocodes and Decision table
Programming aids- Algorithm, Flowchart, Pseudocodes and Decision table
Anjali Technosoft
 
Introduction to Algorithms & flow charts
Introduction to Algorithms & flow chartsIntroduction to Algorithms & flow charts
Introduction to Algorithms & flow charts
Yash Gupta
 
Algorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo codeAlgorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo code
hamza javed
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
FellowBuddy.com
 
Algorithm and pseudocode conventions
Algorithm and pseudocode conventionsAlgorithm and pseudocode conventions
Algorithm and pseudocode conventions
saranyatdr
 

Viewers also liked (7)

Develop and Deploy Scalable Apps with Google App Engine
Develop and Deploy Scalable Apps with Google App EngineDevelop and Deploy Scalable Apps with Google App Engine
Develop and Deploy Scalable Apps with Google App Engine
David Chandler
 
Introdução ao OpenLayers
Introdução ao OpenLayersIntrodução ao OpenLayers
Introdução ao OpenLayers
Fernando Quadro
 
Mapping, GIS and geolocating data in Java
Mapping, GIS and geolocating data in JavaMapping, GIS and geolocating data in Java
Mapping, GIS and geolocating data in Java
Joachim Van der Auwera
 
FOSS4G2011 Report
FOSS4G2011 ReportFOSS4G2011 Report
FOSS4G2011 Report
Meg Murakami
 
Geospatial for Java
Geospatial for JavaGeospatial for Java
Geospatial for Java
Jody Garnett
 
Symbian Os
Symbian OsSymbian Os
Symbian Os
Saatviga Sudhahar
 
Integrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsIntegrating PostGIS in Web Applications
Integrating PostGIS in Web Applications
Command Prompt., Inc
 
Develop and Deploy Scalable Apps with Google App Engine
Develop and Deploy Scalable Apps with Google App EngineDevelop and Deploy Scalable Apps with Google App Engine
Develop and Deploy Scalable Apps with Google App Engine
David Chandler
 
Introdução ao OpenLayers
Introdução ao OpenLayersIntrodução ao OpenLayers
Introdução ao OpenLayers
Fernando Quadro
 
Mapping, GIS and geolocating data in Java
Mapping, GIS and geolocating data in JavaMapping, GIS and geolocating data in Java
Mapping, GIS and geolocating data in Java
Joachim Van der Auwera
 
Geospatial for Java
Geospatial for JavaGeospatial for Java
Geospatial for Java
Jody Garnett
 
Integrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsIntegrating PostGIS in Web Applications
Integrating PostGIS in Web Applications
Command Prompt., Inc
 
Ad

Similar to Algorithm hierarchy (20)

Daa
DaaDaa
Daa
Dhananjay Singh
 
Analysis of Algorithms
Analysis of AlgorithmsAnalysis of Algorithms
Analysis of Algorithms
Amna Saeed
 
Zoho Interview Questions By Scholarhat.pdf
Zoho Interview Questions By Scholarhat.pdfZoho Interview Questions By Scholarhat.pdf
Zoho Interview Questions By Scholarhat.pdf
Scholarhat
 
Data Structures and Algorithms (DSA) in C
Data Structures and Algorithms (DSA) in CData Structures and Algorithms (DSA) in C
Data Structures and Algorithms (DSA) in C
Nabajyoti Banik
 
Tiling matrix-matrix multiply, code tuning
Tiling matrix-matrix multiply, code tuningTiling matrix-matrix multiply, code tuning
Tiling matrix-matrix multiply, code tuning
mukhi265
 
Introduction to cp
Introduction to cpIntroduction to cp
Introduction to cp
SiddhantSaxena26
 
Lecture 01-2.ppt
Lecture 01-2.pptLecture 01-2.ppt
Lecture 01-2.ppt
RaoHamza24
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
Computer Hardware & Trouble shooting
 
ADA_Module 1_MN.pptx- Analysis and design of Algorithms
ADA_Module 1_MN.pptx- Analysis and design of AlgorithmsADA_Module 1_MN.pptx- Analysis and design of Algorithms
ADA_Module 1_MN.pptx- Analysis and design of Algorithms
madhu614742
 
chapter 1
chapter 1chapter 1
chapter 1
yatheesha
 
Bit-Manipulation for competitive programming
Bit-Manipulation for competitive programmingBit-Manipulation for competitive programming
Bit-Manipulation for competitive programming
gaurav77712
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
rajesshs31r
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptx
rajesshs31r
 
Effective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Effective Algorithm for n Fibonacci Number By: Professor Lili SaghafiEffective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Effective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Professor Lili Saghafi
 
Data Structure - Lecture 1 - Introduction.pdf
Data Structure  - Lecture 1 - Introduction.pdfData Structure  - Lecture 1 - Introduction.pdf
Data Structure - Lecture 1 - Introduction.pdf
donotreply20
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
skilljiolms
 
Lecture 1 (bce-7)
Lecture   1 (bce-7)Lecture   1 (bce-7)
Lecture 1 (bce-7)
farazahmad005
 
Unit 1 c programming language Tut and notes
Unit 1 c programming language Tut and notesUnit 1 c programming language Tut and notes
Unit 1 c programming language Tut and notes
achiver792
 
BCS401 ADA First IA Test Question Bank.pdf
BCS401 ADA First IA Test Question Bank.pdfBCS401 ADA First IA Test Question Bank.pdf
BCS401 ADA First IA Test Question Bank.pdf
VENKATESHBHAT25
 
2nd sem
2nd sem2nd sem
2nd sem
nastysuman009
 
Analysis of Algorithms
Analysis of AlgorithmsAnalysis of Algorithms
Analysis of Algorithms
Amna Saeed
 
Zoho Interview Questions By Scholarhat.pdf
Zoho Interview Questions By Scholarhat.pdfZoho Interview Questions By Scholarhat.pdf
Zoho Interview Questions By Scholarhat.pdf
Scholarhat
 
Data Structures and Algorithms (DSA) in C
Data Structures and Algorithms (DSA) in CData Structures and Algorithms (DSA) in C
Data Structures and Algorithms (DSA) in C
Nabajyoti Banik
 
Tiling matrix-matrix multiply, code tuning
Tiling matrix-matrix multiply, code tuningTiling matrix-matrix multiply, code tuning
Tiling matrix-matrix multiply, code tuning
mukhi265
 
Lecture 01-2.ppt
Lecture 01-2.pptLecture 01-2.ppt
Lecture 01-2.ppt
RaoHamza24
 
ADA_Module 1_MN.pptx- Analysis and design of Algorithms
ADA_Module 1_MN.pptx- Analysis and design of AlgorithmsADA_Module 1_MN.pptx- Analysis and design of Algorithms
ADA_Module 1_MN.pptx- Analysis and design of Algorithms
madhu614742
 
Bit-Manipulation for competitive programming
Bit-Manipulation for competitive programmingBit-Manipulation for competitive programming
Bit-Manipulation for competitive programming
gaurav77712
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
rajesshs31r
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptx
rajesshs31r
 
Effective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Effective Algorithm for n Fibonacci Number By: Professor Lili SaghafiEffective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Effective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Professor Lili Saghafi
 
Data Structure - Lecture 1 - Introduction.pdf
Data Structure  - Lecture 1 - Introduction.pdfData Structure  - Lecture 1 - Introduction.pdf
Data Structure - Lecture 1 - Introduction.pdf
donotreply20
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
skilljiolms
 
Unit 1 c programming language Tut and notes
Unit 1 c programming language Tut and notesUnit 1 c programming language Tut and notes
Unit 1 c programming language Tut and notes
achiver792
 
BCS401 ADA First IA Test Question Bank.pdf
BCS401 ADA First IA Test Question Bank.pdfBCS401 ADA First IA Test Question Bank.pdf
BCS401 ADA First IA Test Question Bank.pdf
VENKATESHBHAT25
 
Ad

Recently uploaded (20)

UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
The Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdfThe Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdf
Precisely
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptxWebinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
MSP360
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Connect and Protect: Networks and Network Security
Connect and Protect: Networks and Network SecurityConnect and Protect: Networks and Network Security
Connect and Protect: Networks and Network Security
VICTOR MAESTRE RAMIREZ
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
The Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdfThe Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdf
Precisely
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptxWebinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
MSP360
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Connect and Protect: Networks and Network Security
Connect and Protect: Networks and Network SecurityConnect and Protect: Networks and Network Security
Connect and Protect: Networks and Network Security
VICTOR MAESTRE RAMIREZ
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 

Algorithm hierarchy

  • 1. My 2 Cents of Preparing Coding Interview
  • 2. Introduction ž In most experience of Coding Interview, we have noticed more and more interview questions are focusing on algorithms. ž To tell whether algorithms are better or worse, there is complexity BigO to measure the performance in theory. ž Today, I would like to introduce Algorithm Hierarchy to organize thinking way.
  • 3. Not only Algorithm ž Remember: Not only is Algorithm one key part of coding interview, but also working attitude, communication skills, big picture thinking and so on are more considered etc.
  • 4. Algorithm Hierarchy in thought ž 1. Basic Algorithm ž 2. Space–time tradeoff ž 3. Pruning Algorithm ž 4. Optimized Algorithm ž 5. Big data Algorithm ž Remember: As hierarchy is like pyramid, you would better working more on foundation then looking forward.
  • 5. 1. Basic Algorithm ž (completed and easy reading –cy) ž Recursion, Backtracking, Blind searching and sorting like DFS, BFS, merge sort and qsort etc.
  • 6. 2. Space–time tradeoff ž (completed and fast by additional space –cy) ž Iteration, Dynamic Programming, Hash, Priority queue etc.
  • 7. 3. Pruning Algorithm ž (completed and fast via shortcuts –cy) ž Binary search in rotated array, K largest, Single Linked List cycle detect, Matrix multiplication etc.
  • 8. 4. Optimized Algorithm ž (faster and almost completed –cy) ž Estimated value, Hill climbing, Greedy Heuristic search like A*, D* etc.
  • 9. 5. Big data Algorithm ž (fastest and almost completed –cy) ž Divide and Conquer (Cloud, Cluster) and Machine learning, (Genetic, Ant Colony), Artificial intelligence (Alpha- Beta, MCTS) etc.
  • 10. Example of Algorithm Hierarchy ž Let me explain hierarchy by calculating Fibonacci sequence. ž 0, 1, 1, 2, 3, 5, 8, … ž Now we need to calculate nTh number in Fibonacci sequence.
  • 11. Fibonacci sequence (1) ž 1. Basic Algorithm : Complexity O(n!) ž long long f1(int n) { ž return n < 2 ? n : (f1(n-1) + f1(n-2)); ž }
  • 12. Fibonacci sequence (2) ž 2. Space–time tradeoff : Complexity O(n) ž long long f2(int n){ ž long long f[2] = {0, 1}; ž while (--n>=1) { ž f[0]=f[0]+f[1]; ž swap(f[0], f[1]); ž } ž return f[n+1]; ž }
  • 13. Fibonacci sequence (3) ž 3. Probing Algorithm : Complexity O(log n) ž long long f3(int n){ ž return (n < 2)? n : MatrixPower(n-1).m_00; //power of matrix { {1,1}, {1, 0} } ž }
  • 14. Fibonacci sequence (4) ž 4. Optimized Algorithm : Complexity O(1) ž const double sqrt5 =sqrt(5.0); ž long long f4 (int n){ ž return 0.5 + (pow((1+sqrt5)/2, n)) / sqrt5; ž }
  • 15. Fibonacci sequence (5) ž 5. Big data Algorithm ž long long f5 (int n){ ž return f[n]; ž }
  • 16. Fibonacci sequence (Output) ž f1(90) = timeout ž f2(90) = 2880067194370816120 ž f3(90) = 2880067194370816120 ž f4(90) = 2880067194370824704 ž f5(90) = 2880067194370816120 ž You may see f4(90) is slightly different because of double-precision, but it works for n<=70
  • 17. No Recursion Remember: Don’t use Recursion for large scale problem, using Iteration instead at least, especially for graph problems like tree verify, sum and traversal etc.
  • 18. Algorithm Hierarchy in Interview ž For Algorithm Hierarchy in Coding Interview, in my humble opinion, most Phone interview is on level 1, and most on-site interview is on level 2-3, however, you may asking about level 4-5 algorithm.
  • 19. Real Sample: Amazon’s most asked interview questions ž (source: geeksquiz.com) ž 1) K largest elements from a big file or array. ž 2) Find a triplet a, b, c such that a2 = b2 + c2. Variations of this problem like find a triplet with sum equal to 0. Find a pair with given sum. All such questions are efficiently solved using hashing. ž 3) Binary tree traversal questions like left view, right view, top view, bottom view, maximum of a level, minimum of a level, children sum property, diameter etc. ž 4) Convert a BST into a DLL and DLL to BST in place. ž 5) Vertical traversal of a Binary Tree. ž 6) Lowest Common ancestor in a Binary Search Tree and Binary Tree. ž 7) Implement a stack with push(), pop() and min() in O(1) time. ž 8) Reverse a linked list in groups of size k. ž 9) Given two numbers represented by two linked lists, write a function that returns sum list. ž 10) Rotate a matrix by 90 degree. ž 11) Some stack based questions like stock span problem, next greater element. ž 12) Some Dynamic Programming problems like maximum sum subarray, maximum sum subarray such that no elements are consecutive, edit distance, assembly line scheduling. ž You may easily find out there are 4 questions in each level 1-3, well balanced.
  • 20. KISS in phone interview Think aloud face to face ž Remember: Don’t think too complex in phone interview, just clarify your idea and keep it stupid simple(KISS). ž For on-site interview, you would better to well prepare and think aloud.
  • 21. oj.leetcode.com for preparing ž Last but not least, let me recommend oj.leetcode.com for preparing Coding Interview. ž After solving more than 140 problems in oj.leetcode.com in several days, I could summary out its Hierarchy: 49% level 1, 28% level 2, 23% level 3. ž LeetCode is focusing on data structures and algorithms. It requires not only just workable, but also optimized code. So you need to program in strict time and space complexity.
  • 22. Bottom line to pass interview ž Remember: In order to pass coding interview, you may need to solve 2-5 problems per hour in oj.leetcode.com.
  • 23. Thanks ž Thanks for watching. It is just my humble opinion, my 2 cents. ž Should you have any questions, please feel free to contact me. ž All rights reserved. Please contact changyu.yang for permission to copy, distribute or reprint.