Football Joke

Bud Wilkinson, former football coach at the University of Oklahoma, was in Dallas for a series of lectures on physical fitness. A TV reporter interviewed him about the President’s physical fitness program and asked: “Mr Wilkinson, what would you say is the contribution of modern football to physical fitness?” The reporter expected a lengthy speech.

As if he had been waiting 30 years for this question, he said, “Absolutely nothing.”

The young reporter stared and squirmed and finally stuttered, “Would you care to elaborate on that?”

Wilkinson said, “Certainly. I define football as 22 men on the field who desperately need rest and 50,000 people in the stands who desperately need exercise.

记者问俄克拉荷马大学足球教练布得·W,足球对体育锻炼有何贡献?

“绝对没有”,布得立即回答。

“绝对没有?”吃惊的记者问,“你能说得详细一点吗?”

“当然”,布得说,“我认为足球是二十二个需要休息的人在场上拼命地跑,而五万个需要运动的人却坐在那里看。

七牛许式伟的感言

  • 我为谁提供服务的认知,比我是哪个领域的程序员(工种认知)更重要
  • 有些程序员只关心技术,而不关心业务,我认为这会制约他们的发展,所以才给了这样的忠告。只关心技术的人很快就会遇到成长的天花板。
  • 大部分人学习的时候太功利,不太重视学习基本功,比如编译原理。事实上我认为编译原理是非常非常重要的一门基础知识。某种程度上说可能是名字不够好,我个人更喜欢把这个领域叫做文本处理。
  • 没有正确的编程语言,只有合适自己的语言。选择语言需要基于你对要解决的问题域的理解而做出抉择。当然,这事也和品味有关,不同语言实际上体现的是创始人的个性。不少程序员喜欢把语言看做阵营。我个人没有这种想法,语言说白了只是个工具。
  • 学习新语言的最好办法是实践。你用它写几个程序解决你实际生产环境你遇到的问题,这比任何方式都有效。我记得我第一个C语言程序是在DOS环境下模仿实现了一个doskey,这个东西挺复杂,涉及编辑器、TSR驻留这些领域知识,一个程序写下来有好几千行。这就是我自己的学习方法。

Wolfram MathWorld selected

Recreational Mathematics

Beast Number
http://mathworld.wolfram.com/BeastNumber.html

Hardy-Ramanujan Number
http://mathworld.wolfram.com/Hardy-RamanujanNumber.html

Tangram
https://mathworld.wolfram.com/Tangram.html

Magic Square
https://mathworld.wolfram.com/MagicSquare.html

Pythagorean Square Puzzle
https://mathworld.wolfram.com/PythagoreanSquarePuzzle.html

Tic-Tac-Toe
https://mathworld.wolfram.com/Tic-Tac-Toe.html

Chess
https://mathworld.wolfram.com/Chess.html

Go
https://mathworld.wolfram.com/Go.html

Poker
https://mathworld.wolfram.com/Poker.html

Dice
https://mathworld.wolfram.com/Dice.html

Bowling
https://mathworld.wolfram.com/Bowling.html

Icosian Game
https://mathworld.wolfram.com/IcosianGame.html

Maze
https://mathworld.wolfram.com/Maze.html

String Figure
https://mathworld.wolfram.com/StringFigure.html

Illusions

Ambihelical Hexnut
https://mathworld.wolfram.com/AmbihelicalHexnut.html

Angle Illusions
https://mathworld.wolfram.com/AngleIllusions.html

Benham’s Wheel
https://mathworld.wolfram.com/BenhamsWheel.html

Bullseye Illusion
https://mathworld.wolfram.com/BullseyeIllusion.html

Café Wall Illusion
https://mathworld.wolfram.com/CafeWallIllusion.html

Continuous Line Illusion
https://mathworld.wolfram.com/ContinuousLineIllusion.html

Delboeuf Illusion
https://mathworld.wolfram.com/DelboeufIllusion.html

Ehrenstein Illusion
https://mathworld.wolfram.com/EhrensteinIllusion.html

Fraser’s Spiral
https://mathworld.wolfram.com/FrasersSpiral.html

Freemish Crate
https://mathworld.wolfram.com/FreemishCrate.html

Goblet Illusion
https://mathworld.wolfram.com/GobletIllusion.html

Hering Illusion
https://mathworld.wolfram.com/HeringIllusion.html

Illusory Contour Figures
https://mathworld.wolfram.com/IllusoryContourFigures.html

Impossible Fork
https://mathworld.wolfram.com/ImpossibleFork.html

开源GIS

Server

开源GIS服务器主要有map server和geo server。

Map server

Map server有两个版本,完全免费的那个那个版本是由明尼苏达大学开发的,全部是用C语言完成,效率很高可以媲美ARCGIS SERVER,并且支持我所知道的所有GIS数据源,但是相对来说简陋一些,并且没有内置AJAX支持。而map server的企业版本来是auto desk公司的map guide,这个版本功能很强大,而且还有IDE支持,当然IDE也有两个版本(付费的和不付费的),此外auto desk还封装了很多AJAX组建,因此这个版本可以说是真的企业级支持了。

GEO SERVER

而 geo server则是另外的选择了,它是基于JAVA平台做的,安装时需要JDK1.4(高版本的也不行),其功能上和map server的完全免费版类似,但是性能上次之,只是如果对跨平台要求比较高的话,可以考虑使用它。

Client

桌面GIS

QGIS和GRASS是很好的桌面GIS,当然基于ECLIPSE平台的UDIG也是另外一个选择。QGIS 的最大特点在于界面很友好,熟悉ARCGIS的人都能很快的掌握QGIS的操作,另外QGIS对WMS的支持也不错。再者QGIS可以无缝集成 POSTGIS,最后QGIS几乎完全照搬了GRASS的分析功能,因此其分析功能也很强大。GRASS本是美国军方开发的GIS,开源后一直受到美国大学老师们的青睐,它可以提供很多ARCGIS能提供的分析功能(当然每一种功能可选的算法没后者多),但是GRASS的界面比较丑陋,很多功能需要手动运行命令,因此不太适合大多数人用。基于eclipse平台的UDIG是桌面GIS的又一个选择,由于它是基于eclipse平台的,运行起来比较慢一点,而且比较耗内存。与前两者相比,它的优势在于操作的简单性,而且支持很多种空间数据源,包括很多商业空间数据库,缺点主要是分析功能比较弱。不过现在 UDIG发展很迅速,也建议尝试一下。

OpenLayers for Javascript

OpenLayers 是由 MetaCarta公司开发的, 用于WebGIS客户端的JavaScript包,目前的最高版本是2.5 V,通过BSD License 发行。它实现访问地理空间数据的方法都符合行业标准,比如OpenGIS的WMS和WFS规范, OpenLayers采用纯面向对象的JavaScript方式开发,同时借用了Prototype框架和Rico库的一些组件。

空间数据库

开源的空间数据库主要是postgresql和mysql的空间插件,分别是postGIS和 mySpatial。由于PG对于面向对象支持的更好一些,所以postGIS在性能上和功能上都比myspatial要强一些。但是两者都有一个最重要的缺陷,就是不直接支持栅格数据。解决方案是将栅格数据存储为BLOB类型,并且对其建立四叉树索引,用以模拟商业数据库对栅格数据的存储。相对来说我更喜欢POSTGIS一些,原因有三:1,MYSQL本身不是在所有情况下免费,而PG在所有情况下都免费;2,POSTGIS性能和功能上都强于 myspatial;3,国外已经有很多基于POSTGIS的成功应用,可以降低风险。


码农话题

Algorithms + Data Structures = Programs

Five Pervasive Myths About Older Software Developers
http://www.lessonsoffailure.com/developers/pervasive-myths-older-software-developers/

Where Do The World’s Software Developers Live?
https://www.benfrederickson.com/github-developer-locations/

