# Tianke Youke

A Base for Secreting and Running at Night

0%

11月平均每日阅读43分钟，最高一天阅读4小时，总共21个小时。这意味着，这30天里，我大约有一整天的人生活在书里的世界。幸甚至哉！

In IT5003, I am studying data structures and algorithms. The language we learn with is Python. So I take notes about what I learned, and how to use them in Python. I struct my notes based on data structures, and all the ADTs that are implemented by the data structures are discussed within. I focus on their usage, key design, and sometimes problems. In the future maybe I will append all the implementation codes.

• ADT: Abstract data type, from the point of view of a user, defined by its behavior.
• Data Structure: from the point of view of an implementer, concrete representations of data.

# Linear Data Structures

## Searching and Sorting

### Searching algorithms

Search things in a list:

• if the list doesn't change frequently, better to sort first, then use binary-search everytime.

## Function

### Function Decorator

decorator equals to: foo = track(foo)

# Iterable/Sequences

Strings, ranges, lists and tuples.

“An iterable which supports efficient element access using integer indices via the __getitem__ special method and defines a __len__ method that returns the length of the sequence.”

• use one index to fetch item in a list, the index can't out of the range; but if use slice method, then you can do it out of the range, because the slice will autolly find the greediest indexs.

• assigning a list to another list, like a = b, makes a and b refers to the same list. And a list is mutable. So if we change a, then b will also be affected. It's called alias. Do avoid this.

• Tuple also has order. Just it's immutable.

• Fxxxk, Tuple and Set are different things! A set is like {1, 2, 3}, that is what I thought as not ordered and not duplicated. And a set has intersection() union() difference() symmetric_difference().

To delete items in a set:

• you can insert an interable in a list's slice, though they have different length!

• list() takes an iterable, and makes it a list;

str() shows you the whole object's look.

• range() is also an iterable. It can be slicing, and len()

• a, b = b, a: the b, a on the right firstly is packed into tuple: (b, a), then it is unpacked and individually assigned to each var on the left