BITTIGER #11. Oct
|
|
- Gervais McDowell
- 5 years ago
- Views:
Transcription
1 BITTIGER #11 Oct
2 PROBLEM LIST A. Five in a Row brute force, implementation B. Building Heap data structures, divide and conquer C. Guess Number with Lower or Higher Hints dynamic programming, mathematics
3 FIVE IN A ROW 2 Players Take turns to place pieces(1 piece a time) Who forms 5 pieces as a line win The line could be horizontal, vertical or diagonal
4 FIVE IN A ROW Horizontal line of 3 white pieces Diagonal line of 4 black pieces Vertical line of 4 black pieces
5 DESCRIPTION Problem: For a given board, judge who had complete a continuously line of 5 pieces Input: A 15*15 chess board. as empty, B as Black piece, W as White piece Output: None - no player complete the task White - only white player complete the task Black - only black player complete the task Both both players complete the task
6 HUMAN S WAY OF THINKING Enumerate all possible line of length 5 Check whether it s black or white Horizontal / Vertical / Diagonal
7 BRUTE FORCE Enumerate each line Enumerate each start position Enumerate each direction Enumerate next 5 positions All pieces? Same color?
8 POSITIONS Consider a position as (x, y) The x-th row, y-th column y for x = for y = { } x
9 DIRECTIONS 8 directions Half are useless Since reverse direction are same Only need 4 directions (0, 1) as right (1, -1) as lower-left (1, 1) as lower-right (1, 0) as down
10 DIRECTIONS Use a direction array to represents all direction d 0 = 0,1 as right, d 1 = 1,1 as right down d 2 = 1,0 as down, d 2 = 1, 1 as lower left dx 4 = 0,1,1,1, dy 4 = 1,1,0, 1, d k = dx k, dy k (0, 1) as right (1, -1) as lower-left (1, 1) as lower-right (1, 0) as down
11 PIECES x, y We have x, y as start position We have (dx[k], dy[k]) as direction What s the position of rest pieces? x + dx k 1, y + dy k 1 (x + dx k 2, y + dy k 2) (x + dx k 3, y + dy k 3) (x + dx k 4, y + dy k 4) (dx[k], dy[k]) = x + dx k i, y + dy k i, 1 i 4 Positions of this line x + dx k i, y + dy k i, 0 i 4
12 JUDGE x + dx k i, y + dy k i, 0 i 4 All B exists at least 1 B solution (AnsB true) All W exists at least 1 W solution (AnsW true) Answer AnsB & AnsW: Both AnsB &! AnsW: Black! AnsB & AnsW: White! AnsB &! AnsW: None
13 BRUTE FORCE Algorithm: Step 1: Enumerate each start position as x, y, 1 x 15, 1 y 15 Step 2: Enumerate each direction as dx k, dy k, 1 k 4 Step 3: Enumerate each positions as x + dx k i, y + dy k i, 0 i 4 Step 4: Update AnsW, AnsB by check these positions Step 5: Output answer according to AnsW, AnsB Time Complexity: O n S, n = 15 Solve 100% of the data
14 CODE bool answ = false, ansb = false; for i=1~n for j=1~n for k=0~3 { int countb=0,countw=0; for l=0~4 { int x=i+dx[k] l; int y=j+dx[k] l; if (!valid(x, y)) conitnue; if (position(x,y)== W ) countw++; if (position(x,y)== B ) countb++; } if (countw==5) answ=true; if (countb==5) ansb=true; }
15 M IN A ROW Problem: For a given board, judge who had complete a continuously line of m pieces Input: m the length required of the line A n*n chess board. as empty, B as Black piece, W as White piece Output: None - no player complete the task White - only white player complete the task Black - only black player complete the task Both both players complete the task
16 STILL BRUTE FORCE? Algorithm Step 1: Enumerate each start position as x, y, 1 x n, 1 y n Step 2: Enumerate each direction as dx k, dy k, 1 k 4 Step 3: Enumerate each positions as x + dx k i, y + dy k i, 0 i < m Step 4: Update AnsW, AnsB by check these positions Step 5: Output answer according to AnsW, AnsB Time Complexity: O n S m Better solution?
17 M IN A ROW Black x, y number of black pieces start from(x, y) Black x, y = min Black x, y + 1, 4 + isblack x, y White x, y = min White x, y + 1, 4 + iswhite x, y
18 M IN A ROW Algorithm Step 1: Enumerate each directions Step 2: Enumerate each start positions in order (x=n~1,y=n~1) Step 3: Calculate Black(x, y) and White x, y Black x, y = min Black x, y + 1, 4 + isblack x, y White x, y = min White x, y + 1, 4 + iswhite x, y Step 4: Same as brute force Time Complexity: O n S
19 QUESTION TIME
20 BUILDING HEAP Min Heap Binary Tree Value of a node is smaller than its children Also smaller than all its descendants In-order Traversal Left subtree Root Right subtree Pre-order Traversal Root Left subtree Right subtree
21 DESCRIPTION Problem: Given a Min Heap s in-order traversal Reconstruct this heap Output its preorder traversal Input: An array of N numbers, represents the in-order traversal of a Min Heap Like Output: An array of N numbers, represents the pre-order traversal of the input Min Heap Like
22 HOW TO? What can we get from this array? 1 Heap: Value of a node is smaller than its children Root has the smallest value That is, the value of the root is 1, Otherwise, there is no node can be 1 s parent. So, at least we find the root.
23 THEN? In-order traversal left subtree root right subtree root Left subtree Right subtree left subtree right subtree Build heap by in-order 768, as 1 s left-subtree Build heap by in-order 3 11, as 1 s right-subtree
24 DIVIDE & CONQUER We divide a bigger problem Into 2 smaller problems and 3 11 Solve each smaller problems Then use results of the smaller problems to generate result of the bigger problem
25 DIVIDE & CONQUER Algorithm: Step 1: Find the smallest number in in-order traversal, as the root Left part of the in-order traversal, as in-order traversal of the left-subtree Right part of the in-order traversal, as in-order traversal of the right-subtree Step 2: Construct left-subtree and right-subtree by recursion Step 3: Use root, left-subtree and right-subtree to generate answer left subtree root right subtree
26 DIVIDE & CONQUER Time Complexity: Each node: find the minimum number Each level: O(N) Number of Levels: Average: O(logN) Worst: O(N) Total complexity: Average: O(NlogN) Worst: O(N S )
27 CODE TreeNode divide array a { TreeNode root i a i < a j, 1 j a. size; root value = a i ; root lchild = divide a 1.. i 1 ; root rchild = divide a i a. size ; return root; } void preorder TreeNode root { print root value; preorder root lchild ; preorder root rchild ; }
28 NO TREE? How to avoid build this tree? TreeNode divide array a { TreeNode root i a i < a j, 1 j a. size; root value = a i ; void solve array a { i a i < a j, 1 j a. size; print a i ; solve a 1.. i 1 ; solve a i a. size ; return root; } } root lchild = divide a 1.. i 1 ; root rchild = divide a i a. size ; return root; void preorder TreeNode root { print root value; preorder root lchild ; preorder root rchild ; }
29 DIVIDE & CONQUER + RMQ Use RMQ to pre-calculate some data Reduce complexity of minimum to O(1) Complexity of RMQ is O(NlogN) Total complexity: Average: O(NlogN) Worst: O(NlogN)
30 QUESTION TIME
31 GUESS NUMBER WITH LOWER OR HIGHER HINTS Two players Alice and Bob Alice needs to guess a number n From range [1, N], N 200 In i-th turn Alice guess a number n d Bob choose to tell the relation of n and n d n < n e, n = n e, n > n e Bob can tell what he want, unless it conflicts what he says before Each turn cost n d Alice wants to minimum the total costs Bob wants to maximum the total costs What s the minimum costs? If both players take the best strategy.
32 EXAMPLES N=1 No need to guess Minimum cost is 0 N=2 Alice guess 1 Bob says n=1, no more cost Bob says n>1, only 2 remains, no more cost Whatever Bob says, further cost is 0 Final cost is 1+0=1 Alice guess 2 Bob says n=2, no more cost Bob says n<2, only 1 remains, no more cost Whatever Bob says, further cost is 0 Final cost is 2+0=2 Minimum cost is 1
33 EXAMPLES N=3 Alice guess 1 Bob says n=1, no more cost Bob says n>1, 2 3 remains, further costs is 2 Bob would says n>1 to maximum Alice s cost to 2 Total cost is 1+2=3 Alice guess 2 Bob says n=2, no more cost Bob says n<2, only 1 remains, no more cost Bob says n>2, only 3 remains, no more cost Whatever Bob says, further cost is 0 Total cost is 2+0=2 Alice guess 3 Bob says n=3, no more cost Bob says n<3, 1 2 remains, further costs is 1 Bob would says n<3 to maximum Alice s cost to 1 Total cost is 3+1=4 Minimum cost is 2
34 STRATEGY TREE Algorithm: Step 1: Start from the initial state Step 2: Enumerate Alice s strategy Step 3: Enumerate Bob s strategy Step 4: Transfer to new state using players strategies Step 5: Calculate value of new state by recursion Step 6: Calculate value of initial state by value of new state Initial State minimum maximum New state New state
35 STRATEGY TREE Initial state [1,3] Alice s strategy guess 1 guess 2 guess 3 1[2,3] [1]2[3] [1,2]3 Bob s strategy n=1 n>1 n<2 n=2 n>2 n<3 n=3 [1] [2,3] [1] [2] [3] [1,2] [3] Alice s strategy guess 2 guess 3 guess 1 guess 2 2[3] [2]3 Bob s strategy n=2 n>2 n<3 n=3 [2] [3] [2] [3] 1[2] [1]2 n=1 n>1 n<2 n=2 [1] [2] [1] [2]
36 STRATEGY TREE How to calculate each node s value? Initial state [1,3] guess 1 guess 2 guess 3 1[2,3] [1]2[3] [1,2]3 n=1 n>1 n<2 n=2 n>2 n<3 n=3 [1] [2,3] [1] [2] [3] [1,2] [3] guess 2 guess 3 guess 1 guess 2 2[3] [2]3 n=2 n>2 n<3 n=3 [2] [3] [2] [3] 1[2] [1]2 n=1 n>1 n<2 n=2 [1] [2] [1] [2]
37 STRATEGY TREE All leaf node s value is 0 [1,3] guess 1 guess 2 guess 3 1[2,3] [1]2[3] [1,2]3 0 [2,3] [1,2] 0 guess 2 guess 3 guess 1 guess 2 2[3] [2]3 1[2] [1]
38 STRATEGY TREE From bottom to top Bob will choose the maximum value [1,3] guess 1 guess 2 guess 3 1[2,3] [1]2[3] [1,2]3 0 [2,3] [1,2] 0 guess 2 guess 3 guess 1 guess Bob s strategy
39 STRATEGY TREE From bottom to top Alice will choose the minimum value [1,3] guess 1 guess 2 guess 3 1[2,3] [1]2[3] [1,2] Alice s strategy cost 2 cost 1 cost 3 cost
40 STRATEGY TREE [1,3] guess 1 guess 2 guess Bob s strategy cost 2 cost 3 cost 1 cost
41 STRATEGY TREE 2 Alice s strategy cost 1 cost 2 cost The value of the first state is 2(The Answer) cost 2 cost cost 1 cost
42 STRATEGY TREE Algorithm: Step 1: Start from the initial state Step 2: Enumerate Alice s strategy Step 3: Enumerate Bob s strategy Step 4: Transfer to new state using players strategies Step 5: Calculate value of new state by recursion Step 6: Calculate value of initial state by value of new state Initial State minimum maximum New state New state Time Complexity:O(N g ) Can t solve all of the data
43 CODE EXAMPLE int CalcState(int l, int r) { if (l >=r) return 0; int ansa = ; for k = l ~ r { // Alice s guess int ansb = 0; // n=k ansb = max(ansb, CalcState(l, k-1)); // n<k ansb = max(ansb, CalcState(k+1, l)); // n>k ansa = min(ansa, ansb + k); } return ansa; }
44 REDUNDANCY [1,5] When calculate state [1, 5] 1, 5 1, 4 2, 4 1, 5 2, 5 2, 4 2, 4 were calculated multiple times Memorized Search When calculate the strategy tree If a state is already calculated, skip the recursion and return the value calculated before [1,4] [2,5] [1,3] [2,4] [2,5] A lot of calculation
45 CODE EXAMPLE int CalcState(int l, int r) { if (l >=r) return 0; if (mem[l, r]!= -1) return mem[l, r]; int ansa = ; for k = l ~ r { // Alice s guess int ansb = 0; // n=k ansb = max(ansb, CalcState(l, k-1)); // n<k ansb = max(ansb, CalcState(k+1, l)); // n>k ansa = min(ansa, ansb + k); } mem[l, r] = ansa; return ansa; }
46 REORDER CALCULATION We will calculate all mem l, r, 1 l r N Why not calculate them in specific order So when calculate a state mem[l, r] All the state that it will use were already calculated mem l h, r h, l l h r h r Such an order can be describe as for l = N ~ 1 for r = l ~ N This is a very useful trick in real programming
47 CODE EXAMPLE for l = N ~ 1 for r = l ~ N { mem[l, r] = ; for k = l ~ r { int s = 0; s = max(s, mem[l, k-1]); s = max(s, mem[k+1, l]); mem[l, r] = min(mem[l, r], s + k); } }
48 DYNAMIC PROGRAMMING By the way, we can call this Dynamic Programming f l, r = min {max f l, k 1, f k + 1, r + k l k r} Time Complexity: O N l Solve all of the data
49 MORE? Mathematic trick f l, r = min {max f l, k 1, f k + 1, r + k l k r} f(l, k 1) f(k + 1, r) max f l, k 1, f k + 1, r k k m
50 MORE? f l, r = min {max f l, k 1, f k + 1, r + k l k r} = min (min max f l, k 1, f k + 1, r + k l k k m,, min {max f l, k 1, f k + 1, r + k k m < k r}) = min (min f k + 1, r + k l k k m, min f l, k 1 + k k m < k r}) = min (min f k + 1, r + k l k k m, f l, k m 1 + k m )
51 QUESTION TIME
52 THANKS FOR LISTENING
SET 1C Binary Trees. 2. (i) Define the height of a binary tree or subtree and also define a height balanced (AVL) tree. (2)
SET 1C Binary Trees 1. Construct a binary tree whose preorder traversal is K L N M P R Q S T and inorder traversal is N L K P R M S Q T 2. (i) Define the height of a binary tree or subtree and also define
More informationCh 10 Trees. Introduction to Trees. Tree Representations. Binary Tree Nodes. Tree Traversals. Binary Search Trees
Ch 10 Trees Introduction to Trees Tree Representations Binary Tree Nodes Tree Traversals Binary Search Trees 1 Binary Trees A binary tree is a finite set of elements called nodes. The set is either empty
More information> asympt( ln( n! ), n ); n 360n n
8.4 Heap Sort (heapsort) We will now look at our first (n ln(n)) algorithm: heap sort. It will use a data structure that we have already seen: a binary heap. 8.4.1 Strategy and Run-time Analysis Given
More information2 all subsequent nodes. 252 all subsequent nodes. 401 all subsequent nodes. 398 all subsequent nodes. 330 all subsequent nodes
¼ À ÈÌ Ê ½¾ ÈÊÇ Ä ÅË ½µ ½¾º¾¹½ ¾µ ½¾º¾¹ µ ½¾º¾¹ µ ½¾º¾¹ µ ½¾º ¹ µ ½¾º ¹ µ ½¾º ¹¾ µ ½¾º ¹ µ ½¾¹¾ ½¼µ ½¾¹ ½ (1) CLR 12.2-1 Based on the structure of the binary tree, and the procedure of Tree-Search, any
More informationCOSC160: Data Structures Binary Trees. Jeremy Bolton, PhD Assistant Teaching Professor
COSC160: Data Structures Binary Trees Jeremy Bolton, PhD Assistant Teaching Professor Outline I. Binary Trees I. Implementations I. Memory Management II. Binary Search Tree I. Operations Binary Trees A
More informationFundamental Algorithms - Surprise Test
Technische Universität München Fakultät für Informatik Lehrstuhl für Effiziente Algorithmen Dmytro Chibisov Sandeep Sadanandan Winter Semester 007/08 Sheet Model Test January 16, 008 Fundamental Algorithms
More informationInitializing A Max Heap. Initializing A Max Heap
Initializing A Max Heap 3 4 5 6 7 8 70 8 input array = [-,,, 3, 4, 5, 6, 7, 8,, 0, ] Initializing A Max Heap 3 4 5 6 7 8 70 8 Start at rightmost array position that has a child. Index is n/. Initializing
More informationCSCI 104 B-Trees (2-3, 2-3-4) and Red/Black Trees. Mark Redekopp David Kempe
1 CSCI 104 B-Trees (2-3, 2-3-4) and Red/Black Trees Mark Redekopp David Kempe 2 An example of B-Trees 2-3 TREES 3 Definition 2-3 Tree is a tree where Non-leaf nodes have 1 value & 2 children or 2 values
More informationOn the Optimality of a Family of Binary Trees Techical Report TR
On the Optimality of a Family of Binary Trees Techical Report TR-011101-1 Dana Vrajitoru and William Knight Indiana University South Bend Department of Computer and Information Sciences Abstract In this
More informationAlgorithmic Game Theory and Applications. Lecture 11: Games of Perfect Information
Algorithmic Game Theory and Applications Lecture 11: Games of Perfect Information Kousha Etessami finite games of perfect information Recall, a perfect information (PI) game has only 1 node per information
More informationCSE 21 Winter 2016 Homework 6 Due: Wednesday, May 11, 2016 at 11:59pm. Instructions
CSE 1 Winter 016 Homework 6 Due: Wednesday, May 11, 016 at 11:59pm Instructions Homework should be done in groups of one to three people. You are free to change group members at any time throughout the
More informationPriority Queues 9/10. Binary heaps Leftist heaps Binomial heaps Fibonacci heaps
Priority Queues 9/10 Binary heaps Leftist heaps Binomial heaps Fibonacci heaps Priority queues are important in, among other things, operating systems (process control in multitasking systems), search
More informationCSE 100: TREAPS AND RANDOMIZED SEARCH TREES
CSE 100: TREAPS AND RANDOMIZED SEARCH TREES Midterm Review Practice Midterm covered during Sunday discussion Today Run time analysis of building the Huffman tree AVL rotations and treaps Huffman s algorithm
More informationBinary Tree Applications
Binary Tree Applications Lecture 32 Section 19.2 Robb T. Koether Hampden-Sydney College Wed, Apr 17, 2013 Robb T. Koether (Hampden-Sydney College) Binary Tree Applications Wed, Apr 17, 2013 1 / 46 1 Expression
More informationHomework #4. CMSC351 - Spring 2013 PRINT Name : Due: Thu Apr 16 th at the start of class
Homework #4 CMSC351 - Spring 2013 PRINT Name : Due: Thu Apr 16 th at the start of class o Grades depend on neatness and clarity. o Write your answers with enough detail about your approach and concepts
More informationChapter 16. Binary Search Trees (BSTs)
Chapter 16 Binary Search Trees (BSTs) Search trees are tree-based data structures that can be used to store and search for items that satisfy a total order. There are many types of search trees designed
More information3/7/13. Binomial Tree. Binomial Tree. Binomial Tree. Binomial Tree. Number of nodes with respect to k? N(B o ) = 1 N(B k ) = 2 N(B k-1 ) = 2 k
//1 Adapted from: Kevin Wayne B k B k B k : a binomial tree with the addition of a left child with another binomial tree Number of nodes with respect to k? N(B o ) = 1 N(B k ) = 2 N( ) = 2 k B 1 B 2 B
More informationCMPSCI 311: Introduction to Algorithms Second Midterm Practice Exam SOLUTIONS
CMPSCI 311: Introduction to Algorithms Second Midterm Practice Exam SOLUTIONS November 17, 2016. Name: ID: Instructions: Answer the questions directly on the exam pages. Show all your work for each question.
More informationLecture 4: Divide and Conquer
Lecture 4: Divide and Conquer Divide and Conquer Merge sort is an example of a divide-and-conquer algorithm Recall the three steps (at each level to solve a divideand-conquer problem recursively Divide
More information1 Solutions to Tute09
s to Tute0 Questions 4. - 4. are straight forward. Q. 4.4 Show that in a binary tree of N nodes, there are N + NULL pointers. Every node has outgoing pointers. Therefore there are N pointers. Each node,
More informationPractical session No. 5 Trees
Practical session No. 5 Trees Tree Binary Tree k-tree Trees as Basic Data Structures ADT that stores elements hierarchically. Each node in the tree has a parent (except for the root), and zero or more
More informationUNIT 2. Greedy Method GENERAL METHOD
UNIT 2 GENERAL METHOD Greedy Method Greedy is the most straight forward design technique. Most of the problems have n inputs and require us to obtain a subset that satisfies some constraints. Any subset
More informationPractical session No. 5 Trees
Practical session No. 5 Trees Tree Trees as Basic Data Structures ADT that stores elements hierarchically. With the exception of the root, each node in the tree has a parent and zero or more children nodes.
More informationHeaps. Heap/Priority queue. Binomial heaps: Advanced Algorithmics (4AP) Heaps Binary heap. Binomial heap. Jaak Vilo 2009 Spring
.0.00 Heaps http://en.wikipedia.org/wiki/category:heaps_(structure) Advanced Algorithmics (4AP) Heaps Jaak Vilo 00 Spring Binary heap http://en.wikipedia.org/wiki/binary_heap Binomial heap http://en.wikipedia.org/wiki/binomial_heap
More informationMaximum Contiguous Subsequences
Chapter 8 Maximum Contiguous Subsequences In this chapter, we consider a well-know problem and apply the algorithm-design techniques that we have learned thus far to this problem. While applying these
More informationHeaps
AdvancedAlgorithmics (4AP) Heaps Jaak Vilo 2009 Spring Jaak Vilo MTAT.03.190 Text Algorithms 1 Heaps http://en.wikipedia.org/wiki/category:heaps_(structure) Binary heap http://en.wikipedia.org/wiki/binary_heap
More informationCOMP Analysis of Algorithms & Data Structures
COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Binomial Heaps CLRS 6.1, 6.2, 6.3 University of Manitoba Priority queues A priority queue is an abstract data type formed by a set S of
More information1.6 Heap ordered trees
1.6 Heap ordered trees A heap ordered tree is a tree satisfying the following condition. The key of a node is not greater than that of each child if any In a heap ordered tree, we can not implement find
More informationPRIORITY QUEUES. binary heaps d-ary heaps binomial heaps Fibonacci heaps. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley
PRIORITY QUEUES binary heaps d-ary heaps binomial heaps Fibonacci heaps Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos Last updated
More informationCSE 417 Algorithms. Huffman Codes: An Optimal Data Compression Method
CSE 417 Algorithms Huffman Codes: An Optimal Data Compression Method 1 Compression Example 100k file, 6 letter alphabet: a 45% b 13% c 12% d 16% e 9% f 5% File Size: ASCII, 8 bits/char: 800kbits 2 3 >
More informationAlgorithms PRIORITY QUEUES. binary heaps d-ary heaps binomial heaps Fibonacci heaps. binary heaps d-ary heaps binomial heaps Fibonacci heaps
Priority queue data type Lecture slides by Kevin Wayne Copyright 05 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos PRIORITY QUEUES binary heaps d-ary heaps binomial heaps Fibonacci
More informationAdvanced Algorithmics (4AP) Heaps
Advanced Algorithmics (4AP) Heaps Jaak Vilo 2009 Spring Jaak Vilo MTAT.03.190 Text Algorithms 1 Heaps http://en.wikipedia.org/wiki/category:heaps_(structure) Binary heap http://en.wikipedia.org/wiki/binary
More informationData Structures, Algorithms, & Applications in C++ ( Chapter 9 )
) Priority Queues Two kinds of priority queues: Min priority queue. Max priority queue. Min Priority Queue Collection of elements. Each element has a priority or key. Supports following operations: isempty
More informationUNIT VI TREES. Marks - 14
UNIT VI TREES Marks - 14 SYLLABUS 6.1 Non-linear data structures 6.2 Binary trees : Complete Binary Tree, Basic Terms: level number, degree, in-degree and out-degree, leaf node, directed edge, path, depth,
More informationAdministration CSE 326: Data Structures
Administration CSE : Data Structures Binomial Queues Neva Cherniavsky Summer Released today: Project, phase B Due today: Homework Released today: Homework I have office hours tomorrow // Binomial Queues
More informationChapter wise Question bank
GOVERNMENT ENGINEERING COLLEGE - MODASA Chapter wise Question bank Subject Name Analysis and Design of Algorithm Semester Department 5 th Term ODD 2015 Information Technology / Computer Engineering Chapter
More informationOptimal Satisficing Tree Searches
Optimal Satisficing Tree Searches Dan Geiger and Jeffrey A. Barnett Northrop Research and Technology Center One Research Park Palos Verdes, CA 90274 Abstract We provide an algorithm that finds optimal
More informationLesson 9: Heuristic Search and A* Search
CAP 5602 Summer, 2011 Lesson 9: Heuristic Search and A* Search The topics 1. Heuristic Search 2. The A* Search 3. An example of the use of A* search. 1. Heuristic Search The idea of heuristics is to attach
More informationCSE 417 Dynamic Programming (pt 2) Look at the Last Element
CSE 417 Dynamic Programming (pt 2) Look at the Last Element Reminders > HW4 is due on Friday start early! if you run into problems loading data (date parsing), try running java with Duser.country=US Duser.language=en
More informationCS221 / Spring 2018 / Sadigh. Lecture 9: Games I
CS221 / Spring 2018 / Sadigh Lecture 9: Games I Course plan Search problems Markov decision processes Adversarial games Constraint satisfaction problems Bayesian networks Reflex States Variables Logic
More informationRecitation 1. Solving Recurrences. 1.1 Announcements. Welcome to 15210!
Recitation 1 Solving Recurrences 1.1 Announcements Welcome to 1510! The course website is http://www.cs.cmu.edu/ 1510/. It contains the syllabus, schedule, library documentation, staff contact information,
More informationThe exam is closed book, closed calculator, and closed notes except your three crib sheets.
CS 188 Spring 2016 Introduction to Artificial Intelligence Final V2 You have approximately 2 hours and 50 minutes. The exam is closed book, closed calculator, and closed notes except your three crib sheets.
More informationBasic Data Structures. Figure 8.1 Lists, stacks, and queues. Terminology for Stacks. Terminology for Lists. Chapter 8: Data Abstractions
Chapter 8: Data Abstractions Computer Science: An Overview Tenth Edition by J. Glenn Brookshear Chapter 8: Data Abstractions 8.1 Data Structure Fundamentals 8.2 Implementing Data Structures 8.3 A Short
More informationLecture 9: Games I. Course plan. A simple game. Roadmap. Machine learning. Example: game 1
Lecture 9: Games I Course plan Search problems Markov decision processes Adversarial games Constraint satisfaction problems Bayesian networks Reflex States Variables Logic Low-level intelligence Machine
More informationSuccessor. CS 361, Lecture 19. Tree-Successor. Outline
Successor CS 361, Lecture 19 Jared Saia University of New Mexico The successor of a node x is the node that comes after x in the sorted order determined by an in-order tree walk. If all keys are distinct,
More informationThe Pill Problem, Lattice Paths and Catalan Numbers
The Pill Problem, Lattice Paths and Catalan Numbers Margaret Bayer University of Kansas Lawrence, KS 66045-7594 bayer@ku.edu Keith Brandt Rockhurst University Kansas City, MO 64110 Keith.Brandt@Rockhurst.edu
More informationCSCE 750, Fall 2009 Quizzes with Answers
CSCE 750, Fall 009 Quizzes with Answers Stephen A. Fenner September 4, 011 1. Give an exact closed form for Simplify your answer as much as possible. k 3 k+1. We reduce the expression to a form we ve already
More informationOn the Optimality of a Family of Binary Trees
On the Optimality of a Family of Binary Trees Dana Vrajitoru Computer and Information Sciences Department Indiana University South Bend South Bend, IN 46645 Email: danav@cs.iusb.edu William Knight Computer
More information4/8/13. Part 6. Trees (2) Outline. Balanced Search Trees. 2-3 Trees Trees Red-Black Trees AVL Trees. to maximum n. Tree A. Tree B.
art 6. Trees (2) C 200 Algorithms and Data tructures 1 Outline 2-3 Trees 2-3-4 Trees Red-Black Trees AV Trees 2 Balanced earch Trees Tree A Tree B to maximum n Tree D 3 1 Balanced earch Trees A search
More informationHeap Building Bounds
Heap Building Bounds Zhentao Li 1 and Bruce A. Reed 2 1 School of Computer Science, McGill University zhentao.li@mail.mcgill.ca 2 School of Computer Science, McGill University breed@cs.mcgill.ca Abstract.
More informationDesign and Analysis of Algorithms 演算法設計與分析. Lecture 8 November 16, 2016 洪國寶
Design and Analysis of Algorithms 演算法設計與分析 Lecture 8 November 6, 206 洪國寶 Outline Review Amortized analysis Advanced data structures Binary heaps Binomial heaps Fibonacci heaps Data structures for disjoint
More informationCooperative Games with Monte Carlo Tree Search
Int'l Conf. Artificial Intelligence ICAI'5 99 Cooperative Games with Monte Carlo Tree Search CheeChian Cheng and Norman Carver Department of Computer Science, Southern Illinois University, Carbondale,
More informationMeld(Q 1,Q 2 ) merge two sets
Priority Queues MakeQueue Insert(Q,k,p) Delete(Q,k) DeleteMin(Q) Meld(Q 1,Q 2 ) Empty(Q) Size(Q) FindMin(Q) create new empty queue insert key k with priority p delete key k (given a pointer) delete key
More informationDesign and Analysis of Algorithms. Lecture 9 November 20, 2013 洪國寶
Design and Analysis of Algorithms 演算法設計與分析 Lecture 9 November 20, 2013 洪國寶 1 Outline Advanced data structures Binary heaps (review) Binomial heaps Fibonacci heaps Dt Data structures t for disjoint dijitsets
More informationAlgorithms and Networking for Computer Games
Algorithms and Networking for Computer Games Chapter 4: Game Trees http://www.wiley.com/go/smed Game types perfect information games no hidden information two-player, perfect information games Noughts
More informationQ1. [?? pts] Search Traces
CS 188 Spring 2010 Introduction to Artificial Intelligence Midterm Exam Solutions Q1. [?? pts] Search Traces Each of the trees (G1 through G5) was generated by searching the graph (below, left) with a
More informationThe Tree Data Model. Laura Kovács
The Tree Data Model Laura Kovács Trees (Baumstrukturen) Definition Trees are sets of points, called nodes (Knoten) and lines, called edges (Kanten), connecting two distinct nodes, such that: n 2 n 3 n
More informationWhat is Greedy Approach? Control abstraction for Greedy Method. Three important activities
0-0-07 What is Greedy Approach? Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each decision is locally optimal. These locally optimal solutions will finally
More informationHomework solutions, Chapter 8
Homework solutions, Chapter 8 NOTE: We might think of 8.1 as being a section devoted to setting up the networks and 8.2 as solving them, but only 8.2 has a homework section. Section 8.2 2. Use Dijkstra
More informationBinary Search Tree and AVL Trees. Binary Search Tree. Binary Search Tree. Binary Search Tree. Techniques: How does the BST works?
Binary Searc Tree and AVL Trees Binary Searc Tree A commonly-used data structure for storing and retrieving records in main memory PUC-Rio Eduardo S. Laber Binary Searc Tree Binary Searc Tree A commonly-used
More informationDesign and Analysis of Algorithms 演算法設計與分析. Lecture 9 November 19, 2014 洪國寶
Design and Analysis of Algorithms 演算法設計與分析 Lecture 9 November 19, 2014 洪國寶 1 Outline Advanced data structures Binary heaps(review) Binomial heaps Fibonacci heaps Data structures for disjoint sets 2 Mergeable
More informationAVL Trees. The height of the left subtree can differ from the height of the right subtree by at most 1.
AVL Trees In order to have a worst case running time for insert and delete operations to be O(log n), we must make it impossible for there to be a very long path in the binary search tree. The first balanced
More informationc 2004 Society for Industrial and Applied Mathematics
SIAM J. COMPUT. Vol. 33, No. 5, pp. 1011 1034 c 2004 Society for Industrial and Applied Mathematics EFFICIENT ALGORITHMS FOR OPTIMAL STREAM MERGING FOR MEDIA-ON-DEMAND AMOTZ BAR-NOY AND RICHARD E. LADNER
More information1 Binomial Tree. Structural Properties:
Indian Institute of Information Technology Design and Manufacturing, Kancheepuram Chennai 600, India An Autonomous Institute under MHRD, Govt of India http://www.iiitdm.ac.in COM 0 Advanced Data Structures
More informationAn Analysis of Forward Pruning. University of Maryland Institute for Systems Research. College Park, MD 20742
Proc. AAAI-94, to appear. An Analysis of Forward Pruning Stephen J. J. Smith Dana S. Nau Department of Computer Science Department of Computer Science, and University of Maryland Institute for Systems
More informationBinary Decision Diagrams
Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South Florida Tampa, FL 33620 Email: zheng@cse.usf.edu Phone: (813)974-4757 Fax: (813)974-5456 Hao Zheng
More informationHeaps. c P. Flener/IT Dept/Uppsala Univ. AD1, FP, PK II Heaps 1
Heaps (Version of 21 November 2005) A min-heap (resp. max-heap) is a data structure with fast extraction of the smallest (resp. largest) item (in O(lg n) time), as well as fast insertion (also in O(lg
More informationYao s Minimax Principle
Complexity of algorithms The complexity of an algorithm is usually measured with respect to the size of the input, where size may for example refer to the length of a binary word describing the input,
More informationCS188 Spring 2012 Section 4: Games
CS188 Spring 2012 Section 4: Games 1 Minimax Search In this problem, we will explore adversarial search. Consider the zero-sum game tree shown below. Trapezoids that point up, such as at the root, represent
More informationDM559/DM545 Linear and integer programming
Department of Mathematics and Computer Science University of Southern Denmark, Odense May 22, 2018 Marco Chiarandini DM559/DM55 Linear and integer programming Sheet, Spring 2018 [pdf format] Contains Solutions!
More informationMSU CSE Spring 2011 Exam 2-ANSWERS
MSU CSE 260-001 Spring 2011 Exam 2-NSWERS Name: This is a closed book exam, with 9 problems on 5 pages totaling 100 points. Integer ivision/ Modulo rithmetic 1. We can add two numbers in base 2 by using
More informationBinary Decision Diagrams
Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South Florida Tampa, FL 33620 Email: zheng@cse.usf.edu Phone: (813)974-4757 Fax: (813)974-5456 Hao Zheng
More informationCS 106X Lecture 11: Sorting
CS 106X Lecture 11: Sorting Friday, February 3, 2017 Programming Abstractions (Accelerated) Winter 2017 Stanford University Computer Science Department Lecturer: Chris Gregg reading: Programming Abstractions
More informationThe potential function φ for the amortized analysis of an operation on Fibonacci heap at time (iteration) i is given by the following equation:
Indian Institute of Information Technology Design and Manufacturing, Kancheepuram Chennai 600 127, India An Autonomous Institute under MHRD, Govt of India http://www.iiitdm.ac.in COM 01 Advanced Data Structures
More informationThe suffix binary search tree and suffix AVL tree
Journal of Discrete Algorithms 1 (2003) 387 408 www.elsevier.com/locate/jda The suffix binary search tree and suffix AVL tree Robert W. Irving, Lorna Love Department of Computing Science, University of
More informationBinary and Binomial Heaps. Disclaimer: these slides were adapted from the ones by Kevin Wayne
Binary and Binomial Heaps Disclaimer: these slides were adapted from the ones by Kevin Wayne Priority Queues Supports the following operations. Insert element x. Return min element. Return and delete minimum
More informationChapter 5: Algorithms
Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn Brookshear Presentation files modified by Farn Wang Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
More informationAn Optimal Algorithm for Calculating the Profit in the Coins in a Row Game
An Optimal Algorithm for Calculating the Profit in the Coins in a Row Game Tomasz Idziaszek University of Warsaw idziaszek@mimuw.edu.pl Abstract. On the table there is a row of n coins of various denominations.
More informationPARELLIZATION OF DIJKSTRA S ALGORITHM: COMPARISON OF VARIOUS PRIORITY QUEUES
PARELLIZATION OF DIJKSTRA S ALGORITHM: COMPARISON OF VARIOUS PRIORITY QUEUES WIKTOR JAKUBIUK, KESHAV PURANMALKA 1. Introduction Dijkstra s algorithm solves the single-sourced shorest path problem on a
More informationOutline for this Week
Binomial Heaps Outline for this Week Binomial Heaps (Today) A simple, flexible, and versatile priority queue. Lazy Binomial Heaps (Today) A powerful building block for designing advanced data structures.
More informationTHE LYING ORACLE GAME WITH A BIASED COIN
Applied Probability Trust (13 July 2009 THE LYING ORACLE GAME WITH A BIASED COIN ROBB KOETHER, Hampden-Sydney College MARCUS PENDERGRASS, Hampden-Sydney College JOHN OSOINACH, Millsaps College Abstract
More informationLecture 9: Classification and Regression Trees
Lecture 9: Classification and Regression Trees Advanced Applied Multivariate Analysis STAT 2221, Spring 2015 Sungkyu Jung Department of Statistics, University of Pittsburgh Xingye Qiao Department of Mathematical
More informationHomework Assignment #3. 1 Demonstrate how mergesort works when sorting the following list of numbers:
CISC 5835 Algorithms for Big Data Fall, 2018 Homework Assignment #3 1 Demonstrate how mergesort works when sorting the following list of numbers: 6 1 4 2 3 8 7 5 2 Given the following array (list), follows
More informationDesign and Analysis of Algorithms
Design and Analysis of Algorithms Instructor: Sharma Thankachan Lecture 9: Binomial Heap Slides modified from Dr. Hon, with permission 1 About this lecture Binary heap supports various operations quickly:
More informationLecture outline W.B.Powell 1
Lecture outline What is a policy? Policy function approximations (PFAs) Cost function approximations (CFAs) alue function approximations (FAs) Lookahead policies Finding good policies Optimizing continuous
More informationPriority Queues Based on Braun Trees
Priority Queues Based on Braun Trees Tobias Nipkow September 19, 2015 Abstract This theory implements priority queues via Braun trees. Insertion and deletion take logarithmic time and preserve the balanced
More informationData Structures. Binomial Heaps Fibonacci Heaps. Haim Kaplan & Uri Zwick December 2013
Data Structures Binomial Heaps Fibonacci Heaps Haim Kaplan & Uri Zwick December 13 1 Heaps / Priority queues Binary Heaps Binomial Heaps Lazy Binomial Heaps Fibonacci Heaps Insert Find-min Delete-min Decrease-key
More informationChapter 21. Dynamic Programming CONTENTS 21.1 A SHORTEST-ROUTE PROBLEM 21.2 DYNAMIC PROGRAMMING NOTATION
Chapter 21 Dynamic Programming CONTENTS 21.1 A SHORTEST-ROUTE PROBLEM 21.2 DYNAMIC PROGRAMMING NOTATION 21.3 THE KNAPSACK PROBLEM 21.4 A PRODUCTION AND INVENTORY CONTROL PROBLEM 23_ch21_ptg01_Web.indd
More information0/1 knapsack problem knapsack problem
1 (1) 0/1 knapsack problem. A thief robbing a safe finds it filled with N types of items of varying size and value, but has only a small knapsack of capacity M to use to carry the goods. More precisely,
More informationPricing Options Using Trinomial Trees
Pricing Options Using Trinomial Trees Paul Clifford Yan Wang Oleg Zaboronski 30.12.2009 1 Introduction One of the first computational models used in the financial mathematics community was the binomial
More informationIntroduction to Greedy Algorithms: Huffman Codes
Introduction to Greedy Algorithms: Huffman Codes Yufei Tao ITEE University of Queensland In computer science, one interesting method to design algorithms is to go greedy, namely, keep doing the thing that
More informationCISC 889 Bioinformatics (Spring 2004) Phylogenetic Trees (II)
CISC 889 ioinformatics (Spring 004) Phylogenetic Trees (II) Character-based methods CISC889, S04, Lec13, Liao 1 Parsimony ased on sequence alignment. ssign a cost to a given tree Search through the topological
More informationChapter 7 Sorting (Part II)
Data Structure t Chapter 7 Sorting (Part II) Angela Chih-Wei i Tang Department of Communication Engineering National Central University Jhongli, Taiwan 2010 Spring Outline Heap Max/min heap Insertion &
More informationDESCENDANTS IN HEAP ORDERED TREES OR A TRIUMPH OF COMPUTER ALGEBRA
DESCENDANTS IN HEAP ORDERED TREES OR A TRIUMPH OF COMPUTER ALGEBRA Helmut Prodinger Institut für Algebra und Diskrete Mathematik Technical University of Vienna Wiedner Hauptstrasse 8 0 A-00 Vienna, Austria
More informationStructural Induction
Structural Induction Jason Filippou CMSC250 @ UMCP 07-05-2016 Jason Filippou (CMSC250 @ UMCP) Structural Induction 07-05-2016 1 / 26 Outline 1 Recursively defined structures 2 Proofs Binary Trees Jason
More informationarxiv: v1 [math.co] 31 Mar 2009
A BIJECTION BETWEEN WELL-LABELLED POSITIVE PATHS AND MATCHINGS OLIVIER BERNARDI, BERTRAND DUPLANTIER, AND PHILIPPE NADEAU arxiv:0903.539v [math.co] 3 Mar 009 Abstract. A well-labelled positive path of
More informationThe exam is closed book, closed calculator, and closed notes except your one-page crib sheet.
CS 188 Spring 2015 Introduction to Artificial Intelligence Midterm 1 You have approximately 2 hours and 50 minutes. The exam is closed book, closed calculator, and closed notes except your one-page crib
More informationIt is used when neither the TX nor RX knows anything about the statistics of the source sequence at the start of the transmission
It is used when neither the TX nor RX knows anything about the statistics of the source sequence at the start of the transmission -The code can be described in terms of a binary tree -0 corresponds to
More informationCEC login. Student Details Name SOLUTIONS
Student Details Name SOLUTIONS CEC login Instructions You have roughly 1 minute per point, so schedule your time accordingly. There is only one correct answer per question. Good luck! Question 1. Searching
More informationLecture 5: Tuesday, January 27, Peterson s Algorithm satisfies the No Starvation property (Theorem 1)
Com S 611 Spring Semester 2015 Advanced Topics on Distributed and Concurrent Algorithms Lecture 5: Tuesday, January 27, 2015 Instructor: Soma Chaudhuri Scribe: Nik Kinkel 1 Introduction This lecture covers
More information