Why Do Some Programming Languages Live and Others Die?
https://www.wired.com/2012/06/berkeley-programming-languages/

Twenty Questions for Donald Knuth
http://www.informit.com/articles/article.aspx?p=2213858

John Carmack discusses the art and science of software engineering
https://blogs.uw.edu/ajko/2012/08/22/john-carmack-discusses-the-art-and-science-of-software-engineering/

It’s about social interactions between the programmers or even between yourself spread over time.

软件工程实际是一门社会科学

在计算机学科中,真正谈得上科学的只有算法,“优化”也只能算工程。然而,真正花在算法及其优化上的时间在编程中所占比例很小。90%程序员所做的只是将功能需求以顺序、分支这样的程序形式实现出来。在这方面,我越来越不觉得有什么客观的方法能带来更好的软件。

自然科学的根本在于测量和重现,在于估计和验证。软件工程中除算法和优化外,其他与此毫无关系。相反,它们只跟程序员之间,甚至同一程序员在不同时间,自己跟自己之间的社会化交互有关。程序员总在不断犯错,这已是老生常谈的事实。问题就在于,如果一种错误的做法能以正确的语法形式输入到程序中,那它就肯定会进入我们的程序。因为这个,我本人对静态代码分析极度热衷。因为我们总在不断犯错,我宁愿使用编程语言的一个更为严格的子集,并对程序员写的代码施以更加严格的限制。

最近一段时间,我开始坚持每天做一点代码复查。每天看看提交的代码,找点有启发性的问题给团队讲一讲。有些问题,例如最大限度地保持参数的常量性,相对客观,争议较少。但也有很多东西更像风格问题,虽然多年来我发现它们不断地带来麻烦,但仍有很多人说:“我没见过这样的问题,对我来说这不是问题,我也不会犯这种错误。”因此,能够找到一个实际例子来指出“这就是由它引发的问题”,真是件好事。

意识到软件工程并非科学之后,我希望找到更好的方法来对付人性的弱点。然而,考虑到铁打的团队流水的开发者,想用一致的方法培训团队谈何容易。应对程序员犯错的方法肯定有好坏之分,但很难量化。而且代码会存在很长时间,将有成百上千的程序员看到一段代码,使用它并以某种方式与之交互。

除了通过静态代码分析实施严格限制外,在软件API设计的层面上还有规模更大的问题,艺术的、技术的都有,我希望能在这方面找到更多可量化的方法。

我们正处在一个激进的后开源时代:开源的过去和未来

We’re in a brave, new post open source world

谈谈技术选型
http://www.infoq.com/cn/news/2017/02/Technology-selection

John Carmack discusses the art and science of software engineering

What I heard instead was a hacker’s hacker talk about his recent realization that ** software engineering is actually a social science **.

It’s about social interactions between the programmers or even between yourself spread over time.

John Carmack discusses the art and science of software engineering (2012) (uw.edu)

http://bellard.org
Fabrice Bellard 法国著名的计算机程序员 http://www.bellard.org
FFMPEG, the Open Source Multimedia System. I launched this project in year 2000 and led it for several years.
QEMU is a generic machine emulator and virtualizer.
2000年,他化名Gérard Lantau,创建了FFmpeg项目。

Fabrice Bellard,5年前的FFmpeg政变之夜依稀在眼前

FFmpeg官网上有一个很有意思的耻辱柱(Hall of shame),专门用来列举那些偷用了FFmpeg开源代码却违背FFmpeg遵守的开源协议,也就是说没有在软件发行中进行代码使用的声明,甚至还恬不知耻的表示自主研发。国内几乎所有的播放器和转码工具都在这个耻辱柱上,比如QQ影音、暴风影音、格式工厂等。

https://ffmpeg.org/shame.html

Hall of Shame: companies violating the ffmpeg license (GPL/LGPL) (ffmpeg.org)

FFmpeg Hall of Shame

John Carmack discusses the art and science of software engineering

But those don’t actually occupy that much of the total time spent programming.

It’s about social interactions between the programmers or even between yourself spread over time.

these are all conventions that help software engineering in the large when you’re dealing with mistakes that people make. But they’re not fundamental about what the computer’s doing.

programmers are making mistakes all the time and constantly.

I would like to be able to enable even more restrictive subsets of languages and restrict programmers even more because we make mistakes constantly.

but a lot of people will just say, I’ve never seen that problem. That’s not a problem for me, or I don’t make those mistakes.

there are clearly better and worse ways of doing things but it’s frustratingly difficult to quantify.

It’s kind of fun to think that the game engines, things that we’re playing games on, have more sophisticated software than certainly the things that launch people to the moon and back

I tell people that there’s a good chance that whatever you’re writing here, if it’s not extremely game specific, may well exist a decade from now and it will have hundreds of programmers, looking at the code, using it, interacting with it in some way, and that’s quite a burden.

未来属于算法,而不是代码

编码作为新数字经济的关键技能,就像学习如何阅读一样,已经模糊了我们对算法的理解。算法正逐渐成为我们生活的组成部分,从电影推荐到新闻过滤和寻找合作伙伴。

github

The Impact GitHub is Having on Your Software Career, Right Now…

I spent 2004–2014 working at Red Hat, the world’s largest open source software engineering company. On my very first day there, in July 2004, my boss Marty Messer said to me: “All the work you do here will be in the open. In the future you won’t have a CV — people will just Google you.”

GitHub has become a singular social network that ties together issue tracking and distributed source control.

GitHub is a social network where your social capital, created by your commits and contribution to the global conversation in whatever technology you are working, is yours — not tied to the company you happen to be working at temporarily.

Smart people will take advantage of this — they’ll contribute patches, issues, and comments upstream to the languages and frameworks that they use on the daily in their job — TypeScript, .NET, Redux.

Now that same pathway is open for everyone, into just about any technology. As the world is eaten by open source, the same dynamic is now prevalent everywhere.

In a recent interview Linus Torvalds (49k followers, following 0 on GitHub), the inventor of Linux and git, put it like this:
“You shoot off a lot of small patches until the point where the maintainers trust you, and at that point you become more than just a guy who sends patches, you become part of the network of trust”

However, if that work has been on GitHub, it’s not gone. It’s visible. It’s connected to a network of trust that is visible.

It’s not your code on GitHub that counts — it’s what other people say on GitHub about your code that counts.

That’s your portable reputation.

四五十岁之后,还在编程的程序员都有谁
SOFTWARE DEVELOPERS AFTER 40, 50 AND 60 WHO ARE STILL CODING (PHOTO)
美国劳动力的中值年龄是42岁,而StackOverflow的一项有关年龄的调查表明,40岁之后的开发人员只占开发人员总数的13%。那么其他人到哪里去了?他们被解雇了或者上升到管理岗位了吗?软件开发对于过了40岁的人来说,是不是就意味着终结?

Rob Fletcher,Netflix(Los Gatos,CA)的高级软件工程师,45岁
我每天都写代码。目前最喜欢的语言是Kotlin。我想学习Go语言,平常用得比较多的是Java、Scala和Groovy。我一直在学习新的东西,哪怕是很小的事情。我知道自己会是一个糟糕的管理者,所以我压根没有想往管理方向发展。
很多事情取决于你的态度。不要成为厌恶新技术的老技术人,也不要嘲笑那些正在使用新技术的人。在进行技术选型时,你的经验应该成为决策的基础。如果选择了老技术,那是因为它们正好适合当前的需求,而不是因为要保护你那积攒了多年却即将过时的专业知识,也不是因为害怕那些后进者带着NodeJS和Go语言来抢夺你的工作。

Ebbe Kristensen,Prevas A/S(Denmark)的高级软件设计师,62岁
有时候,你几天甚至几周都不会学进去什么东西,而有时候几个小时学进去的东西就可以把之前“损失”的时间弥补回来。重要的是,你总是想方设法地去学习,时刻准备着,等待机会的出现。

