CS2050 - Final Exam - Dr. Uhlmann

Ace your homework & exams now with Quizwiz!

In the case of using a simple linked-list. What would the big O complexity of the functions DeleteMin() and Insert() be?

DeleteMin - O(N) Insert - O(1)

How would an O(1) operation change with an array of size 100 vs 10 billion.

Nothing would change. O(1) is a constant time proportional to the size of the array

boolean isSorted(int a[], int n) { int i; for (i = 0; i<n-1;i++){ if(a[i]>a[i+1]) return FALSE; } return TRUE; } What is the complexity of this algorithm?

O(N)

Retrieving all the keys within a range min to max isreferred to as a range query. What complexity do youthink can be achieved using binary search?

O(log(N) + k). Scanning to retrieve the k keys that satisfy the query takes O(k) time

If the heap is stored as a balanced binary tree, then the deleteMin operation visits O(log N) nodes and therefore has ________ complexity

O(log(N))

Simple insertion of N randomly-ordered keys will produce a BST of expected _______ height.

O(log(N))

What is the complexity to find the smallest key in hash table that uses balanced BSTs for the buckets?

O(log(N))

What is the time required to perform a binary search on a sorted array of size N.

O(log(N))

What is the worst case-complexity of a counting query?

O(log(N)) The query can be satisfied by using binary search to find the index of the smallest key satisfying the query, and again to find the index of the largest key satisfying the query.A simple subtraction of the two indices (plus 1) gives the answer. Complexity: O(log(n))

Retrieving all the keys within a range min to max is referred to as a range query. What complexity do you think can be achieved using binary search?

O(log(n) + k)

What is the computational complexity for counting queries?

O(log(n))

What is the complexity of treeSort?

O(n*log(n))

What is the time complexity to construct a BST?

O(n*log(n))

How is TreeSort equivalent to QuickSort?

One way to see this is to consider if the first key after random shuffling were used as the first pivot in Quicksort. The left and right subtrees and the left and right subarrays would contain the same set of keys

Suppose you are developing code for a multi-processor vector processing computer that supports a special set of very fast array operations. Two of these operations are getMin(array)and getMax(array), which return the index of the min or max element of an array in O(1) time. Which of the following sorting algorithms could most effectively use operations of this kind?

Selection Sort

What collection ADT contains objects with no duplicates?

Set

What is the inorder predecessor?

The inorder predecessor of a value is the largest value that is less than it

What is the inorder successor?

The inorder successor of a value is the smallest value that is not less than it

Best data structure to use when sorted a data-set of known size?

array

ADT (Abstract Data Type)

defines a general data type like list that describes a collection of data without worrying about the specific implementation. Uhlmann Definition from Slides: A conceptual entity that can be manipulated according to a set of values. The designer doesn't consider how the defined ADT will accomplish goals.

Best data structure to use if you want to quickly tell if a given value exists in a data-set?

hash table

Best data structure to use when sorted a data-set of unknown size?

heap

Which of the following best describes the Bag ADT when reffering to a linked-list?

A linked-list can be a bag. It can also not be a bag. It boils down to the implementation of the linked-list itself.

What is the complexity of merging two sorted lists? (merge sort)

O(N)

What is the complexity to print all values in the Kth column of a 2d array?

O(N)

What is the time complexity of inorder traversal of a BST?

O(N)

What does hashing do?

A hash function for an array of O(N) size takes each key and maps it to an index ranging from 0 to S, where S is O(N)

Examples of balanced binary trees

- A tree in which subtrees of every node are proportional in size. - A tree in which subtrees of every node are proportional in height. - A tree in which subtrees of every node have the same height to within a constant difference

What are the steps for merge sort?

1. Divide the unsorted array into two halves 2. Recursively apply MergeSort to each subarray 3. Merge the two sorted subarrays

Basic algorithm for TreeSort

1. Insert values in the array into a BST - This just requires a loop in which we call tree Insert for each element of the array. 2. Perform an inorder traversal of the BST and write the values back to the array in sorted order - This just requires us to set index to zero and then invoke flatten on the BST we constructed above.

