A simple question for Haskellites: Does Haskell iterate the entire sequence to get the last value? In particular, a different number of commands executed for these two expressions?
Prelude> last "asdf" 'f' Prelude> last "qwerty" 'y'
Yes, the Haskell list is tied separately, and so lastyou need to go through the entire list, creating its runtime O(n).
last
O(n)
In addition to what sepp2k said, it is easy to determine: just run "last [1..1000000000]" and see if it takes some time. As expected, he does.
As the other two answers answered: yes, the last is O (n) operations in standard lists. If you are dealing with text data, you can use the text package that O (1) provides the last function . If you are not dealing with text data, you can look in byte or vector packets.
Source: https://habr.com/ru/post/1778798/More articles:Firefox and html5 video - gray box with x - debuggingIoC using Autofac - dependency-injectionSequence Points in C ++ and Exceptions - c ++Designing a web game that will work in a browser - where do I start? - pythonhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1778797/datetime-has-too-many-decimal-places&usg=ALkJrhhveSko5vKAj3n5wFuCaWavkf9i-wHow to deserialize in PHP an object serialized in Java - javaThe first Java EE project using REST - javabase class using the type defined by the parent class - c ++Table / View "EJB__TIMER__TBL" does not exist - javaКак запустить приложение при запуске телефона? - androidAll Articles