Encoding/Decoding, Counting graphs

Similar documents
Encoding/Decoding and Lower Bound for Sorting

Binomial Coefficients

Encoding/Decoding. Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck. May 9, 2016

Trees. Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck. April 29, 2016

Introduction to Graphs

Eulerian tours. Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck. April 20, 2016

Theory and Frontiers of Computer Science. Fall 2013 Carola Wenk

Master Theorem, Introduction to Graphs

CSE 20 DISCRETE MATH WINTER

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Binomial Coefficient Identities and Encoding/Decoding

Graph Algorithms. Chromatic Polynomials. Graph Algorithms

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

COMP Data Structures

Test 1 Review Questions with Solutions

Divide and Conquer Algorithms

Trees and Intro to Counting

Randomized Algorithms: Selection

L.J. Institute of Engineering & Technology Semester: VIII (2016)

Chapter 4. Divide-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

COMP3121/3821/9101/ s1 Assignment 1

2. (a) Explain when the Quick sort is preferred to merge sort and vice-versa.

Analysis of Algorithms. Unit 4 - Analysis of well known Algorithms

Plotting run-time graphically. Plotting run-time graphically. CS241 Algorithmics - week 1 review. Prefix Averages - Algorithm #1

DESIGN AND ANALYSIS OF ALGORITHMS

Solving Linear Recurrence Relations (8.2)

Divide-and-Conquer. The most-well known algorithm design strategy: smaller instances. combining these solutions

Sorting Pearson Education, Inc. All rights reserved.

Lecture Notes on Karger s Min-Cut Algorithm. Eric Vigoda Georgia Institute of Technology Last updated for Advanced Algorithms, Fall 2013.

Lower Bound on Comparison-based Sorting

Solutions. (a) Claim: A d-ary tree of height h has at most 1 + d +...

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 4 Notes. Class URL:

17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer

CSE 373 MAY 24 TH ANALYSIS AND NON- COMPARISON SORTING

Divide-and-Conquer. Dr. Yingwu Zhu

Multiple-choice (35 pt.)

CMSC 380. Graph Terminology and Representation

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

Math 4242 Polynomial Time algorithms, IndependentSet problem

CSC Design and Analysis of Algorithms

Minimum Spanning Trees

Unit-2 Divide and conquer 2016

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.

Vertex Magic Total Labelings of Complete Graphs 1

Parallel Algorithms for (PRAM) Computers & Some Parallel Algorithms. Reference : Horowitz, Sahni and Rajasekaran, Computer Algorithms

An 11-Step Sorting Network for 18 Elements. Sherenaz W. Al-Haj Baddar, Kenneth E. Batcher

