So, I want to learn more about binary searches, because I really do not understand. A binary search requires a prerequisite for sorting an array. Did I understand correctly? It seems that the method should check for this precondition and raise an exception if it fails. But why is a background check a bad idea?
This is a bad idea, because checking for data sorting takes n. The whole search is about steps log(n).If you are going to check, you can also do a linear search.
n
log(n)
, , , .
, .
- ? , , , , , .
, , , , , , , , .
, . , , , , .
1 . , 1024 10 , , , , .
, , , . + N + log2 N, 1024 1034 , , 512.
. , , , , , , - , , , , , . .
Yep, 0 (log n) 0 (n). , DEBUG, RELEASE.
, . , .
, 'n' - .
O(log(n)) , . O(n).
O(log(n))
O(n)
, n, , .
, . ,
. .
, (O (n), , O (log (n)) .)
, . - - . , , . , .
, : , , , , , log (n) , , .
, -, . .
, . . .
, . - , .
, 0RPM 5000RPM, . .
Source: https://habr.com/ru/post/1720372/More articles:Image Scaling NSToolbarItem - objective-cDeploy SQL Server CE with my Windows Mobile application - windows-mobileExtract audio from FLV and inject into MP3 - c #Visual Studio - Vs Web Project Website - visual-studioImplementing business logic in a 3-tier architecture - phpC ++ system () function - How to collect output from issued command? - c ++xpath: how can you select specific node text before and after the tag? - xpathIdiomatic Python has_one - pythonHow do I disable a conversion message when opening an Office 2007 document using Office 2003? - .netXpath: как вы выбираете второй текст node (конкретный текст node) - xpathAll Articles