CS 1401, Quiz #1, Solutions

Date: Tuesday, January 23, 2007
Name: ____________________________________________________________
Class section (9:00 am or 10:30 am): _______________________________

1. Where does the word "algorithm" come from?

In the 9th century, a mathematician named Al Khorezmi (meaning "from
Khorezm") wrote a book in which he described in detail how to
multiply, how to divide, how to solve simple equations. His
descriptions were so detailed and good that every time someone would
write a good step-by-step description of some procedure, others
would say: "This is as good as the book by Al Khorezmi". When
translated from one language to another, an Oriental-sounding
"Al Khorezmi" became a more European-sounding "algorithm".
2. The language Java was designed to help computers communicate. While previous programming languages translated high-level code directly into machine code, Java first translates into the code for a Java Virtual Machine (JVM) and only then into machine code. Briefly explain how this helps computers to communicate. For extra credit: does this feature make Java faster or slower than other languages (such as C or C++)? Explain why.
Different computers have different machine codes. So, if we use a
language like C++, then computers can only communicate by exchanging
code in C++. When a computer receives such a code, it still needs to
translate it into machine code, and this takes time.

In Java, different computers can exchange code in JVM; JVM code is
close to machine code, so translating from JVM to machine code is much
faster than translating from C++.

In short, for multi-computer computations, Java is much faster.

However, for computations on a single computer, Java is much slower:
because instead of a single translation from C++ to machine code, we
now need two translations: from Java to JVM and from JVM to machine
code.

Besides, when we translate from C++ to machine code, we can have
different translations for different machines, to make the resulting
machine code faster for a particular machine. When we translate from
Java to JVM, this translation has to be generic -- and thus, not so
fast.
3. Mark all the topics discussed in the your reading assignment of Chapter 2: