CSC250 Final Review

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Solve 16/(16+2*5)-6/3%4 ( use order of precedence)

(8/13)-(2%4)=8/13

What are the differences between overloading and overriding methods when it comes to static methods, class, and private & final methods

-Static methods can be overloaded which means a class can have more than one static method of same name, but cannot be overridden -private and final methods can be overloaded but they cannot be overridden. -overloading is being done in the same class while for overriding base and child classes are required. Overriding is all about giving a specific implementation to the inherited method of parent class.

Solve: 16/(6+2*5)-6/2*3%2+2

1-3*3%2+2=1-9%2+2=1-1+2=2

At most, how many comparisons are required to search a sorted vector of 512 elements using the binary search algorithm?

512 = 2^9. This means if we divide 512 in half 9 times we have 1 element left. Therefore we need 9 comparisons

What makes a priority queue different than a general queue

A priority queue is different from a "normal" queue, because instead of being a "first-in-first-out" data structure, values come out in order by priority.

What type of collision would we use if we wanted no duplicates and if we wanted duplicates?

Duplicates: list No duplicates: set

The height of any binary tree with n nodes is always )(log n)? T/F

False. In the best case, the height of a BST is O(log n) if it is balanced. In the worst case, however, it can be Θ(n).

What is the max height of any AVL tree with 8 nodes. assume the height of a tree w/ a single node is 0

If height of AVL tree is h, maximum number of nodes can be 2^(h+1) - 1. 2^(h+1)-1=8 so 2^(h+1)=9, h=2.17 so max height is 3

What are the least number comparisons a bubble sort will execute in sorting an array of a million numbers?

In general the total number of comparisons is (n - 1) + (n - 2)...(2) + (1) = n(n - 1)/2 or O(n2) or 𝑆𝑢𝑚=𝑛(𝑛−1)/2. -𝑆𝑢𝑚=𝑛(𝑛−1)/2 Sum=1million (1million-1)/2=4.99e11 comparisons

What would be the correct option to print the following: I said "Hello" to you.

System.out.println("I said \"Hello \" to you");

it is possible to derive a class from an abstract class without overriding all of the parent's abstract methods. T/F

True- The child class must also be declared as abstract in this case

T/F: a. errors should be caught and handled b. runtimeexceptions cannot be caught and handled c. no exceptions are subclasses of errors d. errors are subclasses of throwable

a. False (usually shouldn't be caught, as it indicates an abnormal condition that should never occur) b. True (is intended to be used for programmer errors) c. False (Exception and Error are subclasses of Throwable) d. True

What are the differences between ArrayList and LinkedList w/ respect to the following: a. search operation b. delete operation c. insertion operation

a. Search: ArrayList search operation is pretty fast compared to the LinkedList search operation. get(int index) in ArrayList gives the performance of O(1) while LinkedList performance is O(n) b. Deletion: LinkedList remove operation gives O(1) performance while ArrayList gives variable performance: O(n) in worst case (while removing first element) and O(1) in best case (While removing last element). c. Insertion: LinkedList add method gives O(1) performance while ArrayList gives O(n) in worst case. Reason is same as explained for remove.

When and why would you use the following a. deque b. vector

a. represents a double ended queue, meaning a queue where you can add and remove elements to and from both ends of the queue. b.Vector can grow or shrink as needed to accommodate adding and removing items.

When and why would you use: a. Map b. Set

a.Stores a collection of key-value pairs. Objects are accessed via the key. - Symbol tables - Wide use within other algorithms b. Maintains a set of objects - Keep track of states that were visited already - Wide use within other algorithms

Which of the following lines of code accesses the second element of the first array in a two-dimensional array of integers, numbers, and stores the result in a variable called num? a. num= numbers [1][2]; b. num= numbers [0][1]; c. num= numbers.getElement (1,2); d. num= numbers.getElement (0,1); e. none of the above are correct

b. [0]= first array [1]= second element ** choice a accesses the 3rd element of the second array. ** choices c and d do not represent valid java syntax

The _______ sort, pairwise comparisons are made in each pass and whenever a pair is out of order, the elements are switched

bubble

A class declared as final

cannot be extended

what would be the output of the following program: public class Lincoln{ public static void main(String[]args){ System.out.print("hi") System.out.println("bye"); } }

compile time error-syntax error. missing semicolon

Which of the following is not a valid relational operator in java: a. <= b. > c. == d. <> e. !=

d. <>

which of the following array declarations are invalid? a. int[]grades = new int[5]; b. int grades []= new int[5]; c. int[]grades= {91,100,67,59,96}; d. all of the above are valid e. none of the above are valid

d. all are valid array declarations. b uses an alternate syntax. c uses an initializer list to initialize the array

Which of the following is true about linked list implementation of stack? a. in push operation, if new nodes are inserted at the beginning of linked list, then in pop operation, nodes must be removed from the end b. in push operation, if new nodes are inserted at the end, then in pop operations nodes must be removed from the beginning c. both of the above d. none of the above

d. none of the above (LIFO)

a _____ loop always executes its loop body at least once

do

true is a reserve keyword in java

false

Let CSC250 be an interface. Then it is possible to create an object by instantiating the CSC250 interface

false; you cannot instantiate an interface

Which of the following loop headers will cause the body of the loop to be executed 10 times?

for (int i=0; i<10; i++)

Which of the following expressions best represents the condition "if the grade is between 75 and 100"

if (75<grade && grade<100);

Which of the following represents "age is between 20 and 45"

if (age!=20 && 20<age && age<45)

Solve and explain: 1000<<4

left shift 4 places: 0000

what does 10<<3 mean?

left shift. left operand value is moved left by the number or bits specified by the right operand. ie A=0011 1100 ; A<<2 is 1111 0000

All java classes are subclasses of the ______ class

object

Assume that an insertion sort algorithm in the worst case takes 1 min and 4 seconds for an input of pool size 8. what will be the max input pool size of a problem that can be solved in 53 min and 20 sec in the worst case?

still dont know

What happens if a case in a switch statement does not end with a break statement?

the switch statement will execute the next case statement as well

What happens if a case in a switch statement does not end with a break statement

the switch statement will execute the next statement as well

Which of the following statements best describes this line of code: int[]numbers=new int[50]

this is the declaration and initialization of an array that holds 50 integers

Assume that an insertion sort algorithm in the worst case takes 3 min and 16 seconds for an input of pool size 7. what will be the max input pool size of a problem that can be solved in 26 min and 40 sec in the worst case?

time complexity: O(n^2) 3min 16 sec== 196 sec with input 7 so 4 26min 40 sec == 1600sec with ratio of 4 so max pool size if 400

If a class implements an interface, it cannot extend another class? T/F

true

_01_CSC250 can be used as an identifier in java

true


Ensembles d'études connexes

Chapter 7 Organizational Planning

View Set

You are now Entering the Human Heart

View Set

Chap. 44 - Assessment of Digestive and Gastrointestinal Function

View Set

Advanced Pharmacology Chapter 31-32 Quiz

View Set