CMSC 341 (Data Structures) Final

Ace your homework & exams now with Quizwiz!

k-d tree(k dimensional tree)

-Allows a search with multiple keys -Worst case running time: O(n) -Average running time: O(log n) (insert, search, remove) -Is in the binary search tree family -The space usage is O(n)

Properties of a red-black tree

-Each tree node is colored either red or black. -The root node of the tree is always black. -Every path from the root to any of the leaf nodes must have the same number of black nodes. -No two red nodes can be adjacent, i.e., a red node cannot be the parent or the child of another red node. -The inserted node is always red. If there are 2 adjacent red nodes after the insertion then we need to restructure the tree

Trie search time

-To find a string of length m we need to visit m nodes, and at every node we need to search for the character at most d times. Then, the worst-case search time would be O(md). Since d is a constant value, we can say search time is O(d). Note: d is the size of alphabet -search is constant time

Trie insertion time

-To insert a string into the tree, we start to search and follow the path, we continue the search until it is not possible to continue, then we start to create a new chain of nodes. If non of the characters is in the tree, we need to create all. Creating a node is O(1), then creating the path for the string would be O(m) where m is the string size. -insertion is constant time

Splaying

-bringing the latest accessed node to the root. -costs O(h) where h is the height of the tree -Worst case running time O(n) -done with a series of rotations

Running times of red-black tree operations

-size = O(1) -empty = O(1) -find = O(log n) -insert = O(log n) -remove = O(log n) -height = O(log n)

What is the recommended load factor for a hash table with quadratic probing collision handling?

0.5

What is the load factor of a hash table with 9 buckets storing the following data points, (5,28,19,15,20,33,12)? (Occupied buckets / total capacity)

0.7

What list presents the results of storing (5,28,19,15,20,33,12) in a hash table using linear probing collision handling. Assume the table has 9 buckets, and the hash function is h(k) = k % 9.

28,19,20,12,5,15,33

Generally, the stack ADT provides "First In First Out" data storage.

False

In a class with memory allocation we do not need to implement an assignment operator. The one provided by the compiler makes deep copies of objects.

False

In a hash table using open addressing collision handling, we can store multiple data items in every bucket

False

In a priority queue, the items leave the queue in the order that they arrived.

False

In a singly linked list with only a head pointer, inserting a node at its tail is as efficient as inserting a node at the tail of a doubly linked list with two pointers to head and tail. Note: efficiency means the number of required node visits.

False

In the Map ADT the keys are always integer numbers.

False

Pre-order traversal can be used to evaluate arithmetic expressions.

False

The space required for the stack ADT for n data points, is O(log n).

False

DFS