John Brothers,Make&Build(Atlanta,GA)的高级软件架构师,47岁
我最近正在使用Node.JS开发一个项目,之前也用过Hadoop、NoSQL,开发过Android应用,也写过Go语言代码,还熟悉JQuery和Bootstrap的各种特性。
我也关注Java的最新动态,还有Spring、JMS、REST、JSON和JPA,以及其他相关的技术。
在过去的几年,我使用了IntelliJ、Eclipse、Sublime、Emacs和Vi这些开发工具,我很喜欢使用这些工具来解决各种问题。我一开始使用的是CVS,后来学习了Subversion,最近在学习git。我也有AWS相关的经验。我还是一个获得认证的Scrum Master、产品经理和开发者。

Roger Whitcomb,Actian公司(Palo Alto,CA)的软件架构师和软件工程师,60岁
我现在要跟上Web和移动开发的速度有点吃力,但离“垂暮”还很远,尽管我已经60岁了。
我认为最关键的是,你要为你的雇主持续地创造价值。
我目前是Apache软件基金会Pivot项目的PMC主席。作为一名Java开发人员(Java相关项目的提交者),我希望Java会永生。最起码不要出现更好的语言,要我把所有的代码都移植过去……

Scott Gartner,Silverback Learning Solutions(Boise,ID)的高级软件工程师,50多岁
我发现我的记忆力大不如前,也没办法记住大型系统的全部模型。不过,我发现我那些丰富的经验变得越来越有价值。
每两年我就会学习一种新的编程语言,有一些是我自己想学的,不过大部分是因为技术发展的需要(也有的是因为新工作的要求)。这样很有趣。目前我在学习数据仓库(OLAP)、ETL处理、Star Schemas和Cubes。

Brian Bowman,SAS(Cary,NC)的首席软件工程师,56岁
我通过四项主要的计算机技能生存下来。
汇编语言级别的大型机系统编程。
基于C语言的多主机平台的可移植编程,包括桌面、中型Unix网络、小型机的后续产品(如VAX),以及大型机。
多层集群服务器环境,由后端的多线程C以及处于中间层满足高可用要求的Java组成,主要面向Windows服务器和Unix环境,也包括Linux。
基于多线程C的大规模并行网格计算,满足虚拟的无限伸缩。
虽然我所拥有的这些技能可以干到退休,但在未来的几年,我还会将我的专业知识领域扩展到机器学习方面。

Alec Cawley,DisplayLink(Palo Alto,California)的首席软件研究员,60多岁
现在的世界与我的职业生涯刚开始的时候(穿孔纸带时期的Fortran)已经很不一样了,而变化仍然在持续。但反过来说,需要解决的问题总是很相似的,无非就是如何将人类的需求转成计算机可以做的事情,以及如何避免犯错、如何找出不可避免所犯下的错误。编程语言、开发环境、工具套件、API等东西只是解决问题的手段,我们只是在需要它们的时候才去学习如何使用它们。
我所在的嵌入式领域似乎比应用程序更加能够扛住潮流的冲刷。应用程序每几年就会有新的东西出现,有些几乎是昙花一现,有些会持续一段时间,经历巅峰,然后逝去。而嵌入式一直保持坚挺,以C语言为基础,再融合一点C++。另一方面,硬件也在持续发生变化,这让事情变得更加有趣。

Victor Volkman,Proquest(Ann Arbor,MI)的高级软件工程师,54岁

Kurt Guntheroth,软件工程师,50多岁
好的开发人员会持续学习,直到他们退休,比如Ken Thompsons和Bjarne Stroustrups。不过,我们大多数人(特别是40岁左右的)最终都会意识到,我们并不能成为行业的大神。
编程是一件很容易的事情。你告诉它们做什么,它们就做什么。它们是可以信赖的,也是可靠的。
代码可能会是难啃的骨头,它们要求对细节的重度关注和相当程度的脑力付出。
编程是关于创新,而不是操纵。

James Grenning,软件顾问,60多岁

Reflections of an “Old” Programmer

Half of what a programmer knows will be useless in 10 years.

Father of Java James Gosling slams cloud vendor lock-in

Medium网站的技术栈

Medium是一个在线发布平台,最初由Twitter联合创始人Evan Williams开发。该平台于2012年启动,现在每个月有6000万独立访客。该网站部署在AWS上,使用NodeJS和Go作为应用程序和服务的开发语言,使用DynamoDB作为数据存储,并使用Amazon Redshift作为数据仓库。

Don’t learn to code. Learn to think.

学会思考,而不只是编程

Interview with Ken Thompson
http://www.drdobbs.com/open-source/interview-with-ken-thompson/229502480

Go Language

It’s expanding every day and not being forced down anybody’s throat. It’s hard to adopt it to a project inside of Google because of the learning curve. It’s brand new and there aren’t good manuals for it, except what’s on the Web. And then, of course, its label of being experimental, so people are a little afraid. In spite of that, it’s growing very fast inside of Google.
Yes. When the three of us [Thompson, Rob Pike, and Robert Griesemer] got started, it was pure research. ** The three of us got together and decided that we hated C++. ** [laughter]
** It’s too complex. And going back, if we’d thought of it, we’d have done an object-oriented version of C back in the old days. **
Yes, but we were not evangelists of object orientation. [Returning to Go,] we started off with the idea that all three of us had to be talked into every feature in the language, so there was no extraneous garbage put into the language for any reason.

Java

Java 积累了最强大的生态系统,你可以说它无所不包, 毋庸置疑,Java 早已是一艘航空母舰的巨大身躯,这足已证明它的地位与成功。但是其语言、库、框架和生态系统的复杂度,对技术人员构筑其巨大的障碍。历史沉淀下来的,让 Java 提供的选项太多,深入后就知道 Java 的学习成本比 C++ 更高,对程序员的要求比 C++ 更高,除非掉队了,还在用 7 年甚至 10 年前的 Java 技术,技术人员要非常精心地组织框架和设计,否则各种复用的结果就是堆砌出一个异常臃肿的程序,其运行时对资源的消耗有时候会让你感到恐惧,而这是太多的基于 Java 所开发的平台被广泛诟病的关键所在,重用是个双刃剑,需要量体裁衣而不是一锅端,拿捏的尺度对开发人员要求无疑是最高昂的,除非语言和标准库提供了最好最直接的选项。

如今 Java 的学习成本和对开发人员的技能要求,已经远高于 C/C++ 的,也许大多数的开发人员无法驾驭 Java 这艘航空母舰。若要长期使用 Java,务必跟上 Java 的最新技术,同时在重用方面一定要拿捏好尺度,这会对人员技能提出更高要求,否则及其容易写出资源占用和运行时效率让人感到恐惧的应用。

IT公司面试题

