Data is a general term describing the numbers, characters, and all kinds of symbolic sets that can be entered into a computer and accepted by a computer.
Basic unit: Data element
Identifying Data elements: Keywords (keyword)
Unique keywords for identifying data elements: PRIMARY key (primary keyword)
Minimum identity unit in Data element: Data item
Data structure (structure): a relationship between elements, a finite set of n (n >= 0) data elements, with a specific element between data elements.
Logical Structure of data: linear structure, tree structure, graph
Storage structure of data: sequential storage, chained storage
Manipulating data: Initializing, judging whether it is empty, accessing, counting, traversing, inserting, deleting, searching, sorting ———— using algorithm to describe.
Data types and abstract data types.
Algorithm: A set of poor rules that determine the sequence of actions that solve a particular type of problem. The algorithm design relies on the logical structure of data, and realizes the storage structure of dependent data. Two aspects of algorithm analysis: Time cost, space cost.
Sequential storage of linear tables (sequential tables) and chain-type storage (linked list)
A sequential table (Seqlist) uses one-dimensional arrays to store book elements at once. One-dimensional arrays occupy a block of memory space, the address of each cell is continuous, by identifying elements, its subscript represents the number of his storage unit, also indicates its location.
It is convenient to find elements in a sequential table, and you can retrieve the elements you want to take, depending on the subscript.
When there is not enough capacity in the sequential table, the sequential table cannot be expanded in place, and another larger capacity is requested to replicate the array elements. Java source code in the ArrayList class expansion of the implementation process is: the first request to increase the capacity of the original capacity of One-second, generate an original capacity of three-seconds of the memory address, and then all the elements to replicate the past.
For inserts, deletes the element: first finds the corresponding position according to the subscript, if inserts the element, after inserts the new insertion position, will be added the position the old element and after the element moves backwards, moves the order is from the backward forward. If you delete an element, the element you want to delete is deleted, and the elements that follow move forward. Insert and delete operation times are primarily used to move elements.
Second, the linear table chain storage structure (linked list linkedlist) is a number of address dispersed storage unit to store data elements, logically adjacent data elements in the physical location is not necessarily adjacent. A storage unit that stores a data element becomes node node, the representation of a single linked table: node (data field, Address field).
For a single list of operations: The traversal operation begins at the No. 0 node, followed by the node's next chain, and sequentially accesses each node in the single linked list, and the nodes are accessed only once. Insert (DELETE) Operation: Depending on the number of nodes to insert (delete), traverse the No. 0 node to find the location to insert (delete), insert the data element to be inserted (delete the element to be deleted), change the link between the original node, do not move data elements. And the time spent in the operation is looking up.
Third, special linear table (stacks and queues)
(a) The special point is that the location of the insert and delete operation is limited:
If the insert and delete operation is only allowed at one end of the linear table, then stack (stack), characterized by advanced;
If the insert and delete operations are performed at both ends of the linear table, the queue is the first and most advanced.
(Ps. Stacks and linear tables are different abstract data types, and the concept of stacks does not depend on linear tables. )
(ii) application
Stacks are the basis for the implementation of nested invocation mechanisms: Because function return order is opposite to call order, by using stack to realize the path of memory function, we can get the path of function return, when the function is called, the operating system put the relevant information of the function (address, parameter, local variable value, etc.) into the stack, which is called the protection scene. A function returns when the stack, get the call function information, called the recovery scene, the program returned to the call function to continue running.
Using stacks to implement recursive algorithms in a non recursive way (there is an algorithm called recursive algorithm that directly or indirectly calls itself);
Queues are used to handle queued issues. (Priority queue)
Tree and two fork tree
Complete binary tree (full two fork tree);
Huffman Tree: The two-fork tree with the smallest length of the path and the optimal binary tree; Huffman encoding is a lossless compression coding technique in data compression.
There are two main traversal rules of a tree: the first root order traversal and the back-root order traversal.
The storage structure of a tree: A tree contains a hierarchical relationship between nodes and sibling relationships, the storage structure of the two relationships is different; the hierarchical relationship of the tree must be stored in a chained storage structure, connecting the parent node and the child node through the chain; the number of children in a node (sibling) is a linear relationship, Can be stored in sequential storage structure or chained storage structure.
B-Tree: High storage efficiency, low query efficiency-database index
Figure
Matrices and planning
Sort
Insert Sort: Inserts an element into its sorted sequence by the size of its key value at a time, repeating until all the elements are inserted.
Direct Insertion Sort: The best case is N; the worst case is n*n; the space complexity is O (1);
Binary insertion Sort: The sequential lookup algorithm is used to find the location when inserting a sort.
Hill sort: Reduces the incremental sort, that is, grouping directly into the sort. Time complexity is not easy to compute, depending on the incremental choice.
Exchange Sort:
Bubble sort: Compares the size of the adjacent two elements, swapping the largest element in the data sequence to the last. N*n; Space complexity: O (1).
Quick sort: Select an element in the data sequence as a datum value, each time from the end of the data series, alternating the elements less than the datum value to the front of the sequence, the elements that are greater than the datum value are exchanged to the back end of the sequence, where the position is the final position of the Datum At the same time, the sequence is divided into two subsequence, then the two subsequence are sorted quickly, until the subsequence length is 1, then the sorting is finished. Best case: N*n; The worst-case scenario is n*n; The fast row is the recursive algorithm, will spend certain time and the space, uses the stack to save the parameter, the stack occupies the space and the recursive call the number of times, the space complexity is O (n) ~ o (n).
Direct selection Sort: The first trip selects the most or the smallest element of the keyword from the data sequence of n elements and places it in the first or last position, then the next trip selects the largest or smallest number from the n-1 parameters and puts them in the corresponding position, and so on. The time complexity is O (n*n), and the space complexity is O (1).
Heap sort: Using a complete binary tree. Move the maximum or minimum value to the root node and change it to find the remaining maximum or minimum value. The time complexity is O (n*n), and the space complexity of heap sorting is O (1).
Merge sort: Merges another sorted subsequence to form a sequence of sorted data. The time complexity is O (n*n), and the space complexity is O (n).