CSCI 2010 FINAL QUIZ 6 – 10 QUESTIONS AND
VERIFIED ANSWERS
The merger sort algorithm contains only one recursive call. - Answers - False
Which of the following best describes the merge sort algorithm? - Answers - The array
is split in half, the two halves are sorted recursively, then the two halves are combined
to put in all items in the correct order.
What is a recursive method? - Answers - A method that calls itself.
Which of the following is NOT required for the correct implementation of a recursive
method? - Answers - Only one branch may contain a recursive call.
Java treats a recursive method call differently from an ordinary method call - Answers -
False
What is the output of the following code?
public static void main(String[] args)
{
System.out.println(getMysteryValue(3));
}
pubic static int getMysteryValue(int n)
{
if (n <= 1)return 1;
else
return getMysteryValue(n - 1) + n;
} - Answers - 6
Which of the following best describes the binary search algorithm? - Answers - A sorted
array is searched starting in the middle. If the middle element is smaller than the search
item, the right half is searched recursively. If the middle element is larger than the
search item, the left half is searched recursively. The search continues until the search
item is found or no items are left.
For large arrays, binary search is much faster than sequential search. - Answers - True
A recursive method must contain a base case, otherwise it will not terminate. - Answers
- True
When does a stack overflow occur? - Answers - When the data structure used to keep
track of recursive calls becomes to large to be stored in available memory.
, Given an sorted array containing the following numbers: 1 3 7 10 12 17 19, what
numbers are compared with the search item by a binary search for the number 12 -
Answers - 10, 17, 12
Which of the following best describes the steps taken by the merge sort algorithm when
sorting the array containing the following numbers: 4 3 2 1. - Answers - 4 3 2 1
3421
3412
1234
QUIZ 7 - Answers -
Which Java class is the preferred class to use for reading from a text file? - Answers -
Scanner
What is the difference between an input stream and an output stream? - Answers - An
input stream reads data from a file or console and sends it to a program. An output
stream takes data from a program and writes it to a file or console.
What is the difference between a full path name and a relative path name? - Answers -
A full path name starts at the root directory while a relative path name starts at the
directory in which the program is running.
What is the difference between a text file and a binary file? - Answers - A text file stores
a sequence of characters while a binary file uses some other encoding of data.
Data in a file remains after program execution ends. - Answers - True
Which Java class is the preferred class to use for writing to a text file? - Answers -
PrintWriter
Which of the following statements open s a text file called "myfile.txt" so that new text
can be appended to the existing contents of file? - Answers - outputStream = new
PrintWriter(new FileOutputStream("myfile.txt", true));
A statement opening a text file for reading or writing may generate a
FileNotFoundException - Answers - True
Which of the following is not a method of the File class? - Answers - close()
Which of the following is the correct way to open a text file called "myfile.txt" for
reading? - Answers - inputStream = new Scanner(new File("myfile.txt"));
A comma-separated values for CSV file is a simple text format used to store a list of
record. - Answers - True
VERIFIED ANSWERS
The merger sort algorithm contains only one recursive call. - Answers - False
Which of the following best describes the merge sort algorithm? - Answers - The array
is split in half, the two halves are sorted recursively, then the two halves are combined
to put in all items in the correct order.
What is a recursive method? - Answers - A method that calls itself.
Which of the following is NOT required for the correct implementation of a recursive
method? - Answers - Only one branch may contain a recursive call.
Java treats a recursive method call differently from an ordinary method call - Answers -
False
What is the output of the following code?
public static void main(String[] args)
{
System.out.println(getMysteryValue(3));
}
pubic static int getMysteryValue(int n)
{
if (n <= 1)return 1;
else
return getMysteryValue(n - 1) + n;
} - Answers - 6
Which of the following best describes the binary search algorithm? - Answers - A sorted
array is searched starting in the middle. If the middle element is smaller than the search
item, the right half is searched recursively. If the middle element is larger than the
search item, the left half is searched recursively. The search continues until the search
item is found or no items are left.
For large arrays, binary search is much faster than sequential search. - Answers - True
A recursive method must contain a base case, otherwise it will not terminate. - Answers
- True
When does a stack overflow occur? - Answers - When the data structure used to keep
track of recursive calls becomes to large to be stored in available memory.
, Given an sorted array containing the following numbers: 1 3 7 10 12 17 19, what
numbers are compared with the search item by a binary search for the number 12 -
Answers - 10, 17, 12
Which of the following best describes the steps taken by the merge sort algorithm when
sorting the array containing the following numbers: 4 3 2 1. - Answers - 4 3 2 1
3421
3412
1234
QUIZ 7 - Answers -
Which Java class is the preferred class to use for reading from a text file? - Answers -
Scanner
What is the difference between an input stream and an output stream? - Answers - An
input stream reads data from a file or console and sends it to a program. An output
stream takes data from a program and writes it to a file or console.
What is the difference between a full path name and a relative path name? - Answers -
A full path name starts at the root directory while a relative path name starts at the
directory in which the program is running.
What is the difference between a text file and a binary file? - Answers - A text file stores
a sequence of characters while a binary file uses some other encoding of data.
Data in a file remains after program execution ends. - Answers - True
Which Java class is the preferred class to use for writing to a text file? - Answers -
PrintWriter
Which of the following statements open s a text file called "myfile.txt" so that new text
can be appended to the existing contents of file? - Answers - outputStream = new
PrintWriter(new FileOutputStream("myfile.txt", true));
A statement opening a text file for reading or writing may generate a
FileNotFoundException - Answers - True
Which of the following is not a method of the File class? - Answers - close()
Which of the following is the correct way to open a text file called "myfile.txt" for
reading? - Answers - inputStream = new Scanner(new File("myfile.txt"));
A comma-separated values for CSV file is a simple text format used to store a list of
record. - Answers - True