IBM社会招聘笔试题

  1. 一个粗细均匀的长直管子,两端开口,里面有4个白球和4个黑球,球的直径、两端开口的直径等于管子的内径,现在白球和黑球的排列是wwwwbbbb,要求不取出任何一个球,使得排列变为bbwwwwbb。
    把管子两端接起来形成一个通环,将黑球从接口挤过去两个
  2. 一只蜗牛从井底爬到井口,每天白天蜗牛要睡觉,晚上才出来活动,一个晚上蜗牛可以向上爬3尺,但是白天睡觉的时候会往下滑2尺,井深10尺,问蜗牛几天可以爬出来? 8
  3. 在一个平面上画1999条直线最多能将这一平面划分成多少个部分?
    1999001
  4. 在太平洋的一个小岛上生活着土人,他们不愿意被外人打扰,一天,一个探险家到了岛上,被土人抓住,土人的祭司告诉他,你临死前还可以有一个机会留下一句话,如果这句话是真的,你将被烧死,是假的,你将被五马分尸,可怜的探险家如何才能活下来?
    我将被五马分尸
  5. 怎样种四棵树使得任意两棵树的距离相等。
    种山上,等边三角锥
  6. 27个小运动员在参加完比赛后,口渴难耐,去小店买饮料,饮料店搞促销,凭三个空瓶可以再换一瓶,他们最少买多少瓶饮料才能保证一人一瓶?
    19
  7. 有一座山,山上有座庙,只有一条路可以从山上的庙到山脚,每周一早上8点,有一个聪明的小和尚去山下化缘,周二早上8点从山脚回山上的庙里,小和尚的上下山的速度是任意的,在每个往返中,他总是能在周一和周二的同一钟点到达山路上的同一点。例如,有一次他发现星期一的8点30和星期二的8点30他都到了山路靠山脚的3/4的地方,问这是为什么?
    那时肯定的,因为上下山只有一条路
  8. 有两根不均匀分布的香,每根香烧完的时间是一个小时,你能用什么方法来确定一段15分钟的时间?
    把第一根一头点着,同时把第二根两头都点着,在第二根燃尽的同时点燃第一根的另一头,这时开始计时,至第一根燃尽就是十五分钟

IBM面试题目

  1. Describe your greatest achievement in the past 4-5 years?

  2. What are your short & long term career objectives? What do you think is the most ideal job for you?

  3. Why do you want to join IBM? What do you think you can contribute to IBM?

Google 中国笔试题目

1.1关于IP协议那个正确
A IP是TCP上层协议B IP协议是应用层协议C由于两个属于同一层协议,他们之间可以直接通信DIP协议不提供可靠的通信
1.2 关于内存正确的是
A内存的存取速度不能低于cpu速度,否则会造成数据丢失
B程序只有在数据和代码等被调入内存后才能运行
C采用虚拟内存技术后程序可以在硬盘上直接运行
D某计算机的内存容量为16MB,那么他的地址总线为24位
1.3单链表中结点的结构为(data,link),若想删除结点p(不是头节点或者尾结点)的直接后继,则应执行下列哪个操作
A p=p->link ; p->link=p->link->linkB p->link->link=p->link;C p=p->link->link Dp->link=p->link->link
1.4已知x>=y and y>=z 为真,那么x>z or y=z 值为
A真B假C无法确定Dx y z同为正数时为真
1.5某请求被随即分配到四台机器进行处理,分配到每台机器的概率A15% B20% C 30% D 35%, 处理请求的失败概率分别为5% ,4%, 3% 2%,现在请求失败,问由C造成的概率最接近A26% B28% C 30% D 32%
1.6假设我们用d=(a1,a2,….a5)表示无向无环图G的5个顶点的度数,下面给出的哪组值是可能的
A{3,4,4,3,1}B{4,2,2,1,1}C{3,3,3,2,2}D{3,4,3,2,1}
1.7设栈S和队列Q的初始状态为空,元素e1,e2,e3,e4,e5,e6一次压入栈S,一个元素出栈后即进入队列Q,若出队列的顺序为e2,e4,e3,e6,e5,e1则栈S的容量要求最小值为
A2B3C4D5
1.8 在堆排序算法中我们用一个数组A来模拟二叉树T,如果该A[0]存放的是T的根节点,那么AK的父亲节点是
A (K-1)/2 B K/2 C(K+1)/2 D 都不对 ( via: unus.cn )
1.9 现有如下任务需要安排在若干机器上并行完成,每个任务都有开始时间和结束时间(开始和结束时间都包括在任务执行时间内)的要求
任务名称 开始时间 结束时间
a 1 7
b 8 9
c 2 5
d 7 11
e 3 6
f 7 9
g 10 13
则最少需要使用的机器数目为
A1B2C3D4
1.10 在设计一个操作系统时,哪项不是必须考虑的
A 设备管理模块B文件系统模块C用户管理模块D进程管理模块
2.1正整数序列Q中的每个元素都至少能被正整数a和b中的一个整除,现给定a和b,需要计算出Q中的前几项,例如,当a=3,b=5,N=6时,序列为3,5,6,9,10,12
(1)设计一个函数void generate(int a,int b,int N ,int * Q)计算Q的前几项
(2)设计测试数据来验证函数程序在各种输入下的正确性
2.2 有一个由大小写组成的字符串,现在需要对他进行修改,将其中的所有小写字母排在答谢字母的前面(大写或小写字母之间不要求保持原来次序),如有可能尽量选择时间和空间效率高的算法 c语言函数原型void proc(char *str) 也可以采用你自己熟悉的语言
2.3 已知一颗无向无环连通图T的所有顶点和边的信息,现需要将其转换为一棵树,要求树的深度最小,请设计一个算法找到所有满足要求的树的根结点,并分析时空复杂度(描述算法即可,无需代码)
1.1关于IP协议那个正确
A IP是TCP上层协议B IP协议是应用层协议C由于两个属于同一层协议,他们之间可以直接通信DIP协议不提供可靠的通信
1.2 关于内存正确的是
A内存的存取速度不能低于cpu速度,否则会造成数据丢失
B程序只有在数据和代码等被调入内存后才能运行
C采用虚拟内存技术后程序可以在硬盘上直接运行
D某计算机的内存容量为16MB,那么他的地址总线为24位
1.3单链表中结点的结构为(data,link),若想删除结点p(不是头节点或者尾结点)的直接后继,则应执行下列哪个操作
A p=p->link ; p->link=p->link->linkB p->link->link=p->link;C p=p->link->link Dp->link=p->link->link
1.4已知x>=y and y>=z 为真,那么x>z or y=z 值为
A真B假C无法确定Dx y z同为正数时为真
1.5某请求被随即分配到四台机器进行处理,分配到每台机器的概率A15% B20% C 30% D 35%, 处理请求的失败概率分别为5% ,4%, 3% 2%,现在请求失败,问由C造成的概率最接近A26% B28% C 30% D 32%
1.6假设我们用d=(a1,a2,….a5)表示无向无环图G的5个顶点的度数,下面给出的哪组值是可能的
A{3,4,4,3,1}B{4,2,2,1,1}C{3,3,3,2,2}D{3,4,3,2,1}
1.7设栈S和队列Q的初始状态为空,元素e1,e2,e3,e4,e5,e6一次压入栈S,一个元素出栈后即进入队列Q,若出队列的顺序为e2,e4,e3,e6,e5,e1则栈S的容量要求最小值为
A2B3C4D5
1.8 在堆排序算法中我们用一个数组A来模拟二叉树T,如果该A[0]存放的是T的根节点,那么AK的父亲节点是
A (K-1)/2 B K/2 C(K+1)/2 D 都不对 ( via: unus.cn )
1.9 现有如下任务需要安排在若干机器上并行完成,每个任务都有开始时间和结束时间(开始和结束时间都包括在任务执行时间内)的要求
任务名称 开始时间 结束时间
a 1 7
b 8 9
c 2 5
d 7 11
e 3 6
f 7 9
g 10 13
则最少需要使用的机器数目为
A1B2C3D4
1.10 在设计一个操作系统时,哪项不是必须考虑的
A 设备管理模块B文件系统模块C用户管理模块D进程管理模块
2.1正整数序列Q中的每个元素都至少能被正整数a和b中的一个整除,现给定a和b,需要计算出Q中的前几项,例如,当a=3,b=5,N=6时,序列为3,5,6,9,10,12
(1)设计一个函数void generate(int a,int b,int N ,int * Q)计算Q的前几项
(2)设计测试数据来验证函数程序在各种输入下的正确性
2.2 有一个由大小写组成的字符串,现在需要对他进行修改,将其中的所有小写字母排在答谢字母的前面(大写或小写字母之间不要求保持原来次序),如有可能尽量选择时间和空间效率高的算法 c语言函数原型void proc(char *str) 也可以采用你自己熟悉的语言
2.3 已知一颗无向无环连通图T的所有顶点和边的信息,现需要将其转换为一棵树,要求树的深度最小,请设计一个算法找到所有满足要求的树的根结点,并分析时空复杂度(描述算法即可,无需代码)

