Data Structures Final Exam Study Guide

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

BST traversal. What's the Post-Order? 10 5 15 1 7 12 18

1, 7, 5, 12, 18, 15, 10

BST traversal. What's the Pre-Order? 10 5 15 1 7 12 18

10, 5, 1, 7, 15, 12, 18

Draw a binary search tree whose element are inserted in the following order 50, 72, 96, 94, 107, 26, 12, 9, 15, 13

50 / \ 26 72 / \ 12 96 /\ / \ 9 15 94 107 / 13

What is the minimum number of levels that a binary search tree with 100 nodes can have?

7 levels

Sorting a heap in an array. If the element has a left child, the child is as position?

(index *2)+1

Sorting a heap in an array. If the element has a right child, the child is as position?

(index *2)+2

Sorting a heap in an array. If the element is not the root, its parent is at position?

(index-1)/2

What are the thee major phases of Java exception mechanism?

Defining the exception, generating the exception, handling the exception.

True or false A binary search of a sorted set of elements in an array is always faster than a sequential search of the elements.

False

Preorder Traversal

Root, left subtree, right subtree

Q / \ K T /\ / \ D M R Y / \ \ / B J P W / N What are the ancestors of node P?

The ancestors of node p are: M, K, Q

How would it benefit the hashing process?

The major benefit of using chaining strategy is to avoid collisions which happens frequently in primitive hashing algorithms.

Why use header node and trailer node?

To simplify the insertion and deletion algorithms

A class that implements an interface can include methods that are not required by the interface.

True

A header node does not contain actual list information.

True

It is possible for a tree node to be both a root and a leaf.

True

What is an object?

an instantiation of a class and a class defines the structure of its objects

Class inheritance

are organized in an "is a" hierarchy

What is a full binary tree?

is a binary tree in which all of the leaves are on the same level and every non leaf node has two children

What is a reference variable?

refers to a class or an array

Transformers

setters and mutators

BST traversal. What's the In-Order? 10 / \ 5 15 /\ /\ 1 7 12 18

1, 5, 7, 10, 12, 15, 18

The element being searched for is not in an array of 100 elements. What is the average number of comparisons needed in a sequential search to determine that the element is not there If the elements are completely unsorted?

100

What is the maximum number of levels that a binary search tree with 100 nodes can have?

100 levels

Q / \ K T /\ / \ D M R Y / \ \ / B J P W / N What is the maximum possible number of nodes at the level of node N?

16 nodes

What would be the order of the following list after the first two rounds of the Bubble Sort algorithm? You should start from the end. 10 2 5 15 20 9 17 8 25 30 4

2 4 10 5 8 15 20 9 17 25 30

Q / \ K T /\ / \ D M R Y / \ \ / B J P W / N What is the maximum possible number of nodes at the level of node W?

8 nodes

Describe the exceptional cases for the array based bounded Stack ADT implementation.

A StackUnderflowException would be thrown when pop or top is attempted on an empty stack. A StackOverflowException would be thrown when push is attempted on full stack.

What is the value of this postfix expression: 1 2 3 x + 4 2 x6 5 - - / ? A. 1 B. 2 C. 3 D. 4 E. None of the above

A. 1

Which of the following Queue method could throw the QueueOverflowException? A. enqueue B. dequeue C. isEmpty D. isFull E. the constructors

A. enqueue

What does an object represent?

An object represents Information and behavior

Q / \ K T /\ / \ D M R Y / \ \ / B J P W / N What is the order in which the nodes are visited by an inorder traversal?

B D J K M N P Q R T W Y

Assuming that this is a circular double linked list Node 1 --> Node 2-->Node 3-->Node 4--> Node 5 A B C Find the info value of node 1, referenced from reference B

B.getBack().getBack();

Assuming that this is a circular double linked list Node 1 --> Node 2-->Node 3-->Node 4--> Node 5 A B C Find the info value of node 2, referenced from reference B

B.getBack().getInfo();

How many comparisons would the insertion sort make on an array of 10 elements that is already in ascending order? A. 7 B. 8 C. 9 D. 24 E. None of the above

C. 9

What is the time complexity of performing merge sort on an array with n elements? A. O(n2) B. O(n) C. O(nlogn) D. O(logn) E. None of the above

C. O(nlogn)

Assuming that this is a circular double linked list Node 1 --> Node 2-->Node 3-->Node 4--> Node 5 A B C Find the info value of node 4, referenced from reference A

C.getBack.getBack();

Assuming that this is a circular double linked list Node 1 --> Node 2-->Node 3-->Node 4--> Node 5 A B C Find the info value of node 1, referenced from reference C

C.getNext().getInfo();

14. Which of these represents the pre-order traversal of this binary search tree? 15 /\ 13 18 /\ /\ 12 14 16 19 A. 12, 14, 13, 16, 18, 19, 15 B. 12, 13, 14, 15, 16, 18, 19 C. 15, 13, 18, 12, 14, 16, 19 D. 15, 13, 12, 14, 18, 16, 19 E. 12, 14, 13, 16, 19, 18, 15

