《算法第四版》学习心得一——怎么学算法

二分查找算法实现《算法(第四版)》 最近开始看《算法(第4版)》这本书,在此记录下自己的学习心得、遇到的问题以及如何解决的。希望能够提升自己帮助他人。         刚开始看这本书遇到的第一个比较有代表性的算法就是二分查找,运用《算法》这本书所提供的工具DrJava(课本官网地址连接http://algs4.cs.princeton.edu/home/)去运行书中所给的代码时遇到一点小小的问题。书上算法源码如下: impo 阅读详情

 一、算法的两个核心

算法的核心内容实际上有两个:

  1. 算法的概念和思路。
  2. 算法的编程实现。

两者相互关联影响,缺一不可。

不理解基本概念和思路,就算把实现代码背下来,也无济于事,因为脑袋里依然是一片模糊。理解了概念和思路,不去用代码实现,脑袋里有的只是概念,无法根据真实需求实现解决方案。

二、学算法需要什么基础

  1. 首先,必须要有一定的编程语言基础,要理解语言中最基本的概念:数据类型,类,成员变量,方法,封装等等。
  2. 有了语言基础,即使没有大量的编程经验,也已经具备了学习算法的概念和思路的能力,因为概念和思路更多是考验学习者的抽象思维能力。思维能力好的人,即使没有大量的编程经历,也可以很快掌握算法的核心概念。反之,思维能力差的人,即使有了多年的编程经验,在接触到一个新算法的时候,也需要花费很长时间才能理解算法的核心概念。
  3. 理解了某个算法的概念和思路,并不意味着掌握了这个算法。在遇到真实问题的时候,它能带给你思路,但不能给你真正解决问题的能力。要想真正具备解决问题的能力,就一定要把算法实现出来。只有自己能够独立实现算法,才是真正掌握了算法。
  4. 这一步就对写代码能力提出了要求。这就相当于在问,如果我能说清楚某个逻辑过程,那我是否有能力把这个过程转化成代码呢?这是一个难倒很多初学者的要求,同时也是每个初学者不得不跨过的坎。我自己到现在也还在被这个问题困扰,但我相信,随着我不断学习和实践,实现代码的能力总是会逐步增强的。

三、怎么学?

  1. 通过前面的分析可以知道,学算法一定要先搞清楚概念和思路。没有理解算法的概念和思路就直接想实现代码,实际上是南辕北辙。因此,每当接触一个新的算法和结构是,先不要忙着去写代码,去实现。先问问自己,这个算法是在做什么呢?它是在解决什么样的问题?它是用了什么样的方法解决问题的?
  2. 反反复复思考这些问题,直到自己基本能够把问题的答案理清楚。实在想不清楚,可以借助书上的代码和图形实例帮助理解。《算法》这本书非常好的一点就是,对于书中提供的算法,基本都
数据结构学习心得总结 开篇经过近一个月的学习,终于将郝斌老师讲的数据结构视频看完了~学习完成后,受益良多,也非常喜悦,非常开心,好像终于打了一场胜仗一样!我打算将这一个月的学习心得做一个汇总,记录下来。 希望能给初学者带来信心和经验,能给大家分享这份快乐~万事开头难刚开始打算学数据结构,是因为找工作面试的时候,很多公司都要求对数据结构有了解。没办法,我只有硬着头皮学了。但是我没有任何学习思路,因为之前上课学习的时候,我 阅读详情

相关推荐

BSGS 大步小步 算法学习心得

学完才发现其实并没有那么复杂,但中间还是有很多地方困扰了我很久orz; 先安利一名神犇的博客:BSGS; 首先,大步小步的思想有点像分块,将整体划分成根号n块,再对每一小块中的根号n种取值找一个最优值; 如果看完了我安利的那篇博客的话,应该是能够自己写出随处取逆元的写法了; 但是这样的做法太慢,考虑怎么把取逆元的过程除去; 首先定义一下符号,求下式的最小整数解 ax≡b(mod&nbs...

santongding 786

关于PCA算法学习心得

关于PCA算法学习心得学习的过程中,以下链接对我帮助较大: 链接:http://blog.codinglabs.org/articles/pca-tutorial.html压缩的实质就是针对样本的属性,让单个属性的方差最大,让样本之间的协方差的为零。PCA算法的是针对原始样本的协方差C的变换,通过对协方差矩阵C的对角化,找到映射后的样本的协方差矩阵Y。需要注意的是,此时D是对角阵,从而满足了我们优

ms140429的博客 1009

四千字干货 - 十三位Java工程师的学习心得

史上最强Java学习大全,多亏我足够无耻,才从公司十三位Java程序员口中问出方法来。

BinSTD的博客 794

Python自动化测试报告:飞书群机器人消息卡片实战

本文详细介绍了如何利用Python和飞书群机器人实现自动化测试报告的智能通知。通过构建可定制的消息卡片,将测试结果(如通过数、失败数)以清晰、美观的格式自动推送至团队群聊,并支持一键跳转查看详细报告,从而显著提升团队协作与问题响应效率。

k6l7m8n9的博客 816

SDM660电源部分配置:

SDM660电源部分配置: Panel power supplies 1、Reference power supplies Description Name Regulator Voltage (V) Panel power supply 0 vddio PMIC 660/L11 1.8 Panel power supply 1 Lab PMIC 660/lab 4.6 Panel power s...

weixin_41811215的博客 4732

从时序博弈到数据稳定:CS1237驱动中的信号滤波与卡尔曼实践

本文探讨了CS1237高精度ADC驱动在复杂工业环境中的信号处理挑战,重点介绍了一阶滤波与自适应卡尔曼滤波算法的实践应用。通过参数优化和动态调整策略,有效提升了数据稳定性和抗干扰能力,为嵌入式系统在噪声环境下的精密测量提供了可靠解决方案。

rnn9storyteller的博客 868

CCF201803-2 碰撞的小球 python

一些话:已经不知道是第几次做这道题了(大概第三次吧),真的常做常新,每次都有新的细节想法。虽然方法简单粗暴,但好在方便理解,对于我这种菜鸟选手而言。 但在做的过程中,最开始还忽略了输入的小球初始位置有可能是无序的,输出的时候要保持相对位置。CCF真的考验细节,希望上考场时能够认真仔细一点。就酱… #碰撞的小球 #当小球坐标为0或L时,会朝相反方向移动 #当两个小球坐标相等时,会分别转向相反的方向 #计算t秒之后小球的位置 n,L,t = map(int,input().split()) location .

tanya_dre的博客 353

手把手教你用STM32CubeMX配置I3C通信(含动态地址分配实战)

本文提供了一份基于STM32CubeMX配置I3C通信的实战指南,重点讲解了动态地址分配的实现步骤。通过详细的工程配置、从设备枚举、CCC命令使用及数据读写示例,帮助开发者快速掌握这一高效通信协议,以替代传统的I2C或SPI接口,满足多传感器连接与低功耗设计需求。

c8d9e0f1的博客 552

切比雪夫插值

切比雪夫插值是一种基于切比雪夫节点的多项式插值方法,其优势是减少插值误差(特别是龙格现象:表现为高维插值时在边缘处插值误差骤增)。本文对其基本操作进行说明。

平和少年的博客 1650

告别AT串口线!用STM32F407的USB FS口直连EC800M进行物联网通信

本文介绍了一种创新的物联网通信方案,利用STM32F407的USB FS接口直连EC800M模块,替代传统的AT串口线连接。通过详细的硬件对比、STM32CubeMX配置和USB驱动调试步骤,展示了如何实现更高效的AT指令通信,同时降低硬件复杂度和功耗。

weixin_29189987的博客 709

淘宝母婴用品数据挖掘及可视化分析研究

1. 背景介绍 在当今的电子商务时代,母婴用品市场已经成为了各大电商平台的一片蓝海。淘宝作为中国最大的电子商务平台,其上的母婴用品交易数据自然引人关注。理解这些数据,可以帮助商家更好地制定营销策略,也可以帮助消费者更好地选择产品。因此,本文将对淘宝母婴用品的数据进行深入的挖掘和分析。 1.1 电子商务的

AI天才研究院 1262

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

上一篇: 背包、栈、队列基于数组和链表的实现
下一篇: Linux数据流重定向
illikang
博客等级 码龄9年 2191粉丝 61原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址