实验二 算法基本功 与 综合思考

来源:互联网 发布:啤酒杯 知乎 编辑:程序博客网 时间:2024/05/01 07:14
1)算法基本功——快速排序

    对文件largeW.txt(下载链接)中的数据,应用快速排序算法进行排序,并与冒泡排序、归并排序进行时间比较。体验算法复杂度对设计算法的影响。

import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.util.ArrayList;import java.util.List;/** *快速排序 */public class QuickSort {private static int partition(Object[] data, int first, int end) {while (first < end) {while (first < end && (Integer)data[first] <= (Integer)data[end]) {//右扫描end--;}if (first < end) {int temp = (Integer)data[first];data[first] = data[end];data[end] = temp;first++;}while (first < end && (Integer)data[first] <= (Integer)data[end]) { //左扫描first++;}if (first < end) {int temp = (Integer)data[first];data[first] = data[end];data[end] = temp;end--;}}return first;}private static void sort(Object[] data, int first, int end) {if (first < end) {int pivot = partition (data, first, end);sort(data, first, pivot-1);sort(data, pivot+1, end);}}private static Object[] getData() {BufferedReader reader;List<Integer> data = null;try {File file = new File("src/dataFile/largeW.txt");reader = new BufferedReader(new FileReader(file));data = new ArrayList<Integer>();String temp = reader.readLine();while (temp != null) {data.add(Integer.valueOf(temp.trim()));temp = reader.readLine();}} catch (FileNotFoundException e) {e.printStackTrace();}  catch (IOException e) {e.printStackTrace();}return data.toArray();}private static void write2File(Object[] data) {FileWriter output = null;try {output = new FileWriter(new File("src/dataFile/largeW_merge.txt"));for (int i=0; i<data.length; i++) {Integer integer = (Integer)data[i];output.write(integer + "\n");}output.flush();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {try {output.close();} catch (IOException e) {e.printStackTrace();}}}public static void main(String[] args) {Object[] testData = getData();sort(testData, 0, testData.length-1);write2File(testData);}}


(3)算法综合实践——搜索引擎

    上网搜索有关“搜索引擎”的相关资料,包括但不限于以下方面(至少要有2个方面):搜索引擎岗位要求、搜索引擎工作原理、搜索引擎涉及到教材中哪些算法、搜索引擎的盈利模式、搜索引擎源码链接、国内外搜索引擎公司现状等。

①搜索引擎指自动从因特网搜集信息,经过一定整理以后,提供给用户进行查询的系统。因特网上的信息浩瀚万千,而且毫无秩序,所有的信息像汪洋上的一个个小岛,网页链接是这些小岛之间纵横交错的桥梁,而搜索引擎,则为用户绘制一幅一目了然的信息地图,供用户随时查阅。

②百度基础算法分析:链接流行度核心算法+百度推广+框计算+开放平台;而Google是使用PageRank技术检查整个网络链接结构

百度的盈利是靠竞价排名和广告,Google主要是广告等,百度的竞价排名虽然可以将网站的排名提前,但是对用户而言,将会导致一些无用的信息增多,降低用户体验,如果当初Google没退出中国,百度绝不会主要靠竞价排名来盈利的。

我感觉我们班很少有人会去做搜索引擎工程师吧(刚毕业时),因为这个只能自学,学校教的也比较少,但是我感觉去做SEO是挺不错的,尤其是在电商快速发展的今天。排名以为着流量,流量意味着金钱。因为我们现在学的主要还是用javac++等开发软件,对搜索引擎的理解还停留在书面上。如果想对搜索引擎有更深刻的理解,我觉得还是要多看算法和多实践。

③搜索引擎工作原理

爬行---抓取存储---预处理---排名

④涉及到的算法有:散列表,余弦相似性,编辑距离等。

盈利模式:1,付费排名 2,广告 3,技术授权费

 

 

 

 

0 0
原创粉丝点击