Editing Array

Jump to: navigation, search

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.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 63: Line 63:
 
* ''Map'': Apply the same unary function to every element in the array, either replacing it by the result of the function, or creating a new array that contains all the return values of the function, without rearranging them. (An example would be converting a string to uppercase.)
 
* ''Map'': Apply the same unary function to every element in the array, either replacing it by the result of the function, or creating a new array that contains all the return values of the function, without rearranging them. (An example would be converting a string to uppercase.)
 
* ''Reduce'': Consider each element of the array in turn, passing it to a binary function to update an accumulator, until all elements have been considered, and then return the accumulator. (Examples would be summing the array or finding its maximum element.)
 
* ''Reduce'': Consider each element of the array in turn, passing it to a binary function to update an accumulator, until all elements have been considered, and then return the accumulator. (Examples would be summing the array or finding its maximum element.)
 
==Limitations==
 
Suppose that a person cuts into line. How do we update the array of names? The problem is that everybody behind this person will have to have their IDs reassigned to reflect the new structure. That is, when we force an element into a particular location in an array, we have to shift over all the elements to its right, which requires a potentially linear amount of work copying elements. The same is true if someone in the middle of the line or the beginning leaves; all the people after him/her in the line will have to be shifted forward one position (backward in the array). When insertions and deletions are frequent, and most access is sequential, a [[linked list]] may perform better; when insertion, deletion, and random access are all frequent, the use of a [[Binary search tree|tree]] is recommended.
 
 
==Derived data structures==
 
The array can easily be used to implement a [[stack]], [[queue]], [[deque]], or [[binary heap]].
 
  
 
[[Category:Data structures]]
 
[[Category:Data structures]]

Please note that all contributions to PEGWiki are considered to be released under the Attribution 3.0 Unported (see PEGWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, 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. Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)