Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Puzzling Problems in Computer Engineering: A Freshman Seminar, Slides of Computer Science

Information about a freshman seminar in computer engineering (ce) at ucsb, focusing on puzzling problems that are related to ce. The course combines mathematical puzzles with ce problems and uses a pass/fail grading system based on attendance and class participation. Examples of euclid sequences, fibonacci sequences, and collatz sequences, and discusses the concept of easy problems in computational complexity.

Typology: Slides

2012/2013

Uploaded on 04/30/2013

naji
naji 🇮🇳

4.3

(6)

88 documents

1 / 17

Toggle sidebar

Related documents


Partial preview of the text

Download Puzzling Problems in Computer Engineering: A Freshman Seminar and more Slides Computer Science in PDF only on Docsity! Easy, Hard, Impossible! Puzzling Problems in Computer Engineering Docsity.com Why a Freshman Seminar in CE? To remedy the problem of CE student not being sufficiently exposed to interesting major-specific problems that could keep them motivated during their first two years of taking basic courses ECE 1 CS 130A ECE 15A ECE 15B CS 170 Math 3A Math 3B Math 3C Math 5A CS 10 CS 20 CS 40 CS 60 Phys 1 Phys 2 Phys 3 Phys 4 Phys 3L Phys 4L Chem 1A Chem 1B Chem 1AL Chem 1BL ECE 2A ECE 2B ECE 2C ECE 152A ECE 152B ECE 154 1 2 3 4 5 Units Engr 101 Upper - division standing ECE 139 Or CS 30 Or PSTAT 120A Or CS 30 Required courses for CE majors at UCSB Docsity.com Now, on to Today’s Topic: Easy, Hard, Impossible is like a war to start to end. to forget. “It’s not as easy as it looks!” “The hardest things to deal with in this job are feelings and lawyers.” “Of course it’s impossible to figure out. Why else would they call it the tax code?” Docsity.com Easy: Euclid Sequences Form a sequence of number pairs (integers) as follows: Begin with any two positive numbers as the first pair In each step, the next number pair consists of (1) the smaller of the current pair of values, and (2) their difference Stop when the two numbers in the pair become equal Challenge: Repeat this process for a few more starting number pairs and see if you can discover something about how the final number pair is related to the starting values (10, 15) (10, 5) (5, 5) (9, 23) (9, 14) (9, 5) (5, 4) (4, 1) (1, 3) (1, 2) (1, 1) (22, 6) (6, 16) (6, 10) (6, 4) (4, 2) (2, 2) Why is the process outlined above guaranteed to end? Docsity.com Not So Easy: Fibonacci Sequences Form a sequence of numbers (integers) as follows: Begin with any two numbers as the first two elements In each step, the next number is the sum of the last two numbers already in the sequence Stop when you have generated the j th number (j is given) Challenge: See if you can find a formula that yields the j th number directly (i.e., without following the sequence) when we begin with 1 1 5 16 21 37 1 1 2 3 5 8 13 21 34 55 89 144 2 0 2 2 4 6 10 16 26 j = 4 j = 9 j = 12 Docsity.com Easy, Not So Easy, Very Hard Euclid: Form a sequence of number pairs (integers) as follows: Begin with any two positive numbers as the first pair In each step, the next number pair consists of (1) the smaller of the current pair of values, and (2) their difference Stop when the two numbers in the pair become equal Collatz: Form a sequence of numbers (integers) as follows: Begin with a given number To find the next number in each step, halve the current number if it is even or triple it and add 1 if it is odd Fibonacci: Form a sequence of numbers (integers) as follows: Begin with any two numbers as the first two elements In each step, the next number is the sum of the last two numbers already in the sequence Stop when you have generated the j th number (j is given) Docsity.com What Makes a Computational Problem Easy? Euclid: Form a sequence of number pairs (integers) as follows: Begin with any two positive numbers as the first pair In each step, the next number pair consists of (1) the smaller of the current pair of values, and (2) their difference Stop when the two numbers in the pair become equal Analysis: Number of steps in the worst case (1, n) (1, n – 1) (1, n – 2) . . . (1, 1) Algorithm: gcd(x , y), greatest common divisor of x and y If x = y, then output x and stop Otherwise, compute gcd(min(x, y), |x – y|) (n – 1 steps) When the number of steps is a polynomial function of the problem size, the problem is considered computationally easy or tractable The idea is that modern computers can perform many billions of computations per second, so even n2 or n5 steps may be manageable Docsity.com Easy Problems: Degrees of Ease Consider the computation of x mod y (remainder of dividing x by y), where x and y are positive integers Analysis: Number of steps in the worst case (n, 1) (n – 1, 1) (n – 2, 1) . . . (0, 1) Algorithm: rem(x , y), remainder of dividing x by y If x < y, then output x and stop Otherwise, compute rem(x – y, y) (n steps) For example, if n ≈ 1016 (i.e., a 16-digit decimal number), and if each computation step takes 1 ns (10–9 s), then the execution time of this algorithm would be 1016/109 s = 107 s ≈ 2778 hr ≈ 116 days ≈ 4 mo Long division would yield the answer much quicker, in time that depends on the number of digits in n (i.e., log n) and not on n itself Computer scientists and engineers pursue more efficient algorithms Docsity.com Getting a Handle on Difficult Problems Use the computer to experiment and find solutions for many instances; then, try to generalize from the results and patterns observed Diagrams from: Weisstein, Eric W., “Collatz Problem,” MathWorld (http://mathworld.wolfram.com/CollatzProblem.html) Number of steps for the Collatz sequence to reach 1, as a function of n In CE, the computer is both an object of study and a tool to help the study Docsity.com Are Collatz Sequences Useful? Not directly, but they help us understand the nature of difficult problems Decision problem: Is there an algorithm to decide whether a given program computing f(n) will eventually stop for every input n? Program in question Decision Algorithm Yes/No Program: Collatz( n ), Collatz sequence for n Print n and set x := n While x > 1 repeat If x is even then x := x/2 else x := 3x + 1 In either case, print the new value of x Collatz’s conjecture is true Collatz’s conjecture is false Suppose such a decision algorithm exists Docsity.com Two Other Easy-Looking Hard Problems The subset sum problem: Given a set of n numbers, determine whether there is a subset whose sum is a given value x S = {3, –4, 32, –25, 6, 10, –9, 50} x = 22 Can’t do fundamentally better than simply trying all 2n subsets (exponential time, intractable for even moderately large n) The traveling salesperson problem: Given a set of n cities with known travel cost cij between cities i and j, find a path of least cost that would take a salesperson through all cities, returning to the starting city A C D E F B 5 2 1 2 1 3 4 5 1 3 3 4 In the worst case, must examine nearly all the (n – 1) ! cycles, which would require exponential time Docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved