[Year 12 SofDev] DLTV Exam 1

ATKINSON-BUCK, Damien Damien.ATKINSON-BUCK at ivanhoe.com.au
Wed Oct 8 22:32:59 EST 2014


Fantastic, thanks Chris that works much better. New VB Code below :)

Module Module1
    Dim StudentNo() As Integer = {1, 125, 250, 375, 500, 625, 750, 875, 999}

    Sub Main()
        Dim low As Integer = 0
        Dim high As Integer = 9
        Dim result As Boolean = False
        Dim searchnum As Integer = 375

        Do While low <= high And result = False
            Dim middle As Integer = Int((low + high) / 2)
            If StudentNo(middle) = searchnum Then
                result = True
                Dim myMessage As String = "Low " & StudentNo(low) & ", High " & StudentNo(high) & ", Mid " & StudentNo(middle)
                MsgBox(myMessage, vbOK, "DONE")
            End If
            If StudentNo(middle) > searchnum Then
                high = middle
            Else
                low = middle
            End If
        Loop
    End Sub

End Module


Damien Atkinson-Buck
Head of Learning Area: Technology/Arts

[cid:image005.jpg at 01CFE347.CCF9A650]

p: +61 3 9490 3848

e: damien.atkinson-buck at ivanhoe.com.au<mailto:damien.atkinson-buck at ivanhoe.com.au>

f: +61 3 9490 3490

w: www.ivanhoe.com.au<http://www.ivanhoe.com.au/>


w: www.ivanhoe100.com.au<http://www.ivanhoe100.com.au/>



From: Chris Bucknell [mailto:Chris.Bucknell at haileybury.vic.edu.au]
Sent: Wednesday, 8 October 2014 10:00 PM
To: Year 12 Software Development Teachers' Mailing List
Subject: Re: [Year 12 SofDev] DLTV Exam 1

Hi Damien,

I agree with your logic and working (love a bit of VB.NET code).  I think that the issue is with the algorithm given (it's wrong with two errors).  This algorithm looks like a binary search but instead of returning the quotient (from the sum of the low and high divided by 2) and using this as the middle it looks like it uses the remainder for the middle.  Hence why you have your oscillating 1 and 125 (you have assumed zero index arrays for the student datasets - who knows what would happen with non-zero ... probably a blue screen of death).  The second error is that the low and high values should hold the index position in the array (not the value in that position).

So if we resolve these the two issues (i.e. 1-use the quotient for generating the middle index value, and 2-use the index of the position of the start and end of the data set in the array) then we'd get something like:

(Note: 0 based array - continue the VB feel :))

Pass

Position
Low

Position
High

Calculation

Quotient

Remainder

Position
Middle

Student(Middle)

Found

1

0

9

(0+9)/2 =

4

1

4

500

False

2

0

4

(0+4)/2=

2

0

2

250

False

3

2

4

(2+4)/2=

3

0

3

375

True



Good catch on this on Damien.

Chris Bucknell
Head of ICT
Chris.Bucknell at haileybury.vic.edu.au<mailto:Chris.Bucknell at haileybury.vic.edu.au>
www.haileybury.vic.edu.au<http://www.haileybury.vic.edu.au>


From: sofdev-bounces at edulists.com.au<mailto:sofdev-bounces at edulists.com.au> [mailto:sofdev-bounces at edulists.com.au] On Behalf Of ATKINSON-BUCK, Damien
Sent: Wednesday, 8 October 2014 5:51 PM
To: Year 12 Software Development Teachers' Mailing List (sofdev at edulists.com.au<mailto:sofdev at edulists.com.au>)
Subject: [Year 12 SofDev] DLTV Exam 1

Hi folks,
            I'm just going through the DLTV Exam and can't quite figure the answer to the algorithm question 12 below.
[cid:image006.png at 01CFE347.CCF9A650]
[cid:image007.png at 01CFE347.CCF9A650]

My desk produces,
Pass

Middle

Low

High

Result

StudentNo(Middle)

1

0

1

999

False

1

2

1

0

999

False

125

3

0

1

999

False

1

