Study Set 1

¡Supera tus tareas y exámenes ahora con Quizwiz!

A binary tree T has 20 leaves. The number of nodes in T having two children is a: 19 b: Could be any number between 11 and 19, inclusive c: 17 d: 18

a

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? a: 30 b: 10 c: 40 d: 20

a

Assume char c = 'A'; Which of the following change value of c to 'a'? a: c = Character.toLowerCase(c); b: Character.toLowerCase(c); c: c.toLowerCase(); d: c = c.toLowerCase();

a

Assume int x = 5; int y = 10; What will be the y value after the execution of following C++ code segment? if(x > y){ y = 8; } else{ if(x > 20); y = 5; } a - 5 b - There is a syntax error c - 8 d - 10

a

Consider an undirected random graph of eight vertices. The probability that there is an edge between a pair of vertices is 1/2. What is the expected number of unordered cycles of length three? a: 7 b: 1 c: 8 d: 1/8

a

Consider the following brute force factoring algorithm. How many numbers the algorithm will check if N = 23457 which happen to be a prime number? Input: Integer N greater than 1. Output: "Prime" if N is prime. If N is composite, return two integers greater than 1 whose product is N. For x = 2 to N-1 If x evenly divides N, Return( x, N/x ) End-for Return( "Prime" ) a: 123455 b: 1 c: 351 d: 123457

a

Suppose that A = {1, 2, 3, 4, 5, 6}, B = {3, 4, 5}, C = {1, 2, 4}, what is A minus left parenthesis B minus C right parenthesis ? a: {1, 2, 4, 6} b: empty set c: {4, 5} d: {6}

a

The following postfix expression with single digit operands is evaluated using a stack: 8 1 3 + / 2 3 * + 5 1 * - The top two elements of the stack after the first * is evaluated are: a: 6, 2 b: 6, 3 c: 5, 7 d: 1, 5

a

What is the output of the following Java code segment? int arr[2]; System.out.println(arr[0]); System.out.println(arr[1]); a: Compile error b: 0 0 c: garbage value garbage value d: Running time Exception

a

What is the output of the following Java program? public class MyClass { int a, b; MyClass(){ a = 1; b = 2; } public void print(){ System.out.println(a + ", " + b); } public static void main(String[] args){ MyClass x = new MyClass(); MyClass y = x; x.a++; x.b++; y.print(); } } a: 2, 3 b: There is a run time exception c: 1, 2 d: There is a compile error

a

Which of the following statement(s)is / are correct regarding Bellman-Ford shortest path algorithm? P: Always finds a negative weighted cycle, if one exists. Q: Finds whether any negative weighted cycle is reachable from the source. a: Q only b: Both P and Q c: P only d: Neither P and Q

a

Which statement can never be reach in following code? #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; } a - cout << "After throw \n"; b - cout << "Caught Exception \n"; c - cout << "Before throw \n"; d - cout << "After catch \n";

a

Suppose that the base class has a private attribute int id; then which of the following methods the child class will use to manipulate id? a - void setId(int _id); b - int setId(int _id); c - int getId() const; d - void getId() const;

a c

A Boolean expression that is a sum of products of literals is said to be in disjunctive normal form (DNF) . A Boolean expression that is a product of sums of literals is said to be in conjunctive normal form (CNF). Indicate whether the following Boolean expressions are in conjunctive normal form or disjunctive normal form or both or neither. (not)yx(not)zw a: DNF b: Both c: Neither d: CNF

b

Count the number of binary strings of length 8 subject to each of the following restrictions: There is at least one 0 and one 1. a: 2 to the power of 8 b: 2 to the power of 8 minus 2 c: 2 to the power of 7 d: 2 to the power of 8 minus 1

b

For every integer n, if n2 is an odd, then n is odd. What is the best way to proof the above statement? a: Direct proof b: proof by contrapositive c: proof by cases d: proof by mathematical induction

b

In AVL tree insert, suppose node w has been inserted by performing standard Binary Search Tree insertion. Starting from w, travel up and find the first unbalanced node. Let z be the first unbalanced node, y be the child of z that comes on the path from w to z and x be the grandchild of z that comes on the path from w to z. Assume the subtree rooted at z as following (here T1, T2, T3, and T4) are subtrees. What shall you do to pre-balance the AVL tree? a: Right Rotate y then Left Rotate z b: Right Rotate z c: Left Rotate y then Right Rotate z d: Left Rotate z

b

In a room there are only two types of people, namely Type 1 and Type 2. Type 1 people always tell the truth and Type 2 people always lie. You give a fair coin to a person in that room, without knowing which type he is from and tell him to toss it and hide the result from you till you ask for it. Upon asking, the person replies the following: "The result of the toss is head if and only if I am telling the truth." Which of the following options is correct? a: If the person is of Type 1, then the result is tail b: The result is head c: The result is tail d: If the person is of Type 2, then the result is tail

