What is the order of growth of its worst-­-case running time

Assignment Help Computer Engineering
Reference no: EM131263130

Algorithms Project - If any question seems ambiguous, you may add an explanation for your answer.

1. Analysis of algorithms.

(a) Tilde notation is more precise than Big-­-Oh notation at describing the growth of a function because:

I. Tilde notation includes the coefficient of the highest order term.

II. Tilde notation provides only a lower bound on the growth of a function.

III. Big-­-Oh notation suppresses lower order terms, so it does not necessarily accurately describe the behavior of a function for small values of N.

Select the best answer.

(a) I only.

(b) I and II only.

(c) I and III only.

(d) I, II and III.

(e) None.

(b) Consider the following code fragment.

int count = 0;

for (int i = 0; i < N; i++)

for (int j = i+1; j < N; j++) for (int k = j+1; k < N; k++)

if (a[i] + a[j] >= a[k]) count++;

1. Suppose that it takes 2 seconds to execute this code fragment when N = 1000. Using tilde notation, express a hypothesis for the number of array accesses of the code fragment as a function of N.

2. Suppose that it takes 2 seconds to execute this code fragment when N = 1000. Using tilde notation, express a hypothesis for the running time (in seconds) of the code fragment as a function of N.

2. Sorting algorithms.

The column on the leU is the original input of strings to be sorted; the column on the right are the string in sorted order; the other columns are the contents at some intermediate step during one of the 8 sorting algorithms listed below. Match up each algorithm by writing its column number aUer the corresponding leXer and sort name. Use each column exactly once.

Input

1

2

3

4

ti

6

7

8

Sorted

COS

ARC

ARC

ARC

COS

ART

CHM

CHE

REL

ARC

PHY

CHE

CHE

ART

COS

CEE

ART

COS

PHY

ART

ELE

COS

COS

CEE

ELE

CHM

ARC

CHM

PHY

CEE

COS

COS

COS

CHE

PHY

ARC

CEE

COS

ELE

CHE

MAT

ECO

ECO

CHM

ARC

COS

CHE

COS

PHI

CHM

MOL

ELE

EEB

COS

LIN

CHE

COS

ART

ORF

COS

LIN

GEO

ELE

COS

MAT

EEB

COS

CEE

ORF

COS

ARC

LIN

ELE

COS

MOL

COS

COS

ARC

COS

COS

ECO

MAE

ENG

COS

CHE

COS

COS

COS

ELE

COS

CHE

MAT

GEO

COS

ECO

COS

COS

COS

EEB

COS

MAE

MOL

LIN

COS

GEO

EEB

COS

MAE

MUS

COS

GEO

PHY

MAE

ECO

MAE

COS

ORF

GEO

GEO

ECO

ORF

ORF

MAT

ORF

EEB

COS

EEB

ORF

ORF

EEB

EEB

EEB

MOL

EEB

ELE

ELE

ENG

EEB

MAT

EEB

ENG

ENG

ORF

ENG

ENG

MAE

ELE

ENG

LIN

ELE

ELE

ELE

PHY

ELE

ORF

ELE

GEO

ELE

COS

ELE

COS

COS

ART

MOL

CEE

ECO

ELE

ECO

COS

ELE

ELE

ELE

CEE

ELE

COS

ENG

MAE

ELE

ECO

ENG

CEE

CEE

COS

ELE

EEB

MAT

EEB

LIN

CEE

GEO

EEB

EEB

EEB

EEB

ELE

LIN

ECO

EEB

CHE

LIN

ART

ART

ELE

PHY

ART

ELE

MUS

MOL

ART

MAE

MUS

MUS

MUS

MUS

MUS

MUS

PHI

MUS

MAT

MAT

PHI

PHI

ORF

PHI

ORF

MAT

ORF

PHI

MAE

MAT

ORF

ORF

PHI

ORF

PHI

ORF

LIN

ORF

ELE

MOL

COS

COS

COS

GEO

COS

GEO

PHY

MAT

COS

MUS

PHY

PHY

PHY

PHY

COS

ORF

MOL

PHY

MOL

ORF

COS

COS

COS

