CS 3303 Data Structures Study

Ace your homework & exams now with Quizwiz!

A list is

Finite ordered sequence of data items

The freelist ...

Holds the list nodes that are no longer in use.

An exchange sort is one where:

Adjacent records in the list and compared and exchanged

Select the answer that best defines Huffman Coding:

An approach of assigning codes to characters such that the frequency length of the code depends upon the relative frequency of the corresponding character in use

In a queue, placing new items in the queue is referred to as a push and taking an item out of the queue is called a pop.

False

Inserting or removing an item at position n-1 within a linked list has the same cost in terms Θ ( n ) time as the same operation in an array based implementation of a list.

False

Recursion is when an algorithm uses a series of loop structures to repeat an operation until the answer has been computed.

False

The benefit of a quicksort is that it provides excellent performance in both the average and worst case:

False

The process of associating a key with the location of a corresponding data record is called folding.

False

The quicksort is typically slower than the heapsort by a constant factor.

False

True/False: There is always one most efficient algorithm to solve a particular problem.

False

The implementation of a data type as a data structure is the physical form of an ADT.

True

The list of children approach uses both pointers and an array structure to represent the tree.

True

The most significant difference between the B+-Tree and the BST is that the B+-Tree stores records only at the leaf nodes.

True

The process for visiting all of the nodes of a binary tree in some order is called a traversal.

True

True/False: Big Theta (Θ) indicates that the Upper and Lower bounds of an algorithm are the same.

True

True/False: The stack data structure is implemented as a LIFO structure (last in first out)

True

The process of determining if two objects are in the same set and then merging those sets is called:

Union / Find

A binary tree traversal that lists every node in the tree exactly once is called:

An enumeration

The upper bound for the growth of the Algorithms running time is represented by:

Big Oh (O)

When big-Oh and big-Omega coincide, we indicate this by using (select the best answer): 1. Big Oh (O) 2. Big Omega (Ω) 3. Big Theta (Θ) 4. Exponential growth

Choice 3

For the following code fragment, select the choice which represents the most appropriate asymptotic analysis: function ( n ) { sum2 = 0; for (i=1; i<=n; i++) for (j=1; j<=i; j++) sum2++; } } Choice 1. Ω ( 1 ) Choice 2. O( 2n ) Choice 3. Θ( n2 ) Choice 4. Ω( n2 ) (NOTE: code fragment is not intended to be functioning code)

Choice 3. Θ( n2 )

Which of the following is NOT true for Linked Lists structures (please select the best choice): Choice 1. Insertion and deletion are Q( 1 ). Choice 2. Direct access of an item in the list structure is Q( n ). Choice 3. Space grows with number of elements. Choice 4. There is no overhead associated with elements in the list structure

Choice 4

For the following code fragment, select the choice which represents the most appropriate asymptotic analysis: public E getValue ( ) { assert (curr >= 0) && (curr < listSize) : "No current element"; return listArray[curr]; } Choice 1. Θ ( n ) Choice 2. O( 2n ) Choice 3. Θ( n log n ) Choice 4. O( 1 ) (NOTE: code fragment is not intended to be functioning code)

Choice 4. O( 1 )

For the following code fragment, select the choice which represents the most appropriate asymptotic analysis: static int function ( n ) { sum = 0; for (i=1; i<=n; i++) sum += n; return sum; } Choice 1. Ω( n2 ) Choice 2. Θ ( n2 ) Choice 3. O( log n ) Choice 4. O( n ) (NOTE: code fragment is not intended to be functioning code)

Choice 4. O( n )

A traversal that visits the left subtree, then the node, and then the right subtree is called:

Inorder Traversal

For the following code fragment, select the option that represents the most appropriate asymptotic analysis: if (a.length > 0) { return a[a.length - 1]; } else { throw new NoSuchElementException(); }

O( 1 ) Explanation: Here n = a.length, and T(n) = 1.

For the following code fragment, select the option that represents the most appropriate asymptotic analysis: for (int i = 0; i < a.length; i++) { System.out.println(a[i]); }

O( n )

The best asymptotic analysis for the selection sort is represented by (select the best option): Option 1. O( n log n ) Option 2. Ω( n^2 ) Option 3. O( n^2 ) Option 4.Θ( n^2)

Option 4

In a stack which option would access the 3rd element from the top of the stack S

S.pop(); S.pop(); S.pop();

