CSC250 Final

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

If the desired Object is not found, binary Search returns ___________.

A negative value

What are the differences between Recursion and Iteration? Explain with example

Both repeatedly execute the set of instructions. Recursion is when a statement in a function calls itself repeatedly. Iteration is when a loop repeatedly executes until the controlling condition becomes false.

Which of the following is not an operation on a stack?

Dequeue

Which of the following algorithms is most easily expressed recursively?

Quick sort

The ____________ operator is used to instantiate an object.

new

The commitment to execute certain code to carry out a method invocation is referred to as _____________.

Binding

1. Step through Dijkstra's algorithm to calculate the single-source shortest paths from A to F. Show your steps in the table below. 2. Cross out old values and write in new ones, from left to right within each cell, as the algorithm proceeds. 3. Finally, indicate the lowest-cost path from node A to node F 4. Write the pseudocode for Dijkstra's algorithm to find the shortest path

Check google doc

Consider the binary search tree T in the Figure shown below. Explain and draw the tree structure with the following types of deletion operations. a) The node M is deleted, b) The node D is deleted

Check google doc

Construct and Explain an AVL search tree by inserting the following elements in the order of their occurrence. Write Java code for it. 64, 1, 44, 26, 13, 110, 98, 85

Check google doc

The daily flights of an airline company appear in Tables (a),(b) below. CITY lists the cities, and ORIG[K] and DEST[K] denote the cities of origin and destination respectively, of the flight NUMBER [K]. Draw the corresponding directed graph of the data.

Check google doc

a) Build a heap H from the following list of numbers. Explain the steps for building it. 44, 30, 50, 22, 60, 55, 77, 55 b) Delete the root R from a heap shown below and also write the steps for deletion operation.

Check google doc

Which of the following types of methods do not have any return type (not even a void return type)?

Constructors

What are the differences between Overriding and Overloading methods?

Overriding: - implements Runtime Polymorphism - occurs between superclass and subclass - same signature, name, and method arguments - the method call is determined at the runtime based on the object type Overloading: - implements Compile time Polymorphism - occurs between the methods in the same class - method names are the same but the parameters are different - the method to call is determine at the compile-time

Let E denote the following algebraic expression: [a + (b - c) ]* [ (d - e) / (f + g - h)] The corresponding binary tree T is shown below. Write down the Preorder and Postorder Traversals of the binary tree T.

Preorder: * + a = b c / - d e - + f g h Postorder: a b c - + d e - f g + h - / *

Which of the following will result from infinite recursion in Java?

The program will run out of memory

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

Consider a timer that has multiple constructors defined as follows. Which constructor is called in the following statement Timer ovenTimer = new Timer(); public class Timer{ Timer(){...} Timer(int minutes){...} Timer(int hours, int minutes){...} } Timer ovenTimer = new Timer();

Timer(){...}

Consider the following stack of characters, where STACK is allocated N = 8 memory cells: STACK: A, C, D, F, K,___,___,___, (For notational convenience, we use "___" to denote an empty memory cell.) Describe the stack as the following operations take place: a) POP(STACK, ITEM) b) POP(STACK, ITEM) c) PUSH(STACK, L) d) PUSH(STACK, P) e) POP(STACK, ITEM) f) PUSH(STACK, R) g) PUSH(STACK, S) h) POP(STACK, ITEM) Write a Java Code for the above input for stack operations.

a) A, C, D, F, ___, ___, ___, b) A, C, D, ___, ___, ___, c) A, C, D, L, ___, ___, ___, d) A, C, D, L, P, ___, ___, ___, e) A, C, D, L, ___, ___, ___, f) A, C, D, L, R, ___, ___, ___, g) A, C, D, L, R, S, ___, ___, ___, h) A, C, D, L, R, ___, ___, ___,

Define each of the following terms: a) Collection b) Collections c) Comparator d) List e) Vector h) HashMap

a) Collection - described as an Interface, many data structures are available. these data structures consist of list, stack, and even queue b) Collections - objects are stored and are able to be manipulated within the program with functions such as searching for a specific value or inserting and deleting values c) Comparator - an interface for sorting Java objects; compares two objects compare(Obj, Obj2) to return an integer based on a pos, equal or neg comparison d) List - collections of ordered elements or objects; ex. linked list and double linked list e) Vector - dynamic array which can grow or shrink its size (no size limit) h) HashMap - a type of data structure that uses keys in order to map to a specific value. This is used in order to store value pairs

Time Complexity Analysis (2 * 2 = 4 points) a) What is the overall time complexity for the following methods? Explain your understanding. void fun(int n, int arr[]) { int i = 0, j = 0; for(i < n; ++i) { while(j < n && arr[i] < arr[j]) j++; } } b) What is time complexity of fun()? Explain: int fun(int n){ int count = 0; for (int i = n; i > 0; i /= 2){ for (int j = 0; j < i; j++){ count += 1; } return count; } }

a) In the first look, the time complexity seems to be O(n^2) due to two loops. But, please note that the variable j is not initialized for each value of variable i. Hence, the inner j++ will be executed at most n times. The i loop also runs n times. So, the whole thing runs for O(n) times. b) i = n n/2 n/4 n/8 ... logn times j = n n/2 n/4 n/8 ... logn time T(n) = n + n/2 + n/4 + n/8 + ... logn time = n(1 + 1/2 + 1/4 + ... logn times) Decreasing GP = O(n)

Discuss whether a stack or a queue is a appropriate structure for determining the order in which elements are processed in each of the following situations. a) Batch computer programs are submitted to to computer center. b) Program A calls subprogram B, which calls subprograms C, and so on. c) Employee have a contract which calls for seniority system for hiring and firing d) People entering an escalator.

a) Queue should be used because it makes sense that FIFO; the computer programs being sent in first should be processed first, thus it should be the first to leave b) Queue should be used because program A is calling B, etc and it if A calls first then that program should be the first out. c) Stack should be used becuase it makes sense that with last in first out (LIFO) that the last one hired will be the first one fired when it comes to the seniority system. d) Stack should be used because with Last in first out (LIFO) the person who gets on the escalator first should be the first one off.

Which iterator method determines whether the Collection contains more elements?

hasNext

Write a java code to generate an output for the below grading system using conditional statement. A college has following rules for grading system: a) Below 25 - F b) 25to- 45 - E c) 45 to 50 - D d) 50 to 60 - C e) 60 to 80 - B f) Above 80 - A Ask user to enter Points and print the corresponding grade.

public class GradeCalc{ public static void main(String[] args) { int score; // To hold a test score char grade; // To hold a letter grade // Create a Scanner object to read input. Scanner console = new Scanner(System.in); // Get the test score. System.out.print("Enter your numeric test score : "); score = console.nextInt(); // Calculate the grade. if (score >= 90) { grade = 'A'; } else if (score >= 80) { grade = 'B'; } else if (score >= 70) { grade = 'C'; } else if (score >= 50) { grade = 'D'; } else { grade = 'F'; } // Display the grade. System.out.println("Your grade is " + grade); } }


Kaugnay na mga set ng pag-aaral

diagnosis quiz 2: mood disorders

View Set

ENT Exam 1 & 2 Missed Questions, CH. 11, CH. 12

View Set

Social Security, Medicare, and Other Government Programs

View Set

Chapter 40: Fluid, Electrolyte, and Acid-Base

View Set

TestOut (PC Pro, Security Chapter)

View Set

RMI 2302: Exam 1 Module- Questions

View Set

ap macroeconomics unit 5 quizzes

View Set