《数据结构与算法》学习之入门篇

To develop a solid understanding of a data structure requires three things: First, you must learn how the information is arranged in the memory of the computer. Second, you must become familiar with the algorithms for manipulating the information contained in the data structure. And third, you must understand the performance characteristics of the data structure so that when called upon to select a suitable data structure for a particular application, you are able to make an appropriate decision.

要点理解:
这段话的意思是,应用数据结构和算法的时候,需要注意3件事,它们也是《数据结构与算法》学习过程中需要注意的地方。
第一,需要了解信息在计算机内存中的存储方式。比如,数组存储为一块连续的内存;链表在内存中是分散的,通过指针联系相邻节点。
第二,需要了解各种算法对数据结构中存储的信息是怎么操作的。比如,不同容器的遍历方法,排序算法的原理、二分法搜索算法的原理等。
第三,需要了解各种数据结构对不同的操作的性能特性。比如,数组支持随机访问,但插入和删除元素效率较低;链表不支持随机访问,需要逐个元素迭代访问,但插入和删除效率比数组高。

Objects  are used to combine data with the procedures that operate on that data. The main advantage of using objects is that they provide both  abstraction  and  encapsulation .

Abstraction can be thought of as a mechanism for suppressing irrelevant details while at the same time emphasizing relevant ones. An important benefit of abstraction is that it makes it easier for the programmer to think about the problem to be solved.

For example, procedural abstraction lets the software designer think about the actions to be performed without worrying about how those actions are implemented. Similarly, data abstraction lets the software designer think about the objects in a program and the interactions between those objects without having to worry about how those objects are implemented.

There are also many different levels of abstraction. The lower the levels of abstraction expose more of the details of an implementation whereas the higher levels hide more of the details.

Encapsulation aids the software designer by enforcing information hiding. Objects encapsulate data and the procedures for manipulating that data. In a sense, the object hides the details of the implementation from the user of that object.

There are two very real benefits from encapsulation--conceptual and physical independence. Conceptual independence results from hiding the implementation of an object from the user of that object. Consequently, the user is prevented from doing anything with an object that depends on the implementation of that object. This is desirable because it allows the implementation to be changed without requiring the modification of the user's code.

Physical independence arises from the fact that the behavior of an object is determined by the object itself. The behavior of an object is not determined by some external entity. As a result, when we perform an operation on an object, there are no unwanted side-effects.


要点理解:

这段话的意思是,面向对象程序设计的最主要的优势是抽象(abstraction)和封装(encapsulation)。抽象的好处是让程序员能够暂时忽略细节(如实现),集中精力去考虑解决问题的方法,类似于创造一个理想模型。抽象分为过程抽象和数据抽象,过程抽象比如函数接口,迭代器等,数据抽象如类型模板等。此外,抽象根据暴露实现细节的不同,又分不同层次。封装也是隐藏实现细节,它的好处是“概念独立”和“物理独立”。我的理解就是让程序更容易模块化,各个模块相互独立,这个是概念独立;而物理独立是对象的完整性,换句话说,不依赖外部输入,它是一个闭包。



你可能感兴趣的:(《数据结构与算法》学习之入门篇)