b

Prove that 1 cross times 2 plus 2 cross times 3 plus... plus n cross times left parenthesis n plus 1 right parenthesis equals fraction numerator n left parenthesis n plus 1 right parenthesis left parenthesis n plus 2 right parenthesis over denominator 3 end fraction If we proof by mathematical induction, what will be the base case? a: k is positive integer and 1 cross times 2 plus 2 cross times 3 plus... plus k cross times left parenthesis k plus 1 right parenthesis equals fraction numerator k left parenthesis k plus 1 right parenthesis left parenthesis k plus 2 right parenthesis over denominator 3 end fraction b:1 cross times left parenthesis 1 plus 1 right parenthesis equals fraction numerator 1 left parenthesis 1 plus 1 right parenthesis left parenthesis 1 plus 2 right parenthesis over denominator 3 end fraction c: 1 cross times 2 plus 2 cross times 3 plus... plus k cross times left parenthesis k plus 1 right parenthesis plus left parenthesis k plus 1 right parenthesis cross times left parenthesis k plus 2 right parenthesis space equals space fraction numerator left parenthesis k plus 1 right parenthesis left parenthesis k plus 2 right parenthesis left parenthesis k plus 3 right parenthesis over denominator 3 end fraction d: cross times 2 plus 2 cross times left parenthesis 2 plus 1 right parenthesis space equals space fraction numerator 2 left parenthesis 2 plus 1 right parenthesis left parenthesis 2 plus 2 right parenthesis over denominator 3 end fraction

b

Solve each of the following recurrence equation with the given initial values. bn = 4bn−1 − 4bn−2. Initial values: b0 = 3, b1 = 10. a: 5 left parenthesis 2 right parenthesis to the power of n minus 3 n left parenthesis 2 right parenthesis to the power of n b: 3 left parenthesis 2 right parenthesis to the power of n plus n left parenthesis 2 right parenthesis to the power of n plus 1 end exponent c: 3 left parenthesis 2 right parenthesis to the power of n minus n left parenthesis 2 right parenthesis to the power of n plus 1 end exponent d: a subscript 1 2 to the power of n plus a subscript 2 n left parenthesis 2 right parenthesis to the power of n

b

Suppose I have the following recursive function, what is the return value when call myop(4)? int myop(int n){ if(n <= 2) return 1; return 1 + myop(n-1) + myop(n-2) } a - 6 b - 5 c - 7 d - 8

b

Suppose in.txt contains one line of data: "Hello World". What will be the content of out.txt after execute the following Java program. Suppose open file to read and open file to write both successfully. import java.io.*; import java.util.*; class MyClass{ public static void main(String[] args) throws Exception{ File inFile = new File("in.txt"); File outfile = new File("out.txt"); Scanner input = new Scanner(inFile); PrintWriter pw = new PrintWriter(outFile); while(input.hasNext()){ String text = input.nextLine(); pw.println(text.toUpperCase()); } input.close(); pw.close(); } } a: Hello World b: HELLO WORLD c: Compile Error d: Nothing

b

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 in-order traversal sequence of the resultant tree? a: 9 8 6 4 2 3 0 1 5 7 b: 0 1 2 3 4 5 6 7 8 9 c: 7 4 1 0 3 2 4 6 8 9 d: 0 2 4 3 1 6 5 9 8 7

b

What is the output of the following Java code segment? String s = "Hello"; // 1 System.out.println(s.size()); // 2 a: 5 b: Compile error in line // 2 c: Compile error in line // 1 d: 6

b

What is the output of the following Java program? class Grandparent { public void fun() { System.out.println("Grandparent"); } } class Parent extends Grandparent{ public void fun() { System.out.println("Parent"); } } Class Child extends Parent { public void fun() { 15 super.super.Print(); System.out.println("Child"); } } public class MyClass{ public static void min(String[] args) { Child c = new Child(); 23 c.print(); } } a: Grandparent Parent Child b: Compile error in line 15 c: Grandparent Child d: Compile error in line 23

b

Which of the following are best code to continue if the file open fails a - exit(0); b - cout << "Cannot open file. Exit the progam"; exit(1); c - exit(1); d - cout << "Cannot open file. Exit the progam"; exit(0);

b

Which of the following code calculate the sum of all elements in given array int a[SIZE}; where SIZE is an int constant that has been initialized. Assume a has been initialized. a -int result; for(int i = 0; i < SIZE; i++) result += a[i]; b - int result = 0; for(int i = 0; i < SIZE; i++) result += a[i]; c - int result = 1; for(int i = 0; i < SIZE; i++) result *= a[i]; d - int result = 0; for(int i = 0; i < SIZE; i++) result *= a[i];

b

Which of the following is needed in order to execute the following statement: time_t timer; a - #include <time.h> b - #include <ctime> c - #include <cstdlib> d - There is a syntax error

