Final exam CSD

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

A

(Choose 1 answer) The height of a complete binary tree with n nodes is 1. nlogn 2. nlog(n+1) 3. log(n) 4. log(n+1) A. 4 B. 2 C. 1 D. 3

B

(Consider the binary tree below. Which statement is correct? (full binary tree = proper binary tree = 2-tree) Answer A. The tree is complete but not full. B. The tree is neither complete nor full. C. The tree is both full and complete. D. The tree is full but not complete.

B

Answer |n a linked list, the tail node is introduced for performance purpose only. A. False B. True

C

Answer Given the character frequencies 32% B C D E F 28% 16:58 16% 6% 18% Using Huffman encoding, what is the code for character C? (Suppose that when constructing a sub tree from 2 nodes we always place node with higher frequency on the left and the left branch of a node gets value 0. the right one gets value 1) A. 10 B. 101 C. 01 D. 001

A

Answer Specify the correct implementation of in-order traverse algorithm for binary trees. A. void inOrder(Node p) {if (p != null) {inOrder(p.left): visit(p); inOrder(p.right):} B. void inOrder(Node p) { inOrder(p.left): visit(p); inOrder(p.right):} C. void inOrder(Node p) {if (p != null) {visit(p): inOrder(p.left); inOrder(p.right):} } D. void inOrder(Node p) {if (p == null) {inOrder(p.left): visit(p); inOrder(p.right):}

D

Answer What is the correct definition of a hash table? (Select the best answer) A. Hash Table T is an array in memory used for storing items. Hash table T is used with a hash function h(x). which transforms a particular key x (string or number), into an index i = h(x) in the table. B. Hash Table T is an array in memory used for storing items. Hash table T is used with a hash function h(x). which transforms a particular key x (a string, number, record, or the like), into an index i = h(x) in the table. C. Hash Table T is an array in memory used for storing items or their addresses. Hash table T is used with a hash function h(x). which transforms a particular key x (a string, number, record, or the like), into an non-negative integer. D. Hash Table T is an array in memory used for storing items or their addresses. Hash table T is used with a hash function h(x). which transforms a particular key x (a string, number, record, or the like), into an index i = h(x) in the table.

E

Answer Which statements are true (select two): A. In a singly-linked| list we can insert a node after a given node with time complexity 0(n) B. In a singly-linked list we can insert a node after a given node with time complexity 0(1) C. In a singly-linked list we can insert a node before a given node in the middle of the list with time complexity 0(1) D. In a singly-linked list there is no efficient way to insert a node before a given node in the middle of the list (the action is considered efficient if it's complexity is 0(1)). E. B & D

B

Consider the following function: int fun(int n) {if(n==0) return(1); else return(n + fun(n/2)); } What is the output when the statement: System.out.println(fun(9)); is run? A. 16 B. 17 C. 15 D. 18

B

Consider the following function: void fun(int n) {if(n <= 0) System.out.println("That's all!"); else {for(int i =1; i<=n; i++) System.out.print("8"); System.out.println(); fun(n-2); } } What is the output when the statement fun(5); is run? A. That's all! ***** *** * B. ****** *** * That's all! C. * *** ***** That's all!

A

Consider the following function: void fun(int n) {if(n>0) {System.out.print(" " +n % 5); fun(n); } } What will happen if the statement fun(33); is run? A. The run-time stack overflows, halting the program B. The results are nondeterministic C. The operating system detects the infinite recursion because of the "repeated state" D. The program keeps running until you press Ctrl-C

D

Consider the following function: void fun(int n) {int m = n/2; int k = n%2; System.out.print(k + " "); if(m>0) {fun(m); } } What is the output when the statement fun(8); is run? A. 0 1 0 1 B. 1 1 0 1 C. 1 0 1 1 D. 0 0 0 1 E. 1 0 1 0

D

Consider the following function: void fun(int n) {int m = n/2; int k = n%2; if(m>0) {fun(m); } System.out.print(k + " "); } What is the output when the statement fun(10); is run? A. 1 1 0 1 B. 0 1 0 1 C. 1 0 1 1 D. 1 0 1 0

A

Consider the following function: void printOut(int count) {if((count %2) == 0) System.err.println("StdErr: Line " + count + "\n"); else System.out.println("StdOut: Line " + count + "\n"); if(count ==0) return; else printOut(count-1); } What value for X the statement printOut(X); will print EXACTLY 5 lines to standard output (Lines start with "StdOut:"), in the fewest number of recursive calls? A. 9 B. 11 C. 10 D. 8

A

Consider the following function: void fun(int n) {if(n<0) {System.out.print("-"); fun(-n); } else if(n<10) System.out.print(n); else {fun(n/10; System.out.println(n%10); } } Which call will result in the most recursive calls? A. fun(-1023); B. fun(0); C. fun(100); D. fun(1025); E. fun(1023);

B

Consider the following function: void fun(int n) {if(n<0) {fun(-n); System.out.println(" n = " +n); } else if(n<15) System.out.println(n); else {System.out.println(n%10); fun(n/15); } } What values of n are directly handled by the stopping (base) case? A. n < 15 B. n >= 0 && n < 15 C. n >= 15 D. n < 0

D

Consider the following function: voidfun(int n) {if (n == 0) System, outprintlnfHello"); else {for(inti = 1; i <= n: i++) Sy ste m. o ut. p ri nt("$"); System.out.println(): fun(n-1); What is the output when the statement fun(3); is run? A. Hello $ $$ $$$ B. $ $$ $S$ Hello C. Hello $S$ $$ $ D

C

Consider the following function: int fun(int n) {if (n < 0) return(fun(-n)); else if(n<5) return (2); else return(n*fun(n-2)); } What is the value of fun(6)7 A. 2 B. 10 C. 5 D. 12 E. 4

C

Consider the following function: int fun(int n)| {if (n < 0) return(fun(-n)); else if(n<5) return (2); else return (n*fun(n/2)); } Which call will result in the most recursive calls? A. fun(1012); B. fun(IOO); C. fun(-1012); D. fun(O

B

Consider the following function: voidfun(int n) Machine: FNANDO-PC Server: EOS_21092012 Duration: 60 minutes Q mark: 1 Exam Code: CSD201 Open Code: Total Marks: 50 Show Question 0000 6:57 {if(n > 0) {System.outprint(" " + n % 5); fun(n): } } What will happen if the statement fun(33); is run? A. The results are nondeterministic B. The operating system detects the infinite recursion because of the "repeated state" C. The program keeps running until you press Ctrl-C Next D. The run-time stack overflows, halting the program

D

Consider the following function: voidfun(int n) {if (n < 0) {System, outprintlnf-"); fun(-n); } else if(n<15) System.outprintln(n): else {fun(n/15); System.outprintln(n%15): } } What values of n are directly handled by the stopping (base) case? A. n<0 B. n <15 C. n >= 15 D. n>=0&& n<15

B

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 the queue else enqueue the character into the queue } while(the queue is not empty) dequeue and write the dequeued character to the screen What is written to the screen for the input "HowAre***You**To****Day" ? A. oDay B. ToDay C. ToDa D. yaDoT

B

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 ""GoodA***fter****Noo**m"? A. GoodAfte B. GoodAfter C. Adoretfoo D. odAfteroo

C

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 the queue else enqueue the character into the queue } whi(the queue is not empty) dequeue and write the dequeued character to the screen What is written to the screen for the input "HowAre***You**To****Day" ? A. yaDoT B. oDay C. ToDay D. ToDa

C

Consider the following pseudocode: declare a queue of characters, which is implemented by circular array of size 6. while(there are more characters in the word to read) {read a character if a character is '*' then dequeue the queue else enqueue the character into the queue } how the queue looks like after processing the input "Hello****Worl**d*"? A. (1) B. (4) C. (3) D. (2)

A

Given a raw message 'FFFF0000FFF00FFFFF00' (without single quote). Run the run-length encoding algorithm for that message, what is the output? A. 4F403F205F20 B. 4F403F205F200 C. 4F403F205F D. FFFF0000FFF00FFFFF00

B

Consider the following pseudocode: declare a stack of characters while(there are more characters in the word to read) {read a character if a character is '*' then pop the stack else push the character into the stack } while(the stack is not empty) pop and write the poped character to the screen What is written to the screen for the input "Comp***ress*ion**" ? A. nospmo B. iserC C. Cresi D. iserO

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 "H*owAre***You**To****Day" ? A. owAreYouTo B. wAreYouTo C. HowAreYou D. HowAreYouT

B

Consider the list of ten integers below: 15, 13, 18, 19, 11, 17, 10, 12, 16, 14 What is the list after the FIRST TWO iterations of the large loop in a selection sort? (sorting from smallest to largest). A. 10, 11, 18, 19, 12, 17, 15, 13, 16, 14 B. 10, 11, 18, 19, 13, 17, 15, 12, 16, 14 C. 10, 11, 18, 19, 13, 17, 15, 13, 16, 14 D, 10, 12, 18, 19, 11, 17, 15, 13, 16, 14

B

Fill in blank to form a correct statement: "A recursive method is a method that invokes itself directly or indirectly. For a recursive method to terminate there must be one or more...............................". A. steps B. base cases C. conditions D. limit conditions

A

Fill in the blank of the statement to form the most correct one: In a every element contains some data and a link to the next element which allows to keep the structure. A. singly linked list B. binary search tree C. doubly linked list D. skip list

B

Given a binary search tree T below, What is a result of breadth-first traverse of T after you delete by merging the node 3? A. 6, 1, 8, 2, 4, 7, 9 B. 6, 1, 8, 2, 7, 9, 4 C. 6, 2, 8, 1, 4, 7, 9 D. 6, 2, 1, 4, 8, 7, 9

C

Given a binary tree below. What is a result of post-order traverse? A. 1, 3, 4, 7, 5, 2, 8, 6 B. 7, 4, 3, 5, 1, 2, 8, 6 C. 7, 4, 5, 3, 8, 6, 2, 1 D. 1, 3, 4, 7, 5, 2, 6, 8

D

Given a binary tree below. What is a result of pre-order traverse? A. 1, 3, 6, 7, 5, 2, 4, 8 B. 1, 3, 6, 5, 7, 2, 8, 4 C. 6, 3, 7, 5, 1, 8, 4, 2 D. 1, 3, 6, 5, 7, 2, 4, 8

B

Given a graph below. What is the output of depth-first traversal from vertex B? (visit nodes in ABC order if there are some nodes having the same selection ability). A. B, A, C, E, G, F, D, H B. B, A, E, G, F, D, C, H C. B, A, E, G, F, D, C D. B, A, E, G, C, D, F, H

D

Given a graph below. What is the output of depth-first traversal from vertex B? (visit nodes in ABC order if there are some nodes having the same selection ability). A. B, A, E, G, C, D, F, H B. B, A, E, G, F, D, C C. B, A, C, E, G, F, D, H D. B, A, E, G, F, D, C, H

A

Given a raw message 'BBBUUUUBBBUUBBBBBUU' (without single quote). Run the run-length encoding algorithm for that message, what is the output? A. 3B4U3B2U5B2U B. 3B4U3B2U5B2UU C. 3B4U3B2U5B D. 3B4U4B3U2B5UU2

C

Given a weighted graph below and you are using the Dijkstra algorithm to find the sortest path from the vertex H to the vertex T. What are the correct order of vertices selected into the set S until the vertex T is selected?(Each step a vertex with minimal current distance is selected into S). A. H, B, D, T B. H, C, T C. H, A, B, C, T D. H, A, B, D, T

B

Given a weighted graph below. What is the total edge-weight of the minimum spanning tree of G? A. 42 B. 39 C. 40 D. 35 E. 45

D

Given a weighted graph below. What is the total edge-weight of the minimum spanning tree of G? A. 43 B. 40 C. 45 D. 37 E. 42

E

Given a weighted graph below. What is the total edge-weight of the minimum spanning tree of G? Answer A. 24 B. 26 C. 28 D. 18 E. 27

B

Given the division hash function h(x) = x%M, where M = 10 and Collision Resolution is quadratic probing. i.e. when inserting a key x, the collision is resolved by finding an available position at (h(x) + i^2)%M), i=1, 2, ... How the hash table looks like after inserting the following keys sequentially? A. (1) B. (4) C. (2) D. (3)

D

Given the division hash function h(x) = x%M, where M = 10 and Collision Resolution is quadratic probing. i.e. when inserting a key x, the collision is resolved by finding an available position at (h(x) + i^2)%M), i=1, 2, ... How the hash table looks like after inserting the following keys sequentially? A. (4) B. (1) C. (2) D. (3)

D

Given the graph G = (V,E) and X is a vertex of G. Suppose there exists at least one Hamilton Cycle for the graph. The following is a backtracking algorithm for finding the first Hamilton cycle from the vertex X: declare an empty array H (which will contain Hamilton cycle) (1) Put the vertex X to H (2) Check if H is a Hamilton cycle then stop, else go to (3) (3) Consider the last vertex Y in H, if there is/are vertex(es) adjacent to Y, select the first adjacent vertex Z (by alphabet order) and put it to H...... Go to (2) Suppose a G is given below (view picture). Which of the followings is the Hamilton cycle from the vertex A, created by above algorithm? A. A, F, C, E, D, B, A B. A, B, D, E, C, F, A C. A, F, D, E, C, B, A D. A, B, C, E, D, F, A E, A, F, D, B, E, C, A

E

Given the graph G = (V.E) and X is a vertex of G. Suppose there exists at least one Hamilton Cycle for the graph. The following is a backtracking algorithm for finding the first Hamilton cycle from the vertex X: declare an empty array H (which will contain Hamilton cycle) (1) Put the vertex X to H (2) Check if H is a Hamilton cycle then stop, else go to (3) (3) Consider the last vertex Y in H. if there is/are vertex(es) adjacent to Y. select the first adjacent vertex Z (by alphabet order) and put it to H. If there no adjacent vertex, remove Y from H and denote it as a bad selection (so you do not select it in the same way again). Go to (2). Suppose a G is given below (view picture). Which of the followings is the Hamilton cycle from the vertex A. created by above algorithm? A. A.C. D. E. B. A B. A. D. E. C. B .A C. A. B. C. D. E. A D. A. B. C. D. E .C .A E. A. B. C. E. D. A

C

If every node u in G is adjacent to every other node v in G, a graph is said to be A. finite B. isolated C. complete D. strongly connected

A

Linked lists are best suited A. for relatively permanent collections of data B. for the size of the structure and the data in the structure are constantly changing

D

Partitioning is a technique used in quicksort The following is a partition pseudocode for sorting from smallestto largest: partition the array a from index low to index up x := a[low], i=low. j=up do increase i and stop at i. where a[i]>x decrease j and stop at j. where a[j]<=x if(i<j) swap a[i] with a[j] while(i<j) swap a [low] with a[j] Consider the list of eight integers (n=8) below: 15.13.18.19.17.12.16.14 What is the list after it is partitioned with low = 0 and up = n-1? A. 12.13.14.15.17.16.18.19 B. 12.13.15.14.17.19.16.18 C. 12.13.15.14.17.19.18 D. 12.13.14.15.17.19.16.18

C

Select the most correct statement about the complexity of bubble sort * A. Both best and worst cases are 0(n~2) B. The best case is 0(n). and the worst case is 0(nlogn)| C. The best case is 0(n). and the worst case is 0(n~2) D. The best case is O(nlogn). and the worst case is 0(n~2)

D

Select the most correct statement about the complexity of insertion sort A. The best case is 0(n), and the worst case is O(nlogn) B. The best case is O(nlogn). and the worst case is 0(n~2) C. Both best and worst cases are 0(n~2)\ D. The best case is 0(n). and the worst case is 0(n~2)

D

Select the most correct statement about the complexity of quicksort A. Both best and worst cases are O(n^2) B. The best case is O(n), and the worst case is O(n^2) C. The best case is O(n), the average case is O(nlogn), and the worst case is O(n^2) D. both best and average cases are O(nlogn), the worst case is O(n^2)

A

Select the most correct statement: A. in all cases the selection sort is O(n^2). B. In the average case the selection sort is O(n^2), in the best case it is O(nlog n). C. In the worst case the selection sort is O(n^2), in the best case it is O(n). D. In the worst case the selection sort is O(n^2), in the best case it is O(nlog n).

A

Select the statement that is most correct A. A recursive method is a method that invokes itself directly or indirectly. For a recursive method to terminate there must be one or more base cases. B B. For a recursive method to terminate there must be one or more steps. C. For a recursive method to terminate there must be one or more limit conditions. D. There is no difference between a recursive method and a non-recursive method.

C

Select the statement that is most correct. Basically, the complexity of finding the position of the minium value in a doubly-linked list of integer numbers is A. O(1) B. O(n^2) C. O(n) D. O(log n)

B

Select the statement that is most correct. Basically, the complexity of inserting new element before a given node in the middle of a singly linked list is A. O(log n) B. O(n) C. O(1) D. O(n^2)

D

Select the statement that is most correct. Suppose we are considering a doubly linked list and p is some node in the list which has successor node. What does the java code snippet below do? Node p1, p2; p1 = new Node(x0; p2 = p.next; p.next = p1; p1.prev = p; p1.next = p2; p2.prev = p1; A. It creates new node with value x at the end of the list. B. It replaces the node p with new node with value x. C. It inserts new node with value xbefore the node p. D. It inserts new node with value x after the node p.

A

Select the statement that is most correct. Suppose we are considering a singly linked list and p is some node in the list which has successor node. What does the java code sippet below do? Node q = p.next; p.next = q.next; A. It deletes the node p. B. It deletes the node after p. C. It deletes the node before p. D. It does not make any change on the list.

C

Select the statement that is most correct. Which of the following applications may not use a stack? A. Keeping track of local variables at run time. B. Undo sequence in a text editor. C. Multi-programming. D. Evaluating arithmetic expressions

D

Specify the correct implementation of dequeueO method of a queue. This queue uses java. util. ArrayList for storing data and the head of the list is treated as the head of the queue. (Choose the most suitable one) A. void dequeue(Objectx) {if (isEmptyO) return(null); pool.remove(pool.size()-1); } B. Object dequeueO {if (isEmptyO) return(null); return(pool.remove(pool.sizeO)); } C. Object dequeueO {if (isEmptyO) return: return(pool.remove(pool.sizeO-1)); } D. Object dequeueO {if (isEmptyO) return(null); return(pool.remove(0)); }

B

Specify the correct implementation of popO method of a stack of Integers. This stack uses java.util.LinkedList for storing data and the end of the list is treated as the top of the stack. (Choose the most suitable one) A. Integer popO {if(isEmptyO) return: return((lnteger) pool.remove(pool.size()-1)); } B. Integer popO {if (isEmptyO) return(null); return((lnteger) pooI.removeLastO); } C. void pop(lntegerx) {if (isEmptyO) return(null); pool.remove(pool.sizeO-l); } D. Integer popO {if (isEmptyO) return(null); return((lnteger) pool.remove(pool.sizeO)): }

B

Specify the correct implementation of popO method of a stack. This stack uses java.util.ArrayList for storing data and the end of the list is treated as the top of the stack. (Choose the most suitable one) A. Object popO {if (isEmptyO) return(null); return(pool.remove(pool.size())); } B. Object popO {if (isEmptyO) return(null); return(pool.remove(pool.size0-1)); } C. void pop(Objectx) {if (isEmptyO) return(null); pool.remove(pool.sizeO-l); } D. Object popO {if (isEmptyO) return: return(pool.remove(pool.sizeO-1)); }

A

Specify the correct statement about a binary search tree(select the most suitable one). A. It is necessary to build a tree with optimized height to stimulate searching operation B. In a binary search tree, all the nodes that are left descendants of node A have key values greater than A; all the nodes that are A's right descendants have key values less than (or equal to) A C. For better searching performance, a tree should be in back-bone shape D. The main purpose of balancing a tree is to keep the tree in good shape

B

Specify the correct statement about chaining method for handling collision A. In chaining, the linked-list is used instead of array for a hash table B. In chaining, some positions of the table is associated with a linked list or chain of structures whose info fields store keys or references to keys C. In this method, the table can never overflow if tree memory is available, because the linked list is extendible D. None of others

B

Specify the reason for data compression (select the best answer): Answer A. Just compress data for individual hobby B. Saving data storage C. Increasing system performance D. Saving network band-width

C

Spectify the statement that is most correct about a circular linked list. A. In circular linked-list, it is required to define both head and tail nodes B. Circular linked list is a normal doubly-linked list C. Circular linked list is a linked list in which the last node of the list points to the first node in the list D. Circular linked list is a normal singly linked list

A

State True or False: Definition of a balanced tree: "A balanced tree is one whose root has many more left descendents than right descendants, or vice versa." A. False B. True

B

Suppose a doubly linked list of integers is given below and p is a reference to the node with value 10 in the list (i.e. p.info=10); (head) 7 9 6 4 5 10 8 2 (tail) what does the list look like after the following java code snippet is run? Node p1, p2; p1 = p.next; p2 = p1.next; p.next = p2; if(p2!=null) p2.prev=p; A. 9 6 4 3 10 8 2 B. 7 9 6 4 3 10 2 C. 7 9 6 4 10 8 2 D. 7 9 6 4 3 8 2 E. 7 9 6 4 3 10 8

B

Suppose a doubly linked list of integers is given below and p is a reference to the node with value 10 in the list(i.e. p.info=10): (head)27 11 6 4 3 10 8 2(tail) What does the list look like after the following java code snippet is run? int x = 19; Node p1, p2; p1 = new Node(x) p2 = p.next; p.next = p1; p1.prev = p; p1.next = p2; p2.prev = p1; A. 27 11 6 4 3 19 10 8 2 B. 27 11 6 4 3 10 19 8 2 C. 27 19 11 6 4 3 10 8 2 D. 27 11 6 4 3 10 8 2 19 E. 19 27 11 6 4 3 10 8 2

E

Suppose a doubly linked list of integers is given below and p is a reference to the node with value 12 in the list(i.e. p.info=12): (head)7 1 6 4 3 12 8 21(tail) What does the list look like after the following java code snippet is run? int x = 13; Node f = p.prev; //prev is a link to predecessor node Node q = new Node(x); q.prev = f; q.next = p; f.next = q; p.prev = q; A. 7 1 6 4 3 12 13 8 21 B. 7 13 1 6 4 3 12 8 21 C. 7 1 6 4 3 12 8 21 13 D. 13 7 1 6 4 3 12 8 21 E. 7 1 6 4 3 13 12 8 21

A

Suppose a singly linked list of integers is given below and p is a reference to the node with value 9 in the list (i.e. p.info=9): (head) 7 11 6 4 3 9 8 21 (tail) What does the list look like after the following java code snippet is run? intx = 13: Node f= head: while(f.next != p) f = f.next Node q = new Node(x); q.next= p: f.next = q: A. 7 11 6 4 3 13 9 8 21 B. 13 7 11 6 4 3 9 8 21 C. 7 13 11 6 4 3 9 8 21 D. 7 11 6 4 3 9 8 21 13 E. 7 11 6 4 3 9 13 8 21

B

Suppose a singly linked list of integers is given below: (head)7 10 12 4 2 13 8 3(tail) What does the list look like after the following java code snippet is run? int x = 15; Node f = head; while(f.next !=tail) f=f.next; Node q = new Node(x); q.next = tail; f.next = q; A. 7 10 12 4 2 13 15 8 3 B. 7 10 12 4 2 13 8 15 3 C. 7 15 10 12 4 2 13 8 3 D. 7 10 12 4 2 13 8 3 15 E. 15 7 10 12 4 2 13 8 3

E

Suppose a singly linked list of integers is given below: (head)7 10 6 4 2 13 8 3(tail) What does the list look like after the following java code snippet is run? int x = 5; Node f = head; while(f.next !=tail) f =f.next; Node q = new Node(x); q.next = tail; f.next q; A. 7 5 10 6 4 2 13 8 3 B. 7 10 6 4 2 13 5 8 3 C. 5 7 10 6 4 2 13 8 3 D. 7 10 6 4 2 13 8 3 5 E. 7 10 6 4 2 13 8 5 3

D

Suppose the graph G = (V.E) satisfies the conditions for the existence of an Eulerian cycle. The following is an algorithm for finding Euler cycle from the vertex X using stack: declare a stack S of characters (a vertex is labeled by a character) declare an empty array E (which will contain Euler cycle) push the vertex X to S while(S is not empty) {ch = top element of the stack S if ch is islated then remove it from the stack and put it to E else select the first vertex T (by alphabet order), which is adjacent to ch, push Y to S and remove the edge (ch,Y) from the graph } the last array E obtained is an Euler cycle of the graph Suppose a multigraph G is given below (view picture). Which of the followings is the Euler cycle from the vertex B, created by above algorithm? A. B, A, B, C, D, B B. B, A, B, D, C, C. B, A, B, D, C, B D. B, D, C, B, A, B

A

Suppose we are considering a doubly linked list and p is some node in the list which has predecessor node. Select the most correct java code snippet that inserts new node with value x before the node p. (prev is a link to predecessor node). A. Node f = p.prev; Node q = new Node(x); q.prev = f; q.next = p; f.next = q; p.prev = q; B. Node f = p.prev; Node q = new Node(x); q.prev = f; q.next = p; f.next = q; C. Node f = p.prev; Node q = new Node(x); q.next = p; f.next = q; D. Node f = p.prev; Node q = new Node(x); q.prev = f; f.next = q; p.prev = q;

C

Suppose we are considering a singly linked list which has at least 2 nodes Select the most correct java code snippet that deletes the last node. A. Node f = head; while(f !=tail)f = f.next; f.next = null; tail = f; B. Node f = head; while(f.next !=tail)f = f.next; tail = f; C. Node f = head; while(f.next != tail)f = f.next; f.next = null; tail = f; D. Node f = head; while(f.next !=tail)f = f.next; f.next = null;

A

Suppose we are considering a singly linked list which is not empty. Select the most correct java code snippet that inserts new node with value x atthe head of the list (the new node will be the first node in the list). A. Node q = new Node(x); q.next= head; head = q: B. Node q = new Node(x); q.next= head; C. Node q = new Node(x); q.next= head; q = head: D. Node q = new Node(x); head.next = q; head = q;

A

Suppose we are implementing a stack of Integers using a singly linked list where the head of the list is treated as the top of the stack. Specify the correct implementation of push() method of the stack. (Choose the most suitable one) A. void push(integer x) { Node p = new Node(x); p.next = head; head=p; } B. void push(integer x) { Node p = new Node(x); p.next = null; head=p; } C. void push(Integer x) { Node p = new Node(x): p.next = head; } D. void push(Integer x) { Node p = new Node(x); p.next = head; head=p.next; }

E

Suppose you are using the LZW algorithm to encode the message AAABDACAADA contents of the dictionary at the beginning of encoding are: (1)A (2)B (3)C (4)D What are the first 4 code words when encoding the above string? A. (1) (5) (1) (4) B. (1) (5) (6) (4) C. (1) (5) (3) (2) D. (1) (1) (1) (2) E. (1) (5) (2) (4)

B

Suppose you are using the LZW algorithm to encode the message AABCADAB 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 (5)7 Answer A. AB B. AA C. ABC D. AAB

D

The complexity of heap sort is A. o(n) B. O(log n) C. O(n^2) D. O(nlog n)

D

The complexity of heap sort is Answer A. 0(log n) B. 0(n) C. O(r02) D. 0(nlog n)

A

The following is the main part of bubble sort pseudocode: do swapped := false for i := 0 to n-2 if a[i] > a[i+1] then swap(a[i],a[i+1]) swapped := true end if end for while wapped Consider the list of ten integers below: 7,4, 10, 11, 2, 9, 1, 3, 8, 6 What is the list after the FIRST iteration (for i = 0 to n-2) in a bubble sort? (sorting from smallest to largest). A. 4, 7, 10, 2, 9, 1, 3, 8, 6, 11 B. 4, 7, 10, 1, 2, 9, 3, 8, 6, 11 C. 4, 7, 10, 9, 2, 1, 3, 8, 6, 11 D. 4, 7, 10, 2, 9, 1, 3, 6, 8, 11

C

The operation for adding an entry to a stack is traditionally called: A. insert B. append C. push D. add

A

The operation for removing and returning the top element of the stack is traditionally called: A. pop B. peek C. remove D. delete

D

The operation of visiting each element in the list exactly once is known as A. Sorting B. Inserting C. Merging D. Traverse

A

To implement an AVL tree, a concept balance factor is introduced (bal = height(right)-height(left). Suppose an AVL tree is created by inserting to the tree the following keys sequentially: 6, 2, 7, 1, 3, 5 What is the balance factor of the node 6? (please note that the tree is still AVL) A. 0 B. -1 C. 1 D. 2

D

To implement an AVL tree, a concept balance factor is introduced (bal = height(right)-height(left). Suppose an AVL tree is created by inserting to the tree the following keys sequentially: 5,3,6,2,4,1 What is the balance factor of the node 4? (please note that the tree is still AVL) A. 0 B. 2 C. 1 D. -1

C

Using the Huffman code tree below. What is the result of decoding the string: 10000010011? A. ABCBD B. ABBDC C. ABBCD D. ABCDB

B

Using the Huffman code tree below. What is the result of decoding the string: 1100000001100 7 Answer A. AABBABAB B. AABBBCAB C. AABBBBBA D. CAABBBBA

A

What is th e minimum number of nodes in a full binary tree with height 3? fin a tree the height of root is 1. and in a full binary tree every node other than t le leaves has two children). A. 7 B. 5 C. 6 D. 4

D

What is the breadth-first traversal of a tree below after deleting the node 25 by merging? A. 40, 35, 15, 50, 45, 30 B. 15, 40, 35, 50, 45, 30 C. 40, 30, 15, 50, 35, 45 D. 40, 15, 50, 35, 45, 30

C

What is the breadth-first traversal of a tree below after deleting the node 5 by copying? A. 2.1.4, 3, 6, 7, 8 B. 2.1.4, 3, 7, 6, 8 C. 4.2, 7.1.3, 6, 8 D. 2.1.4, 3, 7, 8, 6

A

What is the breadth-first traversal of a tree below after deleting the node 5 by merging? A. 2.1.4. 3. 7. 6. 8 B. 4.2. 7.1.3. 6. 8 C. 2.1.4. 3. 6. 7. 8 D. 2.1.4. 3. 7. 8. 6

B

What is the minium number of nodes in a full binary tree with height 3? (In a tree the height of root is 1, and in a full binary tree every node other than the leaves has two children). A. 6 B. 7 C. 5 D. 4

B

What is the result of the breadth first traverse of the binary search tree T, after inserting the following keys into the tree sequentially (suppose T is emptybefore insertion): 16, 7, 3, 1, 12, 20, 17 A. 16, 7, 20, 3, 12, 1, 17 B. 16, 7, 20, 3, 12, 17, 1 C. 16, 7, 20, 3, 17, 12, 1 D. 16, 7, 20, 3, 17, 1, 12

A

What is the value of the Boundary Folding Hash Function if K = 45-35-79-8 and TSize = 100? A. 85 B. 80 C. 89 D. 87

C

What is the value of the Shift Folding Hash Function if K = 42-35-59 and TSize = 100? A. 39 B. 37 C. 36 D. 35

B

Which of the following applications may use a queue? A. Undo sequence in a text editor. B. Multi-programming. C. Keeping track of local variables at run time. D. Store all variables in a program.

C

You are given a singly linked list with at least 3 elements and p is a reference to a middle node (p is not the head nor the tail node). Select the statement about deleting the node p from the list that is most correct. A. We can find the node f before the node p and then deleting the node p by statement f.next = p.next, This solution has O(1) runtime. B. Deleting the node p always takes O(1) time. C. Deleting the node p always takes O(n) time. D. We can delete the node p by moving the data from the next node into the p node and then deleting the next node by statement p.next = p.next.next; This solution has O(1) runtime has O(1) runtime.

A

________________ is a connected graph without any simple circuit. A. Tree B. Pseudo graph C. Simple graph D. Kn

E

cycle. The following is an algorithm for finding Euler cycle from the vertex X using stack: * Answer declare a stack S of characters (a vertex is labeled by a character) declare an empty array E (which will contain Euler cycle) push the vertex X to S while(S is not empty) {ch = top element of the stack S if ch is isolated then remove it from the stack and put it to E else select the first vertex Y (by alphabet order), which is adjacent to ch.push Y to S and remove the edge (ch.Y) from the graph } the last array E obtained is an Euler cycle of the graph Suppose a multigraph G is given below (view picture). Which of the followings is the = Euler cycle from the vertex B. created by above algorithm? A. B.A.B.D.C.B B. B.C.D.A.B C. B.C.D.B.A.B D. B.A.C.D.B E. B.D.C.B.A.B


Conjuntos de estudio relacionados

Ch 9 Assessing the Risk of Material Misstatement

View Set

World History: Imperialism Test Review (from Kahoot)

View Set

Chapter 28: Care of Patients Requiring Oxygen Therapy or Tracheostomy

View Set

Chapter 01: Human Resource Management in Organizations: Aplia Assignment

View Set

Psyc Learning Curve: The Origins of Psychology

View Set