According to textbook by Shaffer, a heap data structure has two properties which are:

it is a complete binary tree and the values stored in it are partially ordered

A tree data structure whose shape obeys the following definition, o A node contains one or two keys o Every internal node has either 2 children if it contains 1 key or 3 children if it contains two keys o All leaves are at the same level in the tree Is called a/an:

2-3 tree

The depth of node H in the following tree is: A B C D E F G H I

3

A compound computed search that combines a binary search to get close to the required record and then uses sequential search to find the item is referred to as a/an:

A Dictionary search

A list that organizes the order of records within the list based upon patterns of actual record access is called a/an (select the best answer):

A Self-organizing list

A sort algorithm that uses two nested loops with the inner loop moving through the array from bottom to top is called the:

Bubble sort

A sorting algorithm that assigns records to bins and then relies on some other sorting technique to sort the records within each bin called:

Bucket sort

Which of the following is not one of the general approaches to search algorithms:

Buffer cache access methods

The process of storing blocks of data in main memory after reading from disk is referred to as:

Buffering

For the following code fragment, select the choice which represents the most appropriate asymptotic analysis: function ( n ) { sum1 = 0; for (i=1; i<=n; i++) for (j=1; j<=n; j++) sum1++; } Choice 1. Θ ( n^2 ) Choice 2. O( 2^n ) Choice 3. Θ( n log n ) Choice 4. Ω( log n^2 ) (NOTE: code fragment is not intended to be functioning code)

Choice 1

