Reprinted data structure and Algorithm

Source: Internet
Author: User

From: http://hi.baidu.com/technical/blog/item/406416a4c8a77bfd9052eed9.html


 

Data structures and algorithms. The content of this part is actually very huge, and it is not easy to cover it all. School
During the course of study, we may need to learn every structure and algorithm, but when looking for a job for a written test or an interview, we need to examine a person's ability in this area in a short time, I have not asked every structure or algorithm.
Reality. Therefore, the actual situation is that enterprises generally look at some seemingly basic concepts and algorithms, or some variants, and then let you implement them. It may seem simple, but if it really makes you put it on paper or
You can quickly complete an algorithm on the computing machine, design test cases, and finally run it, and you will find it difficult. This requires us to be familiar with common algorithms, especially those seemingly simple.
Algorithms, which are widely used, require us to have a solid grasp and improve work efficiency in practical work. Complex algorithms can be quickly implemented through analysis and solid basic skills.
Development.

If you have less time to talk about it, go to the topic below.

I. Data Structure

1. Differences between arrays and linked lists. (It's very simple, but it's common. Remember to answer all questions)

In C ++, Arrays can be used to process data of the same data type. However, dynamic definition of large arrays is not allowed.
Small, that is, the size of the array must be determined before the array is used. In practical applications, before using an array, you sometimes cannot accurately determine the size of the array. Instead, you can define the array to a sufficient size. In this way, some space in the array is
May not be used, resulting in a waste of memory space. A linked list is a common form of data organization, which is implemented by dynamically allocating memory. You can use new to allocate memory when needed.
Delete releases allocated space without wasting memory.
  
Slave
Logical Structure: The array must have a fixed length (number of elements) defined in advance, and cannot adapt to the dynamic increase or decrease of data, that is, the size of the array cannot be changed once defined. When data increases
The number of elements. when data is reduced, memory is wasted. The linked list dynamically stores and distributes data to adapt to the situation where data is dynamically increased or decreased, and data can be conveniently inserted or deleted. (Insert or delete an array
To move other data items ).
  
From the perspective of memory storage: (static) the array allocates space from the stack (in the heap created with NEW), which is convenient and fast for programmers, but has a small degree of freedom. The linked list allocates space from the heap, it has a high degree of freedom, but it is troublesome to apply for management.

In terms of access methods, arrays are stored continuously in the memory. Therefore, subscripts can be used for random access. linked lists are chained storage structures, when accessing elements, you can only access them in a linear way from the front to the back, so the access efficiency is lower than the array.

2. operations on the linked list, such as the reverse operation of the linked list, the judgment of the Existence loop of the linked list (fast and slow pointer), two-way linked list, and related operations on the linked list.

3. Queue (for example, priority queue) and stack application. (For example, a queue is used in a message queue and a stack is used in recursive calls)

4. Basic operations on Binary Trees

Three traversal methods of a binary tree (pre-order, middle-order, and post-order) and their recursive and non-recursive implementations are mainly applied to the three traversal methods (such as suffix expressions ). The time complexity of related operations.

5. String-related

Integer, conversion between floating point and string (atoi, atof, itoa)

Check for exceptions when copying strings, such as null pointers, string overlapping, auto-assigned values, and string Terminator '\ 0.

Ii. Algorithm

1. Sorting Algorithm:

Sorting can be regarded as the most basic and commonly used algorithm, and is also the most common algorithm in the written test interview. Basic
You can use the code to implement the Bubble sorting, select sorting, and insert sorting quickly. These mainly evaluate your actual encoding capabilities. Heap sorting, Merge Sorting, and fast sorting. These algorithms need to be familiar with the main ideas and needs
Note the details. Be familiar with the time and space complexity of common sorting algorithms.

Summary of the Use scope of various sorting algorithms: (1) when the data size is small, you can use a simple sorting algorithm.
For example, directly insert or directly select sorting. (2) When the initial state of the file is basically ordered, you can directly Insert the sort or bubble sort. (3) When the data size is large, a fast sorting algorithm is applied. Yes
To consider using quick sorting. When records are randomly distributed, the average time in the fast sorting is the shortest, but the worst case may occur. The time complexity is O (n ^ 2) and the recursive depth is n, stack space required
Ask O (n ). (4) Heap sorting does not have the worst case like fast sorting, and the auxiliary space required for heap sorting is less than fast sorting. However, these two algorithms are not stable. If the sorting is required to be stable, you can use
And sort. (5) Merge Sorting can be used for internal sorting or external sorting. In external sorting, multiple channels are usually used to merge long and smooth strings to generate long initial strings, which improves host and peripheral
To reduce the number of times of access to external storage and improve the efficiency of external sorting.

2. Search Algorithms

Proficient in writing or coding binary search programs on the computer.

3. hash Algorithm

4. Some algorithm design ideas.

Greedy algorithms, divide and conquer algorithms, Dynamic Planning Algorithms, randomization algorithms, and backtracking algorithms. These can be reviewed based on specific examples.

5. STL

STL (Standard Template
Library) is a data structure and algorithm Library implemented using the template Technology in the C ++ field and has been included in the C ++ standard Library. The
Vecor, list, stack, queue and other structures not only have more powerful functions, but also have higher security. In addition to the data structure, STL also contains a generalized iterator and runs in
Various practical algorithms on the iterator. These requirements for performance are not too high, but it is tempting to implement the algorithm application from the underlying layer.

