SlideShare une entreprise Scribd logo
1  sur  15
kobe [email_address] Thinking in Algorithm Application --  for app developer
Thinking in Algorithm Application feedback from TIAP first time on 2009.6.3 非常有用  by  马程钟 很好,对工作很有帮助  by  孟光 不错,加深了对算法的理解  by  朱岩 相当不错  by  宫晶纬 再讲一遍  by  孙郁芳 ...
Thinking in Algorithm Application JAVA: public static int binarySearch(byte[] a, byte key) C++: template <class ForwardIterator, class T> bool binary_search ( ForwardIterator first, ForwardIterator last, const T& value ); template <class ForwardIterator, class T> pair<ForwardIterator,ForwardIterator> equal_range ( ForwardIterator first, ForwardIterator last, const T& value );
Thinking in Algorithm Application Prime Number: near 600: 599 601 near 1200: 1201 near 3600: 3593 3607 near 86400: 86399
Thinking in Algorithm Application fast recursion framework: void func(array,m,n) { if(...) return; for(;;) { do_someting(); m=new_m1;n=new_n1; func(array,new_m2,new_n2); }//end for } test_vec.begin()
Thinking in Algorithm Application void TopN_most_beautiful_edtion(array,size,top) {  std::make_heap(array,array+top); pos=array; for(;pos!=array+size;pos++) { if(array[pos]<array[0]) { array[top]=array[pos]; std::pop_heap(array,array+top+1); } }//end for }
Thinking in Algorithm Application array range: 10000 0000 top range: 100  average time cost: std::nth_element => 1.13s TopN_most_beautiful_edtion => 0.19s std::sort => 17.21s
Thinking in Algorithm Application self sort: void SelfSort(array) { int pos=array.size()-1; int expect_pos=0; while(pos>=0) { expect_pos=tellme_my_pos(array[pos]); if(expect_pos<pos) swap(array[pos],array[expect_pos]); else pos--; }//end while }
Thinking in Algorithm Application the best way to pickup random record in mysql: SELECT * FROM `table` AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM `table`)-(SELECT MIN(id) FROM `table`))+(SELECT MIN(id) FROM `table`)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id LIMIT 1;
Thinking in Algorithm Application simple KMP by Chenhua: int StrStr(string a, string b) { int m=0,n=0; for(;m<a.size()-b.size();) { while(n<b.size() && a[m]==b[n]) {m++;n++} if(n==b.size()) return m; if(n==0) {m++;continue;} if(n>=SFP) {m=m-n+SFP;} n=0; }//end for return -1; }
Thinking in Algorithm Application what can do in just 1 s, for some &quot;snail&quot; operations we thought: empty loop  => 20 0000 0000 times md5 (256 char) => 60 0000 times mutex pair (lock,unlock) => 8000 0000 times sort (100 0000 array in mem) => 8 times binary search (100 0000 array in mem) => 250 0000 times thread pair (create,delete) => 10 0000 times all data above base on 4CPU 3GHz & 4GMem
Thinking in Algorithm Application some &quot;missing&quot; useful topic: 1, parser 2, matrix(pagerank) 3, parallel programming future study: 1, advanced graph algorithm 2, compiler implement 3, distributed algorithm valuable code base: 1 , C++ standard template library 2 , C++ boost library 3 , Java Development Kit
Thinking in Algorithm Application contributors: 播客排行榜  => fulin@staff 最大 N 元素  => jingwei@staff 原地排序  => yanbo@staff simple KMP => chenhua(yahoo) mysql random => chunsheng1@staff 博文多关键字过滤  => ouyangde@staff SNS 关键用户  => zhiyong@staff 优先队列  => jingwei@staff 80:20 => jingwei@staff zhuyan@staff
Thinking in Algorithm Application thanks to: [email_address] [email_address] [email_address] [email_address] [email_address] [email_address] [email_address] [email_address] [email_address] [email_address] feedback: [email_address]
[object Object]

Contenu connexe

Tendances

Variational Inference in Python
Variational Inference in PythonVariational Inference in Python
Variational Inference in PythonPeadar Coyle
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...Andrey Karpov
 
What is pattern recognition (lecture 6 of 6)
What is pattern recognition (lecture 6 of 6)What is pattern recognition (lecture 6 of 6)
What is pattern recognition (lecture 6 of 6)Randa Elanwar
 
Tensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi chaTensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi chaDonghwi Cha
 
Matlab Feature Extraction Using Segmentation And Edge Detection
Matlab Feature Extraction Using Segmentation And Edge DetectionMatlab Feature Extraction Using Segmentation And Edge Detection
Matlab Feature Extraction Using Segmentation And Edge DetectionDataminingTools Inc
 
(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...Frank Nielsen
 
4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...
4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...
4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...PROIDEA
 
Homomorphic encryption in_cloud
Homomorphic encryption in_cloudHomomorphic encryption in_cloud
Homomorphic encryption in_cloudShivam Singh
 
Computing Information Flow Using Symbolic-Model-Checking_.pdf
Computing Information Flow Using Symbolic-Model-Checking_.pdfComputing Information Flow Using Symbolic-Model-Checking_.pdf
Computing Information Flow Using Symbolic-Model-Checking_.pdfPolytechnique Montréal
 
Partial Homomorphic Encryption
Partial Homomorphic EncryptionPartial Homomorphic Encryption
Partial Homomorphic Encryptionsecurityxploded
 
CS106 Lab 3 - Modulus
CS106 Lab 3 - ModulusCS106 Lab 3 - Modulus
CS106 Lab 3 - ModulusNada Kamel
 
Sparse Data Structures for Weighted Bipartite Matching
Sparse Data Structures for Weighted Bipartite Matching Sparse Data Structures for Weighted Bipartite Matching
Sparse Data Structures for Weighted Bipartite Matching Jason Riedy
 
Robotic Manipulator with Revolute and Prismatic Joints
Robotic Manipulator with Revolute and Prismatic JointsRobotic Manipulator with Revolute and Prismatic Joints
Robotic Manipulator with Revolute and Prismatic JointsTravis Heidrich
 

Tendances (20)

Variational Inference in Python
Variational Inference in PythonVariational Inference in Python
Variational Inference in Python
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
 
What is pattern recognition (lecture 6 of 6)
What is pattern recognition (lecture 6 of 6)What is pattern recognition (lecture 6 of 6)
What is pattern recognition (lecture 6 of 6)
 
Tensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi chaTensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi cha
 
Arrays
ArraysArrays
Arrays
 
Matlab Feature Extraction Using Segmentation And Edge Detection
Matlab Feature Extraction Using Segmentation And Edge DetectionMatlab Feature Extraction Using Segmentation And Edge Detection
Matlab Feature Extraction Using Segmentation And Edge Detection
 
C++ day2
C++ day2C++ day2
C++ day2
 
(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...
 
4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...
4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...
4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...
 
Pythonic Math
Pythonic MathPythonic Math
Pythonic Math
 
Code Tuning
Code TuningCode Tuning
Code Tuning
 
C++ training day01
C++ training day01C++ training day01
C++ training day01
 
Homomorphic encryption in_cloud
Homomorphic encryption in_cloudHomomorphic encryption in_cloud
Homomorphic encryption in_cloud
 
Computing Information Flow Using Symbolic-Model-Checking_.pdf
Computing Information Flow Using Symbolic-Model-Checking_.pdfComputing Information Flow Using Symbolic-Model-Checking_.pdf
Computing Information Flow Using Symbolic-Model-Checking_.pdf
 
Partial Homomorphic Encryption
Partial Homomorphic EncryptionPartial Homomorphic Encryption
Partial Homomorphic Encryption
 
CS106 Lab 3 - Modulus
CS106 Lab 3 - ModulusCS106 Lab 3 - Modulus
CS106 Lab 3 - Modulus
 
Matlab integration
Matlab integrationMatlab integration
Matlab integration
 
Sparse Data Structures for Weighted Bipartite Matching
Sparse Data Structures for Weighted Bipartite Matching Sparse Data Structures for Weighted Bipartite Matching
Sparse Data Structures for Weighted Bipartite Matching
 
Best,worst,average case .17581556 045
Best,worst,average case .17581556 045Best,worst,average case .17581556 045
Best,worst,average case .17581556 045
 
Robotic Manipulator with Revolute and Prismatic Joints
Robotic Manipulator with Revolute and Prismatic JointsRobotic Manipulator with Revolute and Prismatic Joints
Robotic Manipulator with Revolute and Prismatic Joints
 

En vedette

Comparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategiesComparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategiesTalha Shaikh
 
01. design & analysis of agorithm intro & complexity analysis
01. design & analysis of agorithm intro & complexity analysis01. design & analysis of agorithm intro & complexity analysis
01. design & analysis of agorithm intro & complexity analysisOnkar Nath Sharma
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Kumar
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsSwapnil Agrawal
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back trackingTech_MX
 

En vedette (6)

Comparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategiesComparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategies
 
chapter 1
chapter 1chapter 1
chapter 1
 
01. design & analysis of agorithm intro & complexity analysis
01. design & analysis of agorithm intro & complexity analysis01. design & analysis of agorithm intro & complexity analysis
01. design & analysis of agorithm intro & complexity analysis
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 

Similaire à Tiap

Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to AlgorithmsVenkatesh Iyer
 
Федор Поляков (Looksery) “Face Tracking на мобильных устройствах в режиме реа...
Федор Поляков (Looksery) “Face Tracking на мобильных устройствах в режиме реа...Федор Поляков (Looksery) “Face Tracking на мобильных устройствах в режиме реа...
Федор Поляков (Looksery) “Face Tracking на мобильных устройствах в режиме реа...Provectus
 
How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...Codemotion
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source codePVS-Studio
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source codeAndrey Karpov
 
VCE Unit 01 (1).pptx
VCE Unit 01 (1).pptxVCE Unit 01 (1).pptx
VCE Unit 01 (1).pptxskilljiolms
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMSfawzmasood
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxskilljiolms
 
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...Positive Hack Days
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyKimikazu Kato
 
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scalaAutomate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scalaChetan Khatri
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0Yaser Zhian
 
Introduction to computing Processing and performance.pdf
Introduction to computing Processing and performance.pdfIntroduction to computing Processing and performance.pdf
Introduction to computing Processing and performance.pdfTulasiramKandula1
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for SpeedYung-Yu Chen
 
Fosdem2017 Scientific computing on Jruby
Fosdem2017  Scientific computing on JrubyFosdem2017  Scientific computing on Jruby
Fosdem2017 Scientific computing on JrubyPrasun Anand
 
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...Chetan Khatri
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Saket Pathak
 

Similaire à Tiap (20)

Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
Федор Поляков (Looksery) “Face Tracking на мобильных устройствах в режиме реа...
Федор Поляков (Looksery) “Face Tracking на мобильных устройствах в режиме реа...Федор Поляков (Looksery) “Face Tracking на мобильных устройствах в режиме реа...
Федор Поляков (Looksery) “Face Tracking на мобильных устройствах в режиме реа...
 
How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
VCE Unit 01 (1).pptx
VCE Unit 01 (1).pptxVCE Unit 01 (1).pptx
VCE Unit 01 (1).pptx
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPy
 
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scalaAutomate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
 
C#, What Is Next?
C#, What Is Next?C#, What Is Next?
C#, What Is Next?
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
Macro
MacroMacro
Macro
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0
 
Introduction to computing Processing and performance.pdf
Introduction to computing Processing and performance.pdfIntroduction to computing Processing and performance.pdf
Introduction to computing Processing and performance.pdf
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
 
Fosdem2017 Scientific computing on Jruby
Fosdem2017  Scientific computing on JrubyFosdem2017  Scientific computing on Jruby
Fosdem2017 Scientific computing on Jruby
 
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
 

Tiap

  • 1. kobe [email_address] Thinking in Algorithm Application -- for app developer
  • 2. Thinking in Algorithm Application feedback from TIAP first time on 2009.6.3 非常有用 by 马程钟 很好,对工作很有帮助 by 孟光 不错,加深了对算法的理解 by 朱岩 相当不错 by 宫晶纬 再讲一遍 by 孙郁芳 ...
  • 3. Thinking in Algorithm Application JAVA: public static int binarySearch(byte[] a, byte key) C++: template <class ForwardIterator, class T> bool binary_search ( ForwardIterator first, ForwardIterator last, const T& value ); template <class ForwardIterator, class T> pair<ForwardIterator,ForwardIterator> equal_range ( ForwardIterator first, ForwardIterator last, const T& value );
  • 4. Thinking in Algorithm Application Prime Number: near 600: 599 601 near 1200: 1201 near 3600: 3593 3607 near 86400: 86399
  • 5. Thinking in Algorithm Application fast recursion framework: void func(array,m,n) { if(...) return; for(;;) { do_someting(); m=new_m1;n=new_n1; func(array,new_m2,new_n2); }//end for } test_vec.begin()
  • 6. Thinking in Algorithm Application void TopN_most_beautiful_edtion(array,size,top) { std::make_heap(array,array+top); pos=array; for(;pos!=array+size;pos++) { if(array[pos]<array[0]) { array[top]=array[pos]; std::pop_heap(array,array+top+1); } }//end for }
  • 7. Thinking in Algorithm Application array range: 10000 0000 top range: 100 average time cost: std::nth_element => 1.13s TopN_most_beautiful_edtion => 0.19s std::sort => 17.21s
  • 8. Thinking in Algorithm Application self sort: void SelfSort(array) { int pos=array.size()-1; int expect_pos=0; while(pos>=0) { expect_pos=tellme_my_pos(array[pos]); if(expect_pos<pos) swap(array[pos],array[expect_pos]); else pos--; }//end while }
  • 9. Thinking in Algorithm Application the best way to pickup random record in mysql: SELECT * FROM `table` AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM `table`)-(SELECT MIN(id) FROM `table`))+(SELECT MIN(id) FROM `table`)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id LIMIT 1;
  • 10. Thinking in Algorithm Application simple KMP by Chenhua: int StrStr(string a, string b) { int m=0,n=0; for(;m<a.size()-b.size();) { while(n<b.size() && a[m]==b[n]) {m++;n++} if(n==b.size()) return m; if(n==0) {m++;continue;} if(n>=SFP) {m=m-n+SFP;} n=0; }//end for return -1; }
  • 11. Thinking in Algorithm Application what can do in just 1 s, for some &quot;snail&quot; operations we thought: empty loop => 20 0000 0000 times md5 (256 char) => 60 0000 times mutex pair (lock,unlock) => 8000 0000 times sort (100 0000 array in mem) => 8 times binary search (100 0000 array in mem) => 250 0000 times thread pair (create,delete) => 10 0000 times all data above base on 4CPU 3GHz & 4GMem
  • 12. Thinking in Algorithm Application some &quot;missing&quot; useful topic: 1, parser 2, matrix(pagerank) 3, parallel programming future study: 1, advanced graph algorithm 2, compiler implement 3, distributed algorithm valuable code base: 1 , C++ standard template library 2 , C++ boost library 3 , Java Development Kit
  • 13. Thinking in Algorithm Application contributors: 播客排行榜 => fulin@staff 最大 N 元素 => jingwei@staff 原地排序 => yanbo@staff simple KMP => chenhua(yahoo) mysql random => chunsheng1@staff 博文多关键字过滤 => ouyangde@staff SNS 关键用户 => zhiyong@staff 优先队列 => jingwei@staff 80:20 => jingwei@staff zhuyan@staff
  • 14. Thinking in Algorithm Application thanks to: [email_address] [email_address] [email_address] [email_address] [email_address] [email_address] [email_address] [email_address] [email_address] [email_address] feedback: [email_address]
  • 15.