Array
Array is a fundamental data structure used in computer science to store collections of elements (values or variables), each identified by at least one array index or key. An array is stored such that the position of each element can be computed from its index tuple by a mathematical formula. The simplest type of array is a linear array or one-dimensional array, where the index is just a single number. Arrays can be multidimensional, meaning that they have multiple indices to access the elements. In a two-dimensional array, for example, the elements are accessed by two indices, which can be thought of as rows and columns.
Types of Arrays[edit | edit source]
Arrays come in several types, each with its specific utility and characteristics:
- Static arrays have a fixed size, which is known at compile time and cannot be changed during the program's execution.
- Dynamic arrays can grow or shrink in size during the execution of a program to accommodate more or fewer elements as needed.
- Multi-dimensional arrays are arrays of arrays, with each element being an array itself. The most common multi-dimensional array is the two-dimensional array, often used to represent matrices or grids.
Usage[edit | edit source]
Arrays are used in almost every program or software system. Some common uses include:
- Storing data elements of the same type
- Implementing other data structures like stacks, queues, and lists
- Temporal storage of data for sorting or other algorithms that manipulate collections of data
Advantages and Disadvantages[edit | edit source]
Advantages[edit | edit source]
- Arrays allow random access to elements, making it quick to access a specific element if the index is known.
- They are simple and easy to use for storing sequences of data.
Disadvantages[edit | edit source]
- The size of a static array must be known at compile time and cannot change, which can lead to wasted memory space or insufficient space for data.
- Dynamic arrays can mitigate the size limitation but introduce overhead for resizing and can lead to increased processing time and memory usage.
Implementation[edit | edit source]
In most programming languages, arrays are a built-in type. The syntax for declaring and using arrays varies between languages. For example, in C, an array can be declared as `int myArray[10];`, which allocates space for ten integers. In Python, lists serve the purpose of arrays and can be declared as `myArray = [1, 2, 3]`.
See Also[edit | edit source]
Array Resources | ||
---|---|---|
|
|
Navigation: Wellness - Encyclopedia - Health topics - Disease Index - Drugs - World Directory - Gray's Anatomy - Keto diet - Recipes
Search WikiMD
Ad.Tired of being Overweight? Try W8MD's physician weight loss program.
Semaglutide (Ozempic / Wegovy and Tirzepatide (Mounjaro / Zepbound) available.
Advertise on WikiMD
WikiMD is not a substitute for professional medical advice. See full disclaimer.
Credits:Most images are courtesy of Wikimedia commons, and templates Wikipedia, licensed under CC BY SA or similar.
Translate this page: - East Asian
中文,
日本,
한국어,
South Asian
हिन्दी,
தமிழ்,
తెలుగు,
Urdu,
ಕನ್ನಡ,
Southeast Asian
Indonesian,
Vietnamese,
Thai,
မြန်မာဘာသာ,
বাংলা
European
español,
Deutsch,
français,
Greek,
português do Brasil,
polski,
română,
русский,
Nederlands,
norsk,
svenska,
suomi,
Italian
Middle Eastern & African
عربى,
Turkish,
Persian,
Hebrew,
Afrikaans,
isiZulu,
Kiswahili,
Other
Bulgarian,
Hungarian,
Czech,
Swedish,
മലയാളം,
मराठी,
ਪੰਜਾਬੀ,
ગુજરાતી,
Portuguese,
Ukrainian
Contributors: Prab R. Tumpati, MD