In depth first search look as deep as possible (moving vertically before horizontally is typically implemented using a stack push start node onto stack while stack isnt empty, pop the top off the stack, visit it, push all of its unvisited neighbours onto the stack

we go right then right

Left rotation on grandparent, left rotation on parent

we go left then right (Case B)*

Left rotation on parent, right rotation on grandparent

From root we go right

Left rotation on root

ADT stands for ...

Abstract Data Type

Splay Tree

Any valid BST. Amortized O(log n) access. M operations take O(m log n) for m being large #s. Any node getting inserted, removed, or accessed, get's splayed to the root.

BFS

Breadth-first search is an algorithm for searching a tree data structure for a node that satisfies a given property. It starts at the tree root and explores all nodes at the present depth prior to moving on to the nodes at the next depth level.

The following list is the vector presentation of a heap data structure. No key is stored in index 0 of the array. Does a postorder traversal of this heap produce the keys in nonincreasing order? [x, 1, 5, 2, 8, 9, 7, 6]

No

The following list is the vector presentation of a heap data structure. No key is stored in index 0 of the array. Does a preorder traversal of this heap produce the keys in sorted order? [x, 1, 5, 2, 8, 9, 7, 6]

No

Search time of a skip list

O(log n)

The height of a Heap data structure is ...

O(log n)

What is the expected running time of search, insertion, and deletion in a skip list?

O(log n)

What is the worst case running time for merging two leftist heaps?

O(log n)

The following pseudocode presents an algorithm for transferring the information to the current heap object from another heap object. Assuming the algorithm is working correctly, what is the running time of this function? void transfer(heap rhs){ while (rhs is not empty){ Insert_into_current_heap (Remove_from_rhs) } }

O(n log n)

Worst growth rate in running an algorithm

O(n log n)

How much space do we expect skip lists use?

O(n)

How much space does a trie use?

O(n)

We have used a chaining collision handling scheme with doubly linked lists in a hash table implementation. What is the worst case running time for search operations?

O(n)

What is the upper bound for the growth rate of insertion at an arbitrary location in a linked list?

O(n)

What is the upper bound for the growth rate of insertion at the head of an array?

O(n)

Trie construction time

O(n) linear time

What is the upper bound for the growth rate of the following function?

O(n^2)

We are designing an application for the airport control tower which keeps track of airplanes ready for take off. Airplanes take off in the order they get ready. What ADT is a proper one to store the list of planes so that the tower can use to issue the take off permission?

Queue

we go left then left (Case A)*

Right rotation on grandparent, right rotation on parent

we go right then left

Right rotation on parent, left rotation on grandparent

From root we go left

Right rotation on root

We want to design an application which its job is to cypher a message. The algorithm reads the message as a stream of characters, changes some characters randomly and converts them to another character, at the end it writes the message in a reversed stream of characters. Then the reversed message will be sent to the destination. What is the proper ADT to be used in this algorithm?

Stack

Algorithm A executes an O(log n)-time computation for each entry of an n-element array. What is the worst-case running time of algorithm A?

The worst case running time for algorithm A is O(n log n)

If T(n) is O( f ( n ) ) then there is a constant c > 0 such that T(n) ≤ c f (n) for all non-negative n.

True

If we know the number of data points in advance, using an array is more efficient than a linked list with regard to space usage.

True

In a doubly linked list implementation of the queue ADT, both enqueue and dequeue operations run in O(1)

True

In the context of hash tables a good hash function is the one that distributes the data items uniformly across the bucket lists (array).

True

One of the data structures for implementing a dictionary is skip lists.

True

The circular singly linked list is more efficient than a doubly linked list with regard to space usage, when implementing the queue ADT.

True

The function (3n2 + 5n2 log n + n) is O(n^2).

True

What data structure can be used for implementing a hash table in order to obtain running time O(1) for search operation?

an array

How do we prevent modifications to an object, when we pass the object by reference to a function?

by passing the object as const

In a real-time system the search running time is critical. What data structure do you suggest as a collision handling scheme for a hash table implementation in such a system?

chaining with a binary search tree

In a priority queue ADT, the smallest key always has the highest priority.

false

Which nodes are splayed after each operation? find(k)

if key found, use that node if key not found, use parent of ending external node

Application for a trie

information retrieval

What type of numbers are the best for the table size of a hash table?

prime numbers

Trie removal time

removal is constant time

Induction method

step 1: n = 1 step 2: n = k step 3: n = k + 1

Which nodes are splayed after each operation? insert(k)

use the new node containing the entry inserted

Which nodes are splayed after each operation? remove(k)

use the parent of the internal node that was actually removed from the tree (the parent of the node that the removed item was swapped with)

Left rotation in a splay tree

zag operation

If x is the right child of its parent, and its parent is the right child of x's grandparent, we perform two left rotations.

zag-zag

Right rotation in a splay tree

zig operation

This happens when x has only a parent, not a grandparent, the parent is the root.

zig or zag -If x is the left child of its parent, we perform right rotation, i.e. zig. -If x is the right child of its parent, we perform left rotation, i.e. zag.

This happens when x has a parent, and a grandparent. In such cases, we need to perform two rotations. (different)

zig-zag or zag-zig -If x is the left child of its parent, and its parent is the right child of x's grandparent, we perform right rotation about x's parent, then we perform left rotation about x's grandparent. -If x is the right child of its parent, and its parent is the left child of x's grandparent, we perform left rotation about x's parent, then we perform right rotation about x's grandparent

This happens when x has a parent, and a grandparent. In such cases, we need to perform two rotations. (same)

zig-zig -If x is the left child of its parent, and its parent is the left child of x's grandparent, we perform two right rotations.


Related study sets

Riding the wave: Real Estate Cycles

View Set

Unit 1: AC Fundamentals "Transformers"

View Set

Real Estate Unit 15-Real Estate Taxes and Other Liens

View Set

Health B: Chapter 14 Lifestyle Diseases

View Set

CHP15 MONOPOLIES MULTIPLE CHOICE

View Set

1.1: Trig & Inverse Trig with Special Angles (MEMORIZE)

View Set

Chapter 6 Accounting Questions (Regent University Bus 220 2019)

View Set