Question

Subject: Algorithm

4. Give pseudocode for an algorithm that will solve the following problem. Given an array A[1..n) that contains every number

need this urgent please thank you.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. let x = 1, y = n

2. middle_pt = (x+y) / 2

3. run step 4. to 6. while ((y - x) > 1)

4. middle_pt = (x + y) / 2;

5. if ((A[x] - x) is not equal to (A[middle_pt] - middle_pt))

then y = middle_pt

6. else if ((A[y] - y) is not equal to (A[middle_pt] - middle_pt))

then x = middle_pt

7. return (A[middle_pt] + 1) {Missing Element}

here the indexing is starting from 1

The concept behind this solution is that the elements appearing before the missing element will have A[i] – i = 0 and those appearing after the missing element will have A[i] – i = 1.

Add a comment
Know the answer?
Add Answer to:
Subject: Algorithm need this urgent please thank you. 4. Give pseudocode for an algorithm that will solve the following problem. Given an array A[1..n) that contains every number between 1 and n +...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT