Aideen NasiriShargh Nima Ahmadi Pour Anari SaeedReza Seddighin.

Slides:



Advertisements
Similar presentations
Chapter 5: Tree Constructions
Advertisements

Chapter 9 Greedy Technique. Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible - b feasible.
Lecture 15. Graph Algorithms
22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
Analysis of Algorithms
EECS 4101/5101 Prof. Andy Mirzaian. Lists Move-to-Front Search Trees Binary Search Trees Multi-Way Search Trees B-trees Splay Trees Trees Red-Black.
Binary Trees CSC 220. Your Observations (so far data structures) Array –Unordered Add, delete, search –Ordered Linked List –??
Greedy Algorithms Greed is good. (Some of the time)
Greedy Algorithms Clayton Andrews 2/26/08. What is an algorithm? “An algorithm is any well-defined computational procedure that takes some value, or set.
Prof. Sin-Min Lee Department of Computer Science
Great Theoretical Ideas in Computer Science for Some.
1 Discrete Structures & Algorithms Graphs and Trees: III EECE 320.
Minimum Spanning Trees Definition Two properties of MST’s Prim and Kruskal’s Algorithm –Proofs of correctness Boruvka’s algorithm Verifying an MST Randomized.
3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.
Advanced Topics in Algorithms and Data Structures 1 Rooting a tree For doing any tree computation, we need to know the parent p ( v ) for each node v.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
ASC Program Example Part 3 of Associative Computing Examining the MST code in ASC Primer.
Data Structures & Algorithms Radix Search Richard Newman based on slides by S. Sahni and book by R. Sedgewick.
Backtracking.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
Important Problem Types and Fundamental Data Structures
CSE 373 Data Structures Lecture 15
Adapted from slides by Marie desJardins
Instructor: Dr. Sahar Shabanah Fall Lectures ST, 9:30 pm-11:00 pm Text book: M. T. Goodrich and R. Tamassia, “Data Structures and Algorithms in.
Data Structures and Algorithms Graphs Minimum Spanning Tree PLSD210.
Approximating the MST Weight in Sublinear Time Bernard Chazelle (Princeton) Ronitt Rubinfeld (NEC) Luca Trevisan (U.C. Berkeley)
Graphs CS 400/600 – Data Structures. Graphs2 Graphs  Used to represent all kinds of problems Networks and routing State diagrams Flow and capacity.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
Graphs 2 Kevin Kauffman CS 309s. Problem We have sprinklers in our yard which need to be connected with pipe. Assuming pipes may only intersect at sprinkler.
Data Structures - CSCI 102 Binary Tree In binary trees, each Node can point to two other Nodes and looks something like this: template class BTNode { public:
Computer Arithmetic Nizamettin AYDIN
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Chapter 2 Graph Algorithms.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Algorithm Paradigms High Level Approach To solving a Class of Problems.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
Lectures on Greedy Algorithms and Dynamic Programming
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
CHAPTER 8 SEARCHING CSEB324 DATA STRUCTURES & ALGORITHM.
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
Minimum- Spanning Trees
Tutorial 9 Iteration. Reminder Assignment 8 is due Wednesday.
1 CPSC 320: Intermediate Algorithm Design and Analysis July 14, 2014.
Randomized Min-Cut Algorithm
Graphs Representation, BFS, DFS
Greedy Technique.
MCS680: Foundations Of Computer Science
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
CS2210:0001Discrete Structures Induction and Recursion
Sorting.
Graphs Representation, BFS, DFS
Minimum Spanning Tree.
Trees Lecture 9 CS2110 – Fall 2009.
Kruskal’s Minimum Spanning Tree Algorithm
Backtracking and Branch-and-Bound
ITI Introduction to Computing II Lab-12
Minimum Spanning Trees (MSTs)
Presentation transcript:

Aideen NasiriShargh Nima Ahmadi Pour Anari SaeedReza Seddighin

Problem A: A Decimal Number  The range of an int is [-2,147,483,648, 2,147,483,647]  Note: abs(MIN_INT) (that is 2,147,483,648 ) does not fit in an int !  Another Solution: read it as a string!

Problem B: Bold, Italic, Underline  A Good Solution: Recursive Parsing  string fix(string input, int mask) can take an input string and fix it. Mask can be a 3 bit int, standing on B, U or I-ness of the exactly (adjacent) outer tag.  If input is something like “ [inner] ” (where these X’s are matching tags) call fix([inner], mask | (1<< (x’s id)).  Otherwise, if input is not of that kind and mask is not zero, write mask’s implementation around the input. E.g. fix(“a hi z”, 1) may return “ ” + ”a” + fix(“ hi ”,0) + ”z” + “ ”;

Problem C: CapsLock  A boolean variable to hold if it CapsLock is ON or off.  Walk through the text and write non-! Ones.

Problem D: DMail!  Why making the priority twice and hold only powers of 2? Just keep log(priority) that would be a number between 1 and 126 and works properly!  set > in C++ can handle it pretty fine!

Problem E: Empire  You are asked to create 2 components (with railroads) and then connect them with an airline.  Postponing airline construction to the last step and thinking on Kruskal algorithm to get Minimum Spanning Tree, the problem is:  Find an MST, omit the heaviest edge of it!

Problem F: FFS  BackTracking, of course!  Storing achievable states (holding everyone’s cash and value and owner) in a set, you can avoid repeated states.  More bounds?

Problem G: Ghandak and Key  Knowing the carry’s in the sum of a+b, results in equations with digits of a,b as variables.  Solutions to these equations (i.e. first digit of a + first digit of b = 12) can be found by a pre- calculation.  More clever solution: Dynamic programming. Dynamic[k][c] stores the number of ways to choose the leftmost digits of a,b (except the k rightmost ones) so that their sum is what should be, assuming a carry of c on the k th position.

Problem H: How to dance Robot  BFS!  Each node has the 3 field: Xposition, Yposition, AccumulatorValue.  We have 100x100x255 nodes and each of them is connected to at most 12 nodes.  Explore them in “ENSW” order and then “*+-” operations to reach the lexicographically-first path before any other!  Keep parent’s path (like “E+” or “N*”) in 2 characters and write the path recursively.

Problem I: iCalculate  Note : Intermediate values may be very large.  Wrong solution: Use Java’s BigInteger. It’s not going to help, because the results of operations may be too long to store or do computations with.  Correct solution: Choose a prime P (larger that 2 times the magnitude of the result), and do computations mod P. If none of the denominators are divisible by P, we’re good. Else find another random P, and start over.

Problem J: Juliet  For each leaf find all intersections of the line joining Juliet to the shore, and the perimeter of the leaf.  Amongs these points, the point like P whose inner_product(P, Juliets’ position) is maximum or minimum is the entering or exiting point respectively. Put these two inside a list L.  Add Juliet’s position and the origin to L and then sort the points in L with respect to the function inner_product(-P, Juliet).  Iterate over L. Whenever you reach an entering point add 1 to a counter. Whenever you reach an exiting point add -1 to it. Whenever the counter is not 0 and we’re between Juliet and the origin, we are on a leaf.  This way we can find the length of the path we’re on a leaf.