intel的笔试题

智力题

1.每天中午从法国塞纳河畔的勒阿佛有一艘轮船驶往美国纽约,在同一时刻纽约也有一艘轮船驶往勒阿佛。已知横渡一次的时间是7天7夜,轮船匀速航行,在同一航线,轮船近距离可见。
请问今天中午从勒阿佛开出的船会遇到几艘从纽约来的船?

2.巴拿赫病故于1945年8月31日。他的出生年份恰好是他在世时某年年龄的平方,问:他是哪年出生的?

答案:

设他在世时某年年龄为x,则x的平方<1945,且x为自然数。其出生年份x的平方-x=x(x-1),他在世年龄1945-x(x-1)。1945的平方根=44.1,则x应为44或略小于此的数。而x=44时,x(x-1)=44×43=1892,算得其在世年龄为1945-1892=53;又x=43时,x(x-1)=43×42=1806,得其在世年龄为1945-1806=139;若x再取小,其在世年龄越大,显然不妥。故x=44,即他出生于1892年,终年53岁。

笔试题目

1.设计一个重采样系统,说明如何anti-alias。

2.y1(n)=x(2n),y2(n)=x(n/2),问:

如果y1为周期函数,那么x是否为周期函数?

如果x为周期函数,那么y1是否为周期函数?

如果y2为周期函数,那么x是否为周期函数?

如果x为周期函数,那么y2是否为周期函数?

3.如果模拟信号的带宽为5kHz,要用8k的采样率,怎么办。

4.某个程序在一个嵌入式系统(200M的CPU,50M的SDRAM)中已经最优化了,换到另一个系统(300M的CPU,50M的SDRAM)中运行,还需要优化吗?
5.x^4+ax^3+x^2+cx+d最少需要做几次乘法。

6.三个float:a,b,c

问值:

(a+b)+c==(b+a)+c

(a+b)+c==(a+c)+b

7.把一个链表反向填空。

8.下面哪种排序法对12354最快?

A. quick sort

B. buble sort

C. merge sort

9.哪种结构平均来讲获取一个值最快?

A. binary tree
B. hash table
C. stack
10.

#include
“stdafx.h”
#include <iostream.h>
struct bit
{ int a:3;
int b:2;
int c:3;
};
int main(int argc, char* argv[])
{
bit s;
char c = (char)&s;
*c = 0x99;
cout <<
s.a <<endl <<s.b<<endl<<s.c<<endl;
return 0;
}

Output:?
11.

挑bug,在linux下运行:
#include <stdio.h>
char
reverse(char str)
{
int len=0, i=0;
char pstr=str, ptemp,pd;
while(
++pstr)
len++;
pstr–;
//ptemp=(char
)malloc(len+1);
ptemp=(char
)malloc(len+1);
pd=ptemp;
while(len–){
*ptemp=*pstr;
ptemp++;
pstr–;
i++;
}
*ptemp=*pstr;
ptemp++;
*ptemp=‘\0’;
return pd;
}
main()
{
char string[40]= “Hello World!”;
char *pstr=string;
printf(“%s”, pstr);
printf(“%s”, reverse(pstr));
}

实验室笔试题

1.写出下列信号的奈亏斯特频率

(1)f(t)=1+cos(2000pait)+sin(4000pait)
(2)f(t)=sin(4000pait)/pait
(3)f(t)=(sin(4000pait)的平方)/pait

2.有两个线程

void producer()
{
while(1)
{
GeneratePacket();
PutPacketIntoBuffer();
Signal(customer);
}
}
void customer()
{
while(1)
{
WaitForSignal();
if(PacketInBuffer>10)
{
ReadAllPackets();
ProcessPackets();
}
}
}
(1)有没有其他方法可以提高程序的性能

(2)可不可以不使用信号之类的机制来实现上述的功能

3.优化下面的程序

(0)sum=0
(1)I=1
(2)T1=4I
(3)T2=address(A)-4
(4)T3=T2[T1]
(5)T4=address(B)-4
(6)T5=4
I
(7)T6=T4[T5]
(8)T7=T3*T5
(9)sum=sum+T6
(10)I=I+1
(11)IF I<20 GOTO (2)

101道微软IT笔试题

