求索資料結構的第一性原理

sea_bean發表於2021-12-12

資料結構

指計算機儲存、組織資料的方式。

邏輯結構

指反映資料元素之間的邏輯關係的資料結構,其中的邏輯關係是指資料元素之間的前後件關係,而與他們在計算機中的儲存位置無關。

  • 線性結構:資料結構中的元素存在一對一的相互關係

  • 非線性結構

    • 集合:資料結構中的元素除了”同屬於一個集合“的相互關係外,沒有其它關係
    • 樹形結構:資料結構中的元素存在一對多的相互關係
    • 圖形結構:資料結構中的元素存在多對多的相互關係

簡單地說,線性結構就是表中各個結點具有線性關係。如果從資料結構的語言來描述,線性結構應該包括如下幾點:

1、線性結構是非空集。

2、線性結構有且僅有一個開始結點和一個終端結點。

3、線性結構所有結點都最多隻有一個直接前驅結點和一個直接後繼結點。

線性表就是典型的線性結構,還有棧、佇列和串等都屬於線性結構。

簡單地說,非線性結構就是表中各個結點之間具有多個對應關係。如果從資料結構的語言來描述,非線性結構應該包括如下幾點:

1、非線性結構是非空集。

2、非線性結構的一個結點可能有多個直接前驅結點和多個直接後繼結點。

在實際應用中,樹結構和圖結構等資料結構都屬於非線性結構。

物理結構

指資料結構在計算機中的表示(又稱映像),它包括資料元素的機內表示和關係的機內表示。由於具體實現的方法有順序、連結、索引、雜湊等多種,所以,一種資料結構可表示成一種或多種儲存結構。

資料的順序儲存結構的特點是:藉助元素在儲存器中的相對位置來表示資料元素之間的邏輯關係;非順序儲存的特點是:藉助指示元素儲存地址的指標表示資料元素之間的邏輯關係。

常用的有:

  • 順序儲存

  • 鏈式儲存

  • 索引儲存:分別存放資料元素和元素間關係的儲存方式。

    所有的儲存結點存放在一個區域。另設定一個索引區域儲存結點之間的關係。

    索引是為了加速檢索而建立的一種儲存結構。它是針對一個表而建立的,是由存放表的資料頁面以外的索引頁面組成的。每個索引頁面中的行都包含邏輯指標,通過該指標可以直接檢索到資料,這樣就會加速物理資料的檢索。例如,假設在student表的ID列上建立了一個索引,則在索引部分就有指向每個學號所對應的學生的儲存位置的資訊。

  • 雜湊儲存:亦稱“雜湊儲存”,專用於集合結構的一種儲存方式。

    資料元素存放在一塊連續的儲存區域中。資料元素的存放位置是通過一個雜湊函式計算而得的。雜湊函式將資料元素作為自變數,計算得到的函式值是資料元素的儲存地址。

資料型別

和資料結構密切相關的,它是值的集合和定義在這個值集上的一組操作的總稱。

高階語言中資料型別分為兩類:

  • 原子型別:值不可分解,是什麼就是什麼。如整型、字元型等。
  • 結構型別:其值是由若干成分按某種結構組成的,因此可分解,並且它的成分可以是原子型別也可以是結構型別。(套娃,有無限的可能)。比如陣列,其值是由若干分量組成的,每個分量可以是整數,或者也可以是陣列。

? 把資料結構想象成骨架,單單有骨架的話資料還是死的,必須再用資料型別這種肉來填充骨架,有骨有肉這樣資料才是鮮活的!

關於資料結構的奇思妙想

  • 一個因理解錯”陣列“概念而提出的很蠢的問題!

An array is an ordered collection of data elements of the same type, each constrained by n(n>=1) linear relationships. Arrays can be thought of as an extension of linear tables, a common data structure.

Because arrays generally do not do insert or delete operations, we usually use sequential storage to implement the array, that is, in memory to draw a contiguous space to store the array, the contiguous memory address also happens to be the array element number, this implementation is undoubtedly very practical and very reasonable.

However, from the point of view of the feasibility of data structures, I wanted to try to explore more possibilities.

We know that in the computer architecture of the Von Neumann system, data structures are generally stored in the machine in four ways: Sequential storage, chain storage, index storage, and hash storage. Now, can arrays be implemented using chained storage? And is there any possible practical value to this implementation?

@ Welbog

Array is, strictly speaking, a contiguous block of memory, addressed by a base index and offset indexes. The term "array" almost always refers to that specific implementation rather than an abstract data type with multiple implementations. A list is a more general ordered set and might be a more appropriate term for your situation.

陣列是線性表的順序儲存實現,不是一種跟”線性表“那樣的抽象資料結構。

相關文章