20172311-ASL测试 2018-1938872补充博客

20172311-ASL测试 2018-1938872补充博客

课程:《程序设计与数据结构》
班级: 1723
姓名: 赵晓海
学号: 20172311
实验教师:王志强老师
测试日期:2018年10月12日
必修/选修: 必修

测试内容

已知线性表具有元素{5,13,19,21,37,56,64,75,80,88,92},如果使用折半查找法,ASL是多少?
(本题目2分,要求写出结题过程)

测试过程及结果

测试过程中遇到的问题和解决过程

  • 问题1:什么是ASL
  • 问题1解决方案:通过询问同学得知:
  • 问题2:需对折半查找法进行了解
  • 问题2解决方案:通过查阅相关资料找到了一个较好理解的折半查找方法的实现如下:
//查找一给定的值是否在指定的数组中,如果存在输出在数组中的下标,如果不存在则输出-1
public?static?int?getIndex(int?target,?int[]?array)?{
        if?(array?==?null?||?array.length?==?0)
            return?-1;
        if?(target?<?array[0]?||?target?>?array[array.length?-?1])
            return?-1;
        int?left?=?0;
        int?right?=?array.length?-?1;
        int?mid?=?(left?+?right)?/?2;
        while?(left?<=?right)?{
            if?(target?<?array[mid])
                right?=?mid?-?1;
            if?(target?>?array[mid])
                left?=?mid?+?1;
            if?(target?==?array[mid])
                return?mid;
            mid?=?(left?+?right)?/?2;
        }
        return?-1;
    }
public?static?void?main(String[]?args)?{
    int?num[]?=?{?2,?3,?4,?6,?10,?20,?31,?35,?42,?53,?60,?90?};
    System.out.println(getIndex(7,?num));
}

思考

这次实验的内容还是很有意义的,比较深入的学习了折半查找法的原理及实现!!

参考资料

原文地址:https://www.cnblogs.com/zhaoxiaohai/p/9781286.html

时间: 2024-08-30 09:30:33

20172311-ASL测试 2018-1938872补充博客的相关文章

测试代码发布到博客效果(Windows Live Writer发布)

测试代码发布到博客效果(Windows Live Writer发布) public class SwitchCase { /** * 1.switch后面的表达式为常量表达式,类型只能是可以转化为int.enum(1.6+).String(1.7+)的类型 * 2.可以转化为int类型的数据类型有:byte.short.int.char * 3.boolean类型的数据类型推荐用if else,java中不支持使用 * * */ public static int getAge(String n

2017-2018-1 20155305 《信息安全系统设计基础》第四周学习总结(课堂提交作业未来得及提交码云链接myod补充博客)

2017-2018-1 20155305 <信息安全系统设计基础>第四周学习总结(课堂提交作业未来得及提交码云链接myod补充博客) 课堂提交题目要求 编写MyOD.java 用java MyOD XXX实现Linux下od -tx -tc XXX的功能 代码码云链接补交 源代码main函数 #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.

测试使用word2010发布博客

package com.wmfxly.base.cache; ? import com.alisoft.xplatform.asf.cache.ICacheManager; import com.alisoft.xplatform.asf.cache.IMemcachedCache; import com.alisoft.xplatform.asf.cache.memcached.CacheUtil; import com.alisoft.xplatform.asf.cache.memcache

补充博客

An undirected graph is a graph where the pairings representing the edges are _____________. Unordered无序 Two vertices in a graph are ___________ if there is an edge connecting them. B .Adjacent 相邻的 An undirected graph is considered complete if it has

测试通过markdown写博客

目录 Pandoc Integration What is Pandoc Install Pandoc For Mac User For Windows User Use Pandoc FAQ TL;DR: Typora requires Pandoc (≥ v1.20). If you do not have Pandoc or only old version of Pandoc installed on your machine, you could: Download installer

博客测试3 编写css

博客测试3  编写css 博客测试3  编写css 博客测试3  编写css 博客测试3  编写css 博客测试3  编写css 博客测试3  编写css 博客测试3  编写css 博客测试3  编写css 博客测试3  编写css

Python 自动刷博客浏览量

哈哈,今天的话题有点那什么了哈.咱们应该秉承学习技术的角度来看,那么就开始今天的话题吧. 思路来源 今天很偶然的一个机会,听到别人在谈论现在的"刷量"行为,于是就激发了我的好奇心.然后看了下requests模块正好对我有用,就写了一个简单的测试用例.神奇的发现这一招竟然是管用的.那还等什么,开刷咯. 前奏 思路很简单,就是一个发送请求的实现,就可以了.代码如下: headers = { 'referer':'http://blog.csdn.net/', 'User-Agent':'M

mybatis博客学习的方式

1.参考完整的博客笔记:http://www.cnblogs.com/xdp-gacl/tag/MyBatis%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/ 2.补充博客1中的mybatis多对多查询:http://www.cnblogs.com/chenliyang/p/6548400.html

Spring Boot带前后端 渐进式开发企业级博客系统

第1章 Spring Boot 简介   1-1 Spring Boot 博客_课程导学   1-2 Spring Boot 是什么第2章 开启 Spring Boot 的第一个 Web 项目   2-1 -初始化第一个Web项目    2-2 -用Gradle编译项目   2-3 -探索项目第3章 一个Hello World项目   3-1 编写项目构建信息    3-2 自定义存储库,加速构建   3-3 编写程序代码及测试用例    3-4 配置Wrapper,运行程序第4章 开发环境的搭