Algorithms and Programming

  1. Given a rectangular (cuboidal for the puritans) cake with a rectangular piece removed (any size or orientation), how would you cut the remainder of the cake into two equal halves with one straight cut of a knife ?
  2. You’re given an array containing both positive and negative integers and required to find the sub-array with the largest sum (O(N) a la KBL). Write a routine in C for the above.
  3. Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it. You are allowed to destroy the array if you like. [ I ended up giving about 4 or 5 different solutions for this, each supposedly better than the others ].
  4. Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all. [ This one had me stuck for quite some time and I first gave a solution that did have floating point computations ].
  5. Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn’t too pleased and asked me to give a solution which didn’t need the array ].
  6. Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it’s a simple test.]
  7. Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.
  8. How many points are there on the globe where by walking one mile south, one mile east and one mile north you reach the place where you started.
  9. Give a very good method to count the number of ones in a “n” (e.g. 32) bit number.
    ANS. Given below are simple solutions, find a solution that does it in log (n) steps.
    Iterative
    function iterativecount (unsigned int n)
    begin
    int count=0;
    while (n)
    begin
    count += n & 0×1 ;
    n >>= 1;
    end
    return count;
    end
    Sparse Count
    function sparsecount (unsigned int n)
    begin
    int count=0;
    while (n)
    begin
    count++;
    n &= (n-1);
    end
    return count ;
    end
  10. What are the different ways to implement a condition where the value of x can be either a 0 or a 1. Apparently the if then else solution has a jump when written out in assembly. if (x == 0) y=a else y=b There is a logical, arithmetic and a data structure solution to the above problem.
  11. Reverse a linked list.
  12. Insert in a sorted list
  13. In a X’s and 0’s game (i.e. TIC TAC TOE) if you write a program for this give a fast way to generate the moves by the computer. I mean this should be the fastest way possible.
    The answer is that you need to store all possible configurations of the board and the move that is associated with that. Then it boils down to just accessing the right element and getting the corresponding move for it. Do some analysis and do some more optimization in storage since otherwise it becomes infeasible to get the required storage in a DOS machine.
  14. I was given two lines of assembly code which found the absolute value of a number stored in two’s complement form. I had to recognize what the code was doing. Pretty simple if you know some assembly and some fundaes on number representation.
  15. Give a fast way to multiply a number by 7.
  16. How would go about finding out where to find a book in a library. (You don’t know how exactly the books are organized beforehand).
  17. Linked list manipulation.
  18. Tradeoff between time spent in testing a product and getting into the market first.
  19. What to test for given that there isn’t enough time to test everything you want to.
  20. First some definitions for this problem: a) An ASCII character is one byte long and the most significant bit in the byte is always ‘0′. b) A Kanji character is two bytes long. The only characteristic of a Kanji character is that in its first byte the most significant bit is ‘1′.
    Now you are given an array of a characters (both ASCII and Kanji) and, an index into the array. The index points to the start of some character. Now you need to write a function to do a backspace (i.e. delete the character before the given index).
  21. Delete an element from a doubly linked list.
  22. Write a function to find the depth of a binary tree.
  23. Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.
  24. Assuming that locks are the only reason due to which deadlocks can occur in a system. What would be a foolproof method of avoiding deadlocks in the system.
  25. Reverse a linked list.
    Ans: Possible answers -
    iterative loop
    curr->next = prev;
    prev = curr;
    curr = next;
    next = curr->next
    endloop
    recursive reverse(ptr)
    if (ptr->next == NULL)
    return ptr;
    temp = reverse(ptr->next);
    temp->next = ptr;
    return ptr;
    end
  26. Write a small lexical analyzer - interviewer gave tokens. expressions like “a*b” etc.
  27. Besides communication cost, what is the other source of inefficiency in RPC? (answer : context switches, excessive buffer copying). How can you optimize the communication? (ans : communicate through shared memory on same machine, bypassing the kernel _ A Univ. of Wash. thesis)
  28. Write a routine that prints out a 2-D array in spiral order!
  29. How is the readers-writers problem solved? - using semaphores/ada .. etc.
  30. Ways of optimizing symbol table storage in compilers.
  31. A walk-through through the symbol table functions, lookup() implementation etc. - The interviewer was on the Microsoft C team.
  32. A version of the “There are three persons X Y Z, one of which always lies”.. etc..
  33. There are 3 ants at 3 corners of a triangle, they randomly start moving towards another corner.. what is the probability that they don’t collide.
  34. Write an efficient algorithm and C code to shuffle a pack of cards.. this one was a feedback process until we came up with one with no extra storage.
  35. The if (x == 0) y = 0 etc..
  36. Some more bitwise optimization at assembly level
  37. Some general questions on Lex, Yacc etc.
  38. Given an array t[100] which contains numbers between 1..99. Return the duplicated value. Try both O(n) and O(n-square).
  39. Given an array of characters. How would you reverse it. ? How would you reverse it without using indexing in the array.
  40. Given a sequence of characters. How will you convert the lower case characters to upper case characters. ( Try using bit vector - solutions given in the C lib -typec.h)
  41. Fundamentals of RPC.
  42. Given a linked list which is sorted. How will u insert in sorted way.
  43. Given a linked list How will you reverse it.
  44. Give a good data structure for having n queues ( n not fixed) in a finite memory segment. You can have some data-structure separate for each queue. Try to use at least 90% of the memory space.
  45. Do a breadth first traversal of a tree.
  46. Write code for reversing a linked list.
  47. Write, efficient code for extracting unique elements from a sorted list of array. e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) -> (1, 3, 5, 9).
  48. Given an array of integers, find the contiguous sub-array with the largest sum.
    ANS. Can be done in O(n) time and O(1) extra space. Scan array from 1 to n. Remember the best sub-array seen so far and the best sub-array ending in i.
  49. Given an array of length N containing integers between 1 and N, determine if it contains any duplicates.
    ANS. [Is there an O(n) time solution that uses only O(1) extra space and does not destroy the original array?]
  50. Sort an array of size n containing integers between 1 and K, given a temporary scratch integer array of size K.
    ANS. Compute cumulative counts of integers in the auxiliary array. Now scan the original array, rotating cycles! [Can someone word this more nicely?]
    * 51. An array of size k contains integers between 1 and n. You are given an additional scratch array of size n. Compress the original array by removing duplicates in it. What if k << n?
    ANS. Can be done in O(k) time i.e. without initializing the auxiliary array!
  51. An array of integers. The sum of the array is known not to overflow an integer. Compute the sum. What if we know that integers are in 2’s complement form?
    ANS. If numbers are in 2’s complement, an ordinary looking loop like for(i=total=0;i< n;total+=array[i++]); will do. No need to check for overflows!
  52. An array of characters. Reverse the order of words in it.
    ANS. Write a routine to reverse a character array. Now call it for the given array and for each word in it.
    * 54. An array of integers of size n. Generate a random permutation of the array, given a function rand_n() that returns an integer between 1 and n, both inclusive, with equal probability. What is the expected time of your algorithm?
    ANS. “Expected time” should ring a bell. To compute a random permutation, use the standard algorithm of scanning array from n downto 1, swapping i-th element with a uniformly random element <= i-th. To compute a uniformly random integer between 1 and k (k < n), call rand_n() repeatedly until it returns a value in the desired range.
  53. An array of pointers to (very long) strings. Find pointers to the (lexicographically) smallest and largest strings.
    ANS. Scan array in pairs. Remember largest-so-far and smallest-so-far. Compare the larger of the two strings in the current pair with largest-so-far to update it. And the smaller of the current pair with the smallest-so-far to update it. For a total of <= 3n/2 strcmp() calls. That’s also the lower bound.
  54. Write a program to remove duplicates from a sorted array.
    ANS. int remove_duplicates(int * p, int size)
    {
    int current, insert = 1;
    for (current=1; current < size; current++)
    if (p[current] != p[insert-1])
    {
    p[insert] = p[current];
    current++;
    insert++;
    } else
    current++;
    return insert;
    }
  55. C++ ( what is virtual function ? what happens if an error occurs in constructor or destructor. Discussion on error handling, templates, unique features of C++. What is different in C++, ( compare with unix).
  56. Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list).
  57. Given 3 lines of assembly code : find it is doing. IT was to find absolute value.
  58. If you are on a boat and you throw out a suitcase, Will the level of water increase.
  59. Print an integer using only putchar. Try doing it without using extra storage.
  60. Write C code for (a) deleting an element from a linked list (b) traversing a linked list
  61. What are various problems unique to distributed databases
  62. Declare a void pointer ANS. void *ptr;
  63. Make the pointer aligned to a 4 byte boundary in a efficient manner ANS. Assign the pointer to a long number and the number with 11…1100 add 4 to the number
  64. What is a far pointer (in DOS)
  65. What is a balanced tree
  66. Given a linked list with the following property node2 is left child of node1, if node2 < node1 else, it is the right child.
    O P
    |
    |
    O A
    |
    |
    O B
    |
    |
    O C
    How do you convert the above linked list to the form without disturbing the property. Write C code for that.
    O P
    |
    |
    O B
    /
    /
    /
    O ? O ?
    determine where do A and C go
  67. Describe the file system layout in the UNIX OS
    ANS. describe boot block, super block, inodes and data layout
  68. In UNIX, are the files allocated contiguous blocks of data
    ANS. no, they might be fragmented
    How is the fragmented data kept track of
    ANS. Describe the direct blocks and indirect blocks in UNIX file system
  69. Write an efficient C code for ‘tr’ program. ‘tr’ has two command line arguments. They both are strings of same length. tr reads an input file, replaces each character in the first string with the corresponding character in the second string. eg. ‘tr abc xyz’ replaces all ‘a’s by ‘x’s, ‘b’s by ‘y’s and so on. ANS.
    a) have an array of length 26.
    put ‘x’ in array element corr to ‘a’
    put ‘y’ in array element corr to ‘b’
    put ‘z’ in array element corr to ‘c’
    put ‘d’ in array element corr to ‘d’
    put ‘e’ in array element corr to ‘e’
    and so on.
    the code
    while (!eof)
    {
    c = getc();
    putc(array[c - ‘a’]);
    }
  70. what is disk interleaving
  71. why is disk interleaving adopted
  72. given a new disk, how do you determine which interleaving is the best a) give 1000 read operations with each kind of interleaving determine the best interleaving from the statistics
  73. draw the graph with performance on one axis and ‘n’ on another, where ‘n’ in the ‘n’ in n-way disk interleaving. (a tricky question, should be answered carefully)
  74. I was a c++ code and was asked to find out the bug in that. The bug was that he declared an object locally in a function and tried to return the pointer to that object. Since the object is local to the function, it no more exists after returning from the function. The pointer, therefore, is invalid outside.
  75. A real life problem - A square picture is cut into 16 squares and they are shuffled. Write a program to rearrange the 16 squares to get the original big square.
  76. int *a;
    char *c;
    *(a) = 20;
    *c = *a;
    printf(”%c”,*c);
    what is the output?
  77. Write a program to find whether a given m/c is big-endian or little-endian!
  78. What is a volatile variable?
  79. What is the scope of a static function in C ?
  80. What is the difference between “malloc” and “calloc”?
  81. struct n { int data; struct n* next}node;
    node *c,*t;
    c->data = 10;
    t->next = null;
    *c = *t;
    what is the effect of the last statement?
  82. If you’re familiar with the ? operator x ? y : z
    you want to implement that in a function: int cond(int x, int y, int z); using only ~, !, ^, &, +, |, <<, >> no if statements, or loops or anything else, just those operators, and the function should correctly return y or z based on the value of x. You may use constants, but only 8 bit constants. You can cast all you want. You’re not supposed to use extra variables, but in the end, it won’t really matter, using vars just makes things cleaner. You should be able to reduce your solution to a single line in the end though that requires no extra vars.
  83. You have an abstract computer, so just forget everything you know about computers, this one only does what I’m about to tell you it does. You can use as many variables as you need, there are no negative numbers, all numbers are integers. You do not know the size of the integers, they could be infinitely large, so you can’t count on truncating at any point. There are NO comparisons allowed, no if statements or anything like that. There are only four operations you can do on a variable.
  1. You can set a variable to 0.
  2. You can set a variable = another variable.
  3. You can increment a variable (only by 1), and it’s a post increment.
  4. You can loop. So, if you were to say loop(v1) and v1 = 10, your loop would execute 10 times, but the value in v1 wouldn’t change so the first line in the loop can change value of v1 without changing the number of times you loop.
    You need to do 3 things.
  5. Write a function that decrements by 1.
  6. Write a function that subtracts one variable from another.
  7. Write a function that divides one variable by another.
  8. See if you can implement all 3 using at most 4 variables. Meaning, you’re not making function calls now, you’re making macros. And at most you can have 4 variables. The restriction really only applies to divide, the other 2 are easy to do with 4 vars or less. Division on the other hand is dependent on the other 2 functions, so, if subtract requires 3 variables, then divide only has 1 variable left unchanged after a call to subtract. Basically, just make your function calls to decrement and subtract so you pass your vars in by reference, and you can’t declare any new variables in a function, what you pass in is all it gets.
    Linked lists
    * 86. Under what circumstances can one delete an element from a singly linked list in constant time?
    ANS. If the list is circular and there are no references to the nodes in the list from anywhere else! Just copy the contents of the next node and delete the next node. If the list is not circular, we can delete any but the last node using this idea. In that case, mark the last node as dummy!
    * 87. Given a singly linked list, determine whether it contains a loop or not.
    ANS. (a) Start reversing the list. If you reach the head, gotcha! there is a loop!
    But this changes the list. So, reverse the list again.
    (b) Maintain two pointers, initially pointing to the head. Advance one of them one node at a time. And the other one, two nodes at a time. If the latter overtakes the former at any time, there is a loop!
    p1 = p2 = head;
    do {
    p1 = p1->next;
    p2 = p2->next->next;
    } while (p1 != p2);
  1. Given a singly linked list, print out its contents in reverse order. Can you do it without using any extra space?
    ANS. Start reversing the list. Do this again, printing the contents.
  2. Given a binary tree with nodes, print out the values in pre-order/in-order/post-order without using any extra space.
  3. Reverse a singly linked list recursively. The function prototype is node * reverse (node *) ;
    ANS.
    node * reverse (node * n)
    {
    node * m ;
    if (! (n && n -> next))
    return n ;
    m = reverse (n -> next) ;
    n -> next -> next = n ;
    n -> next = NULL ;
    return m ;
    }
  4. Given a singly linked list, find the middle of the list.
    HINT. Use the single and double pointer jumping. Maintain two pointers, initially pointing to the head. Advance one of them one node at a time. And the other one, two nodes at a time. When the double reaches the end, the single is in the middle. This is not asymptotically faster but seems to take less steps than going through the list twice.
    Bit-manipulation
  5. Reverse the bits of an unsigned integer.
    ANS.
    #define reverse(x)
    (x=x>>16|(0×0000ffff&x)<<16,
    x=(0xff00ff00&x)>>8|(0×00ff00ff&x)<<8,
    x=(0xf0f0f0f0&x)>>4|(0×0f0f0f0f&x)<<4,
    x=(0xcccccccc&x)>>2|(0×33333333&x)<<2,
    x=(0xaaaaaaaa&x)>>1|(0×55555555&x)<<1)
    * 93. Compute the number of ones in an unsigned integer.
    ANS.
    #define count_ones(x)
    (x=(0xaaaaaaaa&x)>>1+(0×55555555&x),
    x=(0xcccccccc&x)>>2+(0×33333333&x),
    x=(0xf0f0f0f0&x)>>4+(0×0f0f0f0f&x),
    x=(0xff00ff00&x)>>8+(0×00ff00ff&x),
    x=x>>16+(0×0000ffff&x))
  6. Compute the discrete log of an unsigned integer.
    ANS.
    #define discrete_log(h)
    (h=(h>>1)|(h>>2),
    h|=(h>>2),
    h|=(h>>4),
    h|=(h>>8),
    h|=(h>>16),
    h=(0xaaaaaaaa&h)>>1+(0×55555555&h),
    h=(0xcccccccc&h)>>2+(0×33333333&h),
    h=(0xf0f0f0f0&h)>>4+(0×0f0f0f0f&h),
    h=(0xff00ff00&h)>>8+(0×00ff00ff&h),
    h=(h>>16)+(0×0000ffff&h))
    If I understand it right, log2(2) =1, log2(3)=1, log2(4)=2….. But this macro does not work out log2(0) which does not exist! How do you think it should be handled?
    * 95. How do we test most simply if an unsigned integer is a power of two?
    ANS. #define power_of_two(x) \ ((x)&&(~(x&(x-1))))
  7. Set the highest significant bit of an unsigned integer to zero.
    ANS. (from Denis Zabavchik) Set the highest significant bit of an unsigned integer to zero
    #define zero_most_significant(h)
    (h&=(h>>1)|(h>>2),
    h|=(h>>2),
    h|=(h>>4),
    h|=(h>>8),
    h|=(h>>16))
  8. Let f(k) = y where k is the y-th number in the increasing sequence of non-negative integers with the same number of ones in its binary representation as y, e.g. f(0) = 1, f(1) = 1, f(2) = 2, f(3) = 1, f(4) = 3, f(5) = 2, f(6) = 3 and so on. Given k >= 0, compute f(k).
    Others
  9. A character set has 1 and 2 byte characters. One byte characters have 0 as the first bit. You just keep accumulating the characters in a buffer. Suppose at some point the user types a backspace, how can you remove the character efficiently. (Note: You cant store the last character typed because the user can type in arbitrarily many backspaces)
  10. What is the simples way to check if the sum of two unsigned integers has resulted in an overflow.
  11. How do you represent an n-ary tree? Write a program to print the nodes of such a tree in breadth first order.
  12. Write the ‘tr’ program of UNIX. Invoked as
    tr -str1 -str2. It reads stdin and prints it out to stdout, replacing every occurance of str1 with str2.
    e.g. tr -abc -xyz
    to be and not to be <- input
    to ye xnd not to ye <- output

