1 Below are five computational tasks For each one choose the
1. Below are five computational tasks. For each one, choose the data structure or abstract data type you feel best suited to the task from the following list: Stack, Queue, Hashtable, AVL Tree, Priority Queue, Union-Find. In addition, list the basic operations for the data structure or ADT that you chose and give asymptotic worst-case running times for those operations. No additional explanation is required.
a) While processing a list of objects, check if you have processed a particular object before.
b) Store a list of students and their grades. You must also provide an efficient way for a client to see all students sorted in alphabetical order by name. Give the running time for this operation as well.
c) Process a digital image to divide the image up into groups of pixels of the same color.
d) Compute a frequency analysis on a _le. That is, count the number of times each character occurs in the file, and store the results.
e) Store the activation records (i.e. objects containing the return address and local variable associated with a function call) for nested function calls.
f) What is log2(1; 000; 000; 000) to the nearest whole number?
g) Your friend says she does not like implementing algorithms that have amortized run-time guarantees because amortization makes it harder to debug her code. Why does this argument make no sense? (A one sentence answer is probably enough.)
Don\'t just answer one letter plss. I dont want to post this question again.
Solution
a) While processing a list of objects, check if you have processed a particular object before.
For this you will use hashtable as you can quickly look up value in a hashtable, asymptotic run time for lookup operation is O(1) if proper hash function is choosen.
b) Store a list of students and their grades. You must also provide an efficient way for a client to see all students sorted in alphabetical order by name. Give the running time for this operation as well.
AVL Tree will be best suited to store this data. Reason to choose AVL tree is to quickly get list of students in sorted order.
Basic operation:
insert O(logn) for one insertion
lookup O(logn)
to get list in sorted order after storing O(n) (inorer traversal)
c) Process a digital image to divide the image up into groups of pixels of the same color.
Union-Find: Union find will best suit need here as you can keep sets based on different pixel and can easily find and join them.
d) Compute a frequency analysis on a _le. That is, count the number of times each character occurs in the file, and store the results.
HashTable: in this each entry in hashtable will keep count of charcter seen. Basic operation is insert O(1) and lookup O(1) (time depends on hash function and size of hash table used)