Midterm Review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Assuming our logarithm is base 2, what can the following formula be translated to: log(1) = x • 1^X = 2 • 2^X = 1 • X^1 = 2 • X^2 = 1

2^X = 1

If Method1 recieves the string "JET", about how many actual operations will occur? (Ignore the number of operations performed by line #12 in this count) • 0-9 • 10-19 • 20-29 • 30-39 • 40-49

30-39

Match the comparison method with it's simple definition • >= O(f(N)) - Big-O • == Θ(f(N)) - Theta • <= Ω(f(N)) - Omega • > o(f(N)) - Little-O

>= --> O(f(N)) - Big-O == --> Θ(f(N)) - Theta <= --> Ω(f(N)) - Omega > --> o(f(N)) - Little-O

Assuming this log is a base 2 log, log(A^B) = • B*log(A) • (log(A))^(log(B) • (2^B)(log(A)) • A*(log(B)

B*log(A)

In a recursive method, what are the two main cases that must be handled? • Repeating Case • End Case • Base Case • Recursive Case

Base Case Recursive Case

The main reason to use a stack or queue instead of a general list is • Constant run time for available methods • Remove the need for a linked list or array behind the scenes • Excuse to make more acronyms (LIFO/FIFO) • Less method choices make them easier to set up and use

Constant run time for available methods

After Java 5, diamond operators allowed for a new kind of generic type. What is the term used to explain what the compiler does to a class with diamond operators? • Erasure • Casting • Inheritance • Autoboxing/Unboxing

Erasure

An abstract data type is any class that has the keywork abstract applied to it. • True • False

False

Modulus division returns the amount of times a given number can be evenly divided into another number. • True • False

False

The Java TreeMap can only have unique values inserted into it • True • False

False

We focus on Big-O notation heavily in this course because every possible algorithm for a given problem will produce a unique value in this notation, making it clear which algorithm we should use. • True • False

False

With a standard stack class, it is possible to access any item in the stack without removing any existing items. • True • False

False

With both inheritance and interface generic mechanisms, the main benefits are that the object we want to store in the generic container doesn't need to have the given class type in its hierarchy, and any method from the object we are storing can be directly accessed without casting. • True • False

False

What added benefit do we get from using an AVL tree? • Guaranteed O(N) runtime • Expected O(1) runtime • Expected O(log N) runtime • Guaranteed O(log N) runtime

Guaranteed O(log N) runtime

In an AVL tree node, what additional value should be stored • Height • Path • Depth • Length

Height

What is the Big-O notation for line #16 • O(1) • O(N) • O(N^2) • O(N^3)

O(1)

Reduce the following to Big-O notation: O(N^3) + O(N^2) + O(2^N) • O(N^2) • O(N^3) • O(N) • O(N^5) • O(2^N) • O(N^4)

O(2^N)

Assuming line #12 is O(N), what is the overall Big-O notation for Method1? • O(N) • O(N^3) • O(N^2) • O(1)

O(N)

Reduce the following function to Big-O notation: f(N) = N + 2 + 10N + 1 • O(N) • O(3) • O(11N) • O(1) • O(11N+3)

O(N)

What is the Big-O notation for line #14 • O(N^3) • O(1) • O(N^2) • O(N)

O(N)

Reduce the following function to Big-O notation: f(N) = 5N +N^1.5 + N * log(N) + 5000 • O(N^1.5) • O(5000) • O(5N) • O(N^2.5) • O(N^2) • O(N) • O(1) • O(Nlog(N))

O(N^1.5)

Reduce the following function to Big-O notation: O(N^3) * O(N^2) * O(N^0.5) • O(N^0.5) • O(N) • O(N^1.5) • O(N^2) • O(N^2.5) • O(N^3) • ... • O(N^5.5) • O(N^6) • O(N^6.5)

O(N^5.5)

What is the expected runtime of binary search tree operations? • O(log N) • O(N log N) • O(1) • O(N)

O(log N)

When considering how we compare algorithms in this course, which of the following are of interest to us? • Operation Count • Size/Amount of Input • Compile Time • Average Running Time • Computer Resources

Operation Count Size/Amount of Input Average Running Time

If you were developing a system to handle phone call distribution, which ADT would be best suited to store pending calls? • List - Array • Stack • Queue • List - Linked

Queue

A function that is defined in terms of itself is called recursive. • True • False

True

If an algorithm takes constant time to cut the problem size by a fraction, it takes O(log N) time. • True • False

True

The Java TreeSet can only have unique values stored into it • True • False

True

With Big-O notation, when two functions are added, the smaller components are dropped. • True • False

True

Which of the following ways were available PRE Java 5 for generic access to objects? • Classes with angled brackets to define type • Variable of interface type • Autoboxing/unboxing of primitive data types • Variable of parent class type

Variable of interface type Variable of parent class type

(xA) * (xB) = • X^(A/B) • X^(A-B) • X^(A*B) • X^(A+B)

X^(A+B)

Which of the following has a faster Big-O for the linked list implementation of a basic list, as opposed to an array implementation • add(val) • remove(val) • printList() • get(index)

add(val) remove(val)

What are the common methods for stacks? • get() • pop() • insert() • push()

pop() push()

Which of the following is the correct header for creating a class using a generic type • public class MyClass Generic <E> { • public class MyClass Generic E { • public class MyClass <E> { • public class MyClass{ Generic <E>

public class MyClass <E> {

Match the methods with their Big-O run time. For get/find/remove/delete, assume the val and/or index exists in the current list. Give the most accurate answer. If a method was generally O(N), but we further defined it to be O(N-index), then O(N-index) is the correct answer. • ArrayList: remove(val) • ArrayList: find(val) • ArrayList: insert(val, index) [Assuming growArray not called] • ArrayList: delete(index) • ArrayList: add(val) [Assuming growArray not called] • ArrayList: get(index) • ArrayList: growArray(size)

• ArrayList: remove(val) O(N) • ArrayList: find(val) O(N) • ArrayList: insert(val, index) [Assuming growArray not called] O(N-index) • ArrayList: delete(index) O(N-index) • ArrayList: add(val) [Assuming growArray not called] O(1) • ArrayList: get(index) O(1) • ArrayList: growArray(size) O(N)

Match the methods with their Big-O run time. For get/find/remove/delete, assume the val and/or index exists in the current list. Give the most accurate answer. If a method was generally O(N), but we further defined it to be O(N-index), then O(N-index) is the correct answer. • DoubleLinkedList: remove(val) • DoubleLinkedList: find(val) • DoubleLinkedList: insert(val, index) • DoubleLinkedList: delete(index) • DoubleLinkedList: add(val) • DoubleLinkedList: get(val)

• DoubleLinkedList: remove(val) O(index) • DoubleLinkedList: find(val) O(N) • DoubleLinkedList: insert(val, index) O(index) • DoubleLinkedList: delete(index) O(index) • DoubleLinkedList: add(val) O(1) • DoubleLinkedList: get(val) O(index)

Match the AVL methods that need to be run when inserting new nodes into given positions. Options: • Single rotation • Double rotation • Triple rotation • Right sub-tree of left child • Left sub-tree of right child • Right sub-tree of right child • Left sub-tree of left child

• Right sub-tree of left child --> Double rotation • Left sub-tree of right child --> Double rotation • Right sub-tree of right child --> Single rotation • Left sub-tree of left child --> Single rotation

Match the methods with their Big-O run time. For get/find/remove/delete, assume the val and/or index exists in the current list. Give the most accurate answer. If a method was generally O(N), but we further defined it to be O(N-index), then O(N-index) is the correct answer. • SingleLinkedList: remove(val) • SingleLinkedList: find(val) • SingleLinkedList: insert(val, index) • SingleLinkedList: delete(index) • SingleLinkedList: add(val) • SingleLinkedList: get(val)

• SingleLinkedList: remove(val) O(index) • SingleLinkedList: find(val) O(N) • SingleLinkedList: insert(val, index) O(index) • SingleLinkedList: delete(index) O(index) • SingleLinkedList: add(val) O(N) • SingleLinkedList: get(val) O(index)


Set pelajaran terkait

Chapter 15 Essentials Fluoroscopic Imaging

View Set

Principles of Marketing - Chapter 2 w/ Practice Quiz

View Set

Pharmacology HESI - Musculoskeletal System Drugs

View Set

Organizational Behavior Key Terms

View Set

NURS 3444. Exam 4 (Mid Semester ATI)

View Set