4

1

0

999

False

125

AND SO ON


I've tried it as vb code below and ended in an infinite loop. Am I missing something blatantly obvious here or can anyone see the fix for this?

Module Module1
    Dim StudentNo() As Integer = {1, 125, 250, 375, 500, 625, 750, 875, 999}

    Sub Main()
        Dim low As Integer = 1
        Dim high As Integer = 999
        Dim result As Boolean = False
        Dim searchnum As Integer = 375

        Do While low <= high And result = False
            Dim middle As Integer = (low + high) Mod 2
            If StudentNo(middle) = searchnum Then
                result = True
                Dim myMessage As String = "Low " & low & ", High " & high & ", Mid " & middle
                MsgBox(myMessage, vbOK, "DONE")
            End If
            If StudentNo(middle) > searchnum Then
                high = middle
            Else
                low = middle
            End If
        Loop
    End Sub

End Module




Damien Atkinson-Buck
Head of Learning Area: Technology/Arts
p: +61 3 9490 3848

e: damien.atkinson-buck at ivanhoe.com.au<mailto:damien.atkinson-buck at ivanhoe.com.au>



f: +61 3 9490 3490

w: www.ivanhoe.com.au<http://www.ivanhoe.com.au>

w: www.ivanhoe100.com.au<http://www.ivanhoe100.com.au>

[cid:image008.jpg at 01CFE347.CCF9A650]
Please consider the environment before printing this e-mail.




Privacy, Virus and Copyright Warning

The information contained in this electronic message (e-mail), and any files transmitted with it:

* is intended for the named recipients only. If you have received this in error, please advise the sender and delete it and any copies immediately;
* Any personal information in this email must be used in accordance with the Privacy Act 1988 and this always applies even if it has been sent to you in error.
* represents the views of the sender and does not necessarily represent the views or formal advice of Ivanhoe Grammar School;
* may be subject to Copyright, so no further use should be made of it without the author's permission.

The School does not represent or warrant that the email or any files attached do not contain errors or are free from computer viruses or other defects nor does it accept responsibility for any loss or damage resulting directly or indirectly from the use of the email or any attached files.

________________________________

This email, including any attachments, is confidential. If you are not the intended recipient you must not copy, use, disclose, distribute or rely on this information. If you have received this email in error, please notify the sender immediately by reply email and delete the email from your system. Confidentiality and legal privilege attached to this communication are not waived or lost by reason of mistaken delivery to you. Haileybury does not guarantee that this email is unaffected by computer virus, corruption or other defects. Haileybury monitors all incoming and outgoing email for compliance with its IT Policies. ABN: 34 004 228 906




Privacy, Virus and Copyright Warning

The information contained in this electronic message (e-mail), and any files transmitted with it:

* is intended for the named recipients only. If you have received this in error, please advise the sender and delete it and any copies immediately;
* Any personal information in this email must be used in accordance with the Privacy Act 1988 and this always applies even if it has been sent to you in error.
* represents the views of the sender and does not necessarily represent the views or formal advice of Ivanhoe Grammar School;
* may be subject to Copyright, so no further use should be made of it without the author's permission.

The School does not represent or warrant that the email or any files attached do not contain errors or are free from computer viruses or other defects nor does it accept responsibility for any loss or damage resulting directly or indirectly from the use of the email or any attached files.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.edulists.com.au/pipermail/sofdev/attachments/20141008/47526d8e/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 1024 bytes
Desc: image001.png
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20141008/47526d8e/image001-0001.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.jpg
Type: image/jpeg
Size: 5753 bytes
Desc: image005.jpg
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20141008/47526d8e/image005-0001.jpg 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image006.png
Type: image/png
Size: 56766 bytes
Desc: image006.png
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20141008/47526d8e/image006-0001.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image007.png
Type: image/png
Size: 46976 bytes
Desc: image007.png
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20141008/47526d8e/image007-0001.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image008.jpg
Type: image/jpeg
Size: 22355 bytes
Desc: image008.jpg
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20141008/47526d8e/image008-0001.jpg 


More information about the sofdev mailing list