How many operators are there in C which are used to dereference a pointer?

3 - The struct pointer member access operator -> - The unary indirection operator * - The array subscript operator []

What is Merge Sort an example of?

A divide and conquer algorithm

What is a recursive function?

A function which calls itself

What issues could arise if you used an array of structs for a linked list?

A problem could arise if we needed to change struct members.

Abstraction

A process that asks the user "What" instead of "How". - What do you want to be done - What will be done to the data Client user is the "What" - Implementation is the "How".

What is a simple linked list?

A simple linked list contains one pointer to the head of the list.

What is a balanced binary search tree?

A tree of size N is said to be balanced if and only if its height - the longest path in the tree from the root to a leaf - is proportional to log(N).If a tree of size N has O(log(N)) height, then the tree is a balanced tree. A tree is said to be perfectly balanced if it has minimum possible height

What are the common operations for a Bag ADT?

Add(), Delete(), ItemExists(), IsFull()

How can you keep track of subtree size?

Adding a size counter to the heap-structure

What should a recursive function do?

All are correct

What does the choice of a data structure depend on?

All of the above

What does this code do? typedef struct{ Node *head, *tail; int len; }ListInfo; typedef struct{ ListInfo *lstruct; }List;

All the statements listed are true

What are some examples of collection ADT's?

Bag - Set - List

What collection ADT contains objects with little to no restrictions on its content?

Bag or "Multi-set"

What does keeping track of the size of a subtree guarantee?

Balance

Why shouldn't you initialize a struct at compile time? What is a good way to fix this?

Compile time initialization assumes a specific ordering of the members, as soon as the struct is changed the initialization might assign values to the wrong members. Fix: Use a seperate function to initialize each.

How can you make operations on the front and back of a linked-list more efficient?

Create a head and tail pointer

In the case of using a simple linked-list. What would the big O complexity of the functions DeleteMin() and Insert() be if the list is in sorted order?

DeleteMin would become O(1) because if it is sorted in ascending order than we would just remove from head. Insert would become O(N) because we still need to search through the list to find the sorted order.

Which of the following statements is correct?

Depending on whether the input data set is sorted in ascending or descending order, insertion sort will exhibit either its best-case or worst-case performance.

What should you do when implementing an ADT

Describe its data and specify the operations.

Hashing allows us to do what?

Directly locate a given key by computing its hash value and searching the corresponding list in the hash array

Why Does Binary Search Take O(log N) Time?

Each comparison eliminates half of the elements in the dataset. How many times can a number N be divided in half before theresult is less than 1?

for (i = 0; i < n; i++){ for (j = 0; j < n; j++){ //This part takes O(1) time } } Okay, so how many times does the inner loop perform the O(1) part?

Each loop takes O(1) time but it is proportional to the size N of the array so it takes O(N) time total.

Suppose someone says that they have a search algorithm with worst-case complexity O(1). What can be concluded?

Either the algorithm performs its search using something other than comparison information, or it does not have O(1) worst-case complexity.

In a linked list, what are dummy nodes useful for?

Eliminating special operations at the head and sometimes the tail.

What are the two most common operations for a Queue ADT?

Enqueue() and Dequeue()

How Hard is it to Find the Inorder Predecessor or Successor?

Finding the inorder predecessor of a value for a node requires finding the largest value in its left subtree. Finding the inorder successor of a value for a node requires finding the smallest value in its right subtree.

Examples of Queues

Ticket line, escalator, car wash,

Which of the following statements is true?

Every subtree of a BST must also be a BST

What is the special case may arise if you perform dequeue using a circular linked list?

Executing the code: p->next = rear->next (for dequeue) will SEG FAULT. This is because if we do not use dummy nodes the tail will be NULL

It takes O(log(n)) worst-case time complexity to test if a heap contains a particular value.

False

True or false: Binary search is faster than sequential search in all cases.

False

True or false: If the complexity of dividing a problem into sub-problems, and of combining solutions to those problems, is better than the complexity of your best algorithm for solving the overall problem, then recursive divide-and-conquer will (generally) not yield an algorithm that is as good or better.

False

True or false: Shuffle sort is a useful sorting algorithm

False

True or false: The choice of data structure does not depend critically on the characteristics of the algorithms it supports.

False

A hash table can be used to sort a dataset, because there is a relationship between the order of the generated hash keys and the order of the inserted elements.

False A hash table does not need to respect the insertion order of the keys, and there is no guarantee that there will be a relationship between the ordering of the keys and the ordering of the inserted elements.

The pre-increment and post-increment operators do the same thing. IE: ++i == i++;

False Pre increments before the assignment and post increments after the assignment

True or false: A judicious choice of data structures cannot have a significant impact on both the average and worst-case performance of an algorithm

False - It can have a significant performance

True or False: In a linked-list with a *head and *tail pointer. Can they both be removed efficiently?

False: Head can be removed efficiently but tail cannot. We do not have access to the node before the tail.

True or false: There is no way to make the worst case-complexity of HashInsert, HashDelete, and HashFind better than O(N)

False: The worst-case complexity for the different hashing operations can be reduced to O(log N) simply by replacing the linked lists with balanced binary search trees

If binary search is not always faster than sequential search, what statement can be best made about the efficiency of binary search relative to sequential search?

Given an implementation of binary search and an implementation of sequential search, the worst-case amount of time required to perform a binary search will be less than that for sequential search if the dataset is sufficiently large.

Computational Efficiency

In many cases a tradeoff must be made between execution-time efficiency and storage requirements. Computational complexity analysis may not always reveal very much about the practical efficiency of an algorithm. It really only indicates relative performances of different algorithms in the limit as the problem size gets large. That limit may sometimes not have much relationship to performance on practical-sized problems.

In a BST that has duplicates what must be used to delete/replace nodes?

If the less-than inequality is used as the BST condition, the inorder successor must be used

Which of the following statements is true?

Knowing the computational complexity of an algorithmmay not provide much information about how fast it will run in practice.

What is the downside of keeping track of the size of subtrees in a heap datastructure?

Increases the memory for each node by 33% because of the size member

What does the following code segment do? mysteryFunc ( BST tree ) if tree is Null, then return; mysteryFunc ( tree->left ); print content of tree->info; mysteryFunc( tree->right );

Inorder printing of a BST

What is inorder traversal useful for?

Inorder traversals are useful for obtaining data in sorted order

When using sufficiently small datasets which O(N^2) simple algorithm would be the best?

Insertion

What are the complexities for insert and retrieval using a simple linked list with a Priority Queue operation?

Insertion: O(N) time Retrieval in O(1) time

The Stack ADT supports what?

LIFO (Last-in-first-out)

What are some of the operations for a Priority Queue ADT?

IsFull/Empty(), Insert(), GetMax(), GetMin()

Suppose a data structure permitted the insert and delete-min operations to have O(1) complexity. If the resulting priority queue ADT were used to implement a sorting algorithm, what complexity could be achieved?

It could sort in O(N) time: each of the N keys can be inserted in O(1) time, so all of them are inserted in O(N) time. The keys can then be removed sequentially in sorted order, O(1) time per key, for an overall complexity of O(N). As we'll see, however, this complexity is not possible because no algorithm can sort general keys in O(N) time.

Consider the following code segment: typedef struct{ Node *head, *tail; }List; If the list is empty, what would the head and tail point to?

It depends on how the list is designed/created

What describes a Linked-List

It is a data structure that commonly contains a key and a pointer to the next struct member (this is the link)

for (i = 0; i < n; i++){ for (j = 0; j < n; j++){ count+= array[i] * array[i] } } How much time does the operation in the inner-most loop take?

It takes one unit of time O(1). It just takes a fixed/constant amount of time no matter how big or small the array is.

How do people "think up" new algorithms and data structures to solve complex problems more efficiently?

It's often difficult to directly develop an optimal solution to a complex problem, but solving a simpler problem can usually provide a good first building block

Encapsulation

Keeping details (like data and procedures) together in one part of a program so that programmers working on other parts of the program don't need to know about them. The implementation is "Information Hiding"

What is the algorithm for searching for a node with the value m in a binary search tree?

Let top be a reference to the top of the tree. REPEAT: If top is an empty tree, then return a null reference indicating that m is not in the tree. If top is not empty, then compare m to the key stored in the root. If m is less than the key in the root, then set top equal to the left subtree; if m is greater than the key in the root, then set top equal to the right subtree; otherwise return top

When hashing what can be used to handle index collisions?

Linked lists (buckets)

What collection ADT has a head and a tail?

List ADT

The following statement describes what? The root of every subtree has the smallest key in that subtree

Min-Heap

Consider the following code segment for (i=0; i < n-1; i++) { if ( a[ i ] > a[ i+1 ] ) { // Swap violating pair temp = a[ i ]; a[ i ] = a[ i+1 ]; a[ i+1 ] = temp; } } Does this produce a correctly sorted result?

No

for (i = 0; i < 3*n; i++){ for (j = 0; j < n/2; j++){ count+= array[i] * array[i] } } Suppose the code is changed so that the inner loop iterates n/2 times and the outer loop iterates 3*n times. Does that affect how the overall running time scales with the variable n?

No. It is still proportional to N

Even if the distribution of keys is very non-uniform, the hash function is expected to map the keys uniformly to array indices. This means that expected ____ keys should get mapped to any particular index.

O(1)

Given a circular linked list implementation of a queue of size N with a single pointer to the node representing the front of the queue, what is the complexity to perform N dequeue operations?

O(1)

HashInsert , HashDelete , and HashFind will all have expected complexity of what?

O(1)

If you have an array that is sorted from smallest to largest. What is the complexity to find if 50% of the records is bigger/smaller than a certain given record?

O(1)

In big O, how long would it take to access an element of an array of size N.

O(1)

Suppose you are given a number N. What is the best complexity possible for determining if N is greater than some other given number M?

O(1)

What is the complexity for retrieval using Hashing?

O(1)

What is the time required to access an element of an array?

O(1)

What is the complexity required to determine the largest key in an array that is sorted in ascending order?

O(1) - the largest element is in the last element of the array. Of course it's possible to find the largest key by scanning through the array in O(n) time, but a question like this is implicitly asking for the complexity of the best possible algorithm for solving the problem.

What is the complexity of Push() and Pop() in the stack ADT

O(1) and O(1)

In regards to a simple linked list with a single pointer to the head. What is the big O complexity of remove from head and remove from tail.

O(1) and O(N)

Suppose someone asks about the complexity of reading the first 60 integers from a file containing N integers. What is an appropriate answer?

O(1) because the operation takes a constant amount of time.

What is the complexity required to determine whether an array is sorted in either ascending or descending order? (assume that the array is definitely in sorted order)

O(1) for an array of size N - Just compare the first and last elements of the array.

The time required to list all subsets of a set of size N

O(2^n)

How long would it take to access Kth element of an array of size N.

O(K)

Suppose you are told that you will be reading a data file thatwill consist of M lines with P integers per line, and the values of M and P will be provided at the beginning of the data file. What is the computational complexity required to input the data?

O(M*P)

Suppose a program must read M integers from file A, and N integers from file B, and then compute the sum of all the integers from the two files. What is the overall complexity to read the files and compute that sum?

O(M+N)

What expected case complexity does QuickSort have?

O(N log(N))

The time required enumerate all permutations of N distinct symbols (numbers, characters, or whatever).

O(N!)

What is the worst case complexity of shuffleSort?

O(N!)

How much memory is allocated for pointers for a 2D array (int **array)

O(N)

Suppose you are required to read N lines of data from a file, and each line of data contains 72 alphabetic letters. What is the complexity to print all permutations (possible orderings) of the 72 letters in each line?

O(N)

The time required to perform a sequential scan over a list of size N

O(N)

What is the complexity required for an algorithm that takes N datasets, each of which contains 1000 integers, and returns the sum of all of the integers?

O(N) - The computation time depends only on the size of N because the size of each dataset is just a constant.

What is the complexity required to determine whether an array is sorted in either ascending or descending order? (Assume that the array may or not be in sorted order at all)

O(N) for an array of size N - Apply an O(N) test to check whether the values in the array are in ascending order, then check whether it's in descending order. Regardless, the time spent to perform the two O(N) tests is still O(N).

What is the complexity required to determine whether an array is sorted in ascending order?

O(N) for an array of size N - Just check that no element is larger than the one that follows it.

What is the worst case complexity of HashInsert, HashDelete and HashFind?

O(N) for the unlikely case in which most of the keys are hashed to the same index

Suppose someone asks about the complexity of reading a character string from a file. What is an appropriate answer?

O(N) where N is the number of characters in the string. Or O(S)

The time required by the most efficient sortingalgorithms to sort N elements.

O(N*log(N))

TreeSort using data that has been shuffled into random order is said to have a randomized complexity of _______

O(N*log(N))

Explain treeSorts complexity?

O(N*log(N)) In the worst case in which the N values in the array are already in sorted order, treeInsert will produce a degenerate tree that is essentially a linkedlist. This means that each insertion will require O(N) time. Because O(N) insertions are performed, the overall complexity is O(N^2). However, if the values in the array are in random order, then the resulting BST will tend to be balanced and the expected insertion time will be O(log N), so the overall computational complexity is expected O(N*log(N)).

If the heap is to be used for sorting, then a balanced tree representation of a heap can be constructed in O(N) time, and the retrieval of each of the N keys in rank order takes _________ What is this sorting algorithm called?

O(N*log(N)) - HeapSort

It takes O(N) time to compare two character strings that each have O(N) length. Given a sorted array of N character strings, each of length N, what is the complexity to determine whether a given character string of length N is in the array?

O(N*log(N)) - Since the array is in sorted order we can use binary search which is O(log(N)). Each comparison of a string takes O(N) times. This means the overall complexity takes O(N*log(N)). If the comparison takes O(1) time (like comparing two integers) the overall complexity would just be O(log(N))

Searching a sorted NxN 2d array complexity (answer + explanation)

O(N*log(N)). Each row can be searched using binary search which we know takes O(log(N)) time. If we have multiple arrays that need sorted it will be proportional to the number of arrays which is O(N). So therefore we execute O(log(N)) - O(N) times. Which is O(N*log(N))

Suppose an algorithm can be broken into the following steps: 1. Read N data items from a file. This takes O(N) time. 2. Compare each data item to every other item to identify andremove any duplicates. This takes O(N^2) time. 3. Output the distinct data items (no duplicates). This takes O(N) time. What is the complexity of the overall algorithm?

O(N^2)

Suppose you are given an array with N rows and N columns. How long will it take to initialize all elements of the array to zero?

O(N^2)

Suppose you are given an array with N rows and N columns. How much space does the array occupy?

O(N^2)

The time required to compare every element of a set of size N with every other element.

O(N^2)

What is the complexity of Bubble Sort?

O(N^2)

What is the complexity of insertion sort?

O(N^2)

Printing all the values of a 2D array complexity (answer + explanation)

O(N^2) - This is because if we sequentially print one row it will take O(N) times. However, since we have N number of rows to be printed the O(N) is multiplied by O(N) because are multiple rows to be printed.

for (i = 0; i < n; i++){ for (j = 0; j < n; j++){ //This part takes O(1) time } } What is the total time taken?

O(N^2) because each loop repeats with respect to N which means the complexity does O(N) operations O(N) times or N*O(N) which is O(N^2)

What is the complexity to perform a mix of O(N) insertions and O(N) delete-min operations using a simple linked listimplementation of a priority queue?

O(N^2) because one of the operations will have O(1)complexity and the other will have O(N) complexity. That means that the complexity will be determined by the time required to perform the O(N) operation O(N) times.

Given a 2D integer array what is the complexity to sort all of the rows?

O(N^2*log(N))

Given a NxNxN 3-dimensional integer array. What is the complexity to determine if a given number N is in the array.

O(N^3) because each array is O(N) to traverse and three of them would take O(N*N*N) which is O(N^3)

The time required to compare every element in an NxN array to every other element

O(N^4)

What is the complexity required to read a set of S numbers from a file?

O(S)

If you are inserting into a sorted linked list what is the efficiency to insert the Kth key?

O(k)

What is the complexity to return the kth smallest key in a linked list containing N keys in ascending order?

O(k) - this is because the time it takes is proportional to the number (k) which could be very small or large. Since the linked list takes O(N) to traverse as a whole

What does the following code segment do? mysteryFunc ( BST tree ) if tree is Null, then return; mysteryFunc ( tree->left ); mysteryFunc( tree->right ); print content of tree->info;

Postorder printing of a BST

Summarize insertion sort

Scan a sorted list until you reach its end or find a key that is larger than the one you're trying to insert, then insert the new key at that point

What is Preorder and Postorder traversal useful for?

Preorder and Postorder traversals are often used for writing the content of a BST so that it can be read back and reconstructed later.

What does the following code segment do? mysteryFunc ( BST tree ) if tree is Null, then return; print content of tree->info; mysteryFunc ( tree->left ); mysteryFunc( tree->right );

Preorder printing of a BST

What does inorder print do in a BST?

Print all of the values that are less than the value in the root in sorted order; Then print the value in the root node; Then print all the values that are greater than the value in the root in sorted order.

What does the following code segment do? Node *list, *p; for(p=list; p!=NULL; p=p->next;) printf("%d\n",p->info);

Printing out a linked list

What ADT implementation would be best for a CPU and why?

Priority Queue. A line would be created for the CPU operations to handle. Some items might have a higher priority than others so it will be handled accordingly.

Heap order supports ____________ operations with optimal complexity.

Priority queue

Explanation of a Priority Queue

Priority queue is determined by a set rank. You can be the first item placed into a PQ but someone else with a higher-priority might leave (dequeue) before you.

What should a good hash function do?

Produce a random mapping of keys to array indices. This is useful because we can then assume that the keys are mapped uniformly into the array.

What operations are commonly used with the stack ADT?

Push() and Pop()

Which of the following is most associated with expression "first come, first served"?

Queue

Explanation of a Queue

Queue is determined by positioning. I.E. the first one put into the Queue will be the first to exit the queue. FIFO

Algorithm for inserting into a binary search tree?

REPEAT: If top is an empty tree, then set it equal to the node containing m. Return. If top is not empty, then compare m to the key stored in the root. If m is less than the key in the root, then set top equal to the left subtree; otherwise set top equal to the right subtree.

What is a way to ensure randomness in treesort?

Randomly permute the order of the elements to be sorted

Description of MergeSort?

Recursively divide the array in half and sort each half

Description of QuickSort?

Repeatdely partition the array around a pivot

Description of selection sort?

Repeatedly extract the min/max element

Description of InsertionSort?

Repeatedly insert the next element in sorted order

Description of BubbleSort?

Repeatedly move the maximum of the array to the end.

What ADT implementation would be used to create an "Undo" button?

Stack (LIFO)

How do we store a collection of values in a data structure so that a membership function can be efficiently supported?

Store it sorted by a particular value to exploit binary search

What does binary search assume?

That the list is in a sorted order

What is the best general way to deal with duplicate keys in a BST?

The best general way to deal with duplicated keys is to store all copies of a given key with only a single node in the tree

This code segment is using a linked-list with a pointer to the tail and the head. What is the code doing/accounting for? if(h->tail == NULL) h->head = h->tail = p; else{ h->tail->next = p; h->tail = p; }

The code checks if the tail is NULL which means the list is empty. If the list is not empty then add at the tail.

The practical efficiency of an algorithm is determined by what?

The needs of a particular application

What are the requirements for returning the Kth item from a linked-list?

The pointer has to point before the Kth node you want to remove.

RangeCount ( array, 10, 30 ) - asks to return/retrieve all keys between 10 and 30. What can be said about the complexity of this?

The query can be satisfied by using binary search to find the index of the smallest key satisfying the query, and again to find the index of the largest key satisfying the query. A simple subtraction of the two indices (plus 1) gives the answer. Complexity: O(log(n))

What is good practice to allow user to access elements of a structure?

The use of get and set functions. This will enable the user to access elements of a struct without accessing them directly.

What is Big-O only concerned with?

The worst case possible

Which of the following statements is false?

The worst-case complexity of Insertion Sort is the same as that of Merge Sort.

Suppose the university wants to create an app that will automatically determine the best schedule of classes and classrooms each semester. It is a very complex problem because some classes have a large number of students while some have just a few; some classes meet on MWF while others meet on TTh; and some classes have to be held in classrooms with special equipment. Carla implements an algorithm that she is positive is correct. She is asked whether it will work when there are hundreds of different classes and classrooms. She says she's tested it extensively with 10 classes and 15 classrooms, and in all cases it took only a few minutes to run on her laptop What can we conclude about the suitability of Carla's program for actual use by the university?

There's no way to know from the information she's provided. Her program may take a few minutes or it may take months to run if applied with hundreds of classes and classrooms.

In regards to a linked list with a pointer to the head and tail. What is the big O complexity of add at head and add at tail?

They are both O(1)

What is a collection ADT?

They are commonly referred to as "Containers". They provide useful means for storing a group of objects so that useful operations could be applied.

Big O Notation (definition)

This is the notation to describe (the worst case) complexity of a given algorithm. How does the algorithm scale over a certain dataset? Examples of BigO or (Big-Oh): O(1) - constant time O(N) - time proportional to size N

What does insertion sort do?

To sort the following set of numbers, Insertion Sort takes each successive element from a given list and then scans the destination list for its position in sorted order

What is an alternative of inserting into a heap when not keeping track of the size of each subtree?

Tossing a coin at each node to decide whether to insert in the left subtree or the right subtree. This will tend to enforce balance on average.

A linked list can be efficiently sorted in O(n log(n)) time.

True

For most n, O(log(n)) time complexity is indistinguishable from constant time complexity.

True

True or false: The hash array (or hash table) cannot be used for satisfying any other queries, or for sorting, because there is no relationship between the ordering of the input keys and the ordering of their corresponding hash values.

True

True or false: In many cases the best implementation of an ADT will involve a combination of different data structures

True

True or false: No such search algorithm can have aworst-case complexity better than O(log N)

True

True or false: The choice of algorithm depends critically on the structure of the data.

True

True or false: For virtually all practical purposes, randomized complexity is as good as worst-case complexity because the expected performance does not depend on the particular sequence of data

True Worst-case complexity is sometimes preferred in real-time applications in which it is essential to strictly bound the absolute running time of the routine, but often concerns about expected-time/randomized complexity are unfounded.

An efficient hash table can still be built even if the hash function is imperfect (IE: it might generate the same hash key for two distinct values in the input range).

True Yes, if the hash function is imperfect (which is more often the case than not), we can resolve collisions efficiently by chaining using linked lists or trees. It is only required that the hash function has a sufficiently low collision rate given the input range. It is rare that a hash function on real-world input is perfect (IE: does not produce collisions).

True or false: The process of removing the maximum element in a heap takes time proportional to the height of the tree. What is the complexity?

True: O(log(N))

Will changing which end of a linked-list is the front/rear affect the complexity?

Yes

In the case of a circular linked list, can you perform dequeue?

Yes - because if the list is circular we have access to the rear pointer by using "rear" and the rear also points to the head which we access by using "rear->next" this would make complexity of dequeue O(1) time. In the case of maintaining a Queue with pointers to the head and rear. Complexity would be O(N) for dequeue. This is because we do not have direct access to the node before it. Which we need in order to update the tail pointer.

The length of the longest path in a tree defines the ________ of the tree.

height

What is a recursive call at the end of a function called?

tail recursion

Algorithm for freeing a BST?

void DeleteTree(Tree *t) { if (t == NULL) return; DeleteTree(t->left); DeleteTree(t->right); free(t); }


Related study sets

IB Business Management Topic 4. Marketing - ALL

View Set

Physics 100A multiple choice final

View Set

Vicroads Vic Roads Australia Practice Learner Permit Test

View Set

Chapter 31: Skin Integrity and Wound Care

View Set

ATI Dynamic Quiz: Comprehensive Final

View Set

Med Surg: Chapter 35 Heart Failure

View Set