Pseudo-random

古老的LCG(linear congruential generator)代表了最好的伪随机数产生器算法。主要原因是容易理解,容易实现,而且速度快。

如果需要高质量的伪随机数,内存充足(约2kb),Mersenne twister算法是个不错的选择。Mersenne twister产生随机数的质量几乎超过任何LCG。不过一般Mersenne twister的实现使用LCG产生种子。
Mersenne twister是Makoto Matsumoto (松本)和Takuji Nishimura (西村)于1997年开发的伪随机数产生器,基于有限二进制字段上的矩阵线性再生。可以快速产生高质量的伪随机数,修正了古老随机数产生算法的很多缺陷。 Mersenne twister这个名字来自周期长度通常取Mersenne质数这样一个事实。常见的有两个变种Mersenne Twister MT19937和Mersenne Twister MT19937-64。
Mersenne Twister有很多长处,例如:周期2^19937 - 1对于一般的应用来说,足够大了,序列关联比较小,能通过很多随机性测试。
用Mersenne twister算法实现的伪随机数版本非常多。例如boost库中的高质量快速随机数产生器就是用Mersenne twister算法原理编写的。

matlab的随机函数产生的随机数都是根据伪随机数序列获取的,在v7.7以上的版本中,有如下的伪随机数产生器:
Mersenne twister,
Multiplicative congruential generator,
Multiplicative lagged Fibonacci generator,
Combined multiple recursive generator,
Shift-register generator summed with linear congruential generator,
Modified subtract with borrow generator。

