Question

Let B[1...n] be an array of integers. To express that no integer occurs twice in the...

Let B[1...n] be an array of integers. To express that no integer occurs twice in the B We may write? (check all the answers that apply)

a) forall i 1..n forall j in 1...n B[i] != B[j]

b)for all i in 1...n forall j in 1...n, i != j => B[i] !=B[j]

c)forll i in 1...n forall j in 1...n i != j and B[i] != B[j]

d)forall i in 1...n forall j in 1...n B[i] =B[j] => i=j

e)forall i in 1...n-1 B[i] != B[i+1]

Homework Answers

Answer #1

b)for all i in 1...n forall j in 1...n, i != j => B[i] !=B[j]

c)forll i in 1...n forall j in 1...n i != j and B[i] != B[j]

d)forall i in 1...n forall j in 1...n B[i] =B[j] => i=j

Explanation: to say that an integer at position i is not repeated again we have to check at every position from 1 to n other than i such that none of the integers at these positions should be equal to the integer at i. This should be checked for all positions from 1 to n to say that no integer occurs twice.

Why not a) forall i 1..n forall j in 1...n B[i] != B[j] ?

This will compare an integer at position i with itself and gives wring result

why not e)forall i in 1...n-1 B[i] != B[i+1] ?

This will check adjacent elements only.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Let A[1, . . . , n] be an array of n distinct numbers. If i...
Let A[1, . . . , n] be an array of n distinct numbers. If i < j and A[i] > A[j], then the pair (i, j) is called an inversion of A. 1. Which arrays with distinct elements from the set {1, 2, . . . , n} have the smallest and the largest number of inversions and why? State the expressions exactly in terms of n. 2. For any 0 < a < 1/2, construct an array for...
IN MATLAB: Suppose you are given an array with integers between 1 and 1,000. One integer...
IN MATLAB: Suppose you are given an array with integers between 1 and 1,000. One integer is in the array twice. How can you determine which one?
Let A[1..n] be an array of positive integers (A may not be sorted). Pinocchio claims that...
Let A[1..n] be an array of positive integers (A may not be sorted). Pinocchio claims that there exists an O(n)-time algorithm that decides if there are two integers in A whose sum is 1000. Is Pinocchio right, or will his nose grow? If you say Pinocchio is right, explain how it can be done in O(n) time; otherwise, argue why it is impossible.
C Programming: Write a function that takes in an array of integers and an integer containing...
C Programming: Write a function that takes in an array of integers and an integer containing the count of elements, then have it returns the sum of all the even values inside the array.
Using Tuples in python In this problem, you will be given an array A of integers...
Using Tuples in python In this problem, you will be given an array A of integers of fixed size N and an integer K and you have to find the number of tuples (i, j) such that the following properties are satisfied, ● A[i]*A[i+1]*A[i+2]...A[j-1]*A[j] < K ● -1 < i < N ● i < j + 1 Note that the array is 0-indexed. Input Format The first line will contain integers N and K separated by a single space....
Let a, b, and n be integers with n > 1 and (a, n) = d....
Let a, b, and n be integers with n > 1 and (a, n) = d. Then (i)First prove that the equation a·x=b has solutions in n if and only if d|b. (ii) Next, prove that each of u, u+n′, u+ 2n′, . . . , u+ (d−1)n′ is a solution. Here,u is any particular solution guaranteed by (i), and n′=n/d. (iii) Show that the solutions listed above are distinct. (iv) Let v be any solution. Prove that v=u+kn′ for...
1. Let n be an odd positive integer. Consider a list of n consecutive integers. Show...
1. Let n be an odd positive integer. Consider a list of n consecutive integers. Show that the average is the middle number (that is the number in the middle of the list when they are arranged in an increasing order). What is the average when n is an even positive integer instead? 2. Let x1,x2,...,xn be a list of numbers, and let ¯ x be the average of the list.Which of the following statements must be true? There might...
Given an unsorted integer array A of size n, develop a python version pseudocode with time...
Given an unsorted integer array A of size n, develop a python version pseudocode with time complexity as low as possible to find two indexes i and j such that A[i] + A[j] = 100. Indexes i and j may or may not be the same value.
We are given an array A of size n containing n positive and negative integers (the...
We are given an array A of size n containing n positive and negative integers (the array is indexed starting from 0). Our goal is to find two indices i and j such that 0 ≤ i ≤ j ≤ n and Pk=j k=i A[k] is maximized. Input sequence: [2, -4, 1, 9, -6, 7, -3] Output: [1, 9, -6, 7] or i = 2 and j = 5 Input sequence: [1, 2, 3, 4, 5, 6, -3] Output: [1,...
Let mixsort(A, 1, n) be an algorithm that sorts an array A with n integers. It...
Let mixsort(A, 1, n) be an algorithm that sorts an array A with n integers. It works as follows: mixsort(A, p, q){ if p ≥ q, return; r=partition(A, p, q); //run mixsort on the low part mixsort(A, p, r − 1); //run insert sort on the high part insertsort(A, r + 1, q); } Compute the best-case, worst-case, and average-case complexities of mixsort.