CSCI 675 VA Seminar in Software Engineering - Exit Exam

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

What is the output of the following piece of code? int i = 0; for(; i < 10; i++); cout << i << ", ";

"10, "

Which of the following is needed in order to use function: int isalpha (int) in C++

#include <cctype>

We use (Root, LeftSubTree, RightSubtree) notation to represent a tree. Assume that we have AVL tree (5, NULL, 8), after insert new node 7, what will be the new AVL tree? Here NULL represent empty subtree. In this case, 5 has no left child.

(5, 7, 8)

Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the post-order traversal sequence of the resultant tree?

0 2 4 3 1 6 5 9 8 7

What is the output of the following Java program? import java.util.ArrayList; public class MyClass { public static void main(String [] args){ Arrayist<Integer> arr = new ArrayList<Integer>(); for(int i = 1; i<= 100; i++) arr.add(0, i); System.out.println(arr.indexOf(new Integer("1"))); } }

1

Given the following class template, what changes need to be made to the default constructor definition? template <class T> class containerClass { public: containerClass(); containerClass(int newMaxSize); containerClass(const containerClass& source); ~containerClass(); T getItem(); int getCount(); int getSize(); void addItem(T item); private: T *bag; int maxSize, count; }; containerClass::containerClass() { maxSize = 10; bag = new int[maxSize]; count=0; }

1) add the template prefix. 2) change the type of the dynamic array allocation to T 3) add to the <T> following the class name before the scope resolution operator

Which of the following is true about inheritance in Java. 1) In Java all classes inherit from the Object class directly or indirectly. The Object class is root of all classes. 2) Multiple inheritance is not allowed in Java. 3) Unlike C++, there is nothing like type of inheritance in Java where we can specify whether the inheritance is protected, public or private.

1, 2, and 3

Suppose I have void addOne(int x){ x = x+1; } what will be the out put of the following code? int x = 10; addOne(x); cout << x;

10

What is the output? #include <iostream> #include <set> using namespace std; int main() { set<int> tst; tst.insert(12); tst.insert(21); tst.insert(32); tst.insert(31); set<int> :: const_iterator pos; for(pos = tst.begin(); pos != tst.end(); ++pos) cout << *pos << ' '; return 0; }

12 21 31 32

What is the output of the following code if user's input is 8? import java.util.Scanner; public class MyClass { public static void main(String [] args){ int x, y; Scanner input = new Scanner(System.in); Systerm.out.println("Enter an integer: "); x = input.nextInt(); if(x % 3 == 0) y = 0; else if (x % 3 == 1) y = 1; else y = 2; System.out.println(y); } }

2

If we search a random key that presents in the following binary search tree, what is the expected number of comparison? 10 | \ 5 20 | /\ 4 15 30 / 11

2.57

If we use binary search algorithm to search 1 4 8 9 11 15 19 20 25 28 32 35 36 48 52 for key 15, list the elements that will be compared with key in order of when the comparison happens

20 9 15

Assume that x has prime factorization: , and y has prime factorization: , what is the greatest common divisor of x and y?

2^3 x 3^2 x 5^2 x 7^3

How many undirected graphs (not necessarily connected) can be constructed out of a given set V= {V 1, V 2,...V n} of n vertices ?

2^n(n-1)/2

A hash table of length 10 uses open addressing with hash function h(k)=k mod 10, and linear probing. After inserting 6 values into an empty hash table, the table is as shown below. How many different insertion sequences of the key values will result in the hash table shown above? 0 1 2 | 42 3 | 23 4 | 34 5 | 52 6 | 46 7 | 33 8 9

30

Prove that for n ≥ 4, . If we use mathematical induction to prove, what is the base case?

4! >_ 2^4

6 people line up for a wedding picture, how many different ways to do this if the groom must be immediately to the left of the bride?

5! 5! = 5*4*3*2*1 = 120

What will be the output of the following code? Assume user type 5, 10 on keyboard. int *p, q; p = new int; cin >> *p >> q; cout << *p << ", " << q;

5, 10

What is the output of the following program #include <iostream> using namespace std; int main() { int x = -1; try { cout << "Before throw \n"; if (x < 0) { throw x; cout << "After throw \n"; } } catch (int x ) { cout << "Caught Exception \n"; } cout << "After catch \n"; return 0; }

Before throw Caught Exception After catch

Given a directed graph where weight of every edge is same, we can efficiently find shortest path from a given source to destination using?

Breadth First Traversal is optimal but Dijkstra's path algorithm can also be used

