YuezhenQin / javase

Implement Data Structures and Algorithms (Sorting, Searching, Greedy, DP) from Sketch
2 stars 1 forks source link

Wrap Up: Data Structures #25

Closed YuezhenQin closed 10 months ago

YuezhenQin commented 10 months ago

Q:什么是数据结构? A:数据结构定义了一种性质并维护这种性质。 Q:有没有一种完美的数据结构可以搞定所有事情啊? A:很遗憾地告知您: 并没有,所以要努力学习下面的内容呢!

YuezhenQin commented 10 months ago

In the most basic terms, a data structure is a format for organizing data. In practical terms, we can split data structures into two things: the interface and the implementation.

YuezhenQin commented 9 months ago

The interface is like a contract that specifies how we can interact with the data structure - what operations we can perform on it, what inputs it expects, and what outputs we can expect.

Map

void add(K, V); V remove(K); boolean contains(K); V get(K), V getOrDefault(K, V); void set(K, V); int getSize(); boolean isEmpty();

YuezhenQin commented 9 months ago

The implementation is the code that actually makes the data structure work. This is where the details of how the data is stored and how the operations are performed come into play. For example, the implementation of a dynamic array might involve allocating memory for the list, tracking the size, and rearranging the elements when an operation like remove is called.