排序算法中平均时间复杂度_操作系统中的作业排序(算法,时间复杂度和示例)...

本文介绍了作业排序问题,涉及如何使用贪婪方法按利润升序排列作业,并讨论了其时间复杂度为O(n^2)。通过示例解释了如何找出最大利润和完成的工作数量。
摘要由CSDN通过智能技术生成

排序算法中平均时间复杂度

作业排序 (Job sequencing)

Job sequencing is the set of jobs, associated with the job i where deadline di >= 0 and profit pi > 0. For any job i the profit is earned if and only if the job is completed by its deadline. To complete a job, one has to process the job on a machine for one unit of time. Only one machine is available for processing the jobs.

作业排序是与作业i相关联的一组作业,其中期限di> = 0且利润pi> 0 。 对于任何工作, 我当且仅当作业被其限期完成利润赚。 为了完成一项工作,必须在一台机器上在一个单位时间内处理该工作。 仅一台机器可用于处理作业。

Steps for performing job sequencing with deadline using greedy approach is as follows:

使用贪婪方法在截止日期之前执行作业排序的步骤如下:

  1. Sort all the jobs based on the profit in an increasing order.

    根据利润按升序对所有作业进行排序。

  2. Let α be the maximum deadline that will define the size of array.

    令α为将定义数组大小的最大截止日期。

  3. Create a solution array S with d slots.

    创建具有d个插槽的解决方案数组S。

  4. Initialize the content of array S with zero.

    用零初始化数组S的内容。

  5. Check for all jobs.

    检查所有作业。

    1. If scheduling is possible a lot ith slot of array s to job i.
    2. 如果调度是可能很多我阵列的时隙s到工作我 。
    3. Otherwise look for location (i-1), (i-2)...1.
    4. 否则寻找位置(i-1),(i-2)... 1 。
    5. Schedule the job if possible else reject.
  6. Return array S as the answer.

    返回数组S作为答案。

  7. End.

    结束。

作业排序算法 (Algorithm for job sequencing)

Input: A is the array of jobs with deadline and profit S array will be the output.

输入: A是具有截止日期的职位数组,而利润S数组将是输出。

    1. Begin
    2. Sort all the jobs based on profit Pi so
    3. P1 > P2 > P3 …………………………….>=Pn
    4. d = maximum deadline of job in A
    5. Create array S[1,…………………,d]
    6. For i=1 to n do
        7. Find the largest job x
        8. For j=i to 1
            9. If ((S[j] = 0) and (x deadline<= d))
            10. Then 
                11. S[x] = i;
                12. Break;
            13. End if
        14. End for
    15. End for
    16. End

时间复杂度 (Time complexity)

Job sequencing problems has the time complexity of O(n2).

作业排序问题的时间复杂度为O(n2)。

Example:

例:

Given a set of 9 jobs where each job has a deadline and profit associated to it .Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit if and only if the job is completed by its deadline. The task is to find the maximum profit and the number of jobs done.

给定一组9个工作,每个工作都有一个截止日期和与之相关的利润。每个工作需要1个时间单位才能完成,并且一次只能安排一个工作。 当且仅当工作在截止日期之前完成时,我们才能赚取利润。 任务是找到最大的利润和完成的工作数量。

    Jobs	 Profit	  Deadline
    J1	        85	        5
    J2	        25	        4
    J3	        16	        3
    J4	        40	        3
    J5	        55	        4
    J6	        19	        5
    J7	        92	        2
    J8	        80	        3
    J9	        15	        7


Step 1:

第1步:

job sequencing 1

Step 2:

第2步:

job sequencing 2

Step 3:

第三步:

job sequencing 3

Step 4:

第4步:

job sequencing 4

Step 5:

步骤5:

job sequencing 5

Step 6:

步骤6:

job sequencing 6

So, the maximum profit = 40 + 92 + 80 + 55 + 85 + 15 = 367

因此,最大利润= 40 + 92 + 80 + 55 + 85 + 15 = 367

翻译自: https://www.includehelp.com/operating-systems/job-sequencing.aspx

排序算法中平均时间复杂度

1.冒泡排序原理:通过相邻的两个数据之间的比较和交换,使关键码较小的记录逐渐从底部上浮,关键码较大的记录逐渐从顶部下沉。 算法实现:对n个数据进行n-1次排序,每次从剩余元素的第一个开始进行相邻元素交换比较,实现由小到大的排序。 2.选择排序原理:通过多次关键码的比较,使得在每一趟排序第一位最小。 算法实现:对n个数据,比较n-1趟,在每趟区间将最小数下标记录在k,若k不为1,将b[1]与b[k]交换,始终保持剩余元素的第一个数为该趟最小值,实现由小到大的排序。 3.插入排序原理:将原序列逐个分开,每次比较插入一个新的关键码,与已经排好序的记录码比较,寻找合适位置插入该记录码,实现排序算法实现:对n个数据,比较n-1趟,以第一个数据为初始序列,每趟插入一个原序列的关键码,并进行比较,若找到序列比该关键码大的数据,则该数据之前一位即为插入位置,将该数据连同之后的所有数据后移一位,进行插入,实现由小到大的排序。 4.快速排序原理:通过一趟排序将要排序的记录分割成独立的两部分,其一部分的所有记录关键码比另一部分的都小,再按此方法对两部分数据进行递归,实现快速排序算法实现:从每趟数据的左边界向右搜索一个比它大的数据1,同时从右边界搜索一个比它小的数据2,若数据1的下标大于数据2的下标,则交换位置,如此循环,再对关键数据的左半部分和右半部分进行递归,实现由小到大的排序
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值