CSD201 - Final Key (T1)

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

c

A binary tree has ten nodes. The inorder and the preorder traversal of the tree are shown below. Preorder: J C B A D E F I G H Inorder: A B C D E F J G I H Show the postorder of this tree. Choose one answer. a. Inadequate conditions for the construction of the tree. b. D B E F C A I H G J c. A B E F D C G H I J d. B A C D F E H I G J

b

A graph can be used to show relationships. From the following list of people belonging to the same club (vertices) and their friendships (edges): Peope = {George, Jim, Jean, Frank, Fred, John, Susan} Friendship = {(George, Jean), (Frank, Fred), (George, John), (Jim, Fred), (Jim, Frank), (Jim, Susan), (Susan, Frank)} Find all friends of friends of Jean. Choose one answer. a. Jim and George b. John and Jean c. Nobody d. Fred, Frank and Susan

a

A recursive method may be eliminated by using ................. Choose one answer. a. Iteration statements b. Stacks c. All of the others.

b

After two passes of a sort algorithm, the following array: 47 3 21 32 56 92 has been rearranged as shown below: 3 21 47 32 56 92 Which sorting algorithm is being used? Choose one answer. a. all of them. b. insertion sort. c. selection sort. d. bubble sort.

d

An array contains the elements shown below. The first two elements have been sorted using a bubble sort. What would be the order of the elements in the array after three more passes of the bubble sort algorithm? Use the version of bubble sort that starts from the begin and bubbles up the largest element. 7 8 26 44 13 23 57 98 Choose one answer. a. 7 8 13 26 44 23 57 98 b. 7 8 13 44 26 23 57 98 c. 7 8 13 23 44 26 57 98 d. 7 8 13 23 26 44 57 98

a

An array contains the elements shown below. What would be the order of the elements in the array after phase 1 of the heap sort algorithm? 3 9 7 2 11 16 4 13 12 Choose one answer. a. 16 13 11 12 3 7 4 2 9 b. 16 13 12 11 9 7 4 3 2 c. 16 12 13 4 9 7 11 2 3 d. 16 12 11 9 13 7 4 3 2

a

Consider the AVL tree below. What is the breadth first traversal of the tree after inserting a node with value 28 ? pre-order : 35-20-10-30-25-45-40 in-order : 10-20-30-25-35-45-40 Choose one answer. a. 35, 20, 45, 10, 28, 40, 25, 30 b. 35, 20, 45, 10, 25, 40, 28, 30 c. 35, 20, 45, 10, 30, 40, 28, 25 d. 35, 20, 45, 10, 30, 40, 25, 28

a

Consider the following algorithm in Java: public static boolean DEF(BSTNode p) { if(Math.abs(height(p.left) - height(p.right))==0 || Math.abs(height(p.left) - height(p.right))==1) { return DEF(p.left) && DEF(p.right); } return false; } The above algorithm will ________ Choose one answer. a. check whether a binary tree is balanced. b. check whether the height of left subtree is greater than the height of right subtree. c. None of the others. d. check whether the height of the right subtree is greater than the height of the left subtree.

b

Consider the following algorithm in Java: static void patten(int n){ if (n > 0 && n <4242) { System.out.println(n); System.out.println(n*2); System.out.println(n); return; } System.out.println(n); System.out.println(n); } How many times is the number 840 printed out when pattern(840) is called? Choose one answer. a. 4 b. 2 c. 6 d. 8

d

Consider the following algorithm in Java: static void nonTail(int i) { if(i > 0) { nonTail(i-1); System.out.print(i + ", "); nonTail(i-1); } } How many integers will be printed out when nonTail(3) is called? Choose one answer. a. 8 b. 6 c. 5 d. 7

d

Consider the following algorithm on a binary search tree in Java: public static void XYZ(BSTNode p) { if(p!=null) { if((Integer)p.e1 % 2 == 0) System.out.println(p.e1); XYZ(p.left); XYZ(p.right); } } The above algorithm will ______ Choose one answer. a. print even numbers in ascending order. b. count number of even values in binary tree. c. print and count number of even values in binary tree. d. print even numbers in binary tree.

d

Consider the following algorithm on binary search tree in Java: public static int ABC(BSTNode p) { if(p!=null) { return 1 + Math.max(ABC(p.left), ABC(p.right)); } return 0; } The above algorithm will __________ Choose one answer. a. None of the others. b. count number of non-terminal nodes in the tree. c. count number of nodes in the tree. d. determine the height of the tree.

a

