Simultaneous minimum and maximum (Solution to algorthm)
来源:互联网 发布:淘宝购买电影资源 编辑:程序博客网 时间:2024/04/27 23:07
if we want to get both the Min and Max number from the unsorted sequence ,and we want it's less than 2n comparisions.
so we can get it at most 3(n/2) comparisions;
And it is the algorthm followed:(pseudocode)
MIN_MAX(A)
if A[1]>A[2] then min = A[2],max = A[1];
else min = A[1].max = A[2];
m = n/2;
for i = 2; to m;
if A[2i-1] > A[2i]
then if A[2i] < min then min = A[2i];
if A[2i-1]>max then max = A[2i-1];
//(A[2i-1]<=A[2i])
else if A[2i-1] <min then min = A[2i-1];
if A[2i[>max then max = A[2i];
if n != 2m then if A[n]<min then min = A[n];
if A[n]>max then max = A[n];
return (min ,max);
else min = A[1].max = A[2];
m = n/2;
for i = 2; to m;
if A[2i-1] > A[2i]
then if A[2i] < min then min = A[2i];
if A[2i-1]>max then max = A[2i-1];
//(A[2i-1]<=A[2i])
else if A[2i-1] <min then min = A[2i-1];
if A[2i[>max then max = A[2i];
if n != 2m then if A[n]<min then min = A[n];
if A[n]>max then max = A[n];
return (min ,max);
- Simultaneous minimum and maximum (Solution to algorthm)
- 4.1 Maximum and Minimum Value
- Solution to Point of Maximum Overlap Problem
- Simultaneous Detection and Segmentation
- making 11 connections and the number of simultaneous builds has been throttled to 10
- The Solution to LeetCode 111 Minimum Depth of Binary Tree
- 53. Maximum Subarray Add to List QuestionEditorial Solution
- cool and pythonic solution to leetcode 17.
- find Minimum and Maximum in Rotated Sorted Arrray
- Maximum Subarray Difference Solution
- Simultaneous Localization and Mapping (SLAM)讲义1
- Simultaneous Localization and Mapping (SLAM)讲义1
- Simultaneous Localization and Mapping (SLAM)讲义1
- Simultaneous Localization and Mapping (SLAM)讲义1
- Solution to Articulation Points, Bridges, and Biconnected Components Problem
- [LeetCode] Best Time to Buy and Sell Stock Solution
- [LeetCode] Best Time to Buy and Sell Stock II Solution
- [LeetCode] Best Time to Buy and Sell Stock III Solution
- 判断一个数能否被7或9整除
- 搭建android 2.2 开发环境
- 【牛人】连接
- C/C++单元测试框架Framework
- 异常处理.cpp
- Simultaneous minimum and maximum (Solution to algorthm)
- poj 1389 多边形面积
- 图形化用户界面
- jsp自定义标签实现权限拦截
- 3 双链表
- Max Subsequence Sum 最大子序列和问题 O(NlogN)与O(N)算法的对比
- php,js常用的一些总结
- 解决 Subversion 的 “svn: Can't convert string from 'UTF-8' to native encoding” 错误
- axis2 webservice学习笔记