OurProgrammingLanguage
I’vechosentouseCastheprogramminglanguageforthisbook,ratherthan somehigher-levellanguagesuchasC++,Java,orPython.I’lldiscusswhyand alsojustifyacoupleofotherC-relateddecisionsI’vemade.
WhyUseC?
TheprimaryreasonforusingCisthatIwanttoteachyoudatastructures andalgorithmsfromthegroundup.Whenwewantahashtable,we’llbuild itourselves.Therewillbenorelianceondictionariesorhashmapsorsimilardatastructuresofotherlanguages.Whenwedon’tknowthemaximum lengthofastring,we’llbuildanextensiblearray:wewon’tletthelanguage handlememoryallocationforus.Iwantyoutoknowexactlywhat’sgoing on,withnotricksupmysleeve.UsingChelpsmetowardthisgoal.
SolvingprogrammingproblemsinC,aswedointhisbook,isausefulprimershouldyoudecidetocontinuewithC++.Ifyoubecomeserious aboutcompetitiveprogramming,thenyou’llbehappytoknowthatC++is themostpopularlanguageusedbycompetitiveprogrammers,thankstoits richstandardlibraryandabilitytogeneratecodethatfavorsspeed.
StaticKeyword
Regularlocalvariablesarestoredonwhat’scalledthe callstack.Oneachcall ofafunction,someofthecallstackmemoryisusedtostorelocalvariables. Then,whenthefunctionreturns,thatmemoryisfreedupforotherlocal variablestouselater.Thecallstackissmall,though,andisn’tappropriate forsomeofthemassivearraysthatwe’llmeetinthisbook.Enterthe static keyword.Whenusedonalocalvariable,itchangesthestorageduration fromautomatictostatic,whichmeansthatthevariablemaintainsitsvalue betweenfunctioncalls.Asasideeffect,thesevariablesare not storedinthe samememoryareaalongwithregularlocalvariables,sincethentheirvalues wouldbelostwhenafunctionisterminated.Instead,they’restoredintheir ownseparatesegmentofmemory,wheretheydon’thavetocompetewith whateverelsemightbeonthecallstack.
Onethingtowatchoutforwiththis static keywordisthatsuchlocal variablesareonlyinitializedonce!Foraquickexample,seeListing 1
return0; }
Listing1:Alocalvariablewitha static keyword
I’veused static onlocalvariable x ❶.Withoutthat,you’dexpect 5 to beprintedthreetimes.However,since static isthere,youshouldseethis outputinstead: 5 6 7
IncludeFiles
Tosavespace,Idon’tincludethe #include linesthatshouldbeaddedtothe startofCprograms.You’llbesafeifyouincludethefollowing:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
FreeingMemory
UnlikeJavaorPython,Crequirestheprogrammertofreeallmemorythatis manuallyallocated.Thepatternistoallocatememoryusing malloc,usethat memory,andthenfreethememoryusing free. Fortworeasons,though,Idonotfreememoryhere.First,freeingmemoryaddsclutter,distractingfromtheprimaryteachingpurposeofthecode. Second,theseprogramsarenotlong-lived:yourprogramwillrunonafew testcases,andthat’sit.Theoperatingsystemreclaimsalloftheunfreed memoryonprogramtermination,sothere’snothingtoworryabouteven ifyourunaprogrammanytimes.Ofcourse,notfreeingmemoryisquiteirresponsibleinpractice:nooneishappywithaprogramthatconsumesmore andmorememoryasitruns.Ifyou’dliketopracticefreeingmemory,you canaddcallsof free totheprogramspresentedinthisbook.
TopicSelection
Thefieldsofdatastructuresandalgorithmsaretoolargetobecorralledby onebook(orbythisoneauthor!).Iusedthreecriteriatohelpmedecide whattopicsmadethecut.
First,Ichosetopicsofbroadapplicability:eachcanbeusedtosolvenot onlythecorrespondingproblemsinthebookbutmanyotherproblemsas well.Ineachchapter,Ifocusonatleasttwoproblems.Igenerallyusethe firstproblemtointroducethedatastructureoralgorithmandoneofitsprototypicaluses.Theotherproblemsaremeanttogiveasenseofwhatelse
Another random document with no related content on Scribd:
its outlet in unsystematic and uncriticised imaginative construction. Metaphysics they will certainly have, and if not conscious and coherent, then unconscious and incoherent Metaphysics. The soul that is not at rest in itself without some “sight of that immortal sea which brought it hither,” if hindered from beholding the object of its quest through the clear glass of rational reflection, will none the less seek to discern it amid the distorting hazes and mists of superstition. It is in such seekers after the Infinite that Metaphysics has its natural and proper followers, and for them the study is its own justification and its own reward. If a work like the present should prove of any help to such students, whether by offering positive suggestions which they can accept, or by assisting them to know definitely why they reject its conclusions, it will perhaps have achieved as much as its writer could reasonably expect.
Consult further:—F. H. Bradley, Appearance and Reality, chap. 27; J. E. McTaggart, Studies m Hegelian Cosmology, chap. 9.
235. I use the epithet in its familiar Platonic sense. The “pure” pleasure is that which is not dependent, in whole or in part, for its pleasantness upon a previous ἔνδεια, or actual experience of craving or desire. I do not mean, as Plato possibly did, that a “mixed” pleasure, preceded by such ἔνδεια, is a contrast-effect without positive quality of its own.
236. Compare the argument of Appearance and Reality, chap. 26, pp. 469-485 (1st ed.), and the famous scholium to Prop. 17 of part 1 of Spinoza’s Ethics, where it is contended that “if intellect and volition belong to the eternal essence of God, each of these attributes must at least be understood in a different sense from the current.”
237 I say “finite or infinite” advisedly The mystic’s condemnation of the relational scheme as inadequate to express the full nature of the real, holds good just as much in application to actual finite experience as in application to the ultimate whole. We may say not only of “God,” but of human persons, that they are much more than the “union of thought and will” as such. And in personal human love,
no less than in the saint’s “beatific vision” or the philosopher’s “intellectual love of God,” we have a type of experience which may for some psychological purposes be analysed into a combination of ideational and volitional processes, but emphatically does not, in its concrete existence, consist of a synthesis of actual ideas and actual volitions. See ante, p. 152.
238. Studies in Hegelian Cosmology, p. 292.
INDEX
Absolute, meaning of, 53 ff.; general character of, 60 ff.; not unknowable, 71 ff.; not a “self,” 343 ff.; is it a society? 100, 347 ff.; a spiritual individual, 98 ff.; not necessarily the same as “God,” 399 ff.; not “union of thought and will,” 409 ff.
Activity not identical with conation, 55; and causation, 169; empirical nature of, 189.
Agnosticism, 68, 69, 71, 72; how far justifiable, 412.
Appearance and Reality, connection between, 105 ff.
Aristotle, 6, 42, 97, 266, 361, 386.
Attention, selective, 55, 66, 80; “span” of, 226, 244.
Avenarius, 35, 45, 80, 121, 174, 298 ff. 315.
Baldwin, J. M., 206.
Berkeley, 26, 64 ff., 75, 184, 185, 201 ff.
Body, my own, as describable object, 282.
Body, my own, and others, 203 ff.
Body and Soul, theories of, 313 ff.;
in what sense the same, 332
Bosanquet, B., 19, 26, 164.
Bradley, F. H., 9, 11, 23, 26, 55, 67, 88, 90, 131, 146, 199, 227, 243, 259, 289, 318, 326, 335, 338, 355, 364, 370, 384, 411.
Causation, 165 ff.; cause not identical with ground, 166; causation a postulate, 167 ff.; popular as distinguished from scientific sense, 169; causation and the indefinite regress, 177 ff.; continuity of causation, 171 ff.;
Immanent and Transeunt Causality, 183 ff.; psychophysical causation, 322 ff.
Causes, Plurality of, 180 ff.
Chance, “pure,” meaning of, 231, 232; chance and “free-will,” 378.
Change, 158-164
Character and freedom, 374.
Choice and motives, 373.
Consciousness, a misleading term, 79.
Consequence (see Ground).
Continuity, nature of, 171 (see Causation); continuity of space and time, 244, 250.
Contradiction, principle of, 19 ff.
Cosmology Rational, nature of, 43-49, 192-197.
Couturat, L., 149, 260.
Dedekind, 116, 149, 171.
Degrees of Reality, 108 ff.
Descartes, 128, 185, 318, 400 ff.
Description, as scientific ideal, 174; in physical Science, 280 ff.; in Psychology, 308 ff.
Determinism, 370-376.
Discontinuity of teleological series, 311.
Distance in space and time, 250.
Ends in Nature, 272, 405, 406
Energy, conservation of, 292; kinetic and non-kinetic, 291; doctrine of, and psychophysical interaction, 322 ff.
Epiphenomenalism, 317, 318-320.
Epistemology and Metaphysics, 16.
Evil, problem of, 391 ff., 395 ff.
Evolution, not identical with mere change, 267; implies real ends, 268 ff.; is of finite beings only, 274 ff.; implies real progress and degeneration, 275; originates new individuals, 276
Experience, what, 23 ff., 33 ff.; “pure,” 35, 54
Feeling, 23 ff., 55; in the Absolute, 467 ff.
Freedom, meaning of, 359 ff.
Free-will, origins of belief in, 361 ff.
Geulincx, 184, 185, 186, 317.
Gibson, W. R. B., 288, 329, 366
God, proofs of being of, 400 ff.
Ground and Consequence, meaning of principle of, 164, 165.
Harmony, Pre-established, 187, 317
Hegel, 40 ff., 42 ff., 391, 401.
Herbart, 39, 42, 68.
Hobhouse, L. T., 74, 137, 138, 199.
Hume, 29, 7, 133, 169, 172, 183, 400 ff.
Identity, Psychophysical, doctrine of, 102, 321, 331, 332.
Identity, a teleological concept, 335 (See also Unity of Thing).
Imitation, significance of, for personality, 206
Immanent Causality, 183 ff.
Immediacy, 32.
“Immortality,” 354 ff.
Indeterminism, 376-379
Individuality, nature of, 57, 98 ff.; degrees of, 109 ff.; infinite and finite, 115 ff.
Infinite Regress, 148 ff., 156; in space and time, 255 ff., 259; in causal relation, 177.
Infinity, meaning of, 116.
Interaction, Psychophysical, 317, 329-331.
Introjection, meaning of, 81; origin of, 81, 299 ff.; justification of, 301 ff.
James, W., 53, 91, 318, 370, 383, 390, 400.
Kant, 11, 24, 39, 43, 69, 134, 188, 242 ff., 259, 359, 366, 387, 400 ff.
Law, meaning of, 218 ff.
Laws in Nature, 196, 229
Leibnitz, 68, 82, 86, 91 ff., 117, 187 ff., 317, 366, 401, 404.
Locke, 128, 136, 200, 318, 353, 365, 366.
Lotze, 41, 42, 133, 224, 289.
Mach, E., 174, 175, 192, 223, 228, 283, 290.
Machine, nature of a, 236, 237.
McTaggart, J. E., 345, 357, 391, 398, 413
Malebranche, 184, 185, 317.
Mass, definition of, 289; conservation of, 290; a relative concept, 290, 291
Matter, meaning of, 198 ff.
Mechanical view of Nature, 233 ff., 237 ff., 283 ff.; postulates of, 284, 292 ff.
Mechanism, meaning of, 196, 237 ff.
Method of Metaphysics, 38 ff.
Mill, J. S., 24, 180 ff., 370.
Monadism, 86, 91, 94.
Monism, 85.
Münsterberg, H., 45, 67, 198, 283, 303 ff., 315, 318, 321, 324, 329.
Mysticism, 14, 33, 153; in what sense justifiable, 413.
Necessity and causal relation, 183.
Newton, 128, 200.
Nietzsche, 276.
Number-series, 151 ff., 248-250, 259.
Occasionalism, 184, 317
Ontology, character of, 42.
Order, a teleological concept, 118; order in space and time, 251.
Organism, nature of a, 96.
Parallelism, Psychophysical, 317, 320-329.
Pearson, K., 75, 290.
Phenomenalism, 10, 136.
Physical order, nature of the, 194 ff., 198, 208, 282
Plato, 3, 55, 77, 95, 276, 366, 386, 393, 398, 409.
Pleasure-pain, 55, 344.
Plotinus, 398.
Pluralism, 86 ff.
Position not a principle of individuation, 58; relativity of, 253
Pragmatism, 317.
Prediction in science, 219 ff.
Progress not infinite, 387-389.
Psychical order, nature of the, 298 ff.
Psychology, character of, as a science, 296 ff.
Psychology and Physiology, 303 ff.
Psychology, Rational, nature of, 43 ff.
Purpose, nature of, 55 ff.
Qualities, primary and secondary, 128 ff.
Quality and relation, 140 ff.
Quality and substance, 128 ff.
Quality, spatial and temporal, 244
Rashdall, H., 347, 393, 400.
Realism, Agnostic, 68, 71, 72; Dogmatic, 69, 72-75.
Relation and quality, 140 ff.
Relations and relatedness, 155.
Religion, metaphysical presuppositions of, 389 ff.
Responsibility and the self, 335.
Royce, J., 13, 33, 51, 56, 76, 116, 145, 148 ff., 206, 226, 239, 263, 270, 277, 307, 398.
Russell, B., 36, 58, 91, 142, 189, 243, 250, 253, 404
Self, 98, 107; nature of, 334-340; a teleological concept, 335; temporal character of, 341, 342.
Self-consciousness, genuine and fictitious, 79.
Sidgwick, H., 130, 359, 370.
Space, perceptual, 243-245; conceptual genesis of, 245-249; infinity of, 247; divisibility of, 248; continuity of, 248, 250; homogeneity of, 251; relativity of, 251; is it one or many? 253, 257; is not ultimate, 254-257; antinomies of, 259 ff.; of what is it phenomenal? 260.
Spencer, H., 40, 68.
Spinoza, 62, 101 ff., 318, 399, 411.
Stout, G. F., 33, 67, 135, 154 ff., 208, 247, 318, 324, 332, 378
Subjectivism, what, 75; fallacy of, 76-81, 204 ff.
Substance, concept of, 128 ff.; and quality, 128-140.
Sufficient Reason, principle of, 164.
Teleological description not impossible, 309
Teleological series, discontinuity of, 311.
Teleology, nature of, 55, 99, 125, 287, 371 ff.; in Psychology, 305 ff.; in Biology, 308; and Psychophysical Parallelism, 326 ff.
Thought and the Absolute, 61; not ultimate, 409.
Time, perceptual, 243-245; conceptual, genesis of, 245-249; infinity of, 247; divisibility of, 248; continuity of, 248, 250; homogeneity of, 251; relativity of, 251; is it one or many? 253, 257; not ultimate, 254-257; antinomies of, 259 ff.; of what is it phenomenal? 262; time and the self, 341, 344.
Truth, degrees of, 214.
Uniformities, statistical, 220 ff.
Uniformity in physical nature, 222, 227.
Unity of things teleological, 123-128.
Ward, J., 45, 64, 174, 225, 228, 289 318, 324, 326-328
Whole and Part, category of, 96.
Will, nature of, 61, 118; not ultimate, 410.
Transcriber’s Note
Two words on the first line of p. 70 of this edition (noted below) were missing (blank). They have been supplied from the 5th edition, published in 1920.
On p. 226, a footnote at (226.42) refers to Mr. H. G. Wells’s tale, The New Accumulator, which is certainly a reference to his 1901 tale “The New Accelerator”.
On p. 340, the first paragraph refers to ‘two points’, and prefaces the first with ‘(a)’. But there is no ‘(b)’ to denote the second point. It seems likely that ‘(b)’ should precede the next paragraph, or perhaps following the introductory ‘Further’.
The Index reference to p. 467 for ‘Feeling in the Absolute’ cannot be verified. The page does not exist, and no other page can be identified with certainty.
Errors deemed most likely to be the printer’s have been corrected, and are noted here. The references are to the page and line in the original.
The most common error is missing punctuation: 6.14 purpose[.], 38.29 inquiry[.], 44.12 periphery[.], 44.41 other[.], 56.47 failure[.], 58.27 theory[.], 62.39 “purposive[”], 67.17 life[.], 67.19 subject[.], 79.46 “matter[”], 82.13 it[.], 88.40 exclusive[.], 89.41 facts[.], 99.13 purpose[.], 108.24 admitted[.], 128.23 [“]substance”, 143.19 arisen[.], 215.10 [“]Nature, 224.22 purpose[.], 236.14 based[.], 251.45 series[.], 274.16 advance[.], 320.32 fatum[.], 361.22 considerations[.], 390.5 “temperament[”], 410.22 thing[.]
The name of Professor Hugo Münsterberg is spelled variably as Münsterberg, Munsterberg, and occasionally with a partial umlaut. The spelling has been rendered as Münsterberg to facilitate text searches at 215.5, 305.15, 315.8, 329.40, 418.3.
Other corrected errors are:
xviii.11 to a[s]certain Inserted. xxiii.12 The concept of [e]volution Restored.
37.9 carry out ou[t/r] programme Replaced.
46.46 Grundz[u/ü]ge der Psychologie Replaced.
66.44 on which it “works.[’/”] Replaced.
70.1.1 a modification of your [experience]. Restored.
70.1.2 to ask what [you] mean Restored.
82.22 to know your own meaning[./,] Replaced.
134.42 too diffuse and technical[,/.] Replaced.
136.24 does no[t] destroy Restored.
149.12 in our illustration 12, [23/22], 32 ... Replaced.
180.46 increases indefinitely[)]. Removed.
215.6 Grundz[u/ü]ge der Psychologie Replaced.
215.12 [“]J. Ward Removed.
229.16 deal only with the problem[,/.] Replaced.
306.4 the physical order was const[r]ucted Inserted.
318.8 H[o/ö]ffding Replaced.
*** END OF THE PROJECT GUTENBERG EBOOK ELEMENTS OF METAPHYSICS ***
Updated editions will replace the previous one—the old editions will be renamed.
Creating the works from print editions not protected by U.S. copyright law means that no one owns a United States copyright in these works, so the Foundation (and you!) can copy and distribute it in the United States without permission and without paying copyright royalties. Special rules, set forth in the General Terms of Use part of this license, apply to copying and distributing Project Gutenberg™ electronic works to protect the PROJECT GUTENBERG™ concept and trademark. Project Gutenberg is a registered trademark, and may not be used if you charge for an eBook, except by following the terms of the trademark license, including paying royalties for use of the Project Gutenberg trademark. If you do not charge anything for copies of this eBook, complying with the trademark license is very easy. You may use this eBook for nearly any purpose such as creation of derivative works, reports, performances and research. Project Gutenberg eBooks may be modified and printed and given away—you may do practically ANYTHING in the United States with eBooks not protected by U.S. copyright law. Redistribution is subject to the trademark license, especially commercial redistribution.
START: FULL LICENSE