Question: 2. CSc 220: Algorithms Homework 3 n Class on Thursday September 28 sheet. Plense staple maltiple sheets together write the solution on your you written
2. CSc 220: Algorithms Homework 3 n Class on Thursday September 28 sheet. Plense staple maltiple sheets together write the solution on your you written on sheet(s) of paper with' mollaboralkin wulal anno- naltiple shevts tog thens. Rearemlars your natse anxd CSe230 written at the top of ench own. Also yo e that collaboration is allowed, but that yoxs must ua ust acknowledge all collaborators and all sources (other than the Problem 1: Oa input an array A of n eleeuts, each of which is an integst in method for sorting A in O(n) time Hint: think of altereative s of neving the clements j0., dee ribe a simple Problem 2: As we will see later in the class, a inary search tree (DST) ls a binary tree where ench node r holds a value keylrl. The importa of a BST rooted at , we have that kepla] is larger than structure organized as a of a BST is that for any suhtree the keys of all the nodes stored on the left su thin the keys of all the bodes stored on the right subtree z. An interesting con-quetxe in the tree of this is that by pertorming an inorder" walk of the tree it is possible to out put the keys stored t in sorted order. An inorder walk of the tree rooted at z is the following recursive proerdure INORDER() INORDER Leftal) PRINT key(r): INORDER(Rightz) Notice that INORDER makes no comparisoas since it only reads t Given n elements can you build a BST containing the elements using O(n) comparisons? If yes be elements in the tree in a specific your algorithm. If no, explain why you think it is impossible. Problem 3: Given to arrays A and B each of them containing n elenents, already in sorted onder. Describe a O(log n) algorithm that finds the median of all 2n elements in the arrays
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
