Python data structures and algorithms (a): Introduction

Note: Bloggers start today updated data structures and algorithms, using the Python language, involving basic data structures, ten sorting algorithm, recursive divide and conquer, greedy move return, etc., is intended to study data structures and algorithms to help you more easily and further combing knowledge points.

table of Contents

First, what is the data structure

1. The logical structure of the data

2. The physical structure of the data

Second, what is the algorithm

1. Definition of the algorithm

2. Characteristics of the algorithm

3. algorithm design requirements


First, what is the data structure

Data structure is the operation target programming problems a study in non-numerical calculation, and the subject-related issues of the relationship between them and operation. Simple, it is a collection of data structures is the relationship that exists between each data element of one or more specific relationship. Traditionally, our data structure is divided into logical and physical structure:

  • Logical structure: it refers to the relationship between data objects in the data elements, but also our concerns and discuss the future of most need.

  • Physical structure: storage means in the form of a logical structure of data in a computer.

1. The logical structure of the data

Collection structure :

Tree:

Linear structure:

Graphic structure:

2. The physical structure of the data

According to the definition of the physical structure of our research it is actually how the data elements stored in the computer's memory . The memory for the main memory is concerned, the external memory data organization as a hard disk, floppy disk, optical disk, etc. usually used to describe the file structure. Data storage structure in the form of two elements: sequential storage and chain stores.

  • Sequential storage structure: is the address of the data elements stored in contiguous memory locations, the relationship between the physical and logical relationships whose data are consistent .

  • Storage Structure: the data element is stored in an arbitrary storage unit, the group of memory cells which may be continuous or may be discontinuous.

Obviously, it says so data elements stored relationship chain storage structure does not reflect its logic, it is necessary to store the address data elements using a pointer, this way you can find the location by address associated data elements

Second, what is the algorithm

1. Definition of the algorithm

Describe a specific algorithm to solve the problem solution step, expressed as a finite sequence of instructions in a computer, and each represents one or more instruction operations .

问题:1+2+…+99+100

Direct use of the accumulated solution intuitively:

sum = 0
for i in range(1,101):
    sum += i
print(i)

You may also change a written ~

begin = 1, end = 100
n = end – begin + 1
print((begin+end)*n/2)

2. The algorithm properties

算法具有五个基本特征:输入、输出、有穷性、确定性和可行性。

输入:算法具有零个或多个输入。

输出:算法具有零个或多个输出。

有穷性:指算法在执行有限的步骤之后,自动结束而不会出现无限循环,并且每一个步骤在可接受的时间内完成。

确定性:算法的每一个步骤都具有确定的含义,不会出现歧义。算法在一定条件下,只有一条执行路径,相同的输入只能有唯一的输出结果。

可行性:算法的每一步都必须是可行的,也就是说,每一步都能够通过执行有限次数完成。

3.算法设计的要求

算法并不是唯一的。也就是说同一个问题,可以有多种解决问题的算法,要灵活运用。

a)正确性

b)可读性

c)健壮性

d)时间效率高和存储量低(时间复杂度和空间复杂度)

 

相应面试题可参考如下内容:

BAT大厂数据分析面试经验:“高频面经”之数据分析篇

BAT大厂数据挖掘面试经验:“高频面经”之数据结构与算法篇

BAT大厂数据开发面试经验:“高频面经”之大数据研发篇

BAT大厂机器学习算法面试经验:“高频面经”之机器学习篇

BAT大厂深度学习算法面试经验:“高频面经”之深度学习篇

发布了60 篇原创文章 · 获赞 18 · 访问量 1万+

Guess you like

Origin blog.csdn.net/qq_36936730/article/details/104573312