CS 2420 Midterm

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the key word for inheritance?

Extends

A child class can remove something inherited (T/F)

False

What sort is this? for(int i = 1; i < arr.length; i++) { int val = arr[i]; int j; for(j = i-1; j >= 0 && arr[j] > val; j--) arr[j+1] = arr[j]; arr[j+1] = val; }

Insertion

What type of sort is this? 1-The first array item is the sorted portion of the array 2-Take the second item and insert it into the sorted portion 3-Repeat steps 1/2 for the remainder of the array

Insertion

What is it called when all methods of a class are abstract? (Sometimes called the ultimate abstract class)

Interface

A linked list is _____________ because it is spread out throughout memory and not contained in one continuous chunk.

Noncontiguous

What is the Big-O for insertion in a linked list?

O(1)

What is the Big-O of peek?

O(1)

What is the Big-O of pop?

O(1)

What is the Big-O of push?

O(1)

What is the Big-O for access of items in the worst case with a linked list?

O(N)

What is the best case Big-O behavior for insertion sort?

O(N) (When the array is already sorted)

Which sort is this: 1-Find the minimum item in the unsorted part of array 2-Swap it with the first item in the unsorted part 3-Repeat steps 1/2 to sort remainder of array

Selection

Which of the following is not a primitive type in Java? boolean double short String none of the above

String

What does the following print? int choice = 2; switch(choice) { case 1: System.out.print("1 "); case 2: System.out.print("2 "); case 3: System.out.print("3 "); } System.out.println("Done");

3

After execution of the following, what is true of the value of i? int i = 10; foo(i); System.out.println(i); A. The value is guaranteed to be 10. B. The value is guaranteed not to be 10. C. The value may or may not be 10.

A

The following is an example of what? public static void foo(int i) {...} public static void foo(int i, int j) {...} A. method overloading B. method overriding C. none of the above

A

What is the term describing the structure by which an object cannot be dissected?

Atomic Structure

One can use a switch statement anywhere one can use a if-else statement? A. true B. false

B

After execution of the following, what is true of the value of arr[0]? int[] arr = {1, 3, 5}; foo(arr); System.out.println(arr[0]); A. The value is guaranteed to be 1. B. The value is guaranteed not to be 1. C. The value may or may not be 1.

C

To say an array is all in the same location in memory is to say that it is...?

Contiguous

Decision making (if-else, switch-case), looping, (while, do-while, for), branching (break, continue, return) and exception handling (try-catch, throw) are examples of?

Control Flow

What is the term for grouping/hiding data and operations?

Encapsulation

What is the acronym for a queue?

FIFO (First in, first out)

You can make an object from an abstract class (T/F)

False

What is the key word for interfaces?

Implements

What is the acronym for a stack?

LIFO (Last in, first out)

What sort is this? 1. Divide the unsorted array into two subarrays (½ size). 2. Sort each of the two subarrays (recursively). 3. Combine the two sorted subarrays into one sorted array.

Merge

What is the average case Big-O behavior for insertion sort?

O(N^2)

What is the average case Big-O for selection sort?

O(N^2)

What is the worst case Big-O behavior for insertion sort?

O(N^2)

What is the worst case Big-O for selection sort?

O(N^2)

What is the worst case Big-O of quicksort?

O(N^2)

What is the average case Big-O for shell sort?

O(N^3/2) (w/shell's gaps) O(N^5/4) (w/better gaps)

What is the average case Big-O behavior for merge sort?

O(NlogN)

What is the average case Big-O of quicksort?

O(NlogN)

What is the best case Big-O behavior for merge sort?

O(NlogN)

What is the worst case Big-O behavior for merge sort?

O(NlogN)

What is the worst case Big-O for shell sort?

O(n^2) (using shell's gaps), O(N^3/2) (using better gaps)

What is the term describing when you return but do not remove the top item of a stack?

Peek

What is the term for when you remove the top item of a stack?

Pop

What is the term in adding a new item to the top of a stack?

Push

What sort is this? 1. Choose an item from the array to be the pivot. 2. Partition the array such that all items less than the pivot are to the left and all items greater than are to the right. 3. Recursively sort each partition.

Quick

What sort is this? for(int i = 0; i < arr.length-1; i++) { int j, minIndex; for(j = i+1, minIndex = i; j < arr.length; j++) if(arr[j] < arr[minIndex]) minIndex = j; int temp = arr[i]; arr[i] = arr[minIndex]; arr[minIndex] = temp; }

Selection

What type of sort is this? First compare array items that are far apart, then compare items that are less far apart,..., shrinking toward basic insertion sort.

Shell

Which sort is this? for(int gap = arr.length/2; gap > 0 ; gap /= 2) for(int i = gap; i < arr.length; i++) { int val = arr[i]; int j; for(j = i-gap; j >= 0 && arr[j] > val; j-= gap) arr[j+gap] = arr[j]; arr[j+gap] = val; }

Shell

A child class inherits private and public fields and methods (T/F)

True

A class can implement more than one interface (T/F)

True

An interface can have final static variables (T/F)

True

If there is ever an abstract method the whole class is abstract (T/F)

True

The number of comparisons required for a selection sort will always be the same, no matter the original ordering of the items in the list. (T/F)

True

In what case would you choose quicksort over mergesort?

When memory is important

When do you want to use a linked list over an array?

When the size of the collection is not known

What is the type of the expression x + y in the following? int x = 1; double y = 3.14; System.out.println(x + y);

double


संबंधित स्टडी सेट्स

Practice Exam - Salesperson Course 1

View Set

SmartBook Ch. 16.1 - 16.2 Receptor and General Senses

View Set

Wrist and Hand, Vasculature, Connective Tissue

View Set

Chapter 13 - Reformation and Religious Wars

View Set

Staffing Needs and Scheduling Policies

View Set

Civil Rights and Civil Liberties

View Set

Chapter 11 Motivation Theories and Applications

View Set

Money and Banking: Chapter 13 (Central Banks and the Federal Reserve System)

View Set

(Part 3) Pericardial Effusion & Tamponade

View Set

Ch8 AbPsych Eating and Sleep-Wake Disorders

View Set