LIN

MAT

MOL

MAT

COS

COS

ORF

MAT

MAT

MAT

MAT

PHY

PHY

MAT

MAT

EEB

ORF

CHM

CHM

CHM

MAT

CHM

ORF

ORF

ELE

CHM

PHI

ORF

ORF

ORF

ORF

COS

PHY

ELE

ORF

ENG

PHY

COS

COS

COS

MAE

ORF

PHI

REL

PHY

COS

PHY

REL

REL

REL

REL

REL

REL

PHY

REL

ARC

REL

Input

1

2

3

4

ti

6

7

8

Sorted

(a) Selection sort

(b) Insertion sort

(c) Shell sort (13-­-4-­-1 increments)

(d) Merge sort (top-­-down)

(e) Merge sort (boXom-­-up)

(f) Quick sort (standard, no shuffle)

(g) Quick sort (3-­-way, no shuffle)

(h) Heap sort

Extra credit (just a bit): why don't f and g make use of a shuffle?

 3. Binary heaps.

Consider the following max-­-heap.

224_Figure.png

(a) The max-­-heap above result edaUera sequence of insert and remove-­-the-­-maximum operations. Assume that the last operation was an insert. Which key(s) could have been the one inserted last? Circle all possible keys.

A             E              H             I               J              K             M            O             R             S              T

(b) Draw the heap that results aUer deleting the maximum key from the heap above.

4. More sorting.

(a) Modern computers have memory caches, which speed up reads and writes if they are to locations near recently-­-accessed memory. This makes sequential access to memory faster, in general, than random access. Circle the sorting algorithm below that you would expect to benefit most from caching? (Then explain why you chose that sort.)

inserHonsort      mergesort           quicksort             heapsort

(b) You are managing the accounts for BigIBankCo, and have an array of customers together with their balances. You would like to rearrange the array such that the richest customers (those with balances greater than $1 million) are grouped at the beginning, with everyone else at the end.

Describe an algorithm for performing this task (preferably in linear time, and using only constant extra memory). If you can, adapt an algorithm from the textbook and describe only the changes you would make.

5. Priority queues.

Consider the following code fragment.

MaxPQ<Integer> pq = new MaxPQ<Integer>(); int N = a.length;

for (int i = 0; i < N; i++) { pq.insert(a[i]);

if (pq.size() > k) pq.delMax(); /* MARK */

}

for (int i = 0; i < k; i++) System.out.println(pq.delMax());

Assume that  a[]  is an array of integers,  MaxPQ  is implemented using a binary heap, and N ≥ k ≥ 1.

(a) What does it output?

(b) What is the order of growth of its worst-­-case running time? Circle the best answer.

k log k   k logN   N log k  N logN  N2

Now suppose the marked line was deleted. Repeat the previous two questions.

(c) What does it output?

(d) What is the order of growth of its worst-­-case running time? Circle the best answer.

k log k   k logN   N log k  N logN  N2

 6. Data structures.

Given an N-­-by-­-N grid of sites, you wish to repeated select a site (i; j) at random among all sites not yet chosen. Consider the following code fragment for accomplishing this task.

ArrayList<Integer> sites = new ArrayList<Integer>(); for (int id = 0; id < N*N; id++) { // for each site, sites.add(id); // add to end of list

}

while (!sites.isEmpty()) {

int n = sites.size(); // number of elements left in list int r = StdRandom.uniform(n); // between 0 and n-1

int id = sites.remove(r); // remove and return item at index r int i = id / N, j = id % N; // site (i, j)

...

}

(a) The java.util.ArrayList data type is implemented using an array (with doubling and halving). What is the order-­-of-­-growth of the worst-­-case running time of the code fragment as a function of N? Select the best answer.

N             NlogN   N2           N2logN  N3           N4           2N

(b) Assuming you have to choose an alternative implementation, which data structure that we've encountered in this course might you use instead of java.util.ArrayList? Select an answer and explain why you choseit.

i. union-­-?nd

ii. stack /queue

iii. deque

iv. randomized queue

v. binary heap

(c) For your version in (b), what is the order-­-of-­-growth of the worst-­-case running time as a function of N? Circle the best answer.

N             NlogN   N2           N2logN  N3           N4           2N

(d) For your version in (b), what is the order-­-of-­-growth of the best-­-case running time as a function of N? Circle the best answer.

N             NlogN   N2           N2logN  N3           N4           2N

(e) For your version in (b), what is the order-­-of-­-growth of the average-­-case running time as a function of N? Circle the best answer.

N             NlogN   N2           N2logN  N3           N4           2N

7. Generalized queue.

Design a data structure that supports the following API for a generalized queue.

Generalized queue API

public class GQ<Item item>

GQ() create an empty generalized queue

Item get(int i) return the ith item from queue

void addFirst(Item item) insert item at the front of the queue void addLast(Item item) append item to the end of the queue Item remove(int i) remove the ith item from the queue

Here is a sample client, showing the contents of the queue aUer each insertion / deletion.

GQ<String> gq = new GQ<String>(); gq.addFirst("A");    //A

gq.addFirst("B");              // BA

gq.addLast("C");               // B AC

gq.addLast("D");              // B A CD

gq.addFirst("E");              // E B A CD

gq.addFirst("F");              // F E B A CD

gq.addLast("G");              // F E B A CD G

String s1=gq.get(2);        // s1= "B"

gq.remove(2);   // F E A CD G

String s2=gq.get(2);        // s2 ="A"

Try to produce an efficient data structure (implement all operations in logarithmic time or beXer as a function of the size of the queue). Solutions will be graded for correctness, clarity, efficiency, and conciseness.

Alternatively, describe a data structure that implements all operations except remove in constant amortized time.

(a) Describe the underlying data structure.

(b) Draw it aUer the ?rst 7 insertions for the example above.

(c) Describe how to implement get().

(d) Describe how to implement addFirst() and addLast().

(e) Describe how to implement remove().

Reference no: EM131263130

Questions Cloud

Application of u.s. law to the business sector : Term Paper ACC 538 - You are encouraged to research a topic of your choosing related to the application of U.S. law to the business sector and elements and defenses for each of the common law torts.
What is total cost of the job when it is completed october : Job A3B was ordered by a customer on September 25. During the month of September, Jaycee Corporation requisitioned $2,500 of direct materials and used $4,000 of direct labor. The company applies overhead at the end of each month at a rate of 200% of ..
Inequality and the marginal propensity to consume : According to the study by Chris Carroll et al cited in article #17a by Nick Bunker ("Wealth Inequality and the Marginal Propensity to Consume") middle-income families have a larger mpc than do wealth families. In which case below would the multipl..
What is the importance of research in behavioral sciences : What is the relationship between applied research and basic research? Provide an example from your selected studies, of how each contributes to the body of knowledge. What ethical issues can you identify in the selected articles? How were the issue..
What is the order of growth of its worst-­-case running time : CSC482 Algorithms Project. Assume that  a[]  is an array of integers,  MaxPQ  is implemented using a binary heap, and N ≥ k ≥ 1. What does it output? What is the order of growth of its worst-­-case running time? Circle the best answer
Do you believe that men and women lead differently : Do you believe that men and women lead differently? - Do you believe results differ when men coach women's college teams?
Describe your three selected cultural products : Write a 700- to 1,050-word personal essay that describes your three selected cultural products. In what ways did your examples shape, change, or reinforce your own cultural values?
Which situational leadership model do you prefer : Find three additional leadership quotes attributed to Vince Lombardi at www. vincelombardi.com. - Which situational leadership model do you prefer? Why? Will you use it? Why or why not?

Reviews

len1263130

11/2/2016 5:10:01 AM

Submit your answers to the above questions organized very clearly. If I can’t tell what your answer is or which question you are answering, I can’t give you credit. You may answer your questions in an electronic document or you can answer on paper and then scan those answers in to submit them via D2L. But I must be able to read it, and know which answer goes with which part of which question. There is no need for a proctor. There is no time limit. But I will not accept late submissions. Do not wait until the last minute. Submit your solutions, then if you can answer more questions before the due date and time, submit an update to your answers.

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd