CSD201 p1,2,3,4

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

a

U04 - Q018 The operation for adding an entry to a queue is traditionally called: A.enqueue B.append C.insert D.add

a

U04 - Q028 In the array implementation of the queue, which operations require constant time? A.All of the others. B.enqueue C.isEmpty D.dequeue

d

Which of the following applications may use a stack? A.A parentheses balancing program. B.Keeping track of local variables at run time. C.Syntax analyzer for a compiler. D.All of the others.

d

With respect to recursion, select correct statement. a. Any iterative program may be written recursively. b. Every recursive method may be converted into an iterative version. c. Quicksort and mergesort are recursive in nature. d. All of the others.

ad

(Choice 2) When converting a method from a recursive version into an iterative version, a. Program clarity can be diminished. b. The brevity of program formulation is not be lost c. The program always runs slower. d. The brevity of program formulation lost. However, the brevity may not be an issue in Java.

ac

(Choice 2) Which of the following about stack are true: A.Operations of stack are based on Last in First out structure. B.A stack can be accessed at two ends for storing and retrieving data. C.The most top element is the latest added element. D. The operation pop takes the most bottom element in stack

bc

(Choice 2) Which of the following statement about the Binary Tree is true a. Binary Trees can be implemented as linked lists. b. Binary Trees can be implemented as arrays c. The search process of Binary Search Tree takes O( n ) time in the worst case. d. On the average, The search process of Binary Search Tree always takes O( n ) time

ac

(Choice 2) Which of the following statement about the Tree Traversal is false a. Tree traversal is the process of visiting each node in the tree some times. b. Tree traversal process can not be implemented without using stack. c. Postorder tree traversal can be only implemented in recursion. d. Tree traversal can be implemented in queue

bc

(Choice 2) Which of the following statements are false: a. The data area allocated for a method in stack is called an activation record or stack frame. b. An activation record still exists after a method owning it ends c. An activation record contains code of method owning it d. The sate of each method, including main(), is characterized by the contents of all automatic variables, the values of the method's parameters and the return address.

bc

(Choice 2) Which of the following statements are true: a. Global variables must be stored in activation record. b. The recursive version increases program readability, improves self-documentation and simplifies coding. c. The return address is address of the caller's instruction immediately following the call. d. In the most cases, the code of nonrecursive implementation is shorter than it is in the recursive implementation.

ac

(Choose 2 :) Select correct statement(s) about Doubly Linked List: A. Deleting a node at the end of the list takes constant time O( 1 ). B. Inserting a new node at the end of the list requires O( n ) steps. C. The node which is deleted from the list will be claimed by the garbage collector. D. Methods for processing doubly linked list are simpler than those of singly linked list.

bc

(Choose 2) In the circular array version of the Queue class, which operations require O(n) linear time for their worst-case behavior A. dequeue() B. enqueue() when the capacity has been reached C. clear() D. firstEl()

cd

(Choose 2) Select correct statement(s): A. A linked list is a collection of nodes storing data and links to other nodes B. A linked structure is a data structure composed of nodes, each node holding some information and a reference to another node in the list. C. A singly linked list is a node that has a link only to its successor in this sequence D. Inserting a new node at the end of the singly linked list without tail field requires O( n ) steps.

ac

(Choose 2) Which of the following statements about the Stack are true A. Popping operation in the linked list implementation is executed in the constant time O(1) B. Clear operation in the linked list implementation is executed in the constant time O(1) C. Popping operation in the array implementation is executed in the constant time O(1) D. Pushing operation in the linked list implementation is always executed in the constant time O(1)

cd

(Choose 2:) Which of the following operations take O( 1)time: A. Deleting one any node in linked list B. Inserting one node to the end of singly linked list without tail. C. Deleting one node from the begin of doubly linked list D. Searching one node in singly linked list without tail in the best case.

ace

