#include<iostream>
#include<climits>
using namespace std;
int main()
{
int i,n;
cout<<"Enter size of array : ";
cin>>n;
int arr[n];
cout<<"Enter "<<n<<" elements : ";
for(i=0;i<n;i++)
cin>>arr[i];
int prev=INT_MAX;
for(i=0;i<n;i++)
{
if(arr[i]<prev)
{
prev=arr[i];
continue;
}
else
break;
}
if(i==n)
cout<<"Array is in descending order\n";
else
cout<<"Array not in descending order\n";
}
/*Solution in parallelism, that is to check whether an array of integers are sorted in descending order or not
without storing the elements in array
*/
function main()
{
read n //where n denotes the size of the array
prev=MAX // prev is an integer variable which stores previous visited value of the input
for i=0 to n-1
read currentValue //val is an integer variable that stores current value of the input
if(currentValue<prev) //If previous value is greater than the current value then array is sorted upto this point
prev=currentValue //Update prev value to compare it with the next input
continue;
else
break;
//If the for loop iteration iterated n times
//then array is in descending order otherwise not
if(i==n)
print "Array is in descending order"
else
print "Array is not in descending order"
}
Parallelism:
Since the elements are not stored in a array it is evaluated for the task while taking input that is it is solved using parallelism.
Work:
Since the loop is iterating n times so the work span is O(n)
Consider the following problem Input: array of integers. Check, whether it is sorted in descending order...
The input is an array of N integers ( sorted ) and an integer X. The algorithm returns true if X is in the array and false if X is not in the array. Describe an algorithm that solves the problem with a worst case of O(log N) time.
Consider the following problem: Input: a list of n-1 integers and these integers are in the range of 1 to n. There are no duplicates in list. One of the integers from 1 to n is missing in the list. Output: find the missing integer Let the input array be [2, 4, 1, 6, 3, 7, 8]. Elements in this list are in the range of 1 to 8. There are no duplicates, and 5 is missing. Your algorithm needs...
You are given an array A of integers in sorted order. However, you do not know the length n of the array. Assume that in our programming language arrays are implemented in such a way that you receive an out-of-bounds error message whenever you wish to access an element A[i] with i>n. For simplicity we assume that the error message simply returns the value INT_MAX and that every value in the array is smaller than INT_MAX. (a) Design an algorithm...
Given two arrays A and B of n integers both of which are sorted in ascending order. Write an algorithm to check whether or not A and B have an element in common. Find the worst case number of array element comparisons done by this algorithm as a function of n and its Big-O complexity
1. Please write a Divide-and-Conquer Java algorithm solving the following problem: Given an "almost sorted" array of distinct integers, and an integer x, return the index of x in the array. If the element x is not present in the array, return -1. "Almost sorted" means the following. Assume you had a sorted array A[0…N], and then split it into two pieces A[0…M] and A[M+1…N], and move the second piece upfront to get the following: A[M+1]…A[N]A[0]…A[M]. Thus, the "almost sorted"...
Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers (words)that are read from the console. Be reminded that in a descending sort, the integers are sorted from the largest to the smallest. A “special value” 99999 will beused to signify the end of the input sequence. This value is not to be considered part of the input data set. However, any value greater than 99999 that...
Please use Java recursion knowledge to solve. Given the following sorted array of integers: 1 7 8 11 15 22 38 What are the "middle" elements that the binary search algorithm would examine/compare to as it divides the array into sections when looking for the number 7? 1 7 8 11 15 22 38
6. Consider the following basic problem. You're given an array A consisting of n integers A[1], A[2], , Aln]. You'd like to output a two-dimensional n-by-n array B in which B[i, j] (for i <j) contains the sum of array entries Ali] through Aj]-that is, the sum A[i] Ai 1]+ .. +Alj]. (The value of array entry B[i. Λ is left unspecified whenever i >j, so it doesn't matter what is output for these values.) Here's a simple algorithm to...
You are given an array containing integers in the sorted order: [O] [1] [2] [3] [4] [5] [6] [7] 6 9 17 29 33 41 58 61 [8] [9] [10] [11] [12] [13] 67 87 93 112 118 145 We want to find 12 in the given array, using binary search algorithm. The first comparison will be made with ----- 6 58 61 None. 12 is not in the array.
in C++ HeapSort Implement the heapsort algorithm for sorting an array of integers. Input structure Each case starts with an integer number which indicates the number of elements to be sorted. Then, the elements follow, one per line. You can assume the input is correctly structured (i.e., no data are missing Output structure Output the sorted sequence separeted by";" (in non-decreasing order). Do not insert spaces or a new line at the beginning or at the end of any element.