CSC 1351 Final Exam Questions and
Answers
Recursion - ANSWER-The same computation occurs repeatedly
Recursive Computation - ANSWER-Solves a problem by using the solution to the same
problem with simpler values
In many cases, a recursive solution is easier to understand and implement correctly
than an iterative solution - ANSWER-True
Occasionally, a recursive solution runs much slower than its iterative counterpart -
ANSWER-True
In most cases, the iterative and recursive approaches have comparable efficiency -
ANSWER-True
Measuring Execution Time - ANSWER-long start= System.nanoTime(); //code to be
executed long elapsed = System.nanoTime() - start;
palidrome - ANSWER-a word, sequence or phrase that reads the same forward as it
does backwards, for example words like 'dad', 'mom', 'madam' or numbers like '11',
'121', or '99099'.
A word is a palindrome if - ANSWER-1. The first and last letters match
2. Word obtained by removing the first and last letters is a palindrome
Fibonacci sequence - ANSWER-A sequence of numbers in which each number is the
sum of the preceding two.
Measuring Execution Time - ANSWER-long start = System.nanoTime();
//code to be executed
long elapsed = System.nanoTime() - start;
Sorting arrays is one of the most important operations in programming - ANSWER-True
Algorithm - ANSWER-- A sequence of instructions to solve a problem
-A process or set of rules to be followed in calculations or other problem-solving
operations, especially by a computer
, Bubble Sort - ANSWER-Moving through a list repeatedly, swapping elements that are in
the wrong order.
Selection Sort - ANSWER-A sorting routine that uses a nested loop process to
systematically select the best value among the unsorted elements of the array for the
next position in the array, starting with position zero all the way to the end.
Insertion Sort - ANSWER-A simple sorting algorithm that builds the final sorted array (or
list) one item at time. It is much less efficient on large lists than more advanced
algorithms such as quicksort, heapsort, or merge sort.
Merge Sort - ANSWER-Sorts an array by cutting the array in half Recursively sorting
each half, merging the sorted values.
Which algorithm is associated with "Divide and Conquer"? - ANSWER-Merge Sort
collection - ANSWER-groups together elements and allows them to be retrieved
Lists - ANSWER-A collection that remembers the order of its elements
The two implementations of the Map interface - ANSWER--HashMap
-TreeMap
HashMap - ANSWER-The Hashmap provides an unsorted, unordered Map. With a Map
the elements are not ordered. HashMap allows one null key and multiple null values in a
collection
TreeMap - ANSWER-Red-Black tree based NavigableMap implementation. It is sorted
according to the natural ordering of its keys. TreeMap class implements Map interface
similar to HashMap class.
TreeMaps order items by - ANSWER-Key & in alphabetical order
stacks Remove items ____ - ANSWER-in thee opposite order than they were added
Stacks let you ____ and _____ elements - ANSWER-insert, remove
Stacks order - ANSWER-LIFO
LIFO - ANSWER-Last-in, first-out
The stack push operation - ANSWER-adds a single element to the top
The stack pop operation - ANSWER-Remove the top element
Answers
Recursion - ANSWER-The same computation occurs repeatedly
Recursive Computation - ANSWER-Solves a problem by using the solution to the same
problem with simpler values
In many cases, a recursive solution is easier to understand and implement correctly
than an iterative solution - ANSWER-True
Occasionally, a recursive solution runs much slower than its iterative counterpart -
ANSWER-True
In most cases, the iterative and recursive approaches have comparable efficiency -
ANSWER-True
Measuring Execution Time - ANSWER-long start= System.nanoTime(); //code to be
executed long elapsed = System.nanoTime() - start;
palidrome - ANSWER-a word, sequence or phrase that reads the same forward as it
does backwards, for example words like 'dad', 'mom', 'madam' or numbers like '11',
'121', or '99099'.
A word is a palindrome if - ANSWER-1. The first and last letters match
2. Word obtained by removing the first and last letters is a palindrome
Fibonacci sequence - ANSWER-A sequence of numbers in which each number is the
sum of the preceding two.
Measuring Execution Time - ANSWER-long start = System.nanoTime();
//code to be executed
long elapsed = System.nanoTime() - start;
Sorting arrays is one of the most important operations in programming - ANSWER-True
Algorithm - ANSWER-- A sequence of instructions to solve a problem
-A process or set of rules to be followed in calculations or other problem-solving
operations, especially by a computer
, Bubble Sort - ANSWER-Moving through a list repeatedly, swapping elements that are in
the wrong order.
Selection Sort - ANSWER-A sorting routine that uses a nested loop process to
systematically select the best value among the unsorted elements of the array for the
next position in the array, starting with position zero all the way to the end.
Insertion Sort - ANSWER-A simple sorting algorithm that builds the final sorted array (or
list) one item at time. It is much less efficient on large lists than more advanced
algorithms such as quicksort, heapsort, or merge sort.
Merge Sort - ANSWER-Sorts an array by cutting the array in half Recursively sorting
each half, merging the sorted values.
Which algorithm is associated with "Divide and Conquer"? - ANSWER-Merge Sort
collection - ANSWER-groups together elements and allows them to be retrieved
Lists - ANSWER-A collection that remembers the order of its elements
The two implementations of the Map interface - ANSWER--HashMap
-TreeMap
HashMap - ANSWER-The Hashmap provides an unsorted, unordered Map. With a Map
the elements are not ordered. HashMap allows one null key and multiple null values in a
collection
TreeMap - ANSWER-Red-Black tree based NavigableMap implementation. It is sorted
according to the natural ordering of its keys. TreeMap class implements Map interface
similar to HashMap class.
TreeMaps order items by - ANSWER-Key & in alphabetical order
stacks Remove items ____ - ANSWER-in thee opposite order than they were added
Stacks let you ____ and _____ elements - ANSWER-insert, remove
Stacks order - ANSWER-LIFO
LIFO - ANSWER-Last-in, first-out
The stack push operation - ANSWER-adds a single element to the top
The stack pop operation - ANSWER-Remove the top element