DSAA Learning Experience 2 - the Performance Issue

简单来说一下自己一个个实现各种数据结构的体会

最近新建了一个仓库,按照视频上,把各种数据结构用JavaScript都实现了一次,并且写了不少内置方法。

首先感觉很傻逼,因为这些代码肯定效率极低,比如我写的LinkedList的remove方法,各种while遍历,来逐个查找每一个node。

方法肯定是work的,结果正确,但如果这LinkedList稍微大一点,性能就肯定非常糟糕。

我当然也知道写代码没有银弹,需要一行一行敲出来,但我显然对目前代码的质量和性能不满意。

@i2j/DSAA

其他也没什么可说的。多写吧。只是希望能更优化一下效率。

将来会用Java,C,C++,Python,Go等语言,把这些算法重新再实现一次。

实现数据结构的过程中,另一个深刻的体会就是array。真的是把array的各种常用不常用的api都用到了,例如every,push,popslice等等。真也算长见识了。

The Multiple Entry Points Strategy of SNS (Social Networking Services) Websites

作者:大脑艾瑞克

截至目前,最成功的社交网络肯定是Facebook无疑了。那么,后来者们,包括Twitter,Instagram,知乎,微博和微信朋友圈,这些成功的社交网络,都和Facebook在一个特征上非常相似,而且区别于以雅虎为代表的第一代互联网以及和Google为代表的第二代互联网。

这个特征就是多入口策略。什么意思呢?

比如你打开雅虎或网易新浪等门户网站,甚至包括企业网站在内的大多数信息展示网站,都是有一个单一入口。你从首页,一层层往深入探索,最终,你会探索到最后一层,这就是一个树状结构。但以Facebook为代表的社交网站,则是一个网状结构,而你只是其中一个节点。你进入网站后,首先进入的是你自己的首页,它展示了你自己所有的动态。但是,你的目的不是仅仅探索自己的首页,你还要去探索别人的首页(尚未加好友),或者在你自己的首页上直接能看到别人的动态(已经加了好友)。所有别人的动态,对你来说,就是你正在阅读的信息流;你的动态,对于你的朋友来说,就是他们的信息流(的一部分)。

这种信息流的整合 ,就是多入口策略。也就是说,由于每个人关注的人和事的组合是不同的,他或她接收的信息流的组合当然是不同的,是独一无二的。这种独一无二,意义非常重大。

首先,对于具体某个用户来说,由于没有统一入口,你可以选择自己想要关注的人和话题,加入不同的圈子,从而为自己定制出一个独一无二的信息流集合。这个信息流集合是整个社交网站总信息流的一个子集。这么多子集之间,可以隔绝的非常良好。

有的人觉得这个社交网站没有人情味,有的人觉得这个网站都是装逼,有的人觉得大家都在炫富,有的人觉得每天都在约炮,有的人则饱受约炮信息的骚扰,有的人则是真诚的和大家交流,还有很多人每天发广告,但其实这些人上的都是同一个社交网站。这就是那句著名的评论:有一千个读者,就有一千个哈姆莱特。因此,每个人对这个网站的看法和体验是不一样的。

这种值得探索的网站,才能尽可能留住用户,因为这个网站总会有新鲜的事发生,有陌生的人不认识,有陌生的角落从来没有去逛过。用户们也很难对网站产生厌倦。

这个没有统一入口的特征,就是真实世界的写照。因为每个人都经历了不同的童年和成长经历,生活在不同的地方,上了不同的小学中学大学,遇到了不同的同学和朋友,长大后去了不同的城市,工作后遇到了不同的领导和环境。每个人从小到大,接触到的人和事的合集,都是独一无二的,没有两个人是完全一样的。所有人所有经历的合集,才是整个世界,因此这个世界如此之丰富多彩,值得探索,值得留恋。

其次,对于网站来说,重要意义在于,可以容纳尽可能多的人来使用这个网站。就像上面所说,每个人都为自己构建了一个独一无二的信息流,这对于具体某个用户来说,就是一个单独的小世界,而且是封闭的世界,不受外界打扰的世界。这种信息隔离,可以使得这个网站容纳各种不同的群体、不同三观的人,他们之间几乎不会有交集,甚至可以老死不相往来。即便偶尔会有交集,但这个交集基本上是由热门话题或者大V带起来的,并不会持久,对原有的个人信息流保持了最小限度的冲击。