(Choose 3 :) Which of sentences about singly linked list are true: A. Deleting a node at the beginning of the list takes constant time `O ( 1 )`. B. Deleting last node of the list always takes `O ( lgn )` time. C. On the average, delete operation executes O ( n ) steps. D. Search operation takes O ( n ) time in the best case. E. There is no immediate access to the predecessor of any node in list.

abe

(Choose 3) Select correct statement: A. Breath-First traversal is implemented using queue. B. For a binary tree with n nodes, there are n! different traversals. C. The complexity of searching a node is the length of the path leading to this node. D. A search can takes lg ( n ) time units in the worst case. E. The complexity of searching depends on the shape of the tree and the position of the node in the tree.

cde

(Choose 3) Select incorrect statement: A. There are six possible ordered depth-first traversals. B. Depth-first traversal can be implemented using stack. C. Depth-first traversal can not be implemented if not using stack. D. A recursive implementation of preorder tree traversal uses stack explicitly. E. Morris's algorithm does not temporarily change tree structure.

cde

(Choose 3) Which of the following concepts of tree are true: A. Each node can be reachable from the root through some paths. B. Path is number of arcs. C. The level of a node is the length of the path from the root to the node plus 1. D. The height of a nonempty tree is the maximum level of a node in the tree. E. The level of a node must be between 1 and height of the tree.

bce

(Choose 3) Which of the following methods of queue are true: A. push(el) — Put the element el on the top of the queue. B. isEmpty() — Check to see if the queue is empty. C. enqueue(el) — Put the element el at the end of the queue. D. dequeue() — Take the last element from the queue. E. firstEl() — Return the first element in the queue without removing it. F. lastEl() — Return the last element in the queue without removing it.

ab

(choose 2) Select true statements about stack) A. Stack can be implemented by linked list. B.The Java implementation of the stack is potentially fatal. C. peek () method removes the top element of the stack and return it. D.pop () method returns copy of the top element in the stack.

ab

(choose 2) When a method call is executed, which information is not saved in the activation record? A.Current depth of recursion B.Instances of classes. C.Location where the method should return when done D. Local variables

ab

(choose 2) Which of the following can be executed in constant time O ( n ) A.when deleting a node of a singly linked list in the worst case. B.when deleting a node of a singly linked list in the average case. C.when searching is executed in a skip list in the ideal situation. D.when insertion sort is executed in the worst case.

adf

(choose 3) Which of the following statements are true: A. Polish notation eliminates all parentheses from formulas. B. Preorder, inorder and postorder tree traversal generate unambiguous outputs. C. Polish notation is only applied for compilers. D. Using Polish notation, all expressions have to be broken down unambiguous into separate operations and put into their proper order. E. In a expression tree, leaves are operators and nonterminal nodes are operands. F. Expression trees do not use parentheses.

c

A balanced binary search tree containing one million nodes. What is the maximum number of comparisons needed to find a key in the tree? A. 10 B. 15 C. 20 D. 30

a

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. A. A B E F D C G H I J B. D B E F C A I H G J C. B A C D F E H I G J D. Inadequate conditions for the construction of the tree.

c

A heap implemetation is an excellent demonstration for a ....... A. stack B. queue C. priority queue D. tree

a

A properties of queue is ___________ can be accessed at once. A.Only one item B.Multiple-items C.Two items D.None of the others.

b

A property of a stack is _________ can be accessed at once. A.Multiple-items B.Only one item C.Two items D.None of the others.

a

A queue is implemented using a doubly linked list, which of the following operations require O( n) time? A.clear (remove all elements from the queue). B.enqueue C.dequeue D.None of the others

a

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

c

Consider algorithm of the 8-queen problem: 1 Which of the following statements is true: a. The algorithm ends after finding one solution. b. The algorithm does not find symmetric solutions. c. The algorithm finds all solutions. d. None of the others.

d

Consider the following algorithm: 1 What is maximum number of activation records (including its caller) in runtime stack when calling TriangularNumber(10) A.9 B.13 C.7 D.11

b

Consider the following alogorithm: 1 What is output when calling TriangularNumber(4) A.15 B.10 C.6 D.20

c

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