From: http://hi.baidu.com/technical/blog/item/406416a4c8a77bfd9052eed9.html


 

Data structures and algorithms. The content of this part is actually very huge, and it is not easy to cover it all. School
During the course of study, we may need to learn every structure and algorithm, but when looking for a job for a written test or an interview, we need to examine a person's ability in this area in a short time, I have not asked every structure or algorithm.
Reality. Therefore, the actual situation is that enterprises generally look at some seemingly basic concepts and algorithms, or some variants, and then let you implement them. It may seem simple, but if it really makes you put it on paper or
You can quickly complete an algorithm on the computing machine, design test cases, and finally run it, and you will find it difficult. This requires us to be familiar with common algorithms, especially those seemingly simple.
Algorithms, which are widely used, require us to have a solid grasp and improve work efficiency in practical work. Complex algorithms can be quickly implemented through analysis and solid basic skills.
Development.

If you have less time to talk about it, go to the topic below.

I. Data Structure

1. Differences between arrays and linked lists. (It's very simple, but it's common. Remember to answer all questions)

In C ++, Arrays can be used to process data of the same data type. However, dynamic definition of large arrays is not allowed.
Small, that is, the size of the array must be determined before the array is used. In practical applications, before using an array, you sometimes cannot accurately determine the size of the array. Instead, you can define the array to a sufficient size. In this way, some space in the array is
May not be used, resulting in a waste of memory space. A linked list is a common form of data organization, which is implemented by dynamically allocating memory. You can use new to allocate memory when needed.
Delete releases allocated space without wasting memory.
  
Slave
Logical Structure: The array must have a fixed length (number of elements) defined in advance, and cannot adapt to the dynamic increase or decrease of data, that is, the size of the array cannot be changed once defined. When data increases
The number of elements. when data is reduced, memory is wasted. The linked list dynamically stores and distributes data to adapt to the situation where data is dynamically increased or decreased, and data can be conveniently inserted or deleted. (Insert or delete an array
To move other data items ).
  
From the perspective of memory storage: (static) the array allocates space from the stack (in the heap created with NEW), which is convenient and fast for programmers, but has a small degree of freedom. The linked list allocates space from the heap, it has a high degree of freedom, but it is troublesome to apply for management.

In terms of access methods, arrays are stored continuously in the memory. Therefore, subscripts can be used for random access. linked lists are chained storage structures, when accessing elements, you can only access them in a linear way from the front to the back, so the access efficiency is lower than the array.

2. operations on the linked list, such as the reverse operation of the linked list, the judgment of the Existence loop of the linked list (fast and slow pointer), two-way linked list, and related operations on the linked list.

3. Queue (for example, priority queue) and stack application. (For example, a queue is used in a message queue and a stack is used in recursive calls)

4. Basic operations on Binary Trees

Three traversal methods of a binary tree (pre-order, middle-order, and post-order) and their recursive and non-recursive implementations are mainly applied to the three traversal methods (such as suffix expressions ). The time complexity of related operations.

5. String-related

Integer, conversion between floating point and string (atoi, atof, itoa)

Check for exceptions when copying strings, such as null pointers, string overlapping, auto-assigned values, and string Terminator '\ 0.

Ii. Algorithm

1. Sorting Algorithm:

Sorting can be regarded as the most basic and commonly used algorithm, and is also the most common algorithm in the written test interview. Basic
You can use the code to implement the Bubble sorting, select sorting, and insert sorting quickly. These mainly evaluate your actual encoding capabilities. Heap sorting, Merge Sorting, and fast sorting. These algorithms need to be familiar with the main ideas and needs
Note the details. Be familiar with the time and space complexity of common sorting algorithms.

Summary of the Use scope of various sorting algorithms: (1) when the data size is small, you can use a simple sorting algorithm.
For example, directly insert or directly select sorting. (2) When the initial state of the file is basically ordered, you can directly Insert the sort or bubble sort. (3) When the data size is large, a fast sorting algorithm is applied. Yes
To consider using quick sorting. When records are randomly distributed, the average time in the fast sorting is the shortest, but the worst case may occur. The time complexity is O (n ^ 2) and the recursive depth is n, stack space required
Ask O (n ). (4) Heap sorting does not have the worst case like fast sorting, and the auxiliary space required for heap sorting is less than fast sorting. However, these two algorithms are not stable. If the sorting is required to be stable, you can use
And sort. (5) Merge Sorting can be used for internal sorting or external sorting. In external sorting, multiple channels are usually used to merge long and smooth strings to generate long initial strings, which improves host and peripheral
To reduce the number of times of access to external storage and improve the efficiency of external sorting.

2. Search Algorithms

Proficient in writing or coding binary search programs on the computer.

3. hash Algorithm

4. Some algorithm design ideas.

Greedy algorithms, divide and conquer algorithms, Dynamic Planning Algorithms, randomization algorithms, and backtracking algorithms. These can be reviewed based on specific examples.

5. STL

STL (Standard Template
Library) is a data structure and algorithm Library implemented using the template Technology in the C ++ field and has been included in the C ++ standard Library. The
Vecor, list, stack, queue and other structures not only have more powerful functions, but also have higher security. In addition to the data structure, STL also contains a generalized iterator and runs in
Various practical algorithms on the iterator. These requirements for performance are not too high, but it is tempting to implement the algorithm application from the underlying layer.

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.