在Windows下如果用mt_rand()函数替代rand()函数的话效果也会好很多。这是由于mt_rand()用了Mersenne Twister(马其塞旋转)算法来产生随机数。PHP的文档还说:mt_rand() 可以产生随机数值的平均速度比 libc 提供的 rand() 快四倍。

Joel Spolsky的七个建议

  • 毕业前练好写作 表达能力->影响力
  • 毕业前学好C语言
    • C语言仍然是当前程序员的共同语言
    • 你能解释为什么while (*s++ = *t++);这句代码的作用是复制字符串吗?
  • 毕业前学好微观经济学 商业领域所有重要理论的基础
  • 你一定要去学微观经济学,因为你必须搞懂供给和需求,你必须明白竞争优势,你必须理解什么是净现值(NPV),什么是贴现,什么是边际效用。只有这样,你才会懂得为什么生意是现在这种做法。
    • 从经营一家公司的角度来看,比起那些不懂的程序员,一个理解基本商业规则的程序员将会更有价值。
    • 别忘了,在编程工作中也有很枯燥的东西。每一项工作都有枯燥难耐的时刻。我不想雇用那些只想干有趣事情的人。
  • 选修有大量编程实践的课程
    • 计算机科学与软件开发不是一回事。
  • 别担心所有工作都被印度人抢走
  • 找一份好的暑期实习工作

Java点点

Java语法

  • final域
    final域一旦赋值后将永远不变,因此非常适合用来定义常量。值得注意的是:如果final域是一个基本类型,那么表明改域的值是不能改变的。若final域是一个对象的引用,则仅仅表明改引用不能被改变,也就是永远指向同一个对象,但是被引用的对象自身却是可以改变的。这跟c++中的常量指针很像(不是指向常量的指针)。初始化final域有着特殊的要求:非静态final域要求在构造函数执行后必须被明确赋值,而静态final域在类初始化完成后必须要被明确赋值。

  • JAR地狱(JAR hell):JAR文件不同版本或路径带来的问题,通常是由于不懂类加载模型导致的。指类路径里JAR包太多这个问题。另外一个“JAR地狱”的解释是“反模式”中的一个概念。DLL地狱(DLL hell):不同版本带来的问题,DLL可见性和多版本问题,在微软的Windows上尤为突出

  • ThreadLocal
    A ThreadLocal can be used to avoid the creation of a new SimpleDateFormat for each call.
    It is needed in a multithread context since the SimpleDateFormat is not thread safe

Spring

Jackson Annotations

  • @JsonIgnoreProperties one of the most common annotations in Jackson – is used to mark a property or a list of properties to be ignored at the class level.如果是代理类,由于无法标记在属性或方法上,所以,可以标记在类声明上;也作用于反序列化时的字段解析。作用在类上,用来说明有些属性在序列化/反序列化时需要忽略掉,可以将它看做是@JsonIgnore的批量操作,但它的功能比@JsonIgnore要强,比如一个类是代理类,我们无法将将@JsonIgnore标记在属性或方法上,此时便可用。标注在类声明上,它还有一个重要的功能是作用在反序列化时解析字段时过滤一些未知的属性,否则通常情况下解析到我们定义的类不认识的属性便会抛出异常。
  • @JsonIgnore The @JsonIgnore annotation is used to mark a property to be ignored at the field level.一般标记在属性或方法上;作用于序列化与反序列化。作用在字段或方法上,用来完全忽略被注解的字段和方法对应的属性,即便这个字段或方法可以被自动检测到或者还有其他的注解
  • @JsonPropertyOrder,注释在类声明中
  • @JsonAutoDetect 看上面自动检测,不再重复
  • @JsonProperty 作用在字段或方法上,用来对属性的序列化/反序列化,可以用来避免遗漏属性,同时提供对属性名称重命名,比如在很多场景下Java对象的属性是按照规范的驼峰书写,但是实际展示的却是类似C-style或C++/Microsolft style
  • @JsonUnwrapped 作用在属性字段或方法上,用来将子JSON对象的属性添加到封闭的JSON对象
  • @JsonIdentityInfo 2.0+版本新注解,作用于类或属性上,被用来在序列化/反序列化时为该对象或字段添加一个对象识别码,通常是用来解决循环嵌套的问题,比如数据库中的多对多关系,通过配置属性generator来确定识别码生成的方式,有简单的,配置属性property来确定识别码的名称,识别码名称没有限制。
  • @JsonNaming jackson 2.1+版本的注解,作用于类或方法,注意这个注解是在jackson-databind包中而不是在jackson-annotations包里,它可以让你定制属性命名策略,作用和前面提到的@JsonProperty的重命名属性名称相同。

多态类型处理

jackson允许配置多态类型处理,当进行反序列话时,JSON数据匹配的对象可能有多个子类型,为了正确的读取对象的类型,我们需要添加一些类型信息。可以通过下面几个注解来实现:

  • @JsonTypeInfo 作用于类/接口,被用来开启多态类型处理,对基类/接口和子类/实现类都有效

工具

9 tools to help you with Java Performance Tuning
http://blog.idrsolutions.com/2014/06/java-performance-tuning-tools/

JWT

JWT是 Json Web Token 的缩写。它是基于 RFC 7519 标准定义的一种可以安全传输的 小巧 和 自包含 的JSON对象。由于数据是使用数字签名的,所以是可信任的和安全的。JWT可以使用HMAC算法对secret进行加密或者使用RSA的公钥私钥对来进行签名。

JWT是由三段组成的,按官方的叫法分别是header(头)、payload(负载)和signature(签名):

header.payload.signature

一个比较成熟的JWT类库,叫 jjwt ( https://github.com/jwtk/jjwt )。这个类库可以用于Java和Android的JWT token的生成和验证。

Java JWT: JSON Web Token for Java and Android
https://github.com/jwtk/jjwt

JWTs are incredibly cool for authentication because they let us implement reliable Single Sign-On (SSO) with low overhead on any platform (native, web, VR, whatever…) and across domains. JWTs are a strong alternative to pure cookie or session based auth with simple tokens or SAML, which can fail miserably in native app implementations. We can even use cookies with JWTs if we really want.

For our purposes, we just need to know how to use JWTs within our authentication workflow. When a user logs into our app, the server will check their email and password against the database. If the user exists, we’ll take their {email: , password: } combination, turn it into a lovely JWT, and send it back to the client. The client can store the JWT forever or until we set it to expire.

Whenever the client wants to ask the server for data, it’ll pass the JWT in the request’s Authorization Header (Authorization: Bearer ). The server will decode the Authorization Header before executing every request, and the decoded JWT should contain {email: , password: }. With that data, the server can retrieve the user again via the database or a cache to determine whether the user is allowed to execute the request.

The Expired Password Problem
We still have one last thing that needs modifying in our authorization setup. When a user changes their password, we issue a new JWT, but the old JWT will still pass verification! This can become a serious problem if a hacker gets ahold of a user’s password. To close the loop on this issue, we can make a clever little adjustment to our UserModel database model to include a version parameter, which will be a counter that increments with each new password for the user. We’ll incorporate version into our JWT so only the newest JWT will pass our security.