c

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

a

Consider the following function: 1 Which call will result in the most recursive calls? a. fun(-1012); b. fun(100); c. fun(0); d. fun(1012);

d

Consider the following pseudocode: 1 A.(1) B.(2) C.(3) D.(4)

a

Consider the following pseudocode: 1 What is written to the screen for the input"Good\\Morn\\in\\\g"? A. gMoG B. gMoo C. GoMg D. gMor

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 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" ? A.owAreYouT B.HowAreYo C.HowAreYou D.wAreYouTo

c

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 and write the popped character to the screen else push the character into the stack } What is written to the screen for the input " Go \\odMorn \\ in\\\g" ? A.oGnrnid B.oGnrniM C.oGnrnio D.oGnrndo

a

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. Base cases b. Steps c. Limit conditions d. Conditions

a

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

a

If the values of A, B, C and D are 2, 3, 4, and 5, respectively , manually calculate the value of the following postfix expression: A B C + * D - A. 9 B. 7 C. 6 D. 8

b

In a real computer, what will happen if you make a recursive call without making the problem smaller? a. The program keeps running until you press Ctrl-C b. The run-time stack overflows, halting the program c. The operating system detects the infinite recursion because of the "repeated state" d. The results are nondeterministic

d

In a single method implementation, how many recursive calls can be used? a. 1 b. 2 c. n (where n is the argument of the method). d. There is no fixed maximum number.

b

In all cases, nonrecursive implementation is faster recursive implementation. a. True b. False

a

In the array implementation of queue, enqueuing can be executed in constant time O(1) A.True B.False

d

In the array version of the Queue, which operations require O(n) time for their worst-case behavior? A.dequeue B.insert when the queue is not full. C.isEmpty D.None of the others

e

In the array version of the Stack class, which operation requires linear time for their worst case? A.is-empty B.topEl C.Pop D.push when the array is not yet full. E.None of the others.

b

In the doubly linked list implementation of queue, enqueuing can be executed in constant time O( n). A. True B.False

d

In the linked-list version of the Queue, which operations require linear time for their worst-case behavior? A.dequeue B.insert C.isEmpty D.None of the others

c

In the linked-list version of the Stack class, which operation requires linear time for the worst case? Assume that addtoTail, deletefromTail are used. A.is-empty B.topEl C.Pop D.Push E.None of the others.

a

Let's look at the recursive algorithm that generates Fibonacci numbers. This algorithm belongs to type recursive algorithm ... a. excessive b. tail c. non-tail d. indirect

a

Linked lists allow easy insertion and deletion of information because such operations have a local impact on the list. A. True B. False

a

What is the complexity of inserting a node in a perfectly balanced tree for worst case? A. O(lgn) B. O(nlgn) C. O( n ) D. None of the others.

a

Recursive definitions on most computers are eventually implemented using a run-time stack and this implementation is done by the operating system. a. True b. False

a

Select an incorrect statement. a. Recursion is always more efficient than loops. b. Recursion can make the conceptual design of an algorithm's implementation easier. c. Recursion, gone wrong, can lead to an overflow stack error.

d

Select false statement: A.Stack is applied to Java Virtual Machine. B. Stack can be implemented using linked list. C.In the array list, popping is executed in constant time O ( 1 ) . D.In the array list, poping is executed in O (lgn) to the worst case

a

Select incorrect statement about Recursion: a. The anchor or ground case allows for the construction of new objects out of basic elements or objects that have already been constructed b. Recursive definitions serve generating new elements and testing whether an element belongs to a set c. Recursive definitions are frequently used to define functions and sequences of numbers d. None of above

a

Select the best choice. A stack can be implemented using ..... a. All of the others. b. An array c. A singly linked list d. A double linked list d. A circular linked list

a

The Horner's method is used to calculate the sum of the first n powers of a base b: sum(b, n) = 1 + b **(1 + b *** (1 + b**(1 + ... + b))) The similar recursive expression is ... a. 1 + b * sum(b, n - 1) b. 1 + sum(b, n - 1) c. (1 + b) * sum(b, n - 1) d. sum(1 + b, n - 1)

