text
stringlengths
1
7.76k
source
stringlengths
17
81
12.1. TRAVELING WAVES 285 Comparing (12.7) and (12.8), you can see that E V = cp V (12.9) This relationship between the energy and momentum densities (one is just c times the other) is an extremely general result that applies to all sorts of waves, including electromagnetic waves! 12.1.3 The wave velocity You may ask, ...
University Physics I Classical Mechanics_Page_303_Chunk4501
286 CHAPTER 12. WAVES IN ONE DIMENSION whereas in a denser gas like sulfur hexafluoride the speed of sound is less than in air1. However, if you compare the speed of sound in water to the speed of sound in air, you find it is much greater in water, since water is much harder to compress than air: in this case, the increa...
University Physics I Classical Mechanics_Page_304_Chunk4502
12.1. TRAVELING WAVES 287 waves, that is, wave pulses: a pulse going into a faster medium will widen in length (stretch), whereas a pulse going into a slower medium will become narrower (squeezed). Imagine, for example, several people walking in line, separated by the same distance d, all at the same pace, until they r...
University Physics I Classical Mechanics_Page_305_Chunk4503
288 CHAPTER 12. WAVES IN ONE DIMENSION carried by the incident wave, and whether it is possible for the transmitted wave alone to handle the incoming energy flux or not. As we saw earlier (Eq. (12.8)), the energy per unit volume in a harmonic wave of angular frequency ω and amplitude ξ0 is E/V = 1 2ρ0ω2ξ2 0. If the wave...
University Physics I Classical Mechanics_Page_306_Chunk4504
12.2. STANDING WAVES AND RESONANCE 289 it hard to set up a transmitted wave: the transmitted wave amplitude will be small (compared to that of the incident wave), and the only way to satisfy the condition ξ0,inc + ξ0,refl= ξ0,trans will be to set up a reflected wave with a negative amplitude3—in effect, to flip the reflecte...
University Physics I Classical Mechanics_Page_307_Chunk4505
290 CHAPTER 12. WAVES IN ONE DIMENSION minus sign on the displacement, to get −ξ0 sin[2π(−x + ct)/λ]. The sum of the two waves in the region x > 0 is then ξ(x, t) = ξ0 sin 22π λ (x + ct) 3 −ξ0 sin 22π λ (−x + ct) 3 = 2ξ0 sin $2πx λ % cos (2πft) (12.16) using a trigonometrical identity for sin(a + b), and f = c/λ. The r...
University Physics I Classical Mechanics_Page_308_Chunk4506
12.2. STANDING WAVES AND RESONANCE 291 -1 0 1 0 0.2 0.4 0.6 0.8 1 -1 0 1 -1 0 1 x/L ξ/ξ0 Figure 12.5: The three lowest-frequency normal modes of vibration of a string held down at both ends, corresponding to, from top to bottom, n = 1, 2, 3 Animations of these standing waves can be found in many places; one I particula...
University Physics I Classical Mechanics_Page_309_Chunk4507
292 CHAPTER 12. WAVES IN ONE DIMENSION of the frequencies fn, and each with a different amplitude An. In a musical instrument, this will eventually generate a superposition of sound waves with frequencies f1 = c/2L, f2 = 2f1, f3 = 3f1 . . . (called, in this context, the fundamental, f1, and its overtones, fn = nf1). Eac...
University Physics I Classical Mechanics_Page_310_Chunk4508
12.3. CONCLUSION, AND FURTHER RESOURCES 293 12.3 Conclusion, and further resources This chapter on one-dimensional waves has barely scratched the surface of the extremely rich world of wave phenomena. I have only given you a passing glance at interference, and I have not said anything at all about diffraction, the Doppl...
University Physics I Classical Mechanics_Page_311_Chunk4509
294 CHAPTER 12. WAVES IN ONE DIMENSION 5. Sound is a longitudinal compression-and-rarefaction wave in an elastic medium. It can be described in terms of displacement, pressure or density. The pressure or density disturbance is maximal where the displacement is zero, and vice-versa. 6. The speed of sound in a solid with...
University Physics I Classical Mechanics_Page_312_Chunk4510
12.5. EXAMPLES 295 12.5 Examples 12.5.1 Displacement and density/pressure in a longitudinal wave The picture below shows the displacement of a medium (let’s say air) as a sound pulse travels through it. (Don’t worry about the units on the axes right now! We are only interested in qualitative results here.) ξ displaceme...
University Physics I Classical Mechanics_Page_313_Chunk4511
296 CHAPTER 12. WAVES IN ONE DIMENSION Conversely, if you look at a point with positive slope, such as x = 0, you see that the particles on the right are pushed farther to the right than the particles on the left, which means the density around x = 0 will drop. From this you may conclude that the density versus positio...
University Physics I Classical Mechanics_Page_314_Chunk4512
12.5. EXAMPLES 297 However, if you now try to figure out the shape of the density/pressure wave based on the displace- ment wave, as we did in part (a), you’ll see that it is only reversed left to right, but not flipped upside down! This is a general property of longitudinal waves: the reflected pressure/density wave beha...
University Physics I Classical Mechanics_Page_315_Chunk4513
298 CHAPTER 12. WAVES IN ONE DIMENSION 12.5.2 Violin sounds The “sounding length” of a violin string, from the bridge to the nut at the upper end of the fingerboard, is about 32 cm. (a) If the string is tuned so that its fundamental frequency corresponds to a concert A (440 Hz), what is the speed of a wave on that strin...
University Physics I Classical Mechanics_Page_316_Chunk4514
12.6. ADVANCED TOPICS 299 12.6 Advanced Topics 12.6.1 Chain of masses coupled with springs: dispersion, and long-wavelength limit. Consider a model of an extended elastic medium in which, for simplicity, we separate the two main medium properties, inertia and elasticity, by describing it as a chain of point-like masses...
University Physics I Classical Mechanics_Page_317_Chunk4515
300 CHAPTER 12. WAVES IN ONE DIMENSION Now let us try to see if we can get a sinusoidal solution to this system of differential equations. By analogy with Eq. (12.3) let ξn(t) = A sin 4 2π &xn λ −ft '5 where xn = nd is the equilibrium position of the n-th mass. Then for each of the three masses considered, we have ξn−1(...
University Physics I Classical Mechanics_Page_318_Chunk4516
12.6. ADVANCED TOPICS 301 In the long wavelength limit, however, the dispersion in this model disappears. We can see this as follows. In that limit, λ ≫d (the wavelength is much greater than the distance between the masses), and therefore πd/λ ≪1; we can then make the small-angle approximation in Eq. (12.27), sin(πd/λ)...
University Physics I Classical Mechanics_Page_319_Chunk4517
302 CHAPTER 12. WAVES IN ONE DIMENSION 12.7 Problems Problem 1 When plucked, the D string on a guitar vibrates with a frequency of 147 Hz. (a) What would happen to this frequency if you were to increase the tension in the string? (b) The vibration of the string eventually produces a sound wave of the same frequency, tr...
University Physics I Classical Mechanics_Page_320_Chunk4518
Chapter 13 Thermodynamics 13.1 Introduction The last two lectures this semester are about thermodynamics, an extremely important branch of physics that developed throughout the 19th century, motivated in part by the development of the steam engines that brought about the Industrial Revolution. Physics majors will study...
University Physics I Classical Mechanics_Page_321_Chunk4519
304 CHAPTER 13. THERMODYNAMICS (waves) in which the constituent parts of an object move relative to each other in a way that looks “organized,” or synchronized, from a macroscopic perspective. What is needed next is to account for the random motion, on a microscopic scale, of the smallest parts (atoms or molecules) tha...
University Physics I Classical Mechanics_Page_322_Chunk4520
13.2. INTRODUCING TEMPERATURE 305 and we can use the heat capacity2 to, ultimately, relate the system’s temperature to its energy content in a one-to-one-way. What is found experimentally is that the heat capacity of a homogeneous object (that is, one made of just one substance) is, in general, proportional to its mass...
University Physics I Classical Mechanics_Page_323_Chunk4521
306 CHAPTER 13. THERMODYNAMICS Figure 13.1: In this simple model of a gas of diatomic molecules, each molecule can store “vibrational” potential energy (both potential and kinetic, through the oscillations of the “spring” that models the inter- action between the atoms), plus as at least two kinds of rotational kinetic...
University Physics I Classical Mechanics_Page_324_Chunk4522
13.2. INTRODUCING TEMPERATURE 307 many real-world gases under a wide range of pressure and temperature, where “temperature” literally means simply “what any good thermometer would measure”) immediately tells us what temperature is, at least for this extremely simple system: it is just a measure of the average (translat...
University Physics I Classical Mechanics_Page_325_Chunk4523
308 CHAPTER 13. THERMODYNAMICS Eq. (13.6) to work, the temperature must be measured in degrees Kelvin). The zero point of that scale (what we call absolute zero) is the theoretical point at which an ideal gas would shrink to precisely zero volume. Of course, no gas stays ideal (or even gaseous!) at such low temperature...
University Physics I Classical Mechanics_Page_326_Chunk4524
13.3. HEAT AND THE FIRST LAW 309 thermal energy has no other place to go). Then, eventually, they will reach a state, called thermal equilibrium, in which they will both have the same temperature. This is important for many reasons, not the least of which being that that is what allows us to mea- sure temperature with ...
University Physics I Classical Mechanics_Page_327_Chunk4525
310 CHAPTER 13. THERMODYNAMICS Naturally, this observation was made long before the concept of “energy” was even developed, and so heat was thought of, for a time, as an “invisible fluid” (called, at one point, “caloric fluid”), a sort of indestructible “substance” that literally passed from one body to another. By “inde...
University Physics I Classical Mechanics_Page_328_Chunk4526
13.3. HEAT AND THE FIRST LAW 311 caloric was not a fluid at all, but rather “a form of motion,” since only something like that could be made to increase without any apparent limit. Rumford’s theory was not generally accepted at the time, but later in the 19th century the direct conversion of mechanical energy into therm...
University Physics I Classical Mechanics_Page_329_Chunk4527
312 CHAPTER 13. THERMODYNAMICS 13.4 The second law and entropy The second law of thermodynamics is really little more than a formal statement of the observation that heat always flows spontaneously from a warmer to a colder object, and never in reverse. More precisely, consider two systems, at different temperatures, tha...
University Physics I Classical Mechanics_Page_330_Chunk4528
13.4. THE SECOND LAW AND ENTROPY 313 Equation (13.9) is valid regardless of the temperature scale. If we use the Kelvin scale, in which all the temperatures are positive3, we can rewrite it by dividing both sides by the product T1T2, and using Q2 = −Q1, as Q1 T1 + Q2 T2 ≥0 (13.10) This more symmetric statement of the s...
University Physics I Classical Mechanics_Page_331_Chunk4529
314 CHAPTER 13. THERMODYNAMICS too far from a state of thermal equilibrium). I will not attempt the proof here, but merely note that this provides the following, alternative formulation of the second law of thermodynamics: For every system in thermal equilibrium, there is a state function, the entropy, with the propert...
University Physics I Classical Mechanics_Page_332_Chunk4530
13.4. THE SECOND LAW AND ENTROPY 315 Carnot modeled a “heat engine” as an abstract machine that worked in a cycle. In the course of each cycle, the engine would take in an amount of heat Qh from a “hot reservoir,” give off(or “exhaust”) an amount of heat |Qc| to a “cold reservoir,” and produce an amount of work |W|. (I ...
University Physics I Classical Mechanics_Page_333_Chunk4531
316 CHAPTER 13. THERMODYNAMICS What makes this result more than a theoretical curiosity is the fact that an ideal gas would, in fact, provide a suitable working substance for a Carnot machine, if put through the following cycle (the so-called “Carnot cycle”): an isothermal expansion, followed by an adiabatic expansion,...
University Physics I Classical Mechanics_Page_334_Chunk4532
13.4. THE SECOND LAW AND ENTROPY 317 thermal energy back to work we would need to introduce a colder reservoir (and take advantage, so to speak, of the natural flow of heat from hotter to colder), and then we would only get a relatively small conversion efficiency, unless the cold reservoir is really at a very low Kelvin ...
University Physics I Classical Mechanics_Page_335_Chunk4533
318 CHAPTER 13. THERMODYNAMICS considerable range of values. A state of large entropy corresponds to a broad distribution, and a state of small entropy to a narrow one. For an ideal gas, the temperature determines both the average molecular speed and the spread of the velocity distribution. This is because the average ...
University Physics I Classical Mechanics_Page_336_Chunk4534
13.5. IN SUMMARY 319 13.5 In summary 1. Temperature is a statistical quantity that provides a (typically indirect) measure of the con- centration of thermal energy in a system. For a system that is (approximately) well described by classical mechanics, the temperature, as measured by a conventional thermometer, is di- ...
University Physics I Classical Mechanics_Page_337_Chunk4535
320 CHAPTER 13. THERMODYNAMICS 12. Microscopically, the entropy of a system is a measure of the range of distinct states available to its microscopic components (atoms or molecules) that are compatible with the set of macroscopic constraints that determine its thermal equilibrium state. More entropy means a greater ran...
University Physics I Classical Mechanics_Page_338_Chunk4536
13.6. EXAMPLES 321 13.6 Examples 13.6.1 Calorimetry The specific heat of aluminum is 900 J/kg·K, and that of water is 4186 J·K. Suppose you drop a block of aluminum of mass 1 kg at a temperature of 80◦C in a liter of water (which also has a mass of 1 kg) at a temperature of 20◦C. What is the final temperature of the syst...
University Physics I Classical Mechanics_Page_339_Chunk4537
322 CHAPTER 13. THERMODYNAMICS So, 1 kg of aluminum gives off44.4 kJ of thermal energy and its temperature drops almost 50◦C, from 80◦C to 30.6◦C, whereas 1 kg of water takes in the same amount of thermal energy and its temperature only rises about 10.6◦C. 13.6.2 Equipartition of energy Estimate the speed of an oxygen m...
University Physics I Classical Mechanics_Page_340_Chunk4538
13.7. PROBLEMS 323 13.7 Problems Problem 1 Consider a system of two objects in contact, one initially hotter than the other, so they may directly exchange thermal energy, in isolation from the rest of the world. According to the laws of thermodynamics, what must happen to the system’s total energy and entropy? (Do they...
University Physics I Classical Mechanics_Page_341_Chunk4539
324 CHAPTER 13. THERMODYNAMICS • A diatomic gas molecule, such as O2, can store kinetic energy in the form of vibrations and rotations, in addition to just translation of the center of mass. By contrast, a monoatomic gas molecule such as C has virtually no kinetic energy (at normal temperatures) other than translationa...
University Physics I Classical Mechanics_Page_342_Chunk4540
Algorithms and Data Structures With Applications to Graphics and Geometry
algorithms and data structures_Page_1_Chunk4541
This book is licensed under a Creative Commons Attribution 3.0 License Algorithms and Data Structures With Applications to Graphics and Geometry Jurg Nievergelt Klaus Hinrichs Copyright © 2011 Jurg Nievergelt Editor-In-Chief: Jurg Nievergelt Associate Editor: Marisa Drexel Ulrich Editorial Assistants: Jon Durden, Tessa...
algorithms and data structures_Page_2_Chunk4542
Table of Contents Part I: Programming environments for motion, graphics, and geometry.................................7 1. Reducing a task to given primitives: programming motion...................................................9 A robot car, its capabilities, and the task to be performed.................................
algorithms and data structures_Page_3_Chunk4543
This book is licensed under a Creative Commons Attribution 3.0 License Paths in a graph.............................................................................................................................................. 93 Boolean matrix multiplication.............................................................
algorithms and data structures_Page_4_Chunk4544
The range of data structures studied............................................................................................................ 181 Performance criteria and measures..............................................................................................................182 19. Abstract data types....
algorithms and data structures_Page_5_Chunk4545
This book is licensed under a Creative Commons Attribution 3.0 License Updating the y-table and detecting an intersection.................................................................................... 289 Sweeping across intersections ...................................................................................
algorithms and data structures_Page_6_Chunk4546
Part I: Programming environments for motion, graphics, and geometry Part I of this text book will discuss: • simple programming environments • program design • informal versus formal notations • reducing a solution to primitive operations, and programming as an activity independent of language. The purpose of an artifi...
algorithms and data structures_Page_7_Chunk4547
This book is licensed under a Creative Commons Attribution 3.0 License programming environment suitable for programming graphics and motion, and illustrates how it can gradually be enriched to approach a simple but useful graphics environment. Textbooks on computer graphics. The computer-driven graphics screen is a pow...
algorithms and data structures_Page_8_Chunk4548
This book is licensed under a Creative Commons Attribution 3.0 License 1. Reducing a task to given primitives: programming motion Learning objectives: • primitives for specifying motion • expressing an algorithm in informal notations and in high- and low-level programming languages • program verification • program opti...
algorithms and data structures_Page_9_Chunk4549
1. Reducing a task to given primitives: programming motion A program for the robot is a sequence of commands with distinct labels. The labels serve merely to identify the commands and need not be arranged either consecutively or in increasing order. Execution begins with the first command and proceeds to successive com...
algorithms and data structures_Page_10_Chunk4550
This book is licensed under a Creative Commons Attribution 3.0 License Exhibit 1.3: The robot turns around a spike. Exhibit 1.4: Backing up in a blind alley. Algorithm specified in a high-level language The ideas presented informally in above section are made precise in the following elegant, concise program: { wall to...
algorithms and data structures_Page_11_Chunk4551
1. Reducing a task to given primitives: programming motion Exhibit 1.6: Robot motions as predicate transformers. Algorithm programmed in the robot's language A straightforward translation from the high-level program into the robot's low-level language yields the following seven-line wall-following program: loop left; 1...
algorithms and data structures_Page_12_Chunk4552
This book is licensed under a Creative Commons Attribution 3.0 License 5 goto 2 5 goto 2 6 forward 6 forward 7 goto 1 7 goto 1 An optimization technique called loop rotation allows us to shorten this program by yet another instruction. It changes the structure of the program significantly, as we see from the way the la...
algorithms and data structures_Page_13_Chunk4553
This book is licensed under a Creative Commons Attribution 3.0 License 2. Graphics primitives and environments Learning objectives: • turtle graphics • QuickDraw: A graphics toolbox • frame program • interactive graphics input/output • example: polyline input Turtle graphics: a basic environment Seymour Papert [Pap80] ...
algorithms and data structures_Page_14_Chunk4554
2. Graphics primitives and environments Procedures as building blocks A program is built from components at many different levels of complexity. At the lowest level we have the constructs provided by the language we use: constants, variables, operators, expressions, and simple (unstructured) statements. At the next hig...
algorithms and data structures_Page_15_Chunk4555
This book is licensed under a Creative Commons Attribution 3.0 License length 2πr. We approximate it by drawing short-line segments, about 3 pixels long, thus needing about 2·r line segments. procedure circle(x, y, r: integer); { centered at (x, y); radius r} var a, s, i: integer; { angle, step, counter } begin moveto(...
algorithms and data structures_Page_16_Chunk4556
2. Graphics primitives and environments FrameOval draws an outline just inside the oval that fits inside the specified rectangle, using the current grafPort's pen pattern, mode, and size. The outline is as wide as the pen width and as tall as the pen height. It's drawn with the pnPat, according to the pattern transfer ...
algorithms and data structures_Page_17_Chunk4557
This book is licensed under a Creative Commons Attribution 3.0 License Synchronization In interactive applications we often wish to specify a grid point by letting the user point the mouse-driven cursor to some spot on the screen. The 'procedure GetMouse(v, h)' returns the coordinates of the grid point where the cursor...
algorithms and data structures_Page_18_Chunk4558
2. Graphics primitives and environments • 'patXor' (exclusive-or, also known as "odd parity") sets the result to black iff exactly one of (screen pixel, pattern pixel) is black. A white pixel in the pen leaves the underlying screen pixel unchanged; a black pixel complements it. Thus a black pen inverts the screen. 'pnM...
algorithms and data structures_Page_19_Chunk4559
This book is licensed under a Creative Commons Attribution 3.0 License var c, p: point; r: real; { radius of a circle } L: lineSegment; procedure WaitForClick; begin repeat until Button; while Button do end; procedure GetPoint (var p: point); var v, h: integer; begin GetMouse(v, h); p.x := v; p.y := h { convert integer...
algorithms and data structures_Page_20_Chunk4560
2. Graphics primitives and environments r := Dist(c, p); DrawCircle(c, r, black); end; PenMode(patCopy) end; { DragCircle } procedure Title; begin ShowText; { make sure the text window and … } ShowDrawing; { … the graphics window show on the screen } WriteLn('Frame program'); WriteLn('with simple graphics and interacti...
algorithms and data structures_Page_21_Chunk4561
This book is licensed under a Creative Commons Attribution 3.0 License p, q: point; function EqPoints (p, q: point): boolean; begin EqPoints := (p.x = q.x) and (p.y = q.y) end; function Dist (p, q: point): real; begin Dist := sqrt(sqr(p.x – q.x) + sqr(p.y – q.y)) end; procedure DrawLine (p, q: point; c: Pattern); begin...
algorithms and data structures_Page_22_Chunk4562
2. Graphics primitives and environments 3. Implement your personal graphics frame program as described in “A graphics frame program”. Your effort will pay off in time saved later, as you will be using this program throughout the entire course. 23
algorithms and data structures_Page_23_Chunk4563
This book is licensed under a Creative Commons Attribution 3.0 License 3. Algorithm animation I hear and I forget, I see and I remember, I do and I understand. A picture is worth a thousand words—the art of presenting information in visual form. Learning objectives: • adding animation code to a program • examples of al...
algorithms and data structures_Page_24_Chunk4564
3. Algorithm animation computer interaction. In this use of algorithm animation, the user may be checking his understanding of the algorithm, or may be checking the algorithm's correctness—in principle, he could reason this out, but in practice, it is faster and safer to have the computer animation as a double check. E...
algorithms and data structures_Page_25_Chunk4565
This book is licensed under a Creative Commons Attribution 3.0 License In conclusion, we hold that it is not too difficult to animate simple algorithms as discussed here by interspersing drawing statements into the normal code. Independent of the algorithm to be animated, you can call on your own collection of display ...
algorithms and data structures_Page_26_Chunk4566
3. Algorithm animation i := b[i]; dx[n] := x[n] – x[i]; dy[n] := y[n] – y[i]; MoveTo(px, py); Line(–dx[n], –dy[n]); b[n] := i end; MoveTo(px, py); PenSize(2, 2); Line(–dx[n], –dy[n]); PenNormal end; procedure Title; begin ShowText; ShowDrawing; { make sure windows lie on top } WriteLn('The convex hull'); WriteLn('of n ...
algorithms and data structures_Page_27_Chunk4567
This book is licensed under a Creative Commons Attribution 3.0 License Exhibit 3.1: … and snapshots from two sorting algorithms. Visual test for randomness Our visual system is amazingly powerful at detecting patterns of certain kinds in the midst of noise. Random number generators (RNGs) are intended to simulate "nois...
algorithms and data structures_Page_28_Chunk4568
3. Algorithm animation is one of the most frequent formulas evaluated in scientific and technical computation (e.g. for the solution of differential equations). By proper choice of the constants ci and of initial values z0, z1, … , zd–1 we can generate sequences zk that when plotted in the plane of complex numbers form...
algorithms and data structures_Page_29_Chunk4569
This book is licensed under a Creative Commons Attribution 3.0 License Algorithms and Data Structures 30 A Global Text
algorithms and data structures_Page_30_Chunk4570
3. Algorithm animation Exhibit 3.3: The effect of rounding errors in linear recurrence relations. Programming projects 1. Use your personal graphics frame program (the programming project of “graphics primitives and environments”) to implement and animate the convex hull algorithm example. 31
algorithms and data structures_Page_31_Chunk4571
This book is licensed under a Creative Commons Attribution 3.0 License 2. Use your graphics frame program to implement and animate the behavior of recurrence relations as discussed in the section “A gallery of algorithm snapshots”. 3. Extend your graphics frame program with a set of dialog control operations sufficient...
algorithms and data structures_Page_32_Chunk4572
This book is licensed under a Creative Commons Attribution 3.0 License Part II: Programming concepts: beyond notation Thoughts on the role of programming notations A programming language is the main interface between a programmer and the physical machine, and a novice programmer will tend to identify "programming" with...
algorithms and data structures_Page_33_Chunk4573
This book is licensed under a Creative Commons Attribution 3.0 License 4. Algorithms and programs as literature: substance and form Learning objectives: • programming in the large versus programming in the small • large flat programs versus small deep programs • programs as literature • fractal pictures: snowflakes and...
algorithms and data structures_Page_34_Chunk4574
4. Algorithms and programs as literature: substance and form best way to get started in computer science. We encourage the reader to work out all the details of the examples we present. This book is concerned only with programming in the small. This decision determines our choice of topics to be presented, our style of...
algorithms and data structures_Page_35_Chunk4575
This book is licensed under a Creative Commons Attribution 3.0 License A snowflake Fractal pictures are intuitively characterized by the requirement that any part of the picture, of any size, when sufficiently magnified, looks like the whole picture. Two pieces of information are required to define a specific fractal: ...
algorithms and data structures_Page_36_Chunk4576
4. Algorithms and programs as literature: substance and form segment is to be replaced by a "plain with a mountain in the center", on which side of the segment should the peak point? The drawings above suggest that all peaks stick out on the same side of the curve, the outside. 2. Could our method of description be ext...
algorithms and data structures_Page_37_Chunk4577
This book is licensed under a Creative Commons Attribution 3.0 License Exhibit 4.5: Six generations of the family of Hilbert curves Exhibit 4.6: Productions for painting a square in terms of its quadrants The left-hand side of the first production stands for the task: paint a square of given size, assuming that you ent...
algorithms and data structures_Page_38_Chunk4578
4. Algorithms and programs as literature: substance and form what direction to face, and whether you are painting with your right or left hand. The last detail is to make sure that when the brush exits from one quadrant it gets into the correct state for entering the next. This requires the brush to turn by 90˚, either...
algorithms and data structures_Page_39_Chunk4579
This book is licensed under a Creative Commons Attribution 3.0 License ShowText; ShowDrawing; MoveTo(100, 100); turtleHeading := 0; { initialize turtle state } WriteLn('Enter halfTurn 0 .. 359 (45 for Hilbert curves): '); ReadLn(halfTurn); TurtleTurn(–halfTurn); { init turtle turning angle } Write('Enter depth 1 .. 6: ...
algorithms and data structures_Page_40_Chunk4580
4. Algorithms and programs as literature: substance and form project and language designed by Niklaus Wirth during the 1960s, ended up eclipsing both of these major efforts. Pascal took the best of Algol 60, in streamlined form, and added just one major extension, the then novel type definitions [Hoa 72]. This lightwei...
algorithms and data structures_Page_41_Chunk4581
This book is licensed under a Creative Commons Attribution 3.0 License application) ± Plus-or-minus, used to define an interval [of uncertainty] ∑∏ Sum and product x Ceiling of a real number x (i.e. the smallest integer ≥ x) x Floor of a real number x (i.e. the largest integer ≤ x) √ Square root log Logarithm to th...
algorithms and data structures_Page_42_Chunk4582
4. Algorithms and programs as literature: substance and form routine terminates in one of (at least) two different ways: successfully, by having found the item in question, or unsuccessfully, because of a number of reasons (the item is not present, and some index is about to fall outside the range of a table; we cannot...
algorithms and data structures_Page_43_Chunk4583
This book is licensed under a Creative Commons Attribution 3.0 License our understanding slowly grows toward a firm grasp of an idea, supporting intuition is much more important than formality. Thus we describe data structures and algorithms with the help of figures, words, and programs as we see fit in any particular ...
algorithms and data structures_Page_44_Chunk4584
This book is licensed under a Creative Commons Attribution 3.0 License 5. Divide-and-conquer and recursion Learning objectives: • The algorithmic principle of divide-and-conquer leads directly to recursive procedures. • Examples: Merge sort, tree traversal. Recursion and iteration. • My friend liked to claim "I'm 2/3 C...
algorithms and data structures_Page_45_Chunk4585
5. Divide-and-conquer and recursion "simplicity" that monotonically heads for the predicate 'simple' will do, when algorithm A0 will finish the job. "D is simple" may mean "D has no elements", in which case A0 may have to do nothing at all; or it may mean "D has exactly one element", and A0 may just mark this element a...
algorithms and data structures_Page_46_Chunk4586
This book is licensed under a Creative Commons Attribution 3.0 License In the chapter on “sorting and its complexity”, under the section “merging and merge sorts” we turn this divide- and-conquer scheme into a program. Recursively defined trees A tree, more precisely, a rooted, ordered tree, is a data type used primari...
algorithms and data structures_Page_47_Chunk4587
5. Divide-and-conquer and recursion Exhibit 5.5: Adding coordinate information to productions in order to control graphic layout The translation of these two rules into high-level code is now plain: procedure p1(x, y: coordinate); begin eraseTreeSymbol(x, y); drawLeafSymbol(x, y) end; procedure p2(x, y: coordinate; d: ...
algorithms and data structures_Page_48_Chunk4588
This book is licensed under a Creative Commons Attribution 3.0 License Recursive tree traversal Recursion is a powerful tool for programming divide-and-conquer algorithms in a straightforward manner. In particular, when the data to be processed is defined recursively, a recursive processing algorithm that mirrors the s...
algorithms and data structures_Page_49_Chunk4589
5. Divide-and-conquer and recursion Exhibit 5.7: Three standard orders merged into a triple tree traversal Recursion versus iteration: the Tower of Hanoi The "Tower of Hanoi" is a stack of n disks of different sizes, held in place by a tall peg (Exhibit 5.8). The task is to transfer the tower from source peg S to a tar...
algorithms and data structures_Page_50_Chunk4590
This book is licensed under a Creative Commons Attribution 3.0 License The following procedure is an equally elegant and more efficient iterative solution to this problem. It assumes that the pegs are cyclically ordered, and the target peg where the disks will first come to rest depends on this order and on the parity ...
algorithms and data structures_Page_51_Chunk4591
5. Divide-and-conquer and recursion procedure citr(x, y, r: real; d: integer); var vr: real; { variable radius } i: integer; begin vr := r; for i := 1 to d do { equitr(x, y, vr); vr := vr/2; circle(x, y, vr) } { show that the radius of consecutively nested circles gets exactly halved at each step } end; The flag of Alf...
algorithms and data structures_Page_52_Chunk4592
This book is licensed under a Creative Commons Attribution 3.0 License 6. Syntax Learning objectives: • syntax and semantics • syntax diagrams and EBNF describe context-free grammars • terminal and nonterminal symbols • productions • definition of EBNF by itself • parse tree • grammars must avoid ambiguities • infix, p...
algorithms and data structures_Page_53_Chunk4593
6. Syntax The syntax of a programming language is not as important as the semantics, but good understanding of the syntax often helps in understanding the language. With some practice one can often guess the semantics from the syntax, since the syntax of a well-designed programming language is the frame that supports t...
algorithms and data structures_Page_54_Chunk4594
This book is licensed under a Creative Commons Attribution 3.0 License For each nonterminal symbol there must be at least one production that describes how this syntactic entity is formed from other terminal or nonterminal symbols using the composition constructs above: The following examples show productions and the c...
algorithms and data structures_Page_55_Chunk4595
6. Syntax stmt = nts '=' expr '.' . expr = term { '|' term } . term = factor { factor } . factor = nts | ts | '(' expr ')' | '[' expr ']' | '{' expr '}' . nts= letter { letter | digit } . Example: syntax of simple expressions The following productions for the three nonterminals E(xpression), T(erm), and F(actor) can be...
algorithms and data structures_Page_56_Chunk4596
This book is licensed under a Creative Commons Attribution 3.0 License Exhibit 6.2: Parse tree for the expression # · ( # ) + # / # . Exercise: syntax diagrams for palindromes A palindrome is a string that reads the same when read forward or backward. Examples: 0110 and 01010. 01 is not a palindrome, as it differs from...
algorithms and data structures_Page_57_Chunk4597
6. Syntax Exhibit 6.4: A syntax that generates parse trees of ambiguous structure Now the expression # · # + # can be derived from E in two different ways (Exhibit 6.5). Such an ambiguous grammar is useless since we want to derive the semantic interpretation from the syntactic structure, and the tree at the left contra...
algorithms and data structures_Page_58_Chunk4598
This book is licensed under a Creative Commons Attribution 3.0 License In doing so we change the language. The more complex grammar with three nonterminals E(xpression, T(erm), and F(actor) lets us write expressions that are only partially parenthesized and assigns to them a unique structure compatible with our priorit...
algorithms and data structures_Page_59_Chunk4599
6. Syntax Exhibit 6.7: Suffix expressions have a unique structure even without the use of parentheses. Exercises 1. Consider the following syntax, given in EBNF: S = A. A = B | 'IF' A 'THEN' A 'ELSE' A. B = C | B 'OR' C. C = D | C 'AND' D. D = 'x' | '(' A ')' | 'NOT' D. (a) Determine the sets of terminal and nontermina...
algorithms and data structures_Page_60_Chunk4600