D. 15, 13, 12, 14, 18, 16, 19

Given the following code snippet, what is the element at the front of the queue after all this code executes? NumberQueue q = new LinkedNumberQueue(); q.enqueue(10); q.enqueue(20); q.enqueue(30); q.enqueue(40); q.enqueue(50); NumberStack s = new LinkedNumberStack(); for (int i = 0; i < 3; i++) { s.push(q.dequeue()); } while (s.size() > 0) { q.enqueue(s.pop()); } A. 10 B. 20 C. 30 D. 40 E. 50

D. 40

An object defines the structure of a class.

False

It is considered OK to add something to a list during an iteration.

False

It is easy to access any element of a Priority Queue.

False

The efficiency of insertion sort is O(nlogn) where n is the size of the list being sorted.

False

The static storage allocation approach creates space for a method when the method is invoked.

False

True or false A binary search is an O(N log2N) algorithm.

False

What's the time complexity for insertion sort?

General/Worst case = O(n^2) Best Case= O(n)

A priority queue containing characters is implemented as a heap stored in an array. The precondition states that this priority queue cannot contain duplicate elements. There are 10 elements currently in the priority queue, as shown below. What values might be stored in array positions 7-9 so that the properties of a heap are satisfied? 0 , Z 1, F 2, J 3, E 4, B 5, G 6, H 7, ? 8, ? 9, ?

Index 7=D, Index8=D, Index=9

What's the time complexity for heap Sort?

O(N log2 N)

What's the time complexity for merge sort?

O(N log2 N)

What's the time complexity for bubble sort?

O(N^2)

What's the time complexity for selection sort?

O(N^2)

Q / \ K T /\ / \ D M R Y / \ \ / B J P W / N What is the order in which the nodes are visited by a preorder traversal?

Q K D B J M P N T R Y W

Q / \ K T /\ / \ D M R Y / \ \ / B J P W / N What are the descendants of node K?

The descendants of node K are: D, M, B, J, P, N

When comparing two objects using the == operator what is actually compared is the references to the objects.

True

Postorder Traversal

Visit left subtree, right subtree and then root.

Inorder Traversal

Visit left subtree, root and then right subtree.

Observers

getters and accessors

What is a priority queue?

is an ADT in which only the highest-priority element can be accessed

What's the equation to find out how many comparisons in a selection sort?

n(n-1)/2

The element being searched for is not in an array of 100 elements. What is the average number of comparisons needed in a sequential search to determine that the element is not there If the elements are sorted from smallest to largest?

n/2=50

What is a primitive variable?

primitive data type

What does the "==" operator compare? Reference or Value?

reference

What is the chaining strategy in hashing algorithms?

to store a reference to a linked list (adjacent list) in each hash table slot. By doing so, elements with same hash values are added to the same linked lists.

Which of the following statements is TRUE about the merge sort on an array? A. It divides an array into two subarrays, sorts each half, and merges them back. B. It divides an array into two subarrays, selects the smallest value from the two subarrays, and repeats the process until the array is sorted. C. It recursively divides an array into subarrays, merges them, and sorts each subarray. D. The time complexity of merge sort depends on the initial order of the array. E. None of the above

A. It divides an array into two subarrays, sorts each half, and merges them back.

Which of the following represents "quadratic" time? A. 3n+5n^2+1 B. nlogn C. n7+n+1 D. 2^n+n^2+5 E. None of the above

A.3n+5n2+1

Assuming that this is a circular double linked list Node 1 --> Node 2-->Node 3-->Node 4--> Node 5 A B C Find the info value of node 1, referenced from reference A

A.getBack();

Assuming that this is a circular double linked list Node 1 --> Node 2-->Node 3-->Node 4--> Node 5 A B C Find the info value of node 2, referenced from reference A

A.getInfo();

Q / \ K T /\ / \ D M R Y / \ \ / B J P W / N What is the order in which the nodes are visited by a postorder traversal?

B J D N P M K R W Y T Q

What's an Abstract Data Type(ADT)?

A data type whose properties(domain and operations) are specified independently of any particular implementation

Given the following code snippet, what is the size of the stack after all this code executes? NumberStack s.push(10); s.push(20); s.push(30); s.push(40); s.push(50); s.pop(); int myInt = s.pop(); s.pop(); s.push(myInt); A. 2 B. 3 C. 4 D. 5 E. none of the above

B. 3

How many comparisons would be needed to sort an array containing 100 elements using a selection sort if the original array values were already sorted? a. 10,000 b. 9,900 c. 4,950 d. 99 e. None of these

4,950

What is returned when invoking the method call myFun(4)? int myFun (int n) { if (n <= 1) return 1; else return (myFun(n - 1) + myFun(n / 2)); } A. 3 B. 5 C. 4 D. 10 E. None of the above

B. 5

In a complete binary tree, what is the index number of the parent of the node numbered 20? A. 8 B. 9 C. 10 D. 11 E. 19

B. 9

Under which circumstances should a recursive solution be preferred to an iterative solution? (1) When the recursive version is more easily understood. (2) When the running time is critical. (3) When space (memory) is critical. A. None of them B. Only (1) C. (1) and (2) D. (1) and (3) E. All of them

B. Only (1)

Which is true about the quick sort? a. A recursive version executes faster than a nonrecursive version. b. A recursive version has fewer lines of code than a nonrecursive version. c. A nonrecursive version takes more space on the run-time stack than a recur- sive version. d. It can be programmed only as a recursive function.

B. recursive version has fewer lines of code than a nonrecursive version.

What's the time complexity for insertion sort?

Best case (if data is almost sorted) O(N) General case or Worst Case= O(N^2)

What's the time complexity for quick Sort?

Best/General Case O(N log2 N) Worst Case O(N^2)

For the array based unbounded Queue implementation, what happens if the underlying array is full and an enqueue operation is attempted? A. A QueueOverflowException is thrown. B. A QueueUnderflowException is thrown. C. A linked list is created to hold additional elements. D. A bigger array is created and all the elements in the current array are copied into the new array. E. Nothing happens.

D. A bigger array is created and all the elements in the current array are copied into the new array.

Which of the following Java statement attempts to invoke methods that would potentially throw exception(s)? A. throw B. raise C. catch D. try E. None of the above

D. try

In which situations the array based implementation and the linked based implementation are most suitable? A. Unbounded Stack ADT and bounded Stack ADT, respectively B. Unbounded Stack ADT and unbounded Stack ADT, respectively C. Bounded Stack ADT and bounded Stack ADT, respectively D. Bounded Stack ADT and unbounded Stack ADT, respectively E. They are equally suitable.

D.Bounded Stack ADT and unbounded Stack ADT, respectively

A merge sort is used to sort an array of 1000 test scores in descending order. Which one of the following statements is true? a. The sort is fastest if the original test scores are sorted from smallest to largest. b. The sort is fastest if the original test scores are in completely random order. c. The sort is fastest if the original test scores are sorted from largest to smallest. d. The sort is the same, no matter what the order of the original elements.

D.The sort is the same, no matter what the order of the original elements.

Which of the following statements are TRUE about the heap-based implementation of priority queues? (1) The enqueue method calls reheapDown. (2) The enqueue method calls reheapUp. (3) The dequeue method calls reheapDown. (4) The dequeue method calls reheapUp. (5) The enqueue method adds an element as the root of the heap. (6) The dequeue method removes the root of the heap. A. (1) and (4) B. (1), (4), and (6) C. (2) and (3) D. (2), (3), and (5) E. (2), (3), and (6)

E. (2), (3), and (6)

Which of the following statements is TRUE about linked lists? A. All the elements in a linked list are always stored contiguously. B. Given the position, removing a node from a linked list is extremely inefficient. C. Linked lists support random access. D. You can traverse a singly linked list from head to tail and from tail to head. E. Each node in a singly linked list saves data as well as a link to its next node.

E. Each node in a singly linked list saves data as well as a link to its next node.

Which sorting algorithm uses the most amount of space to sort a sequence on n elements? A. Selection Sort B. Insertion Sort C. Heap Sort D. Quick Sort E. Merge Sort

E. Merge Sort

Which of the following methods is unchanged when moving from a normal linear list implementation to the circular list implementation? A. find B. add C. remove D. toString E. None of the above

E. None of the above

Which of the following structures did we classify as "non-linear"? A. array B. sorted list C. stack D. queue E. tree

E. tree

True or false A binary search of elements in an array requires that the elements be sorted from smallest to largest.

False

What are the three levels in ADT?

Logical, Implementation and Application

What happened when insertion code is called when the linked list is empty?

The new node will become the first and only node on the linked list

Because QueueUnderflowException is an unchecked exception, if it is raised and not caught, it is eventually thrown out to the run-time environment.

True

True or false A high-probability ordering scheme would be a poor choice for arranging an array of elements that are equally likely to be requested.

True

What is the output of the following program? public class TestRecursion { public static void main(String[] args){ myRec(10, 16); } public static void myRec(int a, int b){ if (a > 2){ System.out.println("b is " + b); myRec(b - 4, a - 2); } else System.out.println("a is " + a); } }

b is 16 b is 8 b is 10 b is 2 a is -2

What is a complete binary tree?

is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible

he element being searched for is not in an array of 100 elements. What is the average number of comparisons needed in a sequential search to determine that the element is not there If the elements are sorted from largest to smallest?

n/2=50

What does the level of a binary search tree mean in relation to the searching efficiency?

refers to the distance from the root. For example, if a tree is build efficiently with the minimum amount of levels required will run more efficiently versus a poor constructed tree.


Ensembles d'études connexes

Regulations: Securities Exchange Act '34 Review Questions

View Set

MGMT 490: Exam 1 - Chapter PowerPoints

View Set

Domain 4: Fire Prevention and Protection

View Set