ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
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]
Let's enjoy algorithm application

More Related Content

What's hot (20)

PDF
Variational Inference in Python
Peadar Coyle
?
PPTX
PVS-Studio team experience: checking various open source projects, or mistake...
Andrey Karpov
?
PDF
What is pattern recognition (lecture 6 of 6)
Randa Elanwar
?
PPTX
Tensorflow in practice by Engineer - donghwi cha
Donghwi Cha
?
DOCX
Arrays
poonamchopra7975
?
PPTX
Matlab Feature Extraction Using Segmentation And Edge Detection
DataminingTools Inc
?
PPTX
C++ day2
Gamindu Udayanga
?
PDF
(chapter 4) A Concise and Practical Introduction to Programming Algorithms in...
Frank Nielsen
?
PDF
4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...
PROIDEA
?
PPT
Pythonic Math
Kirby Urner
?
PPT
Code Tuning
guest4df97e3d
?
PPTX
C++ training day01
Gamindu Udayanga
?
PDF
Homomorphic encryption in_cloud
Shivam Singh
?
PDF
Computing Information Flow Using Symbolic-Model-Checking_.pdf
larbaoui
?
PPTX
Partial Homomorphic Encryption
securityxploded
?
PPSX
CS106 Lab 3 - Modulus
Nada Kamel
?
PDF
Matlab integration
pramodkumar1804
?
PDF
Sparse Data Structures for Weighted Bipartite Matching
Jason Riedy
?
DOCX
Best,worst,average case .17581556 045
university of Gujrat, pakistan
?
PDF
Robotic Manipulator with Revolute and Prismatic Joints
Travis Heidrich
?
Variational Inference in Python
Peadar Coyle
?
PVS-Studio team experience: checking various open source projects, or mistake...
Andrey Karpov
?
What is pattern recognition (lecture 6 of 6)
Randa Elanwar
?
Tensorflow in practice by Engineer - donghwi cha
Donghwi Cha
?
Matlab Feature Extraction Using Segmentation And Edge Detection
DataminingTools Inc
?
(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 ...
PROIDEA
?
Pythonic Math
Kirby Urner
?
Code Tuning
guest4df97e3d
?
C++ training day01
Gamindu Udayanga
?
Homomorphic encryption in_cloud
Shivam Singh
?
Computing Information Flow Using Symbolic-Model-Checking_.pdf
larbaoui
?
Partial Homomorphic Encryption
securityxploded
?
CS106 Lab 3 - Modulus
Nada Kamel
?
Matlab integration
pramodkumar1804
?
Sparse Data Structures for Weighted Bipartite Matching
Jason Riedy
?
Best,worst,average case .17581556 045
university of Gujrat, pakistan
?
Robotic Manipulator with Revolute and Prismatic Joints
Travis Heidrich
?

Viewers also liked (6)

PPTX
Comparitive Analysis of Algorithm strategies
Talha Shaikh
?
PPT
chapter 1
yatheesha
?
PDF
01. design & analysis of agorithm intro & complexity analysis
Onkar Nath Sharma
?
PPTX
Back tracking and branch and bound class 20
Kumar
?
PPT
Design and Analysis of Algorithms
Swapnil Agrawal
?
PPTX
8 queens problem using back tracking
Tech_MX
?
Comparitive Analysis of Algorithm strategies
Talha Shaikh
?
chapter 1
yatheesha
?
01. design & analysis of agorithm intro & complexity analysis
Onkar Nath Sharma
?
Back tracking and branch and bound class 20
Kumar
?
Design and Analysis of Algorithms
Swapnil Agrawal
?
8 queens problem using back tracking
Tech_MX
?
Ad

Similar to Tiap (20)

PDF
02 analysis
Rick Boardman
?
ZIP
Analysis
Sri Prasanna
?
PDF
Sienna 2 analysis
chidabdu
?
PPTX
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
yvtinsane
?
PDF
Ch01
gurusodhii
?
PDF
Analysis Of Algorithms An Active Learning Approach 1st Edition Jeffrey J Mcco...
nowfermariih
?
PPS
Data Structures and Algorithms Unit 01
Prashanth Shivakumar
?
PPTX
³ÌÐòԱʵ¼ù֮·
Horky Chen
?
PPTX
2-Algorithms and Complexity analysis.pptx
231b209
?
PDF
complexity analysis.pdf
pasinduneshan
?
PPTX
Design & Analysis of Algorithm course .pptx
JeevaMCSEKIOT
?
PPTX
L1_Start_of_Learning_of_Algorithms_Basics.pptx
3cL1Ps3FTMS
?
KEY
Programming Contest Hacks
Kosei Moriyama
?
PPTX
CH-1.1 Introduction (1).pptx
satvikkushwaha1
?
PPTX
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
?
PDF
2-Algorithms and Complexit data structurey.pdf
ishan743441
?
PPTX
L1_DatabAlgorithm Basics with Design & Analysis.pptx
dpdiyakhan
?
PPTX
Introduction to Algorithms, Steps, Complexity
berggold2024
?
PPTX
Applied Algorithms Introduction to Algorithms.pptx
nishankarsathiyamoha
?
02 analysis
Rick Boardman
?
Analysis
Sri Prasanna
?
Sienna 2 analysis
chidabdu
?
daa18d8d-d333-4398-94dd-a46802d88d79.pptx
yvtinsane
?
Analysis Of Algorithms An Active Learning Approach 1st Edition Jeffrey J Mcco...
nowfermariih
?
Data Structures and Algorithms Unit 01
Prashanth Shivakumar
?
³ÌÐòԱʵ¼ù֮·
Horky Chen
?
2-Algorithms and Complexity analysis.pptx
231b209
?
complexity analysis.pdf
pasinduneshan
?
Design & Analysis of Algorithm course .pptx
JeevaMCSEKIOT
?
L1_Start_of_Learning_of_Algorithms_Basics.pptx
3cL1Ps3FTMS
?
Programming Contest Hacks
Kosei Moriyama
?
CH-1.1 Introduction (1).pptx
satvikkushwaha1
?
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
?
2-Algorithms and Complexit data structurey.pdf
ishan743441
?
L1_DatabAlgorithm Basics with Design & Analysis.pptx
dpdiyakhan
?
Introduction to Algorithms, Steps, Complexity
berggold2024
?
Applied Algorithms Introduction to Algorithms.pptx
nishankarsathiyamoha
?
Ad

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. Let's enjoy algorithm application