c

Select the one TRUE statement. A. Every binary tree is either balanced or perfect balanced. B. Every balanced binary tree is also a perfect balanced binary tree. C. Every perfect balanced binary tree is also a balanced binary tree. D. No binary tree is both balanced and perfect balanced.

a

Select the statement that is most correct. Which of the following applications may use a stack? A.Evaluating arithmetic expressions. B.Store all variables in a program. C.Store a waiting list of printing jobs. D.Multi-programming.

a

Select the statement that is most correct. Which of the following applications may use a stack? A.Evaluating arithmetic expressions. B.Store all variables in a program. C.Store a waiting list of printing jobs. D.Multi-programming.

d

Select the statement that is the most correct . a. There is no difference between a recursive method and a non-recursive method. 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. 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

Select the statement that is the most correct. Which of the following applications may use a stack? A.Store all variables in a program. B.Auxiliary data structure for algorithms. C.Store a waiting list of printing jobs. D.Multi-programming.

a

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

b

State True or False:"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." A. True B. False

d

Study the following statements: (1) A drawback of a balanced tree is the search-time may be out of control. (2) The DSW algorithm can be used to rebalance a binary tree. (3) An AVL tree is one in which the height of the left and the right subtrees of the every node must be same. The statement (1) is ....., the statement (2) is ...... and the statement (3) is ...... A. True, true, true B. False, false, false C. True, false, true D. False, true, false

b

Suppose temp refers to a node in a linked list (using the SLLNode class with instance variables called info and next). What boolean expression will be true when temp refers to the tail node of the list? A. (temp == null) B. (temp.next == null) C. (temp.info == null) D. None of the others.

d

Suppose that the variable temp refers to a node in a linked list (using the SLLNode class with instance variables called info and next). What statement changes temp so that it refers to the next node? A. temp ++; B. temp = next ; C. temp += next D. temp = temp . next ;

d

Suppose the f( n ) function is defined on the set of integer numbers as below. What is the value of f(-5)? 1 a. 18 b. 10 c. 15 d. 3

d

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

d

The problem of printing a string in reverse order can be implemented using ________ a. Recursion. b. Iteration. c. Stack. d. All of the others

a

The top-down method of J. Williams is used to organize the following array as a heap. 4 10 8 3 12 17 5 14 13 Show the contents of the array after we applied this algorithm. A. 17 14 12 13 4 8 5 3 10 B. 17 14 8 13 12 4 5 3 10 C. 17 8 14 5 4 12 13 10 3 D. 17 8 14 12 13 4 5 3 10

a

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

a

To delete a node in a binary search tree that has two children, the deletion by merging method requires to find what node? A. The rightmost node of the left subtree of the deleted node. B. The smallest sibling node. C. The parent node. D. None of the others.

c

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, 4, 7, 3, 5, 2 What is the balance factor of the node 4? (please note that the tree is still AVL) A. 1 B. -1 C. 0 D. 2

b

Tree balancing can be performed locally after an element is inserted into or deleted from the tree using __________ A. The DSW algorithm. B. AVL tree. C. Creating a binary search tree from an ordered array. D. None of the others

a

U04 - Q032 Suppose we are implementing a stack 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(Object x) { Node p = new Node(x); p.next = head; head=p; } B. void push(Object x) { Node p = new Node(x); p.next = head; } C. void push(Object x) { Node p = new Node(x); p.next = null; head=p; } D. void push(Object x) { Node p = new Node(x); p.next = head; head=p.next; }

a

U06 - Q.009 - M ......... will visit nodes of a tree starting from the highest (or lowest) level and moving down (or up) level by level and at a level, it visits nodes from left to right (or from right to left). A. Breath-First Traversal B. Depth-First Traversal C. Stackless Depth-First Traversal D. None of the others

c

U06 - Q.022 - M The DSW algorithm uses ________ A. Right rotation. B. Left rotation. C. All of the others.

