Docsity

Data Structures and Algorithms Test 3, Exams of Data Structures and Algorithms

Toggle sidebar
bg1
Data Structures and
Algorithms Test 2
______ can be used to enforce the walls of an ADT. - ANSencapsulation
-Algorithm A requires time proportional to n^2
-Algorithm B requires time proportional to nlog2n
A's time requirement increases at a slower rate than B's - ANSfalse
A _______________ of height h is full down to the level h-1, with level h filled in
from left to right - ANScomplete binary tree
a binary tree in which the left and right subtrees of any node have heights
that differ by at most 1 - ANSBalanced binary tree
a binary tree of height h that is full to level h - 1 and has level h filled in from
left to right - ANSComplete binary tree
a binary tree of height h with no missing nodes; all leaves are at level h and
all other nodes each have two children - ANSFull binary tree
a binary tree where the value in any node n is greater than the value in
every node in n's left subtree, but less than the value of every node in n's
right subtree - ANSBinary search (ordered) tree - BST
a binary tree with no nodes - ANSEmpty binary tree
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download Data Structures and Algorithms Test 3 and more Exams Data Structures and Algorithms in PDF only on Docsity!

Data Structures and

Algorithms Test 2

______ can be used to enforce the walls of an ADT. - ANSencapsulation -Algorithm A requires time proportional to n^ -Algorithm B requires time proportional to nlog2n A's time requirement increases at a slower rate than B's - ANSfalse A _______________ of height h is full down to the level h-1, with level h filled in from left to right - ANScomplete binary tree a binary tree in which the left and right subtrees of any node have heights that differ by at most 1 - ANSBalanced binary tree a binary tree of height h that is full to level h - 1 and has level h filled in from left to right - ANSComplete binary tree a binary tree of height h with no missing nodes; all leaves are at level h and all other nodes each have two children - ANSFull binary tree a binary tree where the value in any node n is greater than the value in every node in n's left subtree, but less than the value of every node in n's right subtree - ANSBinary search (ordered) tree - BST a binary tree with no nodes - ANSEmpty binary tree

a bubble sort requires at most how many passes to sort an array of n items?

  • ANSn- A client application can use the operations of an ADT without knowing how the ADT is implemented. - ANStrue a comparison of algorithms should focus on significant differences, not reductions in computing costs based on clever coding tricks - ANStrue A full binary tree of height h>= 0 has ____ nodes - ANS2^h- A full binary tree with height 4 has _____ nodes - ANS A heap in which the root contains the item with the largest search key is called a _____ - ANSmaxheap A heap in which the root contains the item with the largest search key is called a - ANSmaxheap a heap is a - ANScomplete binary tree A heap is a - ANScomplete binary tree a merge sort is used to sort an array of 1000 values in ascending order. which of the following statements is true? - ANSThe sort is the same, no matter what the order of the original elements

A reference variable contains the location of an object in memory. - ANStrue A reference-based implementation of the ADT list does not shift items during insertion or deletion. - ANStrue a reference-based stack makes more efficient use of memory - ANStrue a set of nodes that is either empty or partitioned into a root node and one or two subsets that are binary subtrees of the root; each node has at most two children, the left child and the right child - ANSbinary tree a set of one or more nodes, partitioned into a root node and subsets that are general subtrees of the root - ANSgeneral tree a stack is an instance - ANStrue A subtree of node n is a subtree rooted at___ - ANSa child of node n a tree that consists of a child (if any) of n and all the child's descendants - ANSsubtree of node n A variant of linked list in which last node of the list points to the first node of the list is? - ANSCircularly linked list According the following statements: -Algorithm A requires time propoertional to n^ -Algorithm B requires time propertional to nlog2n

Algorithm A's time requirements increase at a slower rate than algorithm B's time requirement - ANSfalse advantage of heapsort over mergesort - ANSheapsort does not require a second array an algorithm's execution time is related to the number of ____ it requires - ANSoperations An array-based implementation of an ADT list: - ANSrequires less memory to store a data element than a reference-based implementation. another name for selection sort - ANSbrute-force algorithm applications of stack - ANSchecking balanced expressions, recognizing palindromes, evaluation algebraic expressions average case quick sort - ANSO(nlog2n) before dequeue, always determine if the queue is empty - ANStrue best case of quick sort - ANSO(nlog2n) bottom - ANSend of stack where things are not removed or inserted bubble sort avg case - ANSO(n^2) bubble sort best case - ANSO(n)

