NAME THAT ALGORITHM #2 HERE ARE SOME PROBLEMS. SOLVE THEM. GL HF.

Slides:



Advertisements
Similar presentations
MATH 224 – Discrete Mathematics
Advertisements

Lecture 19: Parallel Algorithms
Analysis of Algorithms
Greed is good. (Some of the time)
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
Dynamic Programming Dynamic Programming is a general algorithm design technique for solving problems defined by recurrences with overlapping subproblems.
Median/Order Statistics Algorithms
Ver. 1.0 Session 5 Data Structures and Algorithms Objectives In this session, you will learn to: Sort data by using quick sort Sort data by using merge.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu.
1 Lecture 25: Parallel Algorithms II Topics: matrix, graph, and sort algorithms Tuesday presentations:  Each group: 10 minutes  Describe the problem,
Analysis of Algorithms CS 477/677
DAST 2005 Week 4 – Some Helpful Material Randomized Quick Sort & Lower bound & General remarks…
Assignment 4. (Due on Dec 2. 2:30 p.m.) This time, Prof. Yao and I can explain the questions, but we will NOT tell you how to solve the problems. Question.
Ch. 8 & 9 – Linear Sorting and Order Statistics What do you trade for speed?
Design Techniques for Approximation Algorithms and Approximation Classes.
Fundamentals of Algorithms MCS - 2 Lecture # 7
Order Statistics. Order statistics Given an input of n values and an integer i, we wish to find the i’th largest value. There are i-1 elements smaller.
1 Network Models Transportation Problem (TP) Distributing any commodity from any group of supply centers, called sources, to any group of receiving.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 7.
Algorithms Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin,
OPTIMAL CONNECTIONS: STRENGTH AND DISTANCE IN VALUED GRAPHS Yang, Song and David Knoke RESEARCH QUESTION: How to identify optimal connections, that is,
© The McGraw-Hill Companies, Inc., Chapter 12 On-Line Algorithms.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
11 -1 Chapter 12 On-Line Algorithms On-Line Algorithms On-line algorithms are used to solve on-line problems. The disk scheduling problem The requests.
DECISION 1. How do you do a Bubble Sort? Bubble Sort:  You compare adjacent items in a list;  If they are in order, leave them.  If they are not in.
Sorting and "Big Oh" ASFA AP Computer Science A SortingBigOh.
Linear Programming Many problems take the form of maximizing or minimizing an objective, given limited resources and competing constraints. specify the.
Clustering MacKay - Chapter 20.
CSC 421: Algorithm Design & Analysis
CSC 421: Algorithm Design & Analysis
Analysis of Algorithms
Searching – Linear and Binary Searches
Recitation 13 Searching and Sorting.
Finding a Path With Largest Smallest Edge
The minimum cost flow problem
CSC 421: Algorithm Design & Analysis
Dynamic Programming Dynamic Programming is a general algorithm design technique for solving problems defined by recurrences with overlapping subproblems.
Data Structures Using C++ 2E
Algorithm Analysis CSE 2011 Winter September 2018.
Analysis and design of algorithm
Types of Algorithms.
Lecture 22: Parallel Algorithms
Binary Search Back in the days when phone numbers weren’t stored in cell phones, you might have actually had to look them up in a phonebook. How did you.
CS330 Discussion 4 Spring 2017.
Linear Programming.
Algorithm design and Analysis
Wyndor Example; Enter data
Enumerating Distances Using Spanners of Bounded Degree
Unit-2 Divide and Conquer
Types of Algorithms.
Bin Sort, Radix Sort, Sparse Arrays, and Stack-based Depth-First Search CSE 373, Copyright S. Tanimoto, 2002 Bin Sort, Radix.
Chapter 3 The Simplex Method and Sensitivity Analysis
Unit-4: Dynamic Programming
Parallel Sorting Algorithms
Matthew Renner, Trish Beeksma, Patch Kenny
Sorting "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting Hat, Harry Potter.
Dynamic Programming 23-Feb-19.
Bin Sort, Radix Sort, Sparse Arrays, and Stack-based Depth-First Search CSE 373, Copyright S. Tanimoto, 2001 Bin Sort, Radix.
CSC 421: Algorithm Design & Analysis
EE5900 Advanced Embedded System For Smart Infrastructure
Types of Algorithms.
Dynamic Programming II DP over Intervals
Chapter 8: Overview Comparison sorts: algorithms that sort sequences by comparing the value of elements Prove that the number of comparison required to.
CS 583 Analysis of Algorithms
CSC 421: Algorithm Design & Analysis
Sorting We have actually seen already two efficient ways to sort:
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Algorithms Tutorial 27th Sept, 2019.
Presentation transcript:

NAME THAT ALGORITHM #2 HERE ARE SOME PROBLEMS. SOLVE THEM. GL HF

DROP DAT EGG You have N identical eggs, and an H story building. You want to determine the highest floor from which you can drop an egg before it breaks. You may continue to re-use an egg until it breaks. What is the minimum number of total drops necessary to determine this?

SOLUTION Dynamic Programming, O(ND), where D is the total number of drops and is on the order of the Nth root of H.

GET DAT VOLUME You are given the faces of a three-dimensional solid, all of whose edges are parallel to the coordinate axes. Determine the volume of this solid.

SOLUTION Only take faces parallel to one of the three coordinate planes, then sort by the remaining coordinate and determine orientation.

RETURN DAT GRID You are given an NxN grid, filled with 0s and 1s. Return an NxN grid where the entry at (i,j) represents the shortest distance from (i,j) to a 1.

SOLUTION O(N^2), do shortest distance for each column separately and use a stack to figure out what row is optimal to use at each row in the column.

PLAY DAT GAME You have a circular game board with N squares. Each spot on the board is marked with an integral point value, and landing at that spot causes you to gain that many points. You start at square 0, and on each turn you can either quit the game or roll a 6-sided die, and go forward the number of squares that appear on the die. Given that the sum of the point values is negative, determine your maximum possible expected value.

SOLUTION O(NC) iterative process, based on Dynamic Programming. Assume that all squares other than the current one are correct, then update that square. The algorithm should eventually converge, so you could either prove a bound on the convergence or just run it for as many iterations as possible.

RANK DOSE GUESTS A number of guests want to stay at a hotel, and each guest has ranked the hotel rooms in order of preference. Minimize the maximally ranked hotel room that a guest has to stay in (a guest would prefer to stay in a hotel room that is ranked lower).

SOLUTION net flow with iterative edge additions, at the ith each stage add in the edges corresponding to the ith ranked hotel room, stop when you get a flow equal to the number of guests.

GIT DAT PROGRESSION Given a set of N integers, determine the first instance of an arithmetic progression of length 3 among them, if one exists.

SOLUTION O(N^2), loop through all possibilities of the first integer in the progression, then compute the second and third simultaneously by incrementing the third position as becomes necessary to keep up with the second position.

IMPLEMENT DOSE EQUATIONS Starting with the equation x = 0, we can perform two operations: (i) Change the left hand side (LHS) to |LHS - k| for some integer k, (ii) ask for the number of solutions to the equation. Write a program that can implement both operations arbitrarily, given that the range of solutions will always remain within [-1000,1000].

SOLUTION Just keep a list and array of all the solutions, should be O(N^2), where N = range of solutions = 2000 in this case.

COUNT DOSE PATHS Given a graph, determine the number of shortest paths.

SOLUTION Just do a normal dijkstra where you keep track of the number of paths at each point as well.

FIND DOSE DIGITS Find the last 6 digits of n choose k for many different n,k <= 1000.

SOLUTION DP on pascal's identity.

GIT DOSE STRINGS Find the number of binary strings of length N not containing a substring of length K.

SOLUTION O(NK) DP.

DUDE THIS IS HARD Given a set of integers, determine the longest arithmetic progression among them.

SOLUTION Solution: sort them and take the differences between consecutive terms, the problem becomes to determine how to partition them into contiguous sets with equal sums. The naieve solution would be to loop through every possible starting place, and then try all guys to take as the next term in the progression, and make the progression as long as possible. This is O(N^3). We can improve upon this by marking off when we have already used a progression as part of another progression that started earlier, so that the total runtime becomes O(number of progressions * average length of progression * average time to find next term). Since the average time to find the next term is O(logN) with a binary search, and each term can be in at most N progressions, this limits our runtime to O(N^2logN).

GIT DOSE INTS Given a list of distinct, unsorted integers, return the number of elements in the list that are binary searchable. An element is binary searchable if, regardless of how the pivot is chosen, the element will be found by the binary search.

SOLUTION O(N^2), We note that an element X is not binary searchable iff there is an element before X larger than it or if there is an element after X smaller than it. It then becomes trivial. (You can DP it but it's a lot more awkward).