Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. (6 points) A. What is the complexity (big-O) of the following code fragment? for (i = 0; (i < n) || (i < m);

1. (6 points) A. What is the complexity (big-O) of the following code fragment? for (i = 0; (i < n) || (i < m); i++) { sequence of statements } B. We have the following recursive function. Assume you call: something(0, n); find the complexity in terms of n. void something(int b, int e) { if (b >= e) return; int a = 0; for(int i=b; i < e; i++) a++; int k = (b+e)/2; something(b, k); something(k+1, e); } 2. (10 points) Consider this tree and answer these questions: a. Which nodes have degree 2? b. What is the depth of M? c. What is the height of M? d. Which nodes are leaf nodes? e. What is the pre order traversal of the tree? 3. (6 points) a. Is the following array a binary heap? [10, 3, 5, 1, 4, 2] (explain it) b. Draw a max-heap on the following set of integers: {2, 3, 5, 7, 11, 13, 17} (you do not need to use Build-heap algorithm) 4. (6 points) Compare the following sorts in terms of time and space complexity. - Quicksort - Mergesort - Heapsort 5. (4 points) What is the definition of perfect binary tree? What is the definition of complete binary tree? 6. (8 points) Assume you have a hash-table of size 7 and you want to insert these items (in the given order) into the hash-table (using double hashing). Show that how many probes are required to insert these items (in the given order): 51, 40, 69, 5, 55 7. (10 points) Write a code for merging two sorted arrays (L1 and L2). This is the signature of the method: (the result should be stored in array res) void merge(Comparable[] res, Comparable[] L1, Comparable[] L2); What is the time complexity?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

9-9. Is the hard sell approach unethical? Why or why not? [LO-2]

Answered: 1 week ago

Question

9-5. What is the AIDA model, and what are its limitations? [LO2]

Answered: 1 week ago