{"id":2424,"date":"2019-12-21T10:27:33","date_gmt":"2019-12-21T07:27:33","guid":{"rendered":"http:\/\/demensdeum.com\/blog\/?p=2424"},"modified":"2024-12-16T22:32:31","modified_gmt":"2024-12-16T19:32:31","slug":"lexicompare","status":"publish","type":"post","link":"https:\/\/demensdeum.com\/blog\/hi\/2019\/12\/21\/lexicompare\/","title":{"rendered":"Lexicographic comparison algorithm"},"content":{"rendered":"<p>The lexicographic string comparison algorithm works very simply, in a loop the character codes are compared and the result is returned if the characters are not equal.<\/p>\n<p>An example for the C language can be found here:<br \/><a href=\"https:\/\/github.com\/gcc-mirror\/gcc\/blob\/master\/libiberty\/memcmp.c\">https:\/\/github.com\/gcc-mirror\/gcc\/blob\/master\/libiberty\/memcmp.c<\/a><\/p>\n<p>It should be taken into account that the characters need to be compared in a single static encoding, for example, in Swift I used character-by-character comparison on UTF-32. The option of sorting an array using memcmp will work exactly for single-byte characters, in other cases (variable-length encodings) the order may be incorrect. I do not exclude the possibility of implementation based on variable-length encodings, but most likely it will be an order of magnitude more complicated.<\/p>\n<p>Time complexity of the algorithm is O(1) in the best case, O(n) in the average and worst case<\/p>\n<h3>Sources<\/h3>\n<p><a href=\"https:\/\/ru.wikipedia.org\/wiki\/\u041b\u0435\u043a\u0441\u0438\u043a\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435_\u043f\u043e\u0440\u044f\u0434\u043e\u043a\" target=\"_blank\" rel=\"noopener\">https:\/\/ru.wikipedia.org\/wiki\/\u041b\u0435\u043a\u0441\u0438\u043a\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435_\u043f\u043e\u0440\u044f\u0434\u043e\u043a<\/a><\/p>\n<h3>Sources<\/h3>\n<p><a href=\"https:\/\/gitlab.com\/demensdeum\/algorithms\/blob\/master\/lexiCompare\/lexiCompare.swift\" target=\"_blank\" rel=\"noopener\">https:\/\/gitlab.com\/demensdeum \/algorithms\/blob\/master\/lexiCompare\/lexiCompare.swift<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The lexicographic string comparison algorithm works very simply, in a loop the character codes are compared and the result is returned if the characters are not equal. An example for the C language can be found here:https:\/\/github.com\/gcc-mirror\/gcc\/blob\/master\/libiberty\/memcmp.c It should be taken into account that the characters need to be compared in a single static encoding,<a class=\"more-link\" href=\"https:\/\/demensdeum.com\/blog\/hi\/2019\/12\/21\/lexicompare\/\">Continue reading <span class=\"screen-reader-text\">&#8220;Lexicographic comparison algorithm&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[61,52],"tags":[131,135],"class_list":["post-2424","post","type-post","status-publish","format-standard","hentry","category-techie","category-tutorials","tag-algorithms","tag-lexicompare","entry"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"hi","enabled_languages":["en","ru","zh","de","fr","ja","pt","hi"],"languages":{"en":{"title":true,"content":true,"excerpt":false},"ru":{"title":true,"content":true,"excerpt":false},"zh":{"title":true,"content":true,"excerpt":false},"de":{"title":true,"content":true,"excerpt":false},"fr":{"title":true,"content":true,"excerpt":false},"ja":{"title":true,"content":true,"excerpt":false},"pt":{"title":true,"content":true,"excerpt":false},"hi":{"title":false,"content":false,"excerpt":false}}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/posts\/2424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/comments?post=2424"}],"version-history":[{"count":13,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/posts\/2424\/revisions"}],"predecessor-version":[{"id":3929,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/posts\/2424\/revisions\/3929"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/media?parent=2424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/categories?post=2424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/tags?post=2424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}