Basic concepts of data structures and algorithms

Source: Internet
Author: User

Data structure: is a collection of elements that have one or more specific relationships to each other.


Data structure is a subject that studies the problem of programming in non-numerical computing, and the related problems such as the relationship and operation between them.
The essence of program design is to choose a good structure for the problem of determination, plus design a good algorithm.
Program Design = data structure + algorithm


Data: Is the symbol that describes the objective things, is the computer can manipulate the object, is can be recognized by the computer, and input to the computer processing symbol set.
Data is actually a symbol and must have two prerequisites:
1) can be entered into the computer
2) can be processed by computer program


Data elements: The basic unit that makes up the data, with a little meaning, is usually treated as a whole in the computer.
Data item: A data element can consist of several data items. A data item is the smallest unit of data that is inseparable.
Data object: Is a collection of data elements of the same nature, and is a subset of the data.


Different data elements are not independent, but there are specific relationships, and we call these relationships structure


In order to write a "good" program, it is necessary to analyze the characteristics of the object to be handled and the relationship between the objects being processed. This is the meaning of the research data structure.


According to the different viewpoints, we divide the data structure into logical structure and physical structure.


Logical structure: Refers to the interrelationship between data elements in a data object.
1: Collection Structure
Collection structure: Data elements in a collection structure have no other relationship to each other except for the same collection.
2: Linear structure
Linear structure: The data elements in a linear structure are a one to the same relationship.
3: Tree-shaped structure
Tree structure: There is a one-to-many hierarchical relationship between data elements in a tree structure.
4: Graphic structure

Graphical structure: The data elements of a graphical structure are many-to-many relationships.


The logical structure is specific to the problem, in order to solve a problem, on the basis of understanding the problem, choose a suitable data structure to represent the logical relationship between elements.


Physical structure (storage structure)
Physical structure: Refers to the storage form of the logical structure of data in a computer.
The storage structure of the data should correctly reflect the logical relationship between the data elements.

There are two types of storage structures for data elements: sequential storage and chained storage.
1: Sequential storage structure
Sequential storage structure: The data element is stored in an address continuous storage unit, the logical relationship between the data and the physical relationship is consistent.
2: Chained storage structure
Chained storage structure: The data element is stored in any storage unit, this group of storage units can be continuous, or can be discontinuous.


The logical structure is problem-oriented, and the physical structure is computer-oriented, and its basic goal is to store the data and its logical relationship in the memory of the computer.


Data type: Refers to a set of values of the same nature and the general name of some operations defined on this collection.
Data types are divided according to the different values. In high-level languages, each variable, constant, and expression has its own range of values. Types are used to describe the range of values and actions that a variable or expression can take.
Data types can be divided into two categories:
Atomic type: is a basic type that can no longer be decomposed, including integer, real, character, and so on.
struct type: A combination of several types that can be decomposed. For example, an integer array is made up of several integral types of data.


Abstract data types refer to a mathematical model and a set of operations defined on the model.
Abstract data types are not just data types that have been defined and implemented, but can also be data types that computer programmers define themselves when designing software programs.
Also includes a set of operations on the model.


Abstract data types embody the characteristics of problem decomposition, abstraction and information hiding in program design.
Abstract data types decompose real-life problems into small, easy-to-handle problems, then build a data model that can be processed by a computer, and use the implementation details of each function module as a separate unit to hide the implementation process.


Algorithm:
An algorithm is a description of the solution steps for a particular problem, represented as a finite sequence of instructions in a computer, and each instruction represents one or more operations.

The algorithm has five basic characteristics: input, output, poor, deterministic and feasible.

Good algorithms should have the characteristics of correctness, readability, robustness, high efficiency and low storage.


Linear table: A finite sequence of 0 or more data elements.

Stacks and queues: a stack is a linear table that restricts insertions and deletions only at the end of a table.
A queue is a linear table that allows an insert operation at one end and a delete operation at the other end.