b

Which of the following is not a stable sort? a: merge sort b: quick sort c: Insertion sort d: selection sort

b

Which of the following mystrlen is the best implementation? a -size_t mystrlen(const char * source){ size_t result = 0; while(*source != '\0') result++; return result; } b - size_t mystrlen(const char * source){ size_t result = 0; while(*source++ != '\0') result++; return result; } b - size_t mystrlen(char * source){ size_t result = 0; while(*source != '\0'){ result++; source++; } return result; } c - size_t mystrlen(const char * source){ size_t result = 0; while(*++source != '\0') result++; return result; }

b

Apply the following insertion sort to array 4 1 2 5 3. Right after i is increased to 2, before the next iteration of loop body, what is the array? void insertionSort(int arr[], int n) { int i, key, j; for (i = 1; i < n; i++) { key = arr[i]; j = i-1; while (j >= 0 && arr[j] > key) { arr[j+1] = arr[j]; j = j-1; } arr[j+1] = key; } } a: none of these b: 4 1 2 5 3 c: 1 4 2 5 3 d: 1 2 4 5 3

c

Given three functions: int fun(int x) { return x*x;} double funny(int x) { return x;}; double fun(double x) { return x;} What is the output of the following code: cout << setprecision(2) << funny(2.0); a - There is a compile error b - 2.0 c - 2 d - 4.0

c

Simplify the following Boolean Expression: (x+y)xy + xz a: y(x+z) b: xyz c: x(y+z) d: z(x+y)

c

Suppose that I have function void myswap(int *x, int *y){ int temp = *x; *x = *y; *y = temp; } what will be the output of the following code segment? int x = 5, y = 10; myswap(x, y); cout << x << ", " << y; a - 5, 10 b - There is a run time error c - There is a syntax error d - 10, 5

c

True or false? Regarding the following two rules of when to write Big Three: Copy Constructor, Assignment Operator, and Destructor? 1. Only write the one you will explicitly use in your program. For instance, you may write Copy Constructor but not destructor. 2. Prefer to write these methods even if the implicit ones are correct. a - False, True b - True, False c - False, False d - True, True

c

Use Euclid's Algorithm to calculate gcd (72, 27). The result is: a: 3 b: 27 c: 9 d: 1

c

What is the outcome of the following code? class Main { public static void main(String args[]) { int x = 0 ; int y = 10 ; System.out.println( y/x); } } a: Compile error b: 0 c: No compile error but will throw ArithmeticException exception d: 10

c

What is the output of the following Java progam? public class MyClass{ int x; public MyClass(int x){ 4 this.x = x; } public static void main(String[] args){ MyClass myClass1 = new MyClass(10); MyClass myClass2 = new MyClass(10); 10 System.out.println(myClass1.equals(MyClass2)); } } a: Compile error in line 10 b: Compile error in line 4 c: false d:true

c

What is the output of the following code if the value of score is 100? Assume variables score and grade has been declared as int and char, respectively. if(score >= 90) grade = 'A'; else if(score >= 80) grade = 'B'; else if(score >= 70) grade = 'C'; else if(score >= 60) grade = 'D'; 19 else grade = 'U'; 21 System.out.println(grade); a: There is a compile error in line 19 b: There is a compile error in line 21 c: A d: U

c

What will be the output of following piece of code? System.out.println("/"Hello World/""); a: Run time error b: Hello World c: Syntax Error d: "Hello World"

c

You are given pointers to first and last nodes of a singly linked list, which of the following operations are dependent on the length of the linked list? a: remove the first element of the list b: insert in front of the list c: remove the last element of the list d: add new element at the end of the list

c

A 3-ary max heap is like a binary max heap, but instead of 2 children, nodes have 3 children. A 3-ary heap can be represented by an array as follows: The root is stored in the first location, a[0], nodes in the next level, from left to right, is stored from a[1] to a[3]. The nodes from the second level of the tree from left to right are stored from a[4] location onward. An item x can be inserted into a 3-ary heap containing n items by placing x in the location a[n] and pushing it up the tree to satisfy the heap property. Which one of the following is a valid sequence of elements in an array representing 3-ary max heap? a: 9, 3, 6, 8, 5, 1 b: 1, 3, 5, 6, 8, 9 c: 9, 6, 3, 1, 8, 5 d: 9, 5, 6, 8, 3, 1

d

A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of keys. I. 81, 537, 102, 439, 285, 376, 305 II. 52, 97, 121, 195, 242, 381, 472 III. 142, 248, 520, 386, 345, 270, 307 IV. 550, 149, 507, 395, 463, 402, 270 Suppose the BST has been unsuccessfully searched for key 273. Which all of the above sequences list nodes in the order in which we could have encountered them in the search? a: II and III b: I and III c: III and V d: III only

d

By using which operator does point to next element is represent in iterator? a: - b: + c: -- d: ++

d

Identify the correct translation into logical notation of the following assertion. "Some boys in the class are taller than all the girls" Note : taller(x,y) is true if x is taller than y. a: (∃x) (boy(x) → (∀y) (girl(y) ∧ taller(x,y))) b: (∃x) (boy(x) → (∀y) (girl(y) → taller(x,y))) c: (∃x) (boy(x) ∧ (∀y) (girl(y) ∧ taller(x,y))) d: (∃x) (boy(x) ∧ (∀y) (girl(y) → taller(x,y)))

d

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 17, list the elements that will be compared with key in order of when the comparison happens a: 20 35 28 15 b: 20 9 15 17 c: none of these d: 20 9 15 19

d

Let G be a graph with n vertices and m edges. What is the tightest upper bound on the running time on Depth First Search of G? Assume that the graph is represented using adjacency matrix. a: O(m+n) b: O(mn) c: O(n) d: O squared

d

Predict output of the following program #include<iostream> using namespace std; class Base{ public: virtual void show() { cout<< "I am base \n" ; } }; class Derived: public Base{ public: void show() { cout<< "I am derived \n" ; } }; int main( void ){ Base *bp = new Derived; bp->show(); Base &br = *bp; br.show(); return 0; } a - I am base I am base b - I am base I am derived c - I am derived I am base d - I am derived I am derived

d

Suppose I have the following Scanner object: File file = new File("data.txt") Scanner input = new Scanner(file); After I read data from file, which of the following close the file? a: input.close(file); b: file.close(input); c: file.close() d: input.close();

d

What is the Big O notation for following run time function? T left parenthesis n right parenthesis space equals space 1000 n log n space plus space 2 to the power of n space plus space 20000 a: O(1) b: O left parenthesis n squared right parenthesis c: O(n log n) d: O left parenthesis 2 to the power of n right parenthesis

d

What is the output of the following Java code? public class MyClass { public static void mySwap(Integer x, Integer y){ int temp = x; x = y; y = temp; } public static void main(String[] args) { Integer x = new Integer(10); Integer y = new Integer("20"); mySwap(x,y); System.out.println("x = " + x + " y = " + y); } } a: x = 20 y = 10 b: Compile error in main method c: Compile error in mySwap method d: x = 10 y = 20

d

What is the output of the following code segment? char c = 'A'; System.out.println(c+32); a: a b: There is a compile error c: c32 d: 97

d

What is the output of the following code? BigDecimal d1 = new BigDecimal("1.11"); BigDecimal d2 = new BigDecimal("2.22"); System.out.println(d1 + d2); a: 3.33 b: 1.112.22 c: 1.11+2.22 d: There is a syntax error

d

What is the output of the following piece of code? for(int i = 0; i < 5; i++); cout << i << ", "; a - 0, 1, 2, 3, 4, 5, 6, b -0, 1, 2, 3, 4, 5, c -6, d - There is a syntax error

d

What is the value of numbers.capacity() after the following code? a - Unknown b - 0 c - 10 d - 100

d

What is true about the following Java code segment? 6 Scanner input = new Scanner(System.in); do{ char choice; System.out.println("Do again? Enter your choice: "); 10 choice = input.nextLine().charAt(0); 11 }while (choice == 'Y' || choice == 'n'); a: There is no compile error b: Compile error in line 6 c: Compile error in line 10 d: Compile error in line 11

d

Which of the following is correct definition for Student structure which is used in LinkedList that stores student's info: id, gpa, name? a - struct Student{ int id; double gpa; string name; Student next; }; b - structure Student{ int id; double gpa; string name; Student* next; }; c -struct Student{ int id; double gpa; string name; Student* next; } d - struct Student{ int id; double gpa; string name; Student* next; };

d

n the following function template, what must be TRUE in order to use the function with a given data type? template <class T> int smallest( T array[], int size) { int small=0, i; for(i=0;i<size;i++) { if(array[i] < array[small]) small=i; } return small; } a - The data type must be numeric. b - The data type must be a pre-defined data type. c - The data type must be character based. d - The data type must have a < operator defined for it.

d

You are given pointers to first and last nodes of a double linked list, which of the following operations are dependent on the length of the linked list? a: remove the first element of the list b: insert in front of the list c: remove the last element of the list d: add new element at the end of the list e: None of these

e


Conjuntos de estudio relacionados

Ch. 26: Transferability and Holder in Due Course

View Set

Histology - Adipose Tissue Terms (Ch. 9)

View Set

CHAPTER 22: REPRODUCTIVE SYSTEMS

View Set

Fahmy 3030 === Spanish En Sentences

View Set

Medical Insurance Ch 16 & 17 Exam

View Set

Abeka 7th Grade: Of People Reading Quiz K

View Set