Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Lazy initialization
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Theoretical computer science == In the field of [[theoretical computer science]], '''lazy initialization'''<ref>{{Cite book|last1=Moret|first1=B. M. E.|title=Algorithms from P to NP, Volume 1: Design & Efficiency|last2=Shapiro|first2=H. D.|publisher=Benjamin/Cummings Publishing Company|year=1991|isbn=0-8053-8008-6|pages=191β192}}</ref> (also called a '''lazy array''') is a technique to design [[data structure]]s that can work with memory that does not need to be initialized. Specifically, assume that we have access to a table ''T'' of ''n'' uninitialized memory cells (numbered from ''1'' to ''n''), and want to assign ''m'' cells of this array, e.g., we want to assign ''T''[''k<sub>i</sub>''] := ''v<sub>i</sub>'' for pairs (''k''<sub>1</sub>, ''v''<sub>1</sub>), ..., (''k<sub>m</sub>'', ''v<sub>m</sub>'') with all ''k<sub>i</sub>'' being different. The lazy initialization technique allows us to do this in just O(''m'') operations, rather than spending O(''m''+''n'') operations to first initialize all array cells. The technique is simply to allocate a table ''V'' storing the pairs (''k<sub>i</sub>'', ''v<sub>i</sub>'') in some arbitrary order, and to write for each ''i'' in the cell ''T''[''k<sub>i</sub>''] the position in ''V'' where key ''k<sub>i</sub>'' is stored, leaving the other cells of ''T'' uninitialized. This can be used to handle queries in the following fashion: when we look up cell ''T''[''k''] for some ''k'', we can check if ''T''[''k''] is in the range {1, ..., ''m''}: if it is not, then ''T''[''k''] is uninitialized. Otherwise, we check ''V''[''T''[''k'']], and verify that the first component of this pair is equal to ''k''. If it is not, then ''T''[''k''] is uninitialized (and just happened by accident to fall in the range {1, ..., ''m''}). Otherwise, we know that ''T''[''k''] is indeed one of the initialized cells, and the corresponding value is the second component of the pair.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Lazy initialization
(section)
Add topic