Question 1: Learn data structures and algorithms from scratch

Author: Zen and the Art of Computer Programming

1 Introduction

: Data structures and algorithms are essential basic courses for everyone with a computer science background. But even at work, it is difficult not to be exposed to relevant knowledge. Then, this article will start from scratch and lead you to learn data structures and algorithms, and truly master their essence!

2. What are data structures and algorithms?

Data Structures and Algorithms are indispensable basic homework for every programmer. They are abstract methods used to solve problems. For example, if you want to process some complex data, or need to perform the same operation repeatedly, the first thing you should consider is what kind of data structure to use to store the data, and then choose an algorithm to operate on the data. There are four main aspects involved: 1. The logical relationship of data elements; 2. The relationship between data elements; 3. Access methods to data; 4. Data size requirements, etc. The purpose of data structure is to organize data. It is a tool in the computer to store, manage and process data. Generally speaking, data structures are divided into two major categories: one is collection types, such as arrays, stacks, queues, linked lists, etc.; the other is linear structures, such as sequence lists, heaps, trees, graphs, etc. Each data structure has its own specific application scenarios, advantages and disadvantages. Data structures can help us better understand and analyze complex problems and improve our programming efficiency. Algorithms refer to a series of instructions used to implement specific functions for processing data, such as sorting, finding, searching, string matching, etc.

3.Data structure

3.1 Array

Array is the simplest linear data structure. It uses a set of contiguous memory spaces to store multiple data items, and each data item is uniquely determined by an index. Through subscripts, we can quickly find the elements at the corresponding positions and facilitate random access to the data. Arrays have the following main properties:

  1. Orderliness: The physical storage location of the elements in the array is continuous, so it can be accessed directly through subscripts. For other linear data structures, such as stacks and queues, we cannot directly know the physical location of an element. Therefore, in some cases, we need to index based on the order in which the elements are arranged.

  2. Insertion and deletion time complexity: The time complexity of array insertion and deletion is both O(1). This is because we can determine the position of the element through the subscript and do not need to move the element. We only need to add or move at the end of the array. Just remove one element

Supongo que te gusta

Origin blog.csdn.net/universsky2015/article/details/133004291
Recomendado
Clasificación