Data Structures Final Study Guide

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

Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree?

0 1 2 3 4 5 6 7 8 9

What is a data structure?

A systematic way of organizing information, usually in a computer memory

Which of the following scenarios leads to linear running time for a random search hit in a linear-probing hash table?

All keys hash to same index

Why is merge sort more effiecient than selection sort, bubble sort and insertion sort?

Because merge sort takes advantage of the transitivity property (A<B and B<C then A<C)

What are linear sorts and what do they do?

Counting, radix, and bucket - they order the elements without directly comparing them

In delete operation of BST, we need inorder successor (or predecessor) of a node when the node to be deleted has both left and right child as non-empty. Which of the following is true about inorder successor needed in delete operation?

Inorder successor is always either a leaf node or a node with empty left child.

Which of the following sorting algorithms in its typical implementation gives best performance when applied on an array which is sorted or almost sorted (maximum 1 or two elements are misplaced).

Insertion sort

What is common in three different types of tree traversals (Inorder, Preorder and Postorder)?

Left subtree is always visited before right subtree

You have to sort 1 GB of data with only 100 MB of available main memory. Which sorting technique will be most appropriate?

Merge sort

Selection Sort

Nested loop structure: finds smallest element and moves it to the output list then it finds the next smallest value (O(n^2))

Assuming that the hash function for a table works well, and the size of the hash table isreasonably large compared to the number of items in the table, the expected (average) time needed to find an item in a hash table containing n items is

O(1)

For binary search tree, how long does each step take?

O(1)

AVL Performance - Find, insert, and removal

O(log n)

What is the average case time complexity for finding the height of a binary tree?

O(nlogn)

Which one of the following in place sorting algorithms needs the minimum number of swaps?

Selection sort

What are the comparison sorts and what do they do?

Selection, bubble, insertion, merge, quick, heap - they compare elements to find an ordering (O(nlogn))

T/F: If you insert 16 elements in an empty BST, the possible heights of the resulting BST is anywhere between 4 and 15.

True

T/F: In a min-heap, parent node can have value equal to one of its children.

True

T/F: You are given a set of n distinct elements, and an unlabeled binary tree with n nodes. You can populate the tree in only 1 way with the given set such that the tree becomes a binary search tree.

True

The height of a bst...

Worst case O(n) and the best case is O(log n)

Algorithm

a finite set of unambiguous instructions done step by step to achieve a goal

What is a proper binary search tree?

a proper binary tree follows the following properties: the right subtree is greater than the parent and the left is less than

Comparison sort

a type of sorting technique that arranges data by comparing two pieces at a time (no assumptions made about the values)

Heap Sort

array based - in place - stare the keys are they are extracted in the unused tail portion of the array (NOT stable) O(n)+E log n

Asymptotic Analysis

defining mathematical bound of its run-time performance

The number of edges from the root to the node is called ____________ of the tree.

depth

Merge Sort

divide and conquer - divide into two sets, solve subproblems, then combine solutions

Bubble Sort

successively compares adjacent elements, swapping them out if they are out of order (nested loop structure)(O(n^2))

Sort in place

swapping elements within the input array (O(1))

Quick sort time complexity

worst-case: O(n^2) best: O(n log n)

Assuming that the sorting algorithm sorts the input sequence in ascending order. If the input is already in ascending order, then insertion sort runs in

O(n2) time.

Suppose we have a O(n) time algorithm that finds median of an unsorted array. Now consider a QuickSort implementation where we first find median using the above algorithm, then use median as pivot. What will be the worst case time complexity of this modified QuickSort ?

O(nlogn)

The best case, in terms of the asymptotic running time, for QuickSort happens when:

The number of elements to the right of the pivot is approximately equivalent to the number of elements to the left of the pivot.

The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree?

15, 10, 23, 25, 20, 35, 42, 39, 30

What is an AVL tree?

A BST where the height of every node and that of its sibling differ by at most 1.

T/F: A binary tree is said to be a heap data structure if it is a complete binary tree.

False

T/F: The runtime of inserting an element into a BST is guaranteed to be O(log n).

False

Selection sort and bubble sort can be easily designed to

sort in place or stable sort

How long do the methods find, insert, and delete take for proper bst?

O(h)

For binary search tree, what is the total amount of time it takes?

O(log n)

What is the height of an AVL storing n keys?

O(log n)

In a binary max heap containing n numbers, the smallest element can be found in time ...

O(n)

Time complexity of merging two sorted squences

O(n)

What is the best time complexity of bubble sort?

O(n)

What does a binary search tree do?

cut sublist in half, then determines what half the key is in then keeps that half

Insertion sort

left sublist (sorted keys and are not the smallest), right sublist (unsorted keys) (nested loop)

Assume that you are implementing a priority queue PQ that returns the max element on dequeue operation. If we use a max heap to implement the PQ, enqueue is enqueue is O(__________) operation and dequeue is O(________) operation.

log n, log n

Stable sort

ordering of identical keys in the input is preserved in the output (important when entries with identical keys are already ordered by another rule)

Examples of data structures

queue, stack, linked list, heap, or tree

Quick Sort

randomized sorting using divide and conquer - divide into 3 squences around pivot, L < x E = x , G >x. quick sort L and G then combine

In-Order Traversal

records the keys in increasing order

Which of the following is/are TRUE of mergesort and quicksort?

- both take O(n) to divide the problem or combine the pieces. - both are recursive. - both have the same average case complexity.

AVL Performance - A single restructure

O(1)

T/F: The depths of any two leaves in a max heap differ by at most 1.

True


Ensembles d'études connexes

acct 2302, quiz 3: cvp & var. costing

View Set

Knoch Physiology Module Note cards Final Exam

View Set

Экономика организации предприятия

View Set

BULE 303 Final (Ch 17, 18, and Mindtap)

View Set

TEAS Science- Chromosomes, genes, and DNA

View Set

Sum/Difference of Two Numbers: Quiz Review

View Set

Operations Management Chapter 2 Quiz

View Set