信息隔离的重要性在于,这个网站对不同人的意义是不同的,那显然这个网站可以是腐宅集中营,也可以是精英们讨论家国大事的讨论区。总之,阳春白雪和下里巴人,在同一个网站上可以和平共处。而太多论坛,则是单一入口,则由于人数增多,三观开始混杂,用户开始分裂,要么最后是论坛衰落,要么最后是论坛分裂。

Facebook早已经超过10亿用户,全球范围内,各种宗教信仰、各种肤色、各种语言的用户,都可以在Facebook上获得各自想要的信息。甚至 Facebook想通过无人机和气球,在全球范围内为剩下未连接入网的几十亿人提供网络服务。非洲很多国家,都有Facebook控制的Internet.org提供的免费网络,只可以上Facebook。这些人,和美国欧洲的白人用户之间,可以说是完全不同的世界,他们之间的信息隔离足够好,以至于很可能互相都不知道对方的存在。

微信朋友圈就更是这样了,你的好友不同,朋友圈的信息就不同。甚至你可以手动屏蔽那些你不喜欢的朋友圈信息,不看某个人的朋友圈,不让某个人看你的朋友圈。这就更加微观的干预了自己想要看的信息,从而为自己打造一个独一无二的朋友圈。

每个人都完全沉浸在自己的小世界里。

知乎是一个问题为载体的一个社交网站。这个载体就相对单一了,因此知乎的信息隔离其实做的不太好。这是由于这个网站的本质机制决定的。但知乎也在QQ空间上做广告,尝试吸引90后和00后加入知乎。其实90后和00后,还是可以与80后们区分开来。他们关注不同的话题,有不同的兴趣点。他们眼中的知乎,和我们眼中的知乎,是两个知乎;但其实又是同一个知乎。

最后,怎样做社交网站?上面就是答案。

When to Use Val() and Text() in jQuery

This is from the documentation of jQuery:

The .val() method is primarily used to get the values of form elements such as input, select and textarea.

The .text() method cannot be used on form inputs or scripts. To set or get the text value of input or textarea elements, use the .val() method.

That’s the major difference between the two APIs.

Data Structure Learning Experience

Recently, I was reading a thin book about data structure in JavaScript, which has only a little more than 100 pages. But it’s been quite illuminating.

Understand and implement classic data structures and algorithms using JavaScript
Author: Loiane Groner

In this book, the author takes the very basic Array data structure in JavaScript as a starting point. And he adds different sets of properities and functions so that many other types of data structures could be constructed, including list, linked list, set, tree, hash table and even graph.

It’s the first time I have ever realized how data structure works. The constructing process itself is quite illuminating. Then, all my inexplicable fear against data structure is gone.

Then, I take a further step. I start to be guessing that since this book just takes data structures in JavaScript as an example, maybe data structure in other programming languages could be constructed in the same way.

OK, another book confirms my speculation, which is

PHP 7 Data Structures and Algorithms
Author: Mizanur Rahman

A further guess could be that examples in the above two books may be just examples for the purpose of teaching and illustrating. Engineers have to take performance into consideration.

Engineers may use data structure in C language as basic unit to implement that in other higher languages.

Then, what’s next?

Read the source code

最近在看一本讲JavaScript数据结构的小册子,只有100多页,但却获益匪浅。

Understand and implement classic data structures and algorithms using JavaScript
Author: Loiane Groner

在这本书中,作者以JavaScript的Array为基本单位,通过添加一系列的属性和方法,从而构造出多种其他类型的数据结构,包括list,linked list,set,tree,hash table,甚至graph。

这是我第一次意识到数据结果是怎样工作的。这个构造的过程,让我获益匪浅。我对数据结构的无端恐惧突然就消失了。

于是我猜测,PHP、Java和Python等用C实现的高级语言,是不是就是利用C语言的特性,从某些基本的数据结构出发,构造出其他多种多样的数据结构?

后来我看了这本书,证实了我的猜测。

PHP 7 Data Structures and Algorithms
Author: Mizanur Rahman

当然,我也理解书中的这个构造过程,也仅仅是演示而已。在实际工作中,必须把性能纳入考虑范围。

书中的构造可能会有损失。为了追求性能,工程师可以从C语言的多个基本数据结构出发,构造需要的数据结构实现。

以上都是我的猜测。那么下一步怎么办啊?

看源码啊

Content Is King

Original Url: Content Is King

Content is King (1/3/96)

By Bill Gates

Content is where I expect much of the real money will be made on the Internet, just as it was in broadcasting.