Suppose we have Random rand = new Random(); Which of the following expression generates a random integer between 1 and 100, inclusive?

Math.abs(rand.nextint()) % 100 + 1

What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array. Build Heap is used in Heap Sort as a first step for sorting.

O(n)

What is the worse case run time for following algorithm? CountDuplicatePairs This algorithm counts the number of duplicate pairs in a sequence. Input: a1, a2,...,an, where n is the length of the sequence. Output: count = the number of duplicate pairs. count := 0 For i = 1 to n For j = i+1 to n If ( ai = aj ), count := count +1 End-for End-for Return( count )

O(n^2)

If a group of 9 kids have won a total of 100 trophies, then at least one of the 9 kids has won at least 12 trophies What is the best way to prove the above statement?

Proof by Contradiction

What is the output of the following code segment? char c = 'A'; char x = c + 32; System.out.println(x);

There is a compile error

top enclose A large intersection left parenthesis A large union B right parenthesis will equal which of the following?

Top enclose A large intersection B intersection (n) union(u)

Which of the following first order formula is logically valid? Here α(x) is a first order formula with x as a free variable, and β is a first order formula with no free variable.

[(∃x,α(x))→β]→[∀x,α(x)→β]

What is the output of the following Java program? class MyClass{ int a; MyClass(){ this(10); } MyCLass(int a){ this.a = a; } void get(){ print(this); } void print(MyClass obj){ System.out.println("a = " + obj.a); } public static void main(String[] args){ MyClass obj1 = new MyClass(); MyClass obj2 = new MyClass(20); obj1.print(obj2); } }

a = 20

Given characteristic equation for a recurrence relation. Express the solution to recurrence relation as a linear combination of terms. (x-1)(x+2) = 0

a subscript 1 plus a subscript 2 left parenthesis minus 2 right parenthesis to the power of n

What is the output of the following Java program classMyClass { public static void main(String[] args) { try { int a[]= {1, 2}; for(int i = 1; i <= a.length; i++) { System.out.print("a[" + i + "]" + a[i] + "\n"); } } catch (ArrayIndexOutOfBoundsException e){ System.out.println ("ArrayIndexOutOfBoundsException"); } catch (Exception e){ System.out.println("error = " + e); } } }

a[1] = 2 ArrayIndexOut ofBoundsException

Assume that the operators +, -, * are left associative and ^ (power) is right associative. The order of precedence (from highest to lowest) is ^, x , +, -. The postfix expression corresponding to the infix expression a + b * c - d ^ e ^ f is

abc* + de^f^-

Suppose that char c = 'A'; Which of the following change value of c to 'a'? (Choose Two)

c = Character.toLowerCase(c); c = (char) (c + 32)

Let G be an undirected graph. Consider a depth-first traversal of G, and let T be the resulting depth-first search tree. Let u be a vertex in G and let v be the first new (unvisited) vertex visited after visiting u in the traversal. Which of the following statements is always true?

if {u,v} is not an edge in G then u is a leaf in T

Which of the following is the correct recursive function to calculate the sum of 1+2+...+n of a positive int n?

int sum(int n){ return n + sum(n-1); }

BigInteger class belongs to which of the following package?

java.math

A binary tree with n > 1 nodes has n1, n2 and n3 nodes of degree one, two and three respectively. The degree of a node is defined as the number of its neighbors. n3 can be expressed as

n3 = n2 - 1

