算法课_归并排序应用
来源:互联网 发布:数据库备份还原 编辑:程序博客网 时间:2024/05/21 21:47
Question 1
Merging with smaller auxiliary array. Suppose that the subarray a[0] to a[N-1] is sorted and the subarray a[N] to a[2*N-1] is sorted. How can you merge the two subarrays so that a[0] to a[2*N-1] is sorted using an auxiliary array of size N (instead of 2N )?
Question Explanation
Hint: copy only the left half into the auxiliary array.
Hint: copy only the left half into the auxiliary array.
Question 2
Counting inversions. An inversion in an array a[] is a pair of entries a[i] and a[j] such that i<j but a[i]>a[j] . Given an array, design a linearithmic algorithm to count the number of inversions.
Question Explanation
Hint: count while mergesorting.
Hint: count while mergesorting.
Question 3
Shuffling a linked list. Given a singly-linked list containing N items, rearrange the items uniformly at random. Your algorithm should consume a logarithmic (or constant) amount of extra memory and run in time proportional to NlogN in the worst case.
Question Explanation
Hint: design a linear-time subroutine that can take two uniformly shuffled linked lists of sizesN1 and N2 and combined them into a uniformly shuffled linked lists of size N1+N2 .
Hint: design a linear-time subroutine that can take two uniformly shuffled linked lists of sizes
类似归并排序,从1-2-4,
保证两个归并前是随机排序的,即N1和N2里的元素都有 1/N1 和 1/N2 的概率排到每一个位置,那么N1和N2归并的时候,N1/(N1+N2)的概率选择N1,N2/(N1+N2)的概率选择N2,那么每个元素在每个位置的概率都是1/(N1+N2)。例如,两个长度为1的归并,每个都有1/2的概率排在两个位置上。
- 算法课_归并排序应用
- 排序算法-归并排序_归并排序
- 排序算法_归并排序
- 算法导论_归并排序
- JAVA_算法_归并排序
- 排序算法_插入排序、归并算法
- 数据结构(C#)_排序算法(归并排序)
- 归并排序的算法应用
- 基础数据结构算法_快速排序,堆排序,归并排序
- C++_归并排序
- 05_归并排序
- 06_归并排序
- 【算法】_008_归并排序_ 插入法优化
- 归并排序_分治算法 (白书P226)
- 《数据结构与算法》学习笔记20 递归_归并排序
- 排序应用--归并排序
- 排序算法-归并排序
- 排序算法------归并排序
- WCF学习之旅第一讲 简单的WCF应用
- mount nfs4 ....No such file or directory
- UINavigationController
- Java面向对象基础--构造方法私有化
- Android源码目录结构详解
- 算法课_归并排序应用
- 6 - String to Integer (atoi)
- 邮箱验证注册的思路
- 接触互联网的日子
- 通过OCCI操作Oracle数据库详解
- vb6如何在任务栏中显MDI子体窗体的标题
- Linux 查看CPU信息、机器型号等硬件信息
- android selector 简介(通过判断控件的不同状态为其添加背景等操作)
- USB入门系列之一 —— USB概述