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
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?
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.
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,...
1. You are given an array of integers, where different integers may have different number of...
1. You are given an array of integers, where different integers may have different number of digits, but the total number of digits over all the integers in the array is n. Show how to sort the array in O(n) time. 2. You are given an array of strings, where different strings may have different numbers of characters, but the total number of characters over all the strings is n. Show how to sort the strings in O(n) time. (Note...
Given an array, A, of n−2 unique integers in the range from 1 to n, describe...
Given an array, A, of n−2 unique integers in the range from 1 to n, describe an O(n)-time method for finding the two integers in the range from 1 to n that are not in A. You may use only O(1) space in addition to the space used by A.
Suppose an array A stores n integers, each of which is in {0, 1, 2, ...,...
Suppose an array A stores n integers, each of which is in {0, 1, 2, ..., 99}. Which of the following sorting algorithms can sort A in O(n) time in the worst case? Question 16 options: A) merge sort B) counting sort C) quicksort D) None of these options is correct. E) insertion sort
The following algorithm adds all the entries in a square n × n array A. Analyze...
The following algorithm adds all the entries in a square n × n array A. Analyze this algorithm where the work unit is the addition operation. sum = 0 for i = 1 to n do for j = 1 to n do sum = sum + A[i, j] end for end for write (“Total of all array elements is”, sum)
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT