C # Data Structure basics,

Source: Internet
Author: User

C # Data Structure basics,

 

 

Problem:

In the information world, computers are the carriers of processed information. In this process, there are three problems:

1. How to easily and efficiently organize data

2. How to store data (memory and external storage) in a computer)

3. How to perform efficient operations on stored data

 

Purpose:

We all know that we will express one thing. The boss will give you one thing and you will give it to your employees so that they can understand what you mean. Some may give a few simple words.

Let's make things clear, but some people say a lot to understand what he said. This metaphor is not appropriate. We can also see two things in the face of the same program.

Program: Some people write programs with high efficiency, while others use complicated methods to solve a simple problem.

In short, there are three purposes:

1. Build your own Data Structure Knowledge Base

2. Improve the program design level

3. Provide basic skills for programmers

 

 

 

Basic concepts and terms

1. Data: The carrier, numerical Data, sound, and text of information that can be recognized by computers.

2. Data Element and Data Item DE: Data entity DI: Data attributes a record (user) and

Field (username, password, gender, etc)

3. set of Data elements with the same Data Object nature, such as {0, 1, 2, 3, 4}, {a, B, c, d}, {user A, user B, user C ....}

4. Data Type int, string, and so on

 

5. Data StructureA Data Structure is A relational Data Structure organized on the basis of A Data set. Generally, there are four types of local Data structures: A Set B-line Structure C-Tree Structure

Structure D mesh or graphic structure

 

A Set B Linear Structure C Tree Structure D Graphic Structure

Data Structure is a binary group DS = (D, R) D is a finite set of Data elements R is the relationship between elements

 

 

The following three data structures are described in the example:

 

BLinear Data Structure student information table

One row: Data Element column: Relationship between data element and element: 1 to 1

 

 

CTree Structure family tree

 

 

This is not explained much. Node: Data Element relationship: one-to-many or multiple-to-one

 

 

DGraph Structure

 

 

Graphic Structure: traffic map element: city relationship, many-to-many

 

Data Structure

Including the logical structure of data and the physical structure of data. The physical structure is also called the storage structure. We discuss the purpose of the data structure to implement

Now, the operations on it need to be expressed and stored on the computer. The data storage structure is divided into sequential Storage Structure and chain storage structure. Sequential Storage Structure: adjacent

Data is stored physically in the same storage unit. in C #, arrays are used for sequential storage. The most common is arrays. chained storage, Node + Reference

Domain in. net memory stack and stack, stack sequential storage, the corresponding object in the heap, points to the address in the heap.

 

Algorithm

Algorithms are closely related to data structures.

Algorithm features: 1 poor 2 deterministic 3 output and output 4 executable

Evaluation criteria: 1 correctness 2 readability 3 robustness 4 Runtime (Time Complexity) 5 Space occupation (Space Complexity)

Factors Affecting Performance: 1. Hardware conditions 2. Implementing a computer language (the higher the language, the lower the efficiency) 3. Programming Language compiler and interpreter 4 Operating System

 

Time complexity of the algorithm

The algorithm consists of the control structure and the original operation. The execution time of the algorithm depends on the comprehensive effect of the two. To make it easier to compare different algorithms of the same problem, basic operations are usually performed in the algorithm.

The number of repeated executions (frequency) is the time complexity of the algorithm. T (n) = 0 (f (n). If an algorithm does not have cyclic statements, the execution frequency and problems of the current operations in the algorithm

It is irrelevant. It is recorded as 0 (1), and it also becomes a constant order. If the algorithm only involves a loop, it will be recorded as 0 (N) if the execution frequency of the algorithm increases linearly with the problem scale n ), also called linear order

Common examples are square factorial 0 (n * n) cubic order 0 (n * n ).

Example 1: X = n;

Y = 0;

While (y <x)

{

Y = y + 1; // T (n) time complexity

}

 This is a loop. The number of cycles is N. the time complexity is linear: Remember to do T (n) = 0 (0)

Example 2: For (I = 1; I <n; I ++)

{

For (j = 0; j <n; j ++)

{

A [I] [j] = I * j; // T (n) time complexity

}

}

The number of loops in the outer loop of a dual loop is the number of loops in the N inner layer for N. the time complexity T (n) = 0 (n * n );

 

Example 3: X = n;

Y = 0;

While (x> = (y + 1) * (y + 1 ))

{

Y = y + 1; // T (n) time complexity

}

 

The number of while cycles in one loop is root N, so the time complexity T (n) = 0 (root N)

 

Example 4:For (I = 0; I <m; I ++)

{

For (j = 0; j <t; j ++)

{

For (k = 0; k <n; k ++)

{

C [I] [j] = c [I] [j] + a [I] [k] * B [k] [j]; // T (n) number of times the time complexity is executed

}

}

}

Triple cycle: time complexity T (n) = 0 (m * t * j );

 

Basic Mathematical Concepts

When thinking of an algorithm, you have to think of mathematics. Set representation: the exhaustive method S = {,}. Description: S = {x | x is an even number and 0 <X <10 };

Features of a set: deterministic, heterosexual, and sequent

How many digits are required for 1000 different encodings? Repeated log21000 bytes = 10 Characters

How many different encodings can be represented by 10 bits? 10-bit code can generate 1024 different codes.

Classic example: the half-fold algorithm makes an unreliable analogy. The network cable is broken. I don't know where the network cable is broken. The network cable is 100 meters (max). Check more.

Only a few times can we find the fault point, and use the half-fold algorithm (also called the Binary Search Method) log2 100 times

Exponent and logarithm are the basic concepts and mutual conversion processes.

 

C # knowledge point: Interface Icomparable, IEnumerable, IEnumberator, ICollection, IDictionary, IList

, Packing and unpacking, generic

 

To be continued ......

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.