Eboard 22: Searching

You are being recorded and transcribed.

Approximate overview

  • Administrivia [??]
  • Questions [??]
  • Lab [??]

Preliminaries

  • Greetings on the celebration of the revealing of the Quran
  • I hope that you are recovering okay from the time changes.
  • For reasons I will discuss, I will not be in class on Wednesday. You will have a sub.

Upcoming work

  • Monday, 2024-03-10, 11pm, MP5
  • Tuesday, 2024-03-12, 11pm, MP5 post reflection
  • Wednesday, 2024-03-13, Readings
  • Friday, 2024-03-15, 11pm, Third set of LAs.
    • Mostly posted.
    • Let me know if any look wrong.
    • Let me know if you’d like to see any others posted.
    • Grading is still on my priority queue, near the front.

Tokens

Academic/Scholarly

  • Tuesday, 2024-03-12, noon, Some PDR. CS Table.
  • Tuesday, 2024-02-12, 8:00–9:00pm, Science 3821. CSC-207 Mentor Session.

Cultural

  • Friday at 4pm in the Global Living Room. Middle of Everywhere.
    • I don’t know whether or not that’s happening.

Peer

  • Friday at 7pm, Nepali students association celebrating Shivaratri
    • RSVP required.
    • Contract your classmate for the link.

Wellness

  • Tuesday, 2024-03-12, noon-1pm, BRAC P103. HIIT and Strength Fitness Class.
  • Tuesday, 2024-03-12, 12:15–12:50, Bucksbaum 131. Yoga in the Museum.
  • Tuesday, 2024-03-12, 4pm, BRAC P103 (Multipurpose Dance Studio): Yoga.

Misc

Other good things to do (no tokens)

Questions

Administrative

Searching

Other topics

Lab

for-each loops

How to do a for-each loop in Java.

for (T val : values) {
} // for

That’s right! There are no indices! (Or indexes!)

Iterating arrays

Note: Although you can iterate arrays with for-each, they are not Iterable objects.

Assertions in exercise 3

assert and assertThrows are not intended to be real procedures. Rather, they are an indication that you should check that.

For example, assert(binarySearch(2*i, array) == i) could be rendered as

    try {
      int result = binarySearch(2*i, array);
      if (result != i) {
        System.err.println("binarySearch(" + 2*i + ", " + 
          Arrays.toString(array) + ") returned " + result);
      }
    } catch (Exception e) {
      System.err.println("binarySearch(" + 2*i + ", " +
        Arrays.toString(array) + ") threw an unexpected exception");
    } // try/catch

Similarly, assertThrows(binarySearch(2*i+1, array)) could be rendered as

    try {
      int result = binarySearch(2*i + 1, array);
      System.err.println("binarySearch(" + (2*i+1) + ", " +
          Arrays.toString(array) + ") failed to throw an exception");
    } catch (Exception e) {
    }
  • Algorithm LO#1: Sequential search
  • Algorithm LO#2: Binary search

How should I write the code to build all the arrays?