public static int value( int x, int n ) { if ( n > 0 ) return x * value( x, n - 1 ); else return 1; } - ANS Consider the following Java program. What is output by the program? public static void main( void ) { int a, b, result; a = 3; b = 4; result = value( a, b ); System.out.printf("%d\n",result); } public static int value( int x, int n ) { if ( n > 0 ) return x * value( x, n - 1 ); else return 1; } - ANS Data structures are part of an ADT's - ANSimplementation

def of infix expressions - ANSoperator appears between operands def of postfix expressions - ANSoperator appears after its operands def of prefix expressions - ANSoperator appears before its operands deleting an item from a one-element referenced based queue is a special case: code is: - ANSlastNode-null; deletion avg and worst case - ANSO(logn), O(n) each node in a binary tree has - ANSat most two childer each node in a general tree has - ANSat most one parent Each node in a linear linked list references both its predecessor and its successor. - ANSfalse each pass of merges sort requires ____ comparisons - ANSn element x[i]'s children - ANSx[2i+1], x[21+2] element x[i]'s parent - ANSx[i/2] if i odd, x[i/2-1] if i even For a given anArray = <2, 3, 5, 6, 9, 13, 16, 19>, if you are asked to search a target value 6 using a recursive binary search algorithm, what should be returned? - ANS

heapsort worst case - ANSn*logn how many external referenced are necessary when implementing a queue using a circularly linked list? - ANS if 5 items are added to a queue, the first item removed from the queue is the first item added to it - ANStrue If a stack is used by an algorithm to check for balanced braces, which of the following it true once the end of the string is reached? - ANSthe stack is empty In ______ recursion, there can be multiple activations of the same method existing at the same time. - ANSIndirect in _______, the left and right subtrees of any node has heights that differ by at most 1 - ANSbalanced binary tree in a _____ of height h, all nodes that are at a level less than h have two children each - ANSfull binary tree in a binary tree, the left (or right) child (if any) of node n plus its descendants

  • ANSleft (or right) subtree of node n In a linear linked list: - ANSthe next reference of the last node has the value null. In a maxheap, the root contains a search key greater than or equal to the search key in each of its children - ANStrue

In a maxheap, the root contains a search key greater than or equal to the search key in each of its children - ANStrue In a recursive method that checks if a given string is palindrome, the base case(s) should be ______. - ANSa string with length of zero and one in a reference-based implementation of a stack, it is necessary to call the isFull() method before invoking the push method - ANSfalse in a tree, the children of the same parent are called - ANSsiblings in an array based representaiton of a complete binary tree (presuming subscripting beginning at 0), which of the following represents the parent of node tree[i]? - ANStree[(i-1)] in an array based representation of a complete binary tree (presuming subscripting beginning at 0), which of the following represents the right child of noe tree[i]? - ANStree[2*i+2] in an array-based implementation of a heap, the heapDelete operation is ______ - ANSO(logn) in an array-based implementation of a heap, the heapDelete operation is - ANSO(logn) in an array-based implementation of a heap, the heapInsert operation is _____ - ANSO(logn) in an array-based implementation of a heap, the heapInsert operation is - ANSO(logn)

insertion avg, best, worst case - ANSO(n^2), O(n), O(n^2) insertion sort avg case - ANSO(n^2) insertion sort best case - ANSO(n) Insertion sort worst case - ANSn^ int[] array = {22,13,23,15,19,16,26,18}; bubble sort algorithm how many comparisons would be made in order to arrange the data into ascending order if we use the basic version bubble sort algorith? - ANS int[] array = {22,18,23,16,19,26,15,13}; sorted using selection sort. what would be the arrangement after the fourth pass through the array? - ANS13 15 16 18 19 26 23 22 Is access to other items in the stack allowed? - ANSno items from the front of the queue use an operation called ____ - ANSdequeue low-order terms can be ignored in an algorithm's growth-rate function - ANStrue Mergesort avg case - ANSnlogn Mergesort worst case - ANSnlogn

