第一章、數據結構和算法綜述

數據結構:對計算機內存中數據的一種安排。包括:數組、鏈表、棧、二叉樹、哈希表等。

算法:對數據結構中的數據進行各種處理,例如查找特定項,排序等。

解決問題:現實世界中的數據存儲,以前是用索引卡片(一疊卡片)來存儲數據的,現在如果想用計算機來代替索引卡片(凡是用索引卡片的都可以用計算機代替),將會出現一些問題:

• How would you store the data in your computer’s memory?                        --建模

• Would your method work for a hundred file cards? A thousand? A million?  --擴容

• Would your method permit quick insertion of new cards and deletion of old ones?

                                                                                                                        --插入、刪除

• Would it allow for fast searching for a specified card?                                --查找                   

• Suppose you wanted to arrange the cards in alphabetical order. How would you sort them?                                                                                                                                                                                      --排序  

程序員的工具

有些數據結構只會在編程語言中用到,而不會被用戶直接使用。

現實世界的建模

數據結構的特性(圍繞查找、增加、刪除的性能)

Data Structure

Data Structure

Disadvantages

Array

Quick insertion, very

fast access if index

known.

Slow search,

slow deletion,

fixed size.

Ordered array

Quicker search than

unsorted array.

Slow insertion and

deletion, fixed size

Stack

 

Provides last-in,

first-out access.

Slow access to

other items.

Queue

Provides first-in,

first-out access

Slow access to

other items

Linked list

Quick insertion,

quick deletion.

Slow search.

 

Binary tree

Quick search, insertion,

deletion (if tree 

remains balanced).

Deletion algorithm

is complex.

 

Red-black tree

Quick search, insertion,

deletion. Tree always

balanced.

Complex.

2-3-4 tree

Quick search, insertion,

deletion. Tree always

balanced. Similar trees

good for disk storage.

Complex.

Hash table

Very fast access if

key known. Fast insertion.

Slow deletion,

access slow if key

not known, inefficient

memory usage.

Heap

Fast insertion, deletion,

access to largest item.

Slow access to

other items.

Graph

Models real-world

situations.

Some algorithms are

slow and complex.

抽象數據結構:除了數組之外的數據結構。

算法的概述:插入刪除查找,迭代查詢、排序

Summary

• A data structure is the organization of data in a computer’s memory or in a disk file.

• The correct choice of data structure allows major improvements in program efficiency.

• Examples of data structures are arrays, stacks, and linked lists.

• An algorithm is a procedure for carrying out a particular task.

• In Java, an algorithm is usually implemented by a class method.

• Many of the data structures and algorithms described in this book are most often used to build databases.(數據庫的原理看來不簡單啊)

• Some data structures are used as programmer’s tools: They help execute an algorithm.

• Other data structures model real-world situations, such as telephone lines running between cities.(電話線網和數據結構有什麼關係?也涉及到查詢)

• A database is a unit of data storage composed of many similar records.

A record often represents a real-world object, such as an employee or a car part.

• A record is divided into fields. Each field stores one characteristic of the object described by the record.

• A key is a field in a record that’s used to carry out some operation on the data.

For example, personnel records might be sorted by a LastName field.

• A database can be searched for all records whose key field has a certain value.

This value is called a search key.索引

關鍵字:當查詢一條記錄時,所使用的那個字段被稱爲(索引)關鍵字。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章