String: String (String) is a finite sequence of 0 or more characters, also known as a string.


Tree: The tree is a finite set of n (n>=0) nodes. N=0 is called an empty tree. In any non-empty tree species: (1) There is only one specific node called the root, and (2) when n>1, the remaining nodes can be divided into m (m>0) disjoint finite set T1,T2,....,TM, each of which is itself a tree, and is called the root subtree.


A binary tree is a finite set of n (n>=0) nodes, either an empty set (called an empty binary tree), or a two-fork tree consisting of a root node and two disjoint Saozi, called the root node, respectively.


The traversal of a binary tree means that all nodes in the binary tree are accessed sequentially from the root node, so that each node is accessed sequentially and accessed only once.


Access and order.
Traversal mode: Left to right
1: Pre-sequence traversal
The rule is that if the binary tree is empty, then an empty operation is returned, otherwise the root node is accessed first, then the left subtree is traversed before the sequence, and then the right subtree is traversed.
2: Middle Sequence traversal
The rule is that if the tree is empty, then an empty operation is returned, otherwise it starts at the root node (note that the root node is not first accessed), the middle sequence traverses the left subtree of the root node, and then accesses the root node, and the final middle sequence traverses the right subtree.
3: Post-post traversal
The rule is that if the tree is empty, then an empty operation is returned, otherwise the left-to-right leaves the back node in the way of the access subtree, and finally the root node.
4: Sequence traversal
The rule is that if the tree is empty, then an empty operation is returned, otherwise it is accessed from the first layer of the tree, which is the root node, and is traversed from top to bottom, and in the same layer, the nodes are accessed from left to right sequentially.


A pointer to a precursor and a successor is called a Clue, and a two-linked list of clues is called a clue-list, and the corresponding two-fork tree is called the Clue two fork tree.


The tree is converted to a two-fork tree
1: Add line. Add an attachment between all the sibling nodes.
2: Go to the line. For each node in the tree, keep only its connection to the first child, and remove the connection to the other child's knot points.
3: Level adjustment. Take the root node of the tree as the axis, the whole tree clockwise rotation of a certain angle, so that the structure of a clear hierarchy. Note that the first child is the left child of the two Fork tree node, and the child that the brother converts is the node's right child.


Forest converted to two-fork tree
1: Convert each tree to a two-fork tree.
2: The first binary tree does not move, starting from the second binary tree, in turn the root node of the second fork tree as the root node of the previous binary tree, the right child, connected by a line. When all the two forks are connected, a two-fork tree is converted from the forest.


Figure: A graph consists of a set of edges of a vertex with a poor non-empty set and vertices, usually expressed as: g (v,e), where G represents a graph, V is a set of vertices in Figure g, and E is a collection of edges in Figure G.
The storage structure of the graph:
1) adjacency matrix
2) adjacency table
3) Cross linked list
4) adjacency Multiple table


The process is called graph traversal when a vertex goes to the rest of the vertices in the graph and makes each vertex accessible only once.
1: Depth-first traversal
2: Breadth-first traversal


Minimum spanning tree of connected networks, two classical algorithms, Primm algorithm and Kruskal algorithm


Topological ordering, in fact, is the process of constructing topological sequences for a graph with a direction.


Find: A lookup is a data element (or record) in a lookup table that has a keyword equal to a given value, based on a given value.


Sort: Assuming that the sequence containing n records is {R1,R2,......, rn}, the corresponding keywords are {k1,k2,......, kn}, a permutation p1,p2,......, PN,......, n must be determined so that its corresponding keyword satisfies KP1 <=KP2<=......<=KPN (non-descending or non-incrementing) relationships, even if the sequence is called a sequential sequence of keywords {rp1,rp2,......, Rpn}, such operations are called sorting.


Sorting algorithm:
Simple algorithm: Bubble sort, simple select sort, direct insert sort
Improved algorithms: Hill sort, heap sort, merge sort, quick sort













































Basic concepts of data structures and algorithms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.