computer science help urgernt Watch

Fifty345
Badges: 9
Rep:
?
#1
Report Thread starter 1 week ago
#1
how do you work out the arr[mid] in this trace table? question is below.



Name:  Capture.PNG
Views: 3
Size:  77.4 KB
0
reply
winterscoming
Badges: 18
Rep:
?
#2
Report 1 week ago
#2
Firstly, you have an array, called arr which contains the following items:
Code:
3, 5, 13, 43, 655, 872
The question states that the array indexing starts at 1 (i.e. the "index" or "position number" for the first element is index 1).

So:
- arr[1] is 3
- arr[2] is 5
- arr[3] is 13
etc.

If you can calculate 'mid' then 'arr[mid]' is the value in the array which corresponds to index (position) mid.

the calculation for 'mid' is pretty clear -- (left + right) DIV 2
(remember that DIV means integer division so no fractions or remainders, e.g. 1 DIV 2 is zero, 9 DIV 2 is 4, etc. )

Just fill in the trace table one row at a time (each row is a 'cycle' of the while loop) - start with the easy values of 'left' and 'right', afterwards, calculate 'mid', and then you'll be able to get arr[mid].
Last edited by winterscoming; 1 week ago
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

University open days

  • University of Roehampton
    Department of Life Sciences; Department of Psychology Undergraduate
    Thu, 21 Feb '19
  • Edge Hill University
    Undergraduate and Postgraduate - Campus Tour Undergraduate
    Thu, 21 Feb '19
  • St George's, University of London
    Postgraduate Open Evening Postgraduate
    Thu, 21 Feb '19

Do unconditional offers make teenagers lazy?

Yes (238)
59.95%
No (159)
40.05%

Watched Threads

View All