Consider the Node structure as following /* Node of a doubly linked list */ struct Node { int data; Node *next; // Pointer to next node in DLL Node *prev; // Pointer to previous node in DLL }; What will be the code for step 6 in C++? /* Given a node as prev_node, insert a new node after the given node */ void insertAfter(struct Node* prev_node, int new_data) { /*1. check if the given prev_node is NULL */ /* 2. allocate new node */ /* 3. put in the data to the new node */ /* 4. Make next of new node as next of prev_node */ /* 5. Make the next of prev_node as new_node */ /* 6.___________________________________ */ /* 7. Change previous of new_node's next node */ }

new_node -> prev = prev_node;

Which of the following is a void function?

none of the above

What will the output in file data.txt after we execute the following Java program? import java.io.*; class MyClass{ public static void main(String [] args) throws Exception{ File file = new File("data.txt"); PrintWriter pw = new PrintWriter(file); pw.println("Hello"); pw.print("World");

nothing in file

To overload functions with symbolic names (like + - / <<), you must use the keyword ________ before the symbolic name.

operator

To open an output file and add to the end of the data already in the file you would write

outFile.open("project.txt", ios :: app);

If the name of a file to open is in the string variable name fileName, which of the following will correctly open the file for output?

out_file.open(fileName.c_str());

What does the following function do for a given Linked List with first node as head? void fun(struct node* head) { if(head == NULL) return; cout << head->data; fun(head->next); }

print alternative nodes in the linked list in reverse order

What is the output of the following Java program? public class MyClass{ int x; public MyClass(int x){ this.x = x; } public static void main(String [] args){ MyClass myClass1 = new MyClass(10); MyClass myClass2 = new MyClass(10); System.out.println(myClass1.equals(myClass2)); } }

false

What is the output of the following code? class IntWrap{ int i; } public class MyClass { public static void mySwap(IntWrap x, IntWrap y){ int temp = x.i; x.i = y.i; y.i = temp; } public static void main(String [] args){ intWrap x = new IntWrap(); x.i = 10; IntWrap y = new IntWrap(); y.i = 20; mySwap(x, y); System.out.println("x = " + x.i + " y = " + y.i); } }

Compile error(s) in main method

What is the output of the following program? #include <iostream> using namespace std; class Base{ public: Base(){ cout<<"Constructor: Base"<<endl; } virtual ~Base() { cout<<"Destructor : Base"<<endl; } }; class Derived: public Base { public: Derived() { cout<<"Constructor: Derived"<<endl; } ~Derived(){ cout<<"Destructor : Derived"<<endl; } }; int main(){ Base *Var = new Derived(); delete Var; return 0; }

Constructor: Base Constructor: Derived Destructor : Derived Destructor : Base

What will be the output after the execution of the following piece of code? char grade = 'A'; switch(grade){ case'A': cout <<"Excellent"; case'B': cout << "Good"; break; case'C': cout << "Average"; break; default: cout << "Work harder"; break; }

ExcellentGood

Which of the following create a Scanner for file named data.txt?

File file = new File("data.txt"); Scanner input = new Scanner(file);

Which of the following shows the process to calculate GCD(72, 27) by using Euclidean Algorithm?

GCD(72, 27) = GCD(27, 18) = GCD(18, 9) = 9

What is the output of the following Java code segment? String greeting = "Hello"; // 1 for(int i = 0; i < greeting.length(); i++) // 2 System.out.print(greeting[ i ]); // 3

Hello Compile error at line // 2 Compile error at line // 3

Which is the correct way to tell the compiler that the class being declared (ChildClass) is derived from the base class (BaseClass)?

class ChildClass:public BaseClass

Which of the following Boolean function represents the following circuit?

f(x, y, z) = ( top enclose x+y) top enclose xz

Which of the following is correct definition for Node structure which is used in LinkedList that stores integer data?

struct Node{ int data; Node* next; };

Destructor is a member function whose name is same as the class name but is preceded by a

tilde

By the law of Boolean Algebra, x top enclose y plus x y

x

Use the following selection sort to sort int array {2, 5, 3, 6, 4, 1}, Right after i is increased to 2, before the next outer loop, what is the array? void selectionSort(int arr[], int n) { int i, j, min_idx; // One by one move boundary of unsorted subarray for (i = 0; i < n-1; i++) { // Find the minimum element in unsorted array min_idx = i; for (j = i+1; j < n; j++) if (arr[j] < arr[min_idx]) min_idx = j; // Swap the found minimum element with the first element swap(&arr[min_idx], &arr[i]); } }

{1, 2, 3, 6, 4, 5}

Given array {4, 1, 3, 6, 2, 7, 8, 5}, use quick sort algorithm to sort the array. After first partition done, what will be the array? Assume the last element is used as pivot for partition.

{4, 1, 3, 2, 5, 7, 8, 6}

What is the logical translation of the following statement? None of my friend is perfect

¬∃x(F(x) ∧ P(x)).


Kaugnay na mga set ng pag-aaral

Examples of Chemical Nomenclature (Chemistry)

View Set

Prioritizing Client Care: leadershop, delegation, and emergency response planning. NCLEX questions

View Set

Chapter 19 APES Reading Guide Core Case Study and Section 19-1

View Set

Entrepreneurship Chapter 6 - Distribution, Promotion, and Selling

View Set

Intermediate 3 final: computational

View Set

Chapter 9 PRE, HW, and Clicker Questions

View Set

NRS222 Mental health and mental illness

View Set

Ch. 11 Fundamentals of the Nervous System and Nervous Tissue

View Set

Chapter 3 Health, Policy, Politics and Reform

View Set

Smart Book Assignment -Ch 12 - Solutions

View Set

Ky Property and Casualty Exam Notes

View Set