The television revolution that began half a century ago spawned a number of industries, including the manufacturing of TV sets, but the long-term winners were those who used the medium to deliver information and entertainment.

When it comes to an interactive network such as the Internet, the definition of “content” becomes very wide. For example, computer software is a form of content-an extremely important one, and the one that for Microsoft will remain by far the most important.

But the broad opportunities for most companies involve supplying information or entertainment. No company is too small to participate.

One of the exciting things about the Internet is that anyone with a PC and a modem can publish whatever content they can create. In a sense, the Internet is the multimedia equivalent of the photocopier. It allows material to be duplicated at low cost, no matter the size of the audience.

The Internet also allows information to be distributed worldwide at basically zero marginal cost to the publisher. Opportunities are remarkable, and many companies are laying plans to create content for the Internet.

For example, the television network NBC and Microsoft recently agreed to enter the interactive news business together. Our companies will jointly own a cable news network, MSNBC, and an interactive news service on the Internet. NBC will maintain editorial control over the joint venture.

Printed magazines have readerships that share common interests. It’s easy to imagine these communities being served by electronic online editions.

But to be successful online, a magazine can’t just take what it has in print and move it to the electronic realm. There isn’t enough depth or interactivity in print content to overcome the drawbacks of the online medium.

If people are to be expected to put up with turning on a computer to read a screen, they must be rewarded with deep and extremely up-to-date information that they can explore at will. They need to have audio, and possibly video. They need an opportunity for personal involvement that goes far beyond that offered through the letters-to-the-editor pages of print magazines.

A question on many minds is how often the same company that serves an interest group in print will succeed in serving it online. Even the very future of certain printed magazines is called into question by the Internet.

For example, the Internet is already revolutionizing the exchange of specialized scientific information. Printed scientific journals tend to have small circulations, making them high-priced. University libraries are a big part of the market. It’s been an awkward, slow, expensive way to distribute information to a specialized audience, but there hasn’t been an alternative.

Now some researchers are beginning to use the Internet to publish scientific findings. The practice challenges the future of some venerable printed journals.

Over time, the breadth of information on the Internet will be enormous, which will make it compelling. Although the gold rush atmosphere today is primarily confined to the United States, I expect it to sweep the world as communications costs come down and a critical mass of localized content becomes available in different countries.

For the Internet to thrive, content providers must be paid for their work. The long-term prospects are good, but I expect a lot of disappointment in the short-term as content companies struggle to make money through advertising or subscriptions. It isn’t working yet, and it may not for some time.

So far, at least, most of the money and effort put into interactive publishing is little more than a labor of love, or an effort to help promote products sold in the non-electronic world. Often these efforts are based on the belief that over time someone will figure out how to get revenue.

In the long run, advertising is promising. An advantage of interactive advertising is that an initial message needs only to attract attention rather than convey much information. A user can click on the ad to get additional information-and an advertiser can measure whether people are doing so.

But today the amount of subscription revenue or advertising revenue realized on the Internet is near zero-maybe 20 million or 30 million in total. Advertisers are always a little reluctant about a new medium, and the Internet is certainly new and different.

Some reluctance on the part of advertisers may be justified, because many Internet users are less-than-thrilled about seeing advertising. One reason is that many advertisers use big images that take a long time to download across a telephone dial-up connection. A magazine ad takes up space too, but a reader can flip a printed page rapidly.

As connections to the Internet get faster, the annoyance of waiting for an advertisement to load will diminish and then disappear. But that’s a few years off.

Some content companies are experimenting with subscriptions, often with the lure of some free content. It’s tricky, though, because as soon as an electronic community charges a subscription, the number of people who visit the site drops dramatically, reducing the value proposition to advertisers.

A major reason paying for content doesn’t work very well yet is that it’s not practical to charge small amounts. The cost and hassle of electronic transactions makes it impractical to charge less than a fairly high subscription rate.

But within a year the mechanisms will be in place that allow content providers to charge just a cent or a few cents for information. If you decide to visit a page that costs a nickel, you won’t be writing a check or getting a bill in the mail for a nickel. You’ll just click on what you want, knowing you’ll be charged a nickel on an aggregated basis.

This technology will liberate publishers to charge small amounts of money, in the hope of attracting wide audiences.

Those who succeed will propel the Internet forward as a marketplace of ideas, experiences, and products-a marketplace of content.

© 2018 awesome.js All Rights Reserved.
Theme by hiero