a

What graph traversal algorithm uses a queue to keep track of vertices which need to be processed? A. Breadth-first search. B. Depth-first search. C. All of the others D. None of the others.

a

What is the number of comparisons and swaps in the best case for creating a heap using top down method (William's method)? A. The number of comparisons is n - 1 and swaps is zero. B. The number of comparisons is n and swaps is zero. C. The number of comparisons is 2.[n/2] and swaps is zero. D. The number of comparisons is lgn and swaps is zero.

a

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 empty before insertion): 6, 7, 3, 1, 2, 5, 8 A. 6, 3, 7, 1, 5, 8, 2 B. 6, 3, 7, 1, 5, 2, 8 C. 6, 3, 1, 2, 5, 7, 8 D. 6, 3, 7, 1, 2, 5, 8

a

When a method call is executed, which information does its activation record contain? a. None of the others. b. Code of the method. c. Current depth of recursion. d. Name of the method. e. Global variables.

c

When a method call is executed, which information is not saved in the activation record? a. Local variables of the calling method. b. Location where the method should return when done. c. Current depth of recursion. d. Values for all parameters are transferred to the called method.

a

When representing any algebraic expression E which uses only binary operations in a 2-tree (every node other than the leaves has two children), A. the variable in E will appear as external nodes (leaves) and operations in internal nodes. B. the operations in E will appear as external nodes (leaves) and variables in internal nodes. C. the variables and operations in E will appear only in internal nodes. D. the variables and operations in E will appear only in external nodes.

a

Which of the following problems may use stacks implicitly or explicitly? A.All of the others B.Traverse a Binary tree using Depth First Search. C.Eight-queen problem. D.Evaluate a prefix expression..

a

Which of the following problems may use the recursion technique? a. All of the others. b. Maze problems. c. Detect a cycle in a graph. d. Perform symbolic differentiation.

d

Which of the following statement about the Graph is true A. If an adjacency matrix is used, the complexity of DFS can be `O(|V^2|)` , where |V| is number of vertices of graph. B. The complexity of Dijkstra's algorithm is O( |E| + | V| )lg |V| if heap is used. C. All of the others D. None of the others

d

Which of the following statement about the Recursion is true A. Tail recursion is characterized by the use of only one recursive call at the very end of a method implementation. B.The backtracking technique uses recursion C.The recursive version increases program readability, improves self-documentation, and simplifies coding. D. All of the others

a

Which of the following statements is false? A. If every proper subtree of a binary tree is full, then the tree itself must also be full. B. If all of its leaves are at the same level, then the binary tree is full. C. If the binary tree has n nodes and height h, then h >=|lg n| D. A binary tree cannot have more than 2d nodes at depth d.

a

Which of the following statements is false? A. The postorder traversal always visits the right-most node first. B. The preorder traversals always visit the root first. C. The postorder traversal always visits the root last. D. The top-down level order traversals always visit the root first.

a

Which of the following strategies fit to Binary Search trees that only have some elements constantly accessed? A. Use Self-Restructuring tree. B. Use the AVL tree. C. Use the DSW algorithm D. All of the others.

c

With respect to recursion, select correct statement. (1) Recursive version executes slower than iterative version. (2) Iterative version executes slower than recursive version. (3) Recursive version needs more memory than iterative version (4) Iterative version needs more memory than recursive version Statements ..... and ...... are true. a. 1,4 b. 2,3 c. None of the other

d

With respect to the execution of recursive function (method), ....... a. The run-time stack contains an information that marks that this is a recursive call. b. All parameters will be shared in all running activation records of the called methods. c. The run-time stack does not contain dynamic link to caller's activation record. d. None of the others


Kaugnay na mga set ng pag-aaral

Chapter 11: Patient Assessment - Custom Quiz

View Set

Sensation and Perception (Module 17)

View Set

Fotosíntesis y respiración celular

View Set

Clothing Concepts exam #1 MASTER SET

View Set

Essentials of Accounting MidTerm Study

View Set