For the following code fragment, select the option which represents the most appropriate asymptotic analysis: /** @return Position of largest value in "A" */ static int largest(int[] A) { int currlarge = 0; // Position of largest for (int i=1; i<A.length; i++) if (A[currlarge] < A[i]) currlarge = i; // Remember pos return currlarge; // Return largest pos } Choice 1. Θ ( n ) Choice 2. O( 2^n ) Choice 3. Θ( n log n ) Choice 4. Ω( n^2 ) (NOTE: code fragment is not intended to be functioning code)

Choice 1

For the following code fragment, select the choice which represents the most appropriate asymptotic analysis: function ( n ) { sum2 = 0; for (k=1; k<=n; k*=2) for (j=1; j<=k; j++) sum2++; } Choice 1. O( 2^n ) Choice 2. Θ ( n ) Choice 3. Θ( n log n ) Choice 4. Ω( n^2 ) (NOTE: code fragment is not intended to be functioning code)

Choice 2

The lower bound for the growth of the Algorithms running time is represented by (please the best answer): 1. Big Oh (O) 2. Big Omega (Ω) 3. Big Theta (Θ) 4. Exponential growth

Choice 2

For the following code fragment, select the option which represents the most appropriate asymptotic analysis: static int function ( n ) { sum = 0; for (i=1; i<=n; i++) sum += n; return sum; } Option 1. Ω( n^2 ) Option 2. Θ ( n ) Option 3. O( log n ) Option 4. O( 2^n ) (NOTE: code fragment is not intended to be functioning code)

Choice 2. Θ ( n )

For the following code fragment, select the choice which represents the most appropriate asymptotic analysis: /** @return The position of an element in sorted array A with value k. If k is not in A,return A.length. */ static int binary(int[] A, int k) { int l = -1; // Set l and r int r = A.length; // beyond array bounds while (l+1 != r) { // Stop when l, r meet int i = (l+r)/2; // Check middle if (k < A[i]) r = i; // In left half if (k == A[i]) return i; // Found it if (k > A[i]) l = i; // In right half } return A.length; // Search value not in A } Choice 1. Θ ( n ) Choice 2. O( 2^n ) Choice 3. O( log n ) Choice 4. Ω( n^2 ) (NOTE: code fragment is not intended to be functioning code)

Choice 3

For the following code fragment, select the choice which represents the most appropriate asymptotic analysis: static int function ( n ) { for (k=0; k<n; k++) A[k] = k; return A[k]; } Choice 1. Θ ( n log n ) Choice 2. O( 2^n ) Choice 3. O( n ) Choice 4. Ω( n^2 ) (NOTE: code fragment is not intended to be functioning code)

Choice 3

For the following code fragment, select the choice which represents the most appropriate asymptotic analysis: static int function ( n ) { sum = 0; for (j=1; j<=n; j++) for (i=1; i<=j; i++) sum++; return sum; } Choice 1. Θ ( n ) Choice 2. O( 2^n ) Choice 3. Θ( n^2 ) Choice 4. Ω( n^2 ) (NOTE: code fragment is not intended to be functioning code)

Choice 3

Which of the following items is NOT true for Array-Based Lists (please select the best choice): Choice 1. Insertion and deletion operations are Q ( n ) Choice 2. Direct access of an item in the array is Q( 1 ) Choice 3. Space used grows dynamically as the array is populated Choice 4. Array contains wasted space if array positions are not full

Choice 3

For the following code fragment, select the choice which represents the most appropriate asymptotic analysis: function ( n ) { sum1 = 0; for (k=1; k<=n; k*=2) for (j=1; j<=n; j++) sum1++; } Choice 1. Θ ( n ) Choice 2. O( 2^n ) Choice 3. Θ( n log n ) Choice 4. Ω( n^2 ) (NOTE: code fragment is not intended to be functioning code)

Choice 3. Θ( n log n )

For the following code fragment, select the choice which represents the most appropriate asymptotic analysis: static int function ( n ) { sum = 0; for (i=1; i<=n; i++) sum += n; return sum; } Choice 1. Ω( n^2 ) Choice 2. Ω( log n^2 ) Choice 3. Θ( n log n ) Choice 4. O ( n ) (NOTE: code fragment is not intended to be functioning code)

Choice 4. O ( n )

For the following code fragment, select the choice which represents the most appropriate asymptotic analysis: static int function ( n ) { for (k=0; k<n; k++) A[k] = k; return A[k]; } Choice 1. O ( n^2 ) Choice 2. O( 2^n ) Choice 3. Ω( n^2 ) Choice 4. Θ ( n ) (NOTE: code fragment is not intended to be functioning code)

Choice 4. Θ ( n )

In linked lists there are no NULL links in:

Circular linked list

The process of storing records in the order that they were added to a file is called:

Entry-sequenced file

A characteristic of RAM (random access memory) is that it is persistent and is not lost when the power to a computer is turned off.

False

A full binary tree has a restricted shape which starts at the root and fills the tree by levels from left to right.

False

A linked list implementation relies upon static memory allocation where static refers to the requirement to pre-allocate all of the memory that will be used for the list.

False

A list is said to be empty when all of its elements have a zero (0) value

False

A preorder traversal visits every node starting at the leaf nodes and working up the tree.

False

A traversal of a general tree that traverses the roots subtrees from left to right, then visits the root is called a preorder traversal.

False

The full binary tree theorem states "the number of leaves in an empty full binary tree is one more than the number of internal nodes"

False

The most time consuming of the following operations on an array based list implementation is:

Inserting a new element into the head of the list.

A leaf is any node that:

Is any node with two empty children

Setting the dirty bit causes what action to be performed on a block:

It flushes or writes the block out to the disk

Secondary storage is characterized by the following:

It is persistent

Which of the following is not a characteristic of an algorithm?

It must be composed of an infinite number of steps.

An important advantage of the sequential tree implementation is that (select the best answer):

It saves space because no pointers are stored

What is the role of the pivot in a quicksort algorithm?

It specifies the point where the array will be subdivided into partitions and each partition then sorted

Which of the following is NOT one of the buffer pool heuristics defined in the text :

LIFO

A sort where the list is divided into halves, the halves sorted and these two halves are merged is called:

Mergesort

An algorithm that breaks a file to be sorted in smaller files called runs which are sorted and eventually put back together resulting in a sorted file is called:

Mergesort algorithm

For the following code fragment, select the most appropriate asymptotic analysis: // Towers of Hanoi static void solveHanoi(int disks, char fromPole, char toPole, char withPole) { if (disks >= 1) { solveHanoi(disks-1, fromPole, withPole, toPole); moveDisk(fromPole, toPole); solveHanoi(disks-1, withPole, toPole, fromPole); } } static void moveDisk(char fromPole, char toPole) { moves++; }

O( 2^n )

For the following code fragment, select the option that represents the most appropriate asymptotic analysis: // Recursive Fibonacci generator static long fibr(int n) { if ((n == 1) || (n == 2)) return 1; // Base case return fibr(n-1) + fibr(n-2); // Recursive call }

O( 2^n )

The processing time or cost of a sort is defined by the number of comparisons and exchanges that must be made during processing. What is the average cost of the heapsort?

O( n log n )

For the following code fragment, select the option that represents the most appropriate asymptotic analysis: for (int i = 1; i <= n; i *= 2) { for (int j = 0; j < n; j++) { count++; } }

O( n log n ) Explanation: Here the outer loop is done log n times and the inner loop is done n times, so T(n) = n log n. (Note that the default base for logarithms in Computer Science is 2.)

For the following code fragment, select option that represents the most appropriate asymptotic analysis: for (i=0; i<n; i++) { // // Search in array a for smallest element starting at i to n-1 // minIndex = findSmallestElement(a, i, n-1) a[i] = a[minIndex]; } findSmallestElement( int a[], int i, int n ) { int largest = a[i]; while(i<n) { if(a[i] >a[largest]) largest = i; i++; } return(largest); }

O( n^2 ) index-of-smallest element in a[i..j] takes j-i+1 operations • n + (n-1) + (n-2) + (n-3) + ... + 3 + 2 + 1 • this is n2

A method that is designed to create extremely shallow trees is called:

Path compression

Data is stored within the disk drive on the:

Platter

A traversal that visits each node after visiting its children is called:

Postorder Traversal

A traversal that visits each node before visiting its children is called:

Preorder traversal

Each record of a database normally has a unique identifier called the:

Primary key

Which of the following is not a mathematical proof technique?

Proof by consensus

Enqueue and Dequeue are notations associated with which data structure:

Queue

A sort that features a limit of n-1 of record swaps is called:

Selection sort

A significant benefit to using an index to hold and sort keys to a file is:

Smaller keys require less I/O

A solution is said to be efficient if it:

Solves the problem within the required resource constraints

Internal Fragmentation refers to:

Space that is left empty because records do not fit evenly into a sector or Space allocated to a file that is not physically adjacent

Push and Pop are notations associated with which data structure:

Stack

Which of the following is NOT one of the design patterns outlined in our text.

Synergy

Asymptotic Algorithm Analysis is primarily concerned with:

The growth rate demonstrated in the algorithm running time equation

An ADT is:

The realization of a data type as a software component

A finite set of one or more nodes such that there is one designated node call the root is a: (select the best answer)

Tree

A coding scheme that replaces repeated occurrences of strings with a pointer to the location in the file of the first occurrence of the string is called Ziv-Lempel coding.

True

A linear index is an index file organized as a sequence of key/pointer pairs where the keys are in a sorter order.

True

A linked list creates order through the use of pointers that link one element to another.

True

A sequential tree can be represented using a bit vector?

True

A tree whose internal nodes all have exactly K children is called a K-ary tree.

True

The weighted union rule joins a tree with fewer nodes to a tree with more nodes by making the smaller tree's root point to the root of the larger tree.

True

True/False: The queue data structure is implemented as FIFO structure (first in first out):

True

A technique that allows a programmer to use more main memory than exists in the computer is called:

Virtual memory

A collection of one or more trees is called:

a Forest

According to the properties of logarithms, log(nm) = Note: Due to issues with HTML formatting, an exponent is represented by preceding it with the ^ symbol. As such x^2 is equivalent to x to the power 2.

log n + log m

Correctly identify the following heap structure by selecting the best answer: 100 19 36 17 3 25 1 2 7

max-heap structure

If A={1, 2, 3, 4} and B={4, 5, 6}, find A∪ B .

{1,2,3,4,5,6}

For the following code fragment, select the option which represents the most appropriate asymptotic analysis: /** @return Position of largest value in "A" */ static int largest(int[] A) { int currlarge = 0; // Position of largest for (int i=1; i<A.length; i++) if (A[currlarge] < A[i]) currlarge = i; // Remember pos return currlarge; // Return largest pos }

Θ ( n )

The best asymptotic analysis for the selection sort is represented by (select the best option): Option 1. O( n log n ) Option 2. Ω( n^2 ) Option 3. O( n^2 ) Option 4.Θ( n^2)

Θ( n^2)

For the following code fragment, select the option that represents the most appropriate asymptotic analysis: public static int binarySearch(int[] a, int key) { int left = 0; int right = a.length-1; while (left <= right) { int mid = left + (right-left)/2; if (key < a[mid]) right = mid-1; else if (key > a[mid]) left = mid+1; else return mid; } //not found return -1; }

Ω( 1 ), O( log n )


Related study sets

Dating 👨‍❤️‍💋‍👨💘

View Set