method to retrieve from the stack the item that was added most recently, but does not remove - ANSpeek nodes with a single common parent (i.e. direct ancestor) - ANSsiblings operations on a queue can be carried out at ___ - ANSboth it's front and back operations on a queue can be carried out at ________ - ANSboth its front and back Postorder traversal - ANSLRN prefix and postfix expressions don't need order of operations - ANStrue preorder traversal - ANSNLR queues are first-in, first-out data structures - ANStrue quick sort is usually extremely fast in practice - ANStrue quicksort worst case - ANSn^ radix sort avg case - ANSn radix sort is comparison base - ANSfalse

correctly), but no other methods have been defined in the implementation of the Circle class. What will happen when we try to execute this code? Circle c1 = new Circle(12.0); Circle c2 = new Circle(12.0); boolean same = (c1.equals(c2)); - ANSThe value of same will be false. suppose that a selection sort of n items requires n^2/2+5*n/2-3 basic operations -- the selection sort is - ANSn^ suppose that the following list: 469 681 532 94 353 760 was input to the radix sort algorithm. What would the arrangement of the list after the second pass of the algorithm? - ANS532 353 760 479 681 94 Suppose that we have an ordered array of 980 entries. How many elements would need to be moved/shifted if it was determined that an element was to be inserted at position 401? - ANS Syntax errors of a program are removed during the coding phase of the software life cycle. - ANStrue the _____ compares adjacent items and exchanges them if they are out of order - ANSbubble sort the _____ method of the ADT stack removes the element at the top of the stack - ANSpop The binary search algorithm can be applied to an unsorted array. - ANSfalse the binary search algorithm is a quadratic algorithm - ANSfalse

the efficiency of the selection sort depends on the initial arrangement of the data - ANSfalse the enqueue operation throw QueueException whenit tries to - ANSadd an item to an array-based implementation of a queue that is already full the heapsort is _____ in the worst case - ANSO(nlogn) the heapsort is ______ in the worst case - ANSO(nlogn) the max number of nodes that a binary tree of height h can have is_____ - ANS2^h- the maximum height of a binary tree of n nodes is - ANSn/ the maximum number of comparisons for a retrieval operation in a binary search tree is the - ANSheight of the tree the mergesort is a recursive sorting algorithm - ANStrue the mergesort is more efficient than the heapsort in the worst case - ANSfalse the mergesort is more efficient than the heapsort in the worst case - ANSfalse the minimum height of a binary tree of n nodes is - ANSlog2(n+1) the minimum height of a binary tree with n nodes is _____ - ANS[log2(n+1)]

to sort a list of data items, the basic operation is - ANScomparison top - ANSthe end of the stack where items are removed or inserted Traversal avg and worst case - ANSO(n), O(n) What best describes the purpose of this code snippet: for (Node curr = head; curr != null; curr = curr.next) { // code goes in here } - ANSTraversing a linked list what is NOT an ADT operation - ANSpush What is the effect of the following recursive Java method, assuming that X and Y are positive integers? public static int Mystery (int X, int Y) { if (X == 0) return Y; else return 1 + Mystery(X - 1, Y); } - ANSIt computes and returns X + Y. What is the value of the prefix expression: -*38+65 - ANS13`

what should algorithm analysis be independent of? - ANSdata, specific implementation, computers When a linked list is empty, the value of the head reference is null. - ANStrue when assessing the efficiency of a factorial program, which of the following operations would you focus on? - ANSmultiplication when implementing a queue using a reference-based approach, the operation dequeueAll is not needed. - ANSfalse when implementing a queue using an array-based approach, it is not necessary to determine if the queue is full before adding a new item to the queue - ANSfalse When implementing a queue using reference-based, the operation isFull() is not needed - ANStrue when implementing a queue, a naive approach is more efficient in terms of memory when compared to a circular array approach - ANSfalse when implementing a stack as a linked-list, you must make sure the stack isn't full before inserting an item - ANSfalse when infix expressions are converted to postfix expressions, the operands always stay in the same order with respect to one another - ANStrue