Data Structure Array list set map


One. Data structure is divided into two categories: a logical structure (the relationship between elements) b physical structure (storage form).
Logical structure: a data object relationships between data elements.
Physical Structure: logical structure data stored in the form of a computer.

a. Logical structure:
1. a set of configuration: the set of elements belonging to a same set, there is no relationship other dubious.
2. Linear structures: linear structure element is a one to one relationship. An array of strings (character linear form)
3. tree structure: the presence of many hierarchical relationship of the elements of the tree structure.
4. Structure graphic: graphic element structure there is a relationship between a plurality of pairs.

b. Physical Structure:
1. sequential storage structure:
data elements in consecutive addresses in the memory unit, and the logical relationship between the physical relationship which is consistent with the data. Array ArrayList

2. chain structure:
LinkedList
by example to understand the chain structure: now such as banks, hospitals have set up a queuing system. Everyone will go to receive a number, waiting for the call number. Tell you when you can go to conduct business. While waiting, you can go anywhere, as long as you called when you come to it. Your concern here is that you are in front of that number. Chain structure is so flexible than the sequential structure.

Storage Structure: The data is stored in an arbitrary storage unit, the set of memory cells may be continuous or may be discontinuous. Data storage structure of elements of the chain, the storage structure not reflect logic. The address pointer may be used to store data elements, data elements find the location of the address.

Second, arrays and collections (Array list set map)

list: List
rrayList and are LinkedList class implements the List interface container for storing a series of object references. They can add or delete elements change search operation.

ArrayList , it is time to add or delete elements of the collection of end used is the same, but it will greatly increase with the time when you add or delete a list in the middle section. But it is very fast in finding elements of the index time. Namely: the end of the additions and deletions fast, fast query

LinkedList on the contrary, it is inserted, deleted the set time element anywhere it takes are the same, but it is slower than the index query an element of time. Namely: anywhere fast additions

 

ArrayList and LinkedList approximate difference:

1.ArrayList data structure is implemented based on dynamic array, LinkedList based linked list structure.

2. The get and set methods for random access, ArrayList LinkedList superior, because LinkedList to move the pointer.

3. For new and delete operations add and remove, LinkedList comparative advantage, because ArrayList to move data.

They have disadvantages in terms of performance:

1. ArrayList and LinkedList, in the end of the list increased spending spent one element is fixed. For ArrayList, the main increase in an internal array, pointing to the added elements, it may occasionally lead to re-allocate the array; while LinkedList is concerned, this overhead is a unified, assign an internal Entry object.

2. Add or delete an element in the ArrayList collection, the current list of all elements will be moved. And add or delete elements of a LinkedList collection costs are fixed.

3.LinkedList collection does not support efficient random random access (RandomAccess), because it may produce behavior quadratic term.

Waste of space 4.ArrayList is mainly reflected in the list at the end of the list to reserve a certain volume of space and the space it takes LinkedList is reflected in each of its elements need to consume considerable space , so additions or deletions to the elements in our investigation when in operation, with a search operation when ArrayList, additions or deletions to operate best when used LinkedList.

Summary: The best LinkedList additions and deletions
to check the end of the additions and deletions to change the best ArrayList +

set: set (element does not repeat)
HashSet: underlying hash table, thread-safe, disordered, high efficiency, the only element
TreeSet: underlying binary tree, ordered, thread-safe
LinkedHashSet: Ordered

Use an array list and set Summary:

If the length is fixed, consistent element selected array

Otherwise:
If the element can be repeated, select list
generally choose ArrayList (Universal),
if not frequent delete insert, preference ArrayList;
if elements that require frequent insertion, deletion, select LinkedList,
using if in multithreaded conditions, consider Vector ;

If the only elements in the table, select the set
For more efficient access to the set, select hashSet;
For automatic sorting to a set of elements, selected TreeSet,
For holding element by way of insertion order, select LinkedHashSet.

 

map: map
Map Features: Map once the elements keep a
Hashtable: the underlying hash table, thread-safe (synchronized), keys and values are not be null

HashMap: + bottom layer is an array list (key-value stored in one of the Entry, Entry unidirectional list structure, a hash value is calculated by Key, i.e., the hash value of array subscript available Entry, if the Entry list more than one traversal of this list ), using a hashing algorithm, thread-safe, the key may be null; multithread ConcurrentHashMap thread safe use
factors properties: initial capacity (i.e. initial capacity HashMap array size) and load factor (for judging whether the expansion HashMap current array size> = current capacity of the load factor *). The default load factor 0.75, an increase of conflict is too large, the list lengthened, the query efficiency decreases; the space is too small waste
PS: Hash address generated by the bit operation, so that high efficiency

TreeMap: binary tree is a bottom, sortable

 

Guess you like

Origin www.cnblogs.com/ynhk/p/10983427.html