Analyze the obvious algorithm, 5 points Here is the most obvious algorithm for this problem: (LastLargerElement[A[1..n]:

Algorithms: Efficiency, Analysis, techniques for solving problems using computer approach or methodology but not programming

Randomized Algorithms, Hash Functions

Lecture 3, Review of Algorithms. What is Algorithm?

22 Elementary Graph Algorithms. There are two standard ways to represent a

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

Vertex Magic Total Labelings of Complete Graphs

15110 Principles of Computing, Carnegie Mellon University - CORTINA. Binary Search. Required: List L of n unique elements.

Ph.D. Comprehensive Examination Design and Analysis of Algorithms

Divide and Conquer. Divide and Conquer

would be included in is small: to be exact. Thus with probability1, the same partition n+1 n+1 would be produced regardless of whether p is in the inp

22 Elementary Graph Algorithms. There are two standard ways to represent a

Searching Algorithms/Time Analysis

Computer Algorithms. Introduction to Algorithm

Pseudo code of algorithms are to be read by.

Greedy algorithms. Given a problem, how do we design an algorithm that solves the problem? There are several strategies:

Throughout this course, we use the terms vertex and node interchangeably.

ON THE STRONGLY REGULAR GRAPH OF PARAMETERS

COMP Analysis of Algorithms & Data Structures

2 A Template for Minimum Spanning Tree Algorithms

Lecture 2: Algorithms, Complexity and Data Structures. (Reading: AM&O Chapter 3)

( D. Θ n. ( ) f n ( ) D. Ο%

CSE 20 DISCRETE MATH. Fall

Outline. Computer Science 331. Heap Shape. Binary Heaps. Heap Sort. Insertion Deletion. Mike Jacobson. HeapSort Priority Queues.

Run Times. Efficiency Issues. Run Times cont d. More on O( ) notation

FINAL EXAM SOLUTIONS

COMP Analysis of Algorithms & Data Structures

PERFORMANCE OF VARIOUS SORTING AND SEARCHING ALGORITHMS Aarushi Madan Aarusi Tuteja Bharti

Computer Science 236 Fall Nov. 11, 2010

Algorithmic Analysis. Go go Big O(h)!

Chapter 5. Decrease-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Problem. Input: An array A = (A[1],..., A[n]) with length n. Output: a permutation A of A, that is sorted: A [i] A [j] for all. 1 i j n.

Today. Types of graphs. Complete Graphs. Trees. Hypercubes.

Hiroki Yasuga, Elisabeth Kolp, Andreas Lang. 25th September 2014, Scientific Programming

CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION

Notation Index 9 (there exists) Fn-4 8 (for all) Fn-4 3 (such that) Fn-4 B n (Bell numbers) CL-25 s ο t (equivalence relation) GT-4 n k (binomial coef

D.K.M.COLLEGE FOR WOMEN (AUTONOMOUS), VELLORE-1.

A 12-STEP SORTING NETWORK FOR 22 ELEMENTS

Advanced Algorithms. Problem solving Techniques. Divide and Conquer הפרד ומשול

Algorithm. Algorithm Analysis. Algorithm. Algorithm. Analyzing Sorting Algorithms (Insertion Sort) Analyzing Algorithms 8/31/2017

Question And Answer.

Greedy algorithms is another useful way for solving optimization problems.

Second Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

Problem Set 2 Solutions

Lecture 5: Graphs. Rajat Mittal. IIT Kanpur

CSCI 104 Log Structured Merge Trees. Mark Redekopp

l So unlike the search trees, there are neither arbitrary find operations nor arbitrary delete operations possible.

CS301 - Data Structures Glossary By

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment

1. A busy airport has 1500 takeo s perday. Provetherearetwoplanesthatmusttake o within one minute of each other. This is from Bona Chapter 1 (1).

Faster Sorting Methods

O(n): printing a list of n items to the screen, looking at each item once.

Transcription:

Encoding/Decoding, Counting graphs Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck http://cseweb.ucsd.edu/classes/sp16/cse21-bd/ May 13, 2016

11-avoiding binary strings Let s consider the set of all n-bit binary strings with the property that 11 is not a substring. example: 100010100001010 How many of these strings are there? A. 2 $ B. 2 $&' C. F $*+ (Fibonacci number.) D. n! n E. k

11-avoiding binary strings Let s consider the set of all n-bit binary strings with the property that 11 is not a substring. How many of these strings are there? Let S(n) be the set of all n-bit binary strings of this type. Then split them into two subsets: S1(n) is the subset that starts with 1 S0(n) is the subset that starts with 0 Are S1(n) and S0(n) disjoint?

11-avoiding binary strings Let s consider the set of all n-bit binary strings with the property that 11 is not a substring. S(n) = S1(n) S0(n) and S1 n S0 n = S n = S1 n + S0 n All elements of S0(n) are of the form 0[11-avoiding (n-1)-bit binary string] All elements of S1(n) are of the form 10[11-avoiding (n-2)-bit binary string] S0 n = S n 1 S1 n = S n 2 S n = S(n 1) + S n 2

11-avoiding binary strings what does this look like? What is S(1)? What is S(2)? S n = S(n 1) + S n 2

11-avoiding binary strings what does this look like? S n = S(n 1) + S n 2 S(1) =2 S(2) =3 S n = F $*+ (Fibonacci number.) F ' = 1, F + = 1

11-avoiding binary strings (encoding) The most straightforward way to encode one of these strings is by using the string itself. This gives us an upper bound on the number of bits needed to encode these types of strings. n-bits is enough to encode these strings so this means that S n = F $*+ 2 $

Theoretically Optimal Encoding A theoretically optimal encoding for length n 11-avoiding binary strings would use the ceiling of log + F $*+ bits. How? - List all length n 11-avoiding binary strings in lex-order - To encode: Store the position of a string in the list, rather than the string itself. - To decode: Given a position in list, need to determine string in that position.

Lex Order E.g. the 13 Length n=5 11-avoiding binary strings: Original string, s Encoded string (i.e. position in this list) 00000 0 = 0000 00001 1 = 0001 00010 2 = 0010 00100 3 = 0011 00101 4 = 0100 01000 5 = 0101 01001 6 = 0110 01010 7 = 0111 10000 8 = 1000 10001 9 = 1001 10010 10 = 1010 10100 11 = 1011 10101 12 = 1100

Lex Order: Algorithm? Need two algorithms, given specific n: s à E(s,n) and p à D(p,n) Idea: Use recursion (reduce & conquer).

Lex Order: Algorithm? For E(s,n): 0. 0. 1.. 1. 1. Length n-1 11-avoiding binary strings Length n-2 11-avoiding binary strings Any string that starts with 0 must have position before S n 1 = F n*1 Any string that starts with 1 must have position at or after S n 1 = F n*1

Lex Order: Algorithm? Example: Encode 00101001 (Note: this is a length 9 binary string.)

Lex Order: Algorithm? Example: Encode 010101001 (Note: this is a length 9 binary string.) Initialize p:=0, n:=9 The first bit is 0 so p:=p+0=0, n:=8 The second bit is 1 so p: = p + F $*' = p + F H = p + 34 = 34, n:=7 The third bit is 0 so p:=p+0=34, n:=6 The fourth bit is 1 so p: = p + F $*' = p + F L = p + 13 = 47, n:=5 The fifth bit is 0 so p:=p+0=47, n:=4 The sixth bit is 1 so p: = p + F $*' = p + F N = p + 5 = 52, n:=3 The seventh bit is 0 so p:=p+0=52, n:=2 The eighth bit is 0 so p:=p+0=52, n:=1 The ninth bit is 1 so p: = p + F $*' = p + F + = p + 1 = 53, n:=0

Lex Order: Algorithm? Example: Encode 010101001 (Note: this is a length 9 binary string.) So this string is number 53 in the list and so it will be encoded by the binary expansion of 53 which is 110101. The maximum number of bits needed to store any of these strings is log (F '' ) = 7. So we will pad the left with 0 s E(010101001,9)=0110101

Lex Order: Algorithm? Example: Decode 1001011 = 75 into a length 9 binary string.

Lex Order: Algorithm? Example: Decode 1001011 = 75 into a length 9 binary string. 75>55=F_10 so the first bit is 1 75-55=20 20<34=F_9 so the next bit is 0 20<21=F_8 so the next bit is 0 20>13=F_7 so the next bit is 1 20-13=7 7<8=F_6 so the next bit is 0 7>5=F_5 so the next bit is 1 7-5=2 2<3=F_4 so the next bit is 0 2=2=F_3 so the next bit is 1 2-2=0 0<1=F_2 so the next bit is 0 D(1001011,9)=100101010

Theoretically Optimal Encoding A theoretically optimal encoding for length n 11-avoiding binary strings would use the ceiling of log + F $*+ bits. How big is log + F $*+? So. F $*+ < 1.6 $*+ 2 T.L $*+ = 2 T.L$*'.U log + F $*+ < log + 2 T.L$*'.U = 0.7n + 1.4

Another application of counting lower bounds Searching algorithm of sorted list: performance was measured in terms of number of comparisons between list elements What's the fastest possible worst case for any searching algorithm of sorted lists?

Another application of counting lower bounds Searching algorithm of sorted list: performance was measured in terms of number of comparisons between list elements What's the fastest possible worst case for any searching algorithm of sorted lists? Tree diagram represents possible comparisons we might have to do, based on relative sizes of elements.

Another application of counting lower bounds Searching algorithm of sorted list: If we construct a tree of all possible comparisons to find all elements, how many leaves will the tree have?

Another application of counting lower bounds Searching algorithm of sorted list: If we construct a tree of all possible comparisons to find all elements, how many leaves will the tree have? n How tall will this tree be?

Another application of counting lower bounds Searching algorithm of sorted list: If we construct a tree of all possible comparisons to find all elements, how many leaves will the tree have? n How tall will this tree be? log(n) So log(n) is the fastest possible runtime and binary search achieves this!!!!

Another application of counting lower bounds Sorting algorithm: performance was measured in terms of number of comparisons between list elements What's the fastest possible worst case for any sorting algorithm?

Another application of counting lower bounds Sorting algorithm: performance was measured in terms of number of comparisons between list elements What's the fastest possible worst case for any sorting algorithm? Tree diagram represents possible comparisons we might have to do, based on relative sizes of elements.

Another application of counting lower bounds Tree diagram represents possible comparisons we might have to do, based on relative sizes of elements. a, b, c distinct integers Rosen p. 761

Another application of counting lower bounds Sorting algorithm: performance was measured in terms of number of comparisons between list elements What's the fastest possible worst case for any sorting algorithm? Maximum number of comparisons for algorithm is height of its tree diagram.

Another application of counting lower bounds How many leaves will there be in a decision tree that sorts n elements? A. 2 n D. C(n,2) B. log n E. None of the above. C. n!

Another application of counting lower bounds Sorting algorithm: performance was measured in terms of number of comparisons between list elements What's the fastest possible worst case for any sorting algorithm? Maximum number of comparisons for algorithm is height of its tree diagram. For any algorithm, what would be smallest possible height? What do we know about the tree? * Internal nodes correspond to comparisons. * Leaves correspond to possible input arrangements.

Another application of counting lower bounds Sorting algorithm: performance was measured in terms of number of comparisons between list elements What's the fastest possible worst case for any sorting algorithm? Maximum number of comparisons for algorithm is height of its tree diagram. For any algorithm, what would be smallest possible height? What do we know about the tree? * Internal nodes correspond to comparisons. Depends on algorithm. * Leaves correspond to possible input arrangements. n!

Another application of counting lower bounds What's the fastest possible worst case for any sorting algorithm? Maximum number of comparisons for algorithm is height of its tree diagram. For any algorithm, what would be smallest possible height? What do we know about the tree? * Internal nodes correspond to comparisons. Depends on algorithm. * Leaves correspond to possible input arrangements. n! Each tree diagram must have at least n! leaves, so its height must be at least log 2 (n!).

Another application of counting lower bounds What's the fastest possible worst case for any sorting algorithm? Maximum number of comparisons for algorithm is height of its tree diagram. For any algorithm, what would be smallest possible height? What do we know about the tree? * Internal nodes correspond to comparisons. Depends on algorithm. * Leaves correspond to possible input arrangements. n! Each tree diagram must have at least n! leaves, so its height must be at least log 2 (n!). i.e. fastest possible worst case performance of sorting is log 2 (n!)

Another application of counting lower bounds What's the fastest possible worst case for any sorting algorithm? log 2 (n!) How big is that? Lemma: For n>1, Proof:

Another application of counting lower bounds What's the fastest possible worst case for any sorting algorithm? log 2 (n!) How big is that? Lemma: for n>1, Theorem: log 2 (n!) is in Proof: For n>1, taking logarithm of both sides in lemma gives i.e.

Another application of counting lower bounds What's the fastest possible worst case for any sorting algorithm? log 2 (n!) How big is that? Lemma: for n>1, Theorem: log 2 (n!) is in Therefore, the best sorting algorithms will need comparisons in the worst case. i.e. it's impossible to have a comparison-based algorithm that does better than Merge Sort (in the worst case).

Representing undirected graphs Strategy: 1. Count the number of simple undirected graphs. 2. Compute lower bound on the number of bits required to represent these graphs. 3. Devise algorithm to represent graphs using this number of bits. What's true about simple undirected graphs? A. Self-loops are allowed. B. Parallel edges are allowed. C. There must be at least one vertex. D. There must be at least one edge. E. None of the above. Rosen p. 641-644

Representing undirected graphs: Counting In a simple undirected graph on n (labeled) vertices, how many edges are possible? A. n 2 B. n(n-1) C. C(n,2) D. 2 C(n,2) E. None of the above. ** Recall notation: C(n,k) = **

Representing undirected graphs: Counting In a simple undirected graph on n (labeled) vertices, how many edges are possible? A. n 2 B. n(n-1) C. C(n,2) Possibly one edge for each set of two distinct vertices. D. 2 C(n,2) E. None of the above. ** Recall notation: C(n,k) = **

Representing undirected graphs: Counting How many different simple undirected graphs on n (labeled) vertices are there? A. n 2 B. n(n-1) C. C(n,2) D. 2 C(n,2) E. None of the above.

Representing undirected graphs: Lower bound How many different simple undirected graphs on n (labeled) vertices are there? A. n 2 B. n(n-1) C. C(n,2) D. 2 C(n,2) For each possible edge, decide if in graph or not. E. None of the above. Conclude: minimum number of bits to represent simple undirected graphs with n vertices is log 2 (2 C(n,2) ) = C(n,2) = n(n-1)/2

Representing undirected graphs: Algorithm Goal: represent a simple undirected graph with n vertices using n(n-1)/2 bits. Idea: store adjacency matrix, but since - diagonal entries all zero no self loops - matrix is symmetric undirected graph only store the entries above the diagonal. How many entries of the adjacency matrix are above the diagonal? A. n 2 D. 2n B. n(n-1) E. None of the above. C. C(n,2)

Representing undirected graphs: Algorithm Goal: represent a simple undirected graph with n vertices using n(n-1)/2 bits Idea: store adjacency matrix, but since - diagonal entries all zero no self loops - matrix is symmetric undirected graph only store the entries above the diagonal. Can be stored as 0111101100 which uses C(5,2) = 10 bits.

Representing undirected graphs: Algorithm Decoding:? What simple undirected graph is encoded by the binary string 011010 110101 111111 000000 110101 110010? A. B. 001101011 000101111 000111000 000000011 000000101 000000110 000000001 000000000 C. Either one of the above. D. Neither one of the above.

Representing directed graphs: Counting In a simple directed graph on n (labeled) vertices, how many edges are possible? A. n 2 B. n(n-1) C. C(n,2) D. 2 C(n,2) E. None of the above. Simple graph: no self loops, no parallel edges.

Representing directed graphs: Counting In a simple directed graph on n (labeled) vertices, how many edges are possible? A. n 2 B. n(n-1) Choose starting vertex, choose ending vertex. C. C(n,2) D. 2 C(n,2) E. None of the above. Simple graph: no self loops, no parallel edges.

Representing directed graphs: Counting How many different simple directed graphs on n (labeled) vertices are there? A. n 2 B. n(n-1) C. C(n,2) D. 2 C(n,2) E. None of the above.

Representing directed graphs: Counting Another way of counting that there are 2 n(n-1) simple directed graphs with n vertices: Represent a graph by For each of the C(n,2) pairs of distinct vertices {v,w}, specify whether there is * no edge between them * an edge from v to w but no edge from w to v * an edge from w to v but no edge from v to w * edges both from v to w and from v to w.

Representing directed graphs: Counting Another way of counting that there are 2 n(n-1) directed graphs with n vertices: Represent a graph by For each of the C(n,2) pairs of distinct vertices {v,w}, C(n,2) pairs specify whether there is * no edge between them each has 4 options * an edge from v to w but no edge from w to v * an edge from w to v but no edge from v to w * edges both from v to w and from v to w. Product rule! (4)(4).(4) = 4 C(n,2) =4 (n(n-1)/2) =2 n(n-1)

Representing directed graphs: Lower bound Conclude: minimum number of bits to represent simple directed graphs with n vertices is log 2 (2 n(n-1) ) = n(n-1)

Representing directed graphs: Algorithm Encoding: For each of the n vertices, indicate which of the other vertices it has an edge to. How would you encode this graph using bits (0s and 1s)? A. 123232443 B. 0110 0000 0101 0010 C. 110 000 011 001 D. None of the above.

Representing directed graphs: Algorithm Decoding: Given a string of 0s and 1s of length n(n-1), Define vertex set { 1,, n }. First n-1 bits indicate edges from vertex 1 to other vertices. Next n-1 bits indicate edges from vertex 2 to other vertices. etc. What graph does this binary string encode? 0110 1001 0001 1011 0100