Welcome! I'm LIUeng, Frontend Developer Engineer from HangZhou, China
📔 Full stack engineer
📕 Focus on the technology community
📗 Focus AI
📘 Make career plans
⏰ Be in progress...
alogrithm clock in
Welcome! I'm LIUeng, Frontend Developer Engineer from HangZhou, China
📔 Full stack engineer
📕 Focus on the technology community
📗 Focus AI
📘 Make career plans
⏰ Be in progress...
将某个变量赋值给指针,实际上就是将这个变量的地址赋值给指针,或者反过来说,指针中存储了这个变量的内存地址,指向了这个变量,通过指针就能找到这个变量
警惕指针丢失和内存泄漏
加入哨兵
思考
数组是一种线性表数据结构,它用一组连续的内存空间,来存储一组类型相同的数据
// data_type_size 存储的类型数据大小
a[i]_address = base_address + i + data_type_size
时间复杂度为O(1):数组支持随机访问,支持下标随机访问
插入操作
删除操作
C语言数组越界,会一直处于死循环(了解C语言越界问题)
int main(int argc, char* argv[]){
int i = 0;
int arr[3] = {0};
for(; i<=3; i++){
arr[i] = 0;
printf("hello world\n");
}
return 0;
}
a[k]_address = base_address + k * type_size
a[k]_address = base_address + (k - 1) * type_size
a[i][j]_address = base_address + (i * n + j) * type_size
JVM标记清除算法:
大多数主流虚拟机采用可达性分析算法来判断对象是否存活,在标记阶段,会遍历所有 GC ROOTS,将所有 GC ROOTS 可达的对象标记为存活。只有当标记工作完成后,清理工作才会开始。
不足:1.效率问题。标记和清理效率都不高,但是当知道只有少量垃圾产生时会很高效。2.空间问题。会产生不连续的内存空间碎片。
复杂度分析
所有代码的执行时间T(n)与每行代码的执行次数成正比
T(n) = O(f(n))
大O时间复杂度表示法
代码执行时间随数据增长的变化趋势(渐进时间复杂度-时间复杂度)
只关注循环次数最多的那一段代码
加法法则:总复杂度等于量级最大的那段代码的次数
乘法法则:嵌套代码等于嵌套内外代码复杂度的乘积
常见时间复杂度大O表示法
// 全局变量,大小为10的数组array,长度len,下标i。
int array[] = new int[10];
int len = 10;
int i = 0;
// 往数组中添加一个元素
void add(int element) {
if (i >= len) { // 数组空间不够了
// 重新申请一个2倍大小的数组空间
int new_array[] = new int[len*2];
// 把原来array数组中的数据依次copy到new_array
for (int j = 0; j < len; ++j) {
new_array[j] = array[j];
}
// new_array复制给array,array现在大小就是2倍len了
array = new_array;
len = 2 * len;
}
// 将element放到下标为i的位置,下标i加一
array[i] = element;
++i;
}
最好时间复杂度是:O(1) 数组空闲时,直接插入对应的下标
最坏时间复杂度是:O(n) 数组非空闲时,申请两倍大小,遍历2*n次,常数阶忽略
均摊时间复杂度:O(1) 每2n次遍历之后连续接n-1次O(1)操作
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.