Exam 16: Sorting, Searching, and Algorithm Analysis
Exam 1: Introduction to Computers and Java42 Questions
Exam 2: Java Fundamentals53 Questions
Exam 3: Decision Structures52 Questions
Exam 4: Loops and Files48 Questions
Exam 5: Methods50 Questions
Exam 6: A First Look at Classes49 Questions
Exam 7: A First Look at Gui Applications49 Questions
Exam 8: Arrays and the Arraylist Class52 Questions
Exam 9: A Second Look at Classes and Objects40 Questions
Exam 10: Text Processing and More About Wrapper Classes49 Questions
Exam 11: Inheritance49 Questions
Exam 12: Exceptions and Advanced File Io46 Questions
Exam 13: Advanced Gui Applications46 Questions
Exam 14: Applets and More39 Questions
Exam 15: Recursion34 Questions
Exam 16: Sorting, Searching, and Algorithm Analysis46 Questions
Exam 17: Generics50 Questions
Exam 18: Collections50 Questions
Exam 19: Array-Based Lists20 Questions
Exam 20: Linked Lists36 Questions
Exam 21: Stacks and Queues36 Questions
Exam 22: Binary Trees, Avl Trees, and Priority Queues45 Questions
Select questions type
The worst case complexity function is a good measure to use when
Free
(Multiple Choice)
4.8/5
(39)
Correct Answer:
B
One can sort an array a[ ] as follows.Start by observing that at stage 0,the array segment consisting of the single element a[0] is sorted.Now suppose that at the stage k,the segment a[0..k] is sorted.Take the element a[k+1],and call it X.By moving some of the elements in a[0..k] one place to the right,create a place to put X in so that now a[0..k+1] is sorted.The algorithm that uses this strategy is called
Free
(Multiple Choice)
4.9/5
(45)
Correct Answer:
B
When applied to an array a[ ] of integers,the pseudo code
Boolean sort = true
Int k = 0
While sort == true and k < a.length-1
If a[k] > a[k+1] Then
Sort = false
End If
K = k +1
End While
Free
(Multiple Choice)
4.8/5
(47)
Correct Answer:
C
An array a[ ] of N elements is being sorted using the insertion sort algorithm.The algorithm is at the last stage,with the segment of the array in positions 0 through N-2 already sorted.How many array elements will a[N-1] have to be compared to,before it can be placed into its proper position?
(Multiple Choice)
4.8/5
(36)
Let F be an algorithm with complexity function f(n),and let G be an algorithm with complexity function g(n).If there exists a positive constant K such that the ratio f(n)/g(n)is less or equal to K for all n greater or equal to 1,then
(Multiple Choice)
4.9/5
(38)
Consider the following implementation of insertion sort:
Public static void insertionSort(int [ ] array){
Int unsortedValue;// The first unsorted value
Int scan;// Used to scan the array
// The outer loop steps the index variable through
// each subscript in the array,starting at 1.This
// is because element 0 is considered already sorted.
For (int index = 1;index < array.length;index++){
// The first element outside the sorted segment is
// array[index].Store the value of this element
// in unsortedValue
UnsortedValue = array[index];
// Start scan at the subscript of the first element
// outside the sorted segment.
Scan = index;
// Move the first element outside the sorted segment
// into its proper position within the sorted segment.
While (scan > 0 && array[scan-1] > unsortedValue){
Array[scan] = array[scan - 1];
Scan --;
}
// Insert the unsorted value in its proper position
// within the sorted segment.
Array[scan] = unsortedValue;
}
}
This method uses the < and > operators to compare array subscripts,as when index is compared against the length of the array,a.length.The method also uses these operators to compare array elements against each other,for example,in an expression such as a[scan-1] >unSortedValue.What would happen if we change every < operator to >,and change every > operator to < ?
(Multiple Choice)
4.8/5
(33)
A search for an item X in an array starts at the lower end of the array,and then looks for X by comparing array items to X in order of increasing subscript.Such a method is called
(Multiple Choice)
4.9/5
(30)
If lower is the first subscript in a contiguous portion of an array,and upper is the last subscript,then the array item in the middle of that array portion is at subscript
(Multiple Choice)
4.8/5
(42)
A contigous segment of an array is given by specifying two subscripts,lower and upper.Which of the following expressions gives the subscript of the array element that is three quarters of the way from lower to upper?
(Multiple Choice)
4.9/5
(31)
Assuming a method
Int findMax(int array[ ],int last)that returns the subscript of the largest value in the portion of an array whose elements are at 0 through last (inclusive),a recursive method for sorting in ascending order a portion of an array between 0 and last,inclusive,can be written as follows:
Void rSort(int array[ ],int last){
If (last >= 1){
// Missing code
}
}
If a method
Void swap(int array[ ],int pos1,int pos2)can be used to swap the contents of two array entries,then the logic for the missing code is
(Multiple Choice)
4.8/5
(45)
Let F be an algorithm with complexity function f(n),and let G be an algorithm with complexity function g(n).If the ratio f(n)/g(n)converges to infinity as n increases to infinity,then
(Multiple Choice)
4.9/5
(35)
Linear time is the class of all complexity functions that are in
(Multiple Choice)
4.8/5
(38)
The best method for searching an array that is not sorted is
(Multiple Choice)
4.9/5
(42)
If an array is known to be sorted,it can be searched very quickly by using
(Multiple Choice)
4.8/5
(38)
Showing 1 - 20 of 46
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)