Submission by Nov 5th 6:00pm PT CS5800 Homework5 Requirements 1. Use greedy strategy wherever needed. 2. Note all edge cases 3. Solve for the questions asked 4. Be mindful of the variable names 5....

1 answer below »
I'd like a quotation for this assignment for my algorithms course. Proper code is not required, mostly pseudocode, runtime analysis along with detailed explanations for each question.



Submission by Nov 5th 6:00pm PT CS5800 Homework5 Requirements 1. Use greedy strategy wherever needed. 2. Note all edge cases 3. Solve for the questions asked 4. Be mindful of the variable names 5. Comment your pseudo code 6. Give runtimes in big O notation Problem 1 Minimum airport gates open (25pts) An airport has to decide the minimum number of gates to keep open depending on the schedules of flights arriving and departing at a given day. Given arrival and departure times of all flights, and the total number of available gates for that airport, on day X, give an algorithm that finds the minimum number of gates to keep open for that day. No flight should be kept waiting. Provide time and space complexities. (25pts) Problem 2 Find if present (25 pts) A binary tree is constructed with the following rules Now the binary tree is polluted, in that all treeNode.val have been changed to -1 Write a function FindIfPresent that takes a value and the polluted tree and returns True if and only if the value is present in the recovered tree. Provide time and space complexities. class TreeNode(object): def __init__(self, val=None, left=None, right=None): self.val = val self.left = left self.right = right root.val = 0 If treeNode.val == x and treeNode.left != null, then treeNode.left.val == 2 * x + 1 If treeNode.val == x and treeNode.right != null, then treeNode.right.val == 2 * x + 2 -1 0 / \ recovered to / \ -1 -1 1 2 / \ / \ -1 -1 3 4 Problem 3 Sell stocks (25pts) Mark wants to know how much money he could have made yesterday if he had been trading Amazon stocks all day! So he looked at the volatility of Amazon stock prices from yesterday and put them in an array of tuples called : AmznPrices AmznPrices = [ (time1, price1), (time2, price2), (time3, price3)…. (timen, pricen) ] Where time1, time2… timen are the number of minutes past the opening time. If the opening time is 9:00am EST, and time1 = 30, then it refers to 9:30 am EST. price1, price2…., pricen : is the price for one share of Amazon stock at that time. Write an efficient method that takes AmznPrices and returns the best profit Mark could have made from one purchase and one sale of one share of Amazon stock yesterday. Think of all edge cases!! Provide time and space complexity of your algorithm Problem 4 Best Party (25 pts) It’s Natalie’s birthday and she decides to host the best party ever. She puts together a list of her n friends. She also knows which of her friends knows whom and she decides to use this info to design an awesome social party. Natalie decides it would be best to invite the maximum number of friends possible with following constraints. At the party, each person should know at least 4 people and they should also NOT know at least 4 people. Design an efficient algorithm that takes the list of n people and the list of pairs who know each other and outputs the best choice of party invitees. Provide the time and space complexity of your algorithm. Requirements Problem 1 Minimum airport gates open (25pts) Problem 2 Find if present (25 pts) Problem 3 Sell stocks (25pts) Problem 4 Best Party (25 pts)
Answered 3 days AfterNov 03, 2021

Answer To: Submission by Nov 5th 6:00pm PT CS5800 Homework5 Requirements 1. Use greedy strategy wherever...

Shubham Kumar answered on Nov 06 2021
117 Votes
Problem 1 : Minimum Airport Gates Open
Algorithmic Approach :
Let us assume that the arrival and departure times of the flights are provided in two separate lists of the same now.
Also, the arrival and departure times are 4 digit number, i.e. 2259 represents the time 10:59 PM. The maximum value in both the lists can be 2359, and the minimum value can be 0. Then we create a list, named count, having 2400 0 stored in it. Now we start our algorithm :
Step 1 : We iterate over the arrival list, and do the following :
        count[arrival[i]] = count[arrival[i]] + 1
Step 2 : We iterate over the departure list, and do the following :
        count[departure[i]] = count[departure[i]] - 1
Step 3 : We do cumulative addition over the count list, i.e. :
        count[i] = count[i]+count[i-1]
Step 4 : The maximum value stored in count list will give us the minimum number of gates that are required to be opened
Pseudocode :
def solve(arrival, departure) :
count = [0] * 2400     // initialized the count array
// iterate over the arrival and departure arrays
for val in arrival :
count[val] = count[val] + 1;
for val in departure :
count[val] = count[val] - 1;
    //iterated over the count array, doing cumulative addition, and storing the maximum value
gates = -1;
start = 1;
while(start<2400) :
count[start] = count[start] + count[start-1]
gates = max(gates, count[start]);
    //returns the minimum number of gates required to be open
return gates;
Complexity Analysis :
We are iterating over the arrival and departure list’s once, and then we are iterating over the count array once, hence, the Complexity of the solution will be O(n + 2400), which can be reduced to O(n) , where n is the number of flights.
The space complexity will be O(2400) as...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here