[Solved] CSE321 Homework 2

$25

File Name: CSE321_Homework_2.zip
File Size: 160.14 KB

SKU: [Solved] CSE321 Homework 2 Category: Tag:
5/5 - (1 vote)

1)

Apply insertion sort to the following sample array:

Array={6,5,3,11,7,5,2}

Show each step of the algorithm. At each step, you are required to not only create the arrray with its new order, but also explain why you created that sequence.

2) What is the time complexity of the following programs? Explain in detail by providing your reasoning.

  1. a) function(int n){

if (n==1) return; for (int i=1; i<=n; i++){ for (int j=1; j<=n; j++){ printf(*); break;

}

}

}

  1. b)

void function(int n)

int count = 0;

for (int i=n/3; i<=n; i++)

for (int j=1; j+n/3<=n; j = j++) for (int k=1; k<=n; k = k * 3)

count++;

}

  • We have an unordered array in which we are looking for pairs whose multiplication yields the desired numbers. For example, let our array be {1,2,3,6,5,4} and let the desired number be 6. In this case, our pairs will be (1,6) and (2,3). Provide an algorithm that solves this problem with time complexity O(n(logn)). Express your algorithm as pseudocode (write actual code using Python) and prove that its complexity is O(n(logn)).
  • You are given a binary search tree (BST) with n You are required to merge this tree with another n-node BST. What is the time complexity of this process? Explain in detail by providing your reasoning.
  • Suppose that you are given two arrays, where one of them is larger than the other one. Propose a linear time algorithm that finds, if exists, the elements of the small array in the big array. Express your algorithm using pseudocode and calculate the worst case complexity of the algorithm.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSE321 Homework 2
$25