Consider the following algorithm: public <T extends Comparable<? super T>> void selectionsort(T[] data) { int i, j, least; for(i=0; i<data.length-1; i++) { for(j=i+1, least = i; j<data.length; j++) { if(data[j].compareTo(data[least]) < 0) least = j; } if(least != i) swap(data, least, i); } } Assume that this algorithm is executed with array {9, 8, 6, 3, 1, 4}. What is output after iteration i=3 of the outer for loop completed? Choose one answer. a. 1, 3, 4, 6, 9, 8 b. 1, 3, 4, 8, 6, 9 c. 1, 8, 6, 3, 9, 4 d. 1, 3, 8, 6, 9, 4

b

Consider the following algorithm: public static int unknown(SLLNode<Integer> p, int i) { Stack<Integer> s = new Stack<Integer>(); int j = -1; while(p!=null) { s.push(p.info); p = p.next; j++; } while(!s.isEmpty) { if(i == s.pop()) return j; else j--; } return -1; } What is output after executing unknow(p, 9), where p has position as the below image: 9(p) ---> 7 ---> 1 ---> 9 ---> 14 Choose one answer. a. 0 b. 2 c. None of the others. d. 4 e. 1

b

Consider the following algorithm: public <T extends Comparable<? super T> void XYZsort(T[] data) { int i, j, least; for(i=0; i<data.length-1; i++) { for(j=i+1; least=i; j<data.length; j++) { if(data[j].compareTo(data[least]) < 0) least = j; } if(least != i) swap(data, least, i); } } Assume that the data array contains initial values: {4,10,8,3,12,17,5,14,13}. After executing 4 iterations of outer loop, the data array contains: Choose one answer. a. {10, 8, 4, 3, 12, 17, 5, 14, 13} b. {3, 4, 5, 8, 12, 17, 10, 14, 13} c. {3, 4, 5, 8, 10, 12, 13, 14, 17} d. {3, 4, 10, 8, 12, 17, 5, 14, 13}

a

Consider the following method: public static SLLNode<Integer> unknown(SLLNode<Integer> p, int i) { SLLNode<Integer> tmp, prev; for(tmp = p, prev = p; tmp != null; tmp = tmp.next) { if(tmp.info.equals(i)) break; else prev = tmp; } if(tmp == prev || tmp == null) return null; else return prev } What is output when executing unknow(p, 7), where p has position as the below image: 10(p) ---> 3 ---> 15 ---> 7 ---> 5 Choose one answer. a. The node of info of 15. b. The node has info of 5. c. The node has info of 7. d. null

d

Consider the following method: public static String unknown(String s, char ch) { if(s.length() > 0) { if(ch==s.charAt(0)) return unknown(s.substring(1), ch); return s.substring(0, 1) + unknown(s.substring(1), ch); } return ""; } This method is used to ......................................... Choose one answer. a. Removes the character at the specified position in the string. b. Removes the first occurrence of the specified character from the string, if it is present. c. None of the others. d. Removes all occurrences of the specified character from the string, if it is present.

a

Consider the following method: public static void unknown(SLLNode<Integer> p) { if(p != null) { unknown(p.next); System.out.print(p.info + " "); } } What is output after executing unknow(p), where p has position as the below image: 3(p) ---> 7 ---> 2 ---> 9 ---> 5 Choose one answer. a. 5 9 2 7 3 b. 3 7 2 9 5 c. Stack overflow error. d. 3 5 7 9 2

d

Consider the following pseudocode: declare a queue of characters while(there are more characters in the word to read) {read a character if a character is '*' then dequeue and write the dequeued character to the screen else enqueue the character into the queue } What is written to the screen for the input "HowAre***You**To****Day" ? Choose one answer. a. wAreYouTo b. HowAreYo c. owAreYouT d. HowAreYou

a

Give the breath-first traversal (by alphabet order) of the following graph, starting from vertex A A to B, C, G B to E C to D, F D to H E to G F to G, H Choose one answer. a. A B C G E D F H b. A B G C D E F H c. A B E G C F D H d. A B C D E G F H

b

Given a graph below and colors numbered 1, 2, 3, ... are assigned to vertices with the sequential coloring algorithm that orders vertices by alphabetical order (i.e. the vertex labeled A comes first, then the vertex B,...) A to B, C, G, D B to E, C C to E D to F E to F, G What is the color of the vertex E? Choose one answer. a. 5 b. 1 c. 2 d. 3 e. 4

a

Given a weighted graph below. What is the total edge-weight of the minimum spanning tree of G? A - 3B, 6C, 8D B - 4C, 19E C - 10E D - 17F E - 15F Choose one answer. a. 40 b. 25 c. 31 d. 48

b

How many recursive calls to calculate the 5th Fibonacci number? Choose one answer. a. 22 b. 15 c. 9 d. 32

b

Imagine we have the singly linked list, the head reference allows to manage this list. Show what would happen if we applied the following statements to this list? for (temp = head; temp.next != null; temp = temp.next) { } temp.next = head; Choose one answer. a. Insert the temp node successfully. b. This will create a circularly linked list. c. Nothing happens, the temp reference points at the end of the list. d. We have lost control this list, the head is overwritten by the other reference.

d

In a circular singly linked list, we can use only one permanent reference, the tail. The familiar reference, the head, is: Choose one answer. a. The null reference. b. The predecessor of the tail. c. The implicit reference. d. The successor of the tail.

a

In a real computer, what will happen if you make a recursive call without making the problem smaller? Choose one answer. a. The run-time stack overflows, halting the program b. The run-time stack overflows, halting the program c. The program keeps running until you press Ctrl-C d. The results are nondeterministic

d

In run-length encoding algorithm, a run is defined as ... Choose one answer. a. number of different characters in the input. b. size of the result of encoding input data. c. amount of time required to the compression algorithm. d. a sequence of identical characters.

a

In the array implementation of the queue, which operations require constant time? Choose one answer. a. isEmpty b. enqueue c. dequeue d. All of the others.

c

Specify the correct implementation of dequeue() method of a queue. This queue uses java.util.LinkedList, here is pool, for storing data and the head of the list is treated as the head of the queue. (Choose the most suitable one) Choose one answer. a. void dequeue(Object x) { if (isEmpty()) return(null); pool.remove(pool.size()-1); } b. Object dequeue() {if (isEmpty()) return; return(pool.remove(pool.size()-1)); } c. Object dequeue() { if (isEmpty()) return(null); return(pool.removeFirst(); } d. Object dequeue() { if (isEmpty()) return(null); return(pool.removeLast()); }

d

Specify the correct statement about hashing algorithm (Select the best answer). Choose one answer. a. If the coalesced method is used for collision resolution, insertion and searching (and sometimes deletion) always take constant time: O( 1 ). b. If the chaining method is used for collision resolution, insertion and searching (and sometimes deletion) can take constant time: O( 1 ). c. No matter how many data items there are, insertion and searching (and sometimes deletion) always take constant time: O( 1 ). d. The expected complexity of hashing algorithm is O( 1 ). However by the collision resolution, sometimes it may take O( n ).

e

Study the following recursive method in Java: static void T(int t){ if (t/2 > 0) { T(t/2); System.out.println("t: "+t/2); } System.out.println(t%2); } What is the output if T(37) is called. Choose one answer. a. 100100 b. 1 c. 101101 d. 0110 e. None of the others

d

Suppose the frequencies of use of characters are given by: E [40%], A [30%], M [20%], N [5%], T [5%] What is the Huffman code of M? Choose one answer. a. 010 b. 01 c. 10 d. 001

b

Suppose the frequencies of use of characters is given by: A [10%], B [20%], C [70%] What is the average length of the Huffman codes? Choose one answer. a. 2 b. 1.3 c. 1.5 d. 1

b

Suppose we are considering a doubly linked list which is not empty. Select the most correct java code snippet that inserts new node with value x at the head of the list (the new node will be the first node in the list). Choose one answer. a. Node q = new Node(x); q.prev=null; q.next = head; head.prev = q; b. Node q = new Node(x); q.prev=null; q.next = head; head.prev = q; head = q; c. Node q = new Node(x); q.prev=null; q.next = head; head = q; d. Node q = new Node(x); q.next = head; head.prev = q; head = q;

b

Suppose we are considering a singly linked list and p is some node in the list which has successor node. Select the most correct java code snippet that deletes the successor node of p (the node after p). Choose one answer. a. p = p.next; p.next = null; b. Node q = p.next; p.next = q.next; c. p.next= null; d. Node q = p.next; q.next = p.next.next;

c

Suppose you are using the LZW algorithm to encode the message AABAACAABD contents of the dictionary at the beginning of encoding are: (1) A (2) B (3) C (4) D What string is denoted by code word (7)? Choose one answer. a. BAA b. AB c. BA d. ABA e. AC

d

The Java Collections Framework contains a Map interface. An implementation of this interface is ... Choose one answer. a. Singly Linked List b. Connected Graph c. Priority Queue d. HashTable

b

There are two approaches to writing repetitive algorithms: Choose one answer. a. direct recursion and indirect recursion. b. iteration and recursion. c. tail recusion and nontail recursion. d. nested recursion and excessive recursion.

B

Using the coalesced hashing to put the following values in a table with 10 elements: A5, A2, A3, B5, A9, B2, B9, C2 Using the extraction method to extract the number as the key. What is the chain to begin with A5? Choose one answer. a. A5-B2-C2 b. A5-B5-A9-B9 c. A5-A2-A3 d. A5-B5

c

We implement the stack as a singly linked list and use AddtoHead() method of the linked list to implement push() method. A top pointer of the stack is ... Choose one answer. a. Any one reference. Depending on the node that is accessed. b. Nothing. We need a doubly linked list. c. The head reference of the singly linked list. d. The tail reference of the singly linked list.

a

What is the number of comparisons and swaps in the best case for creating a heap using top down method (William's method)? Choose one answer. a. The number of comparisons is n - 1 and swaps is zero. b. The number of comparisons is 2.[n/2] and swaps is zero. c. The number of comparisons is n and swaps is zero. d. The number of comparisons is lgn and swaps is zero.

b

What is the output of the following Java code? class A {int f() {return 0;}} classB extends A {int f() {return 1;}} classC extends B {int f() {return 2;}} public class test { public static void main(String[] args) { A ref1 = new C(); B ref2 = (B) ref1; System.out.println(ref2.f()); } } Choose one answer. a. 0 b. 2 c. 1 d. The code will cause errors when compiling

d

What is the output when the following Java code is executed: import java.util.*; public class TestLinkedList { public static void main(String[] args) { LinkedList<Integer> list = new LinkedList<>(); for (int i = 0; i < 10; i++) { list.add(i); } list.removeFirst(); list.removeLast(); list.remove(4); for (int j = 0; j < list.size(); j++) { System.out.println(list.get(j)+" "); } } } Choose one answer. a. 2 3 4 5 6 7 8 b. 1 2 3 5 6 7 8 c. 1 2 3 4 5 7 8 d. 1 2 3 4 6 7 8

b

What type of the hash functions that can be used in an English - Vietnamese dictionary? Choose one answer. a. Radix transformation b. Extraction c. Mid-square function d. Folding

c

What will be printed when the following program is run? class A { String g() {return "this is g of A";} } class B extends A { } class C extends B {String g() {return "this is g of C";} } public class test { public static void main(String[] args) { A ref1 = new C(); B ref2 = (B) ref1; System.out.println(ref2.g()); } } Choose one answer. a. The code will cause errors when it is compiled. b. "this is g of A" c. "this is g of C" d. Nothing is printed.

c

When representing any algebraic expression E which uses only binary operations in a 2-tree (every node other than the leaves has two children). Choose one answer. a. the operations in E will appear as external nodes (leaves) and variables in internal nodes. b. the variables and operations in E will appear only in external nodes. c. the variable in E will appear as external nodes (leaves) and operations in internal nodes. d. the variables and operations in E will appear only in internal nodes.

b

When the compiler compiles your program, how is a recursive call treated differently than a non-recursive method call? Choose one answer. a. Primitive values are all treated as reference variables. b. None of the others c. There is no duplication of local variables. d. Reference variables are all treated as primitive values.

d

Which of the following Sorting algorithms use Divide and Conquer strategy? Choose one answer. a. Heap sort b. Radix sort c. Bubble sort d. Quick sort

d

Which of the following is NOT a valid order in which the vertices of the graph below can be marked as "visited" during a depth-first search? (directed) A to B, C, D B to D, E C to D, F D to E, F Choose one answer. a. ABEDFC b. ADEFCB c. ABDFEC d. ABCDEF

a

Which of these operations are likely to have a constant time for worst-case in the singly linked lists? Choose one answer. a. None of the others. b. removeLastOccurrence (): Removes the last occurrence of the specified element in list. c. get(int index):Returns the element at the specified position in this list. d. InsertAfter (int index) : insert a new element into after an element in the list.


Ensembles d'études connexes

Vocabulary Workshop Level E Unit 13 Answers

View Set

Foundations and Practice of Mental Health Nursing HESI EXIT 5

View Set

server 2008 infrastructure chp 5

View Set

Macroeconomics Chapter 18 True/False

View Set

FT 3023 Test 1 - Multiple choice

View Set