Data Structures & Algorithms in Python 1st Edition John Canning - eBook PDF pdf download
Data Structures & Algorithms in Python 1st Edition John Canning - eBook PDF pdf download
https://ebookluna.com/download/data-structures-algorithms-in-
python-ebook-pdf/
https://ebookluna.com/download/data-structures-algorithms-in-python-
ebook-pdf/
ebookluna.com
https://ebookluna.com/download/fundamentals-of-python-data-structures-
ebook-pdf/
ebookluna.com
https://ebookluna.com/download/data-structures-ebook-pdf/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-data-structures-algorithm-
analysis-in-c-4th-edition/
ebookluna.com
Data Structures & Algorithm Analysis in C++ 4th Edition
(eBook PDF)
https://ebookluna.com/product/data-structures-algorithm-analysis-
in-c-4th-edition-ebook-pdf/
ebookluna.com
https://ebookluna.com/download/introduction-to-algorithms-for-data-
mining-and-machine-learning-ebook-pdf/
ebookluna.com
https://ebookluna.com/download/data-structures-and-applications-a-
simple-and-systematic-approach-ebook-pdf/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-data-structures-3rd-edition/
ebookluna.com
Data Structures & Algorithms in Python
Data Structures & Algorithms in
Python
John Canning
Alan Broder
Robert Lafore
John Canning
Alan Broder
Contents
1. Overview
2. Arrays
3. Simple Sorting
5. Linked Lists
6. Recursion
7. Advanced Sorting
8. Binary Trees
13. Heaps
14. Graphs
2. Arrays
The Array Visualization Tool
Using Python Lists to Implement the Array Class
The Ordered Array Visualization Tool
Python Code for an Ordered Array Class
Logarithms
Storing Objects
Big O Notation
Why Not Use Arrays for Everything?
Summary
Questions
Experiments
Programming Projects
3. Simple Sorting
How Would You Do It?
Bubble Sort
Selection Sort
nsertion Sort
Comparing the Simple Sorts
Summary
Questions
Experiments
Programming Projects
5. Linked Lists
Links
The Linked List Visualization Tool
A Simple Linked List
Linked List Efficiency
Abstract Data Types and Objects
Ordered Lists
Doubly Linked Lists
Circular Lists
terators
Summary
Questions
Experiments
Programming Projects
6. Recursion
Triangular Numbers
Factorials
Anagrams
A Recursive Binary Search
The Tower of Hanoi
Sorting with mergesort
Eliminating Recursion
Some Interesting Recursive Applications
Summary
Questions
Experiments
Programming Projects
7. Advanced Sorting
Shellsort
Partitioning
Quicksort
Degenerates to O(N2) Performance
Radix Sort
Timsort
Summary
Questions
Experiments
Programming Projects
8. Binary Trees
Why Use Binary Trees?
Tree Terminology
An Analogy
How Do Binary Search Trees Work?
Finding a Node
nserting a Node
Traversing the Tree
Finding Minimum and Maximum Key Values
Deleting a Node
The Efficiency of Binary Search Trees
Trees Represented as Arrays
Printing Trees
Duplicate Keys
The BinarySearchTreeTester.py Program
The Huffman Code
Summary
Questions
Experiments
Programming Projects
13. Heaps
ntroduction to Heaps
The Heap Visualization Tool
Python Code for Heaps
A Tree-Based Heap
Heapsort
Order Statistics
Summary
Questions
Experiments
Programming Projects
14. Graphs
ntroduction to Graphs
Traversal and Search
Minimum Spanning Trees
Topological Sorting
Connectivity in Directed Graphs
Summary
Questions
Experiments
Programming Projects
Author: Various
Language: English
GRAHAM’S MAGAZINE.
Vol. XXX. January, 1847. No. 1.
Table of Contents
Fiction, Literature and Articles
GRAHAM’S
AMERICAN MONTHLY
MAGAZINE
Of Literature and Art,
EMBELLISHED WITH
MEZZOTINT AND STEEL ENGRAVINGS, MUSIC, ETC.
VOLUME XXX.
PHILADELPHIA:
GEORGE R. GRAHAM & CO. 129 CHESTNUT STREET.
......
1847.
CONTENTS
OF THE
THIRTIETH VOLUME.
POETRY.
Ægeus. By Wm. H. C. Hosmer, 100
A Prayer. By J. B. 161
Autumn. By Jesse E. Dow, 229
April. 245
Are They Not All Ministering Spirits. By S. Dryden 319
Phelps,
A Prayer. By Mrs. C. E. Da Ponte, 336
Caius Marius. By Mrs. E. J. Eames, 20
Fanny. By Mrs. Mary Sumner, 179
Fanny’s First Smile. By Frances S. Osgood, 262
Hawking. By E. M. Sidney, 81
Heart Struggles. By Mrs. J. C. Campbell, 176
Love. By J. Bayard Taylor, 27
Lady Jane Grey. By Mrs. E. J. Eames, 110
Lines. By L. J. Cist, 180
Love Unrequited. By Alice G. Lee, 228
Lines to a Jews-Harp. By L. B. M., 262
Lines on Visiting Broad Street Hotel. By W. H. C. 344
Hosmer,
Miriam. By Kate Dashwood, 9
Midnight Masses. By Arthur Allyn, 132
Morning Invitation. By The Private Scholar, 336
Night. By Alice Grey, 292
“Oh Mother of a Mighty Race.” By Wm. C. Bryant, 20
“Oh! that a Little Cot were Mine!” By Robert F. 120
Greely,
Pittsburgh. By E. M. Sidney, 249
Picture of Tasso. By Mrs. E. J. Eames, 371
MUSIC.
I’ve Been upon the Briny Deep. A New Song. 140
Composed by Charles E. Cathrall,
ENGRAVINGS.
The Departure, engraved by J. Sartain, Esq.
Title Page for 1847, designed and engraved by E.
Tucker, Esq.
Paris Fashions, from Le Follet,
Josh Educating a Pig.
The Gleaner, engraved by Rawdon, Wright & Hatch.
Herds of Bisons and Elks, engraved by Rawdon,
Wright & Hatch.
Paris Fashions, from Le Follet.
Saukie and Fox Indians, engraved by Rawdon,
Wright & Hatch.
Falls of the Towalaga, engraved by Smillie.
Paris Fashions, from Le Follet.
Saratoga and Stillwater Battle-Ground, engraved by
Smillie.
Pittsburg, engraved by A. W. Graham.
Paris Fashions, from Le Follet.
Mandan Women, engraved by Rawdon, Wright &
Hatch.
Lover’s Leap, engraved by Smillie.
Colored Flower, executed by E. Quarré.
The Home-Bird, engraved by A. L. Dick.
Paris Fashions, from Le Follet.
———
BY CHARLES J. PETERSON.
———
“Did you get the pass, Macdonald?” said a young man, looking
up, as his servant entered the room of a lodging-house in
Charleston, in the latter part of the year 1780.
“Yes, sir, and the baggage and horses are ready,” was the reply of
a stalwart youth, whose dress betokened a condition removed from
that of an ordinary menial, and partaking rather of that of a familiar,
though humble companion. “I think we can give them the slip, sir—
Lord! how I wish for a crack at these fellows! and once with Marion,
we’ll not long want an opportunity.”
“Be in waiting for me at midnight, then,” said the first speaker;
and, as Macdonald retired, he threw himself back again in his chair,
and fixing his eyes on the floor, resigned himself to the abstraction
out of which he had been roused.
Howard Preston, the hero of our story, had just returned from
Europe, where he had been fulfilling the injunctions of his father’s
will, by a course of study and travel until his twenty-fourth year. The
first great sorrow of his life had been his parting, at sixteen, with the
only child of his guardian, Kate Mowbray, then a lovely little girl, who
for years had been his pet and playmate. Many were the tears she
also shed at the separation, and faithfully did she promise not to
forget her boy lover. Such childish preferences usually end with
youth; but it was not so in the present instance. With every letter
from abroad came a gift for Kate, which she requited with some
trifle worked by her own hands. But as years elapsed, and Kate
approached womanhood, these presents were no longer returned,
and Preston, piqued at what he thought neglect, gradually came to
confine himself, in his letters home, to a cold inquiry after her
health, instead of devoting, as heretofore, two-thirds of the epistle
to her. Yet he never thought of America without also thinking of
Kate; and when he landed at Charleston, a month before our tale
begins, he was wondering into what kind of a woman she had grown
up.
Still his old feeling of pique was uppermost when shown into her
father’s magnificent parlor; and this, combined with his
astonishment at seeing a graceful and high bred woman announced
as his old playmate, lent an air of coldness and embarrassment to
his greetings. Whether it was this or some other cause, Kate, who
was advancing eagerly, suddenly checked herself, colored, and put
on all her dignity. The interview, so inauspiciously begun, was short
and formal, and to Preston, at least, unsatisfactory. He had
expected, in spite of their tacit misunderstanding, that Kate would
meet him as rapturously as of old, forgetting that the child had now
become a woman. He overlooked, also, the effect his own restraint
might have produced. Thus he returned to his lodgings, dissatisfied
and angry, half disposed to dislike, yet half compelled to admire, the
beautiful and dazzling creature from whom he had just parted. The
truth was, Preston, though hitherto ignorant of it, had loved his old
playmate from boyhood. This had made him feel her neglect so
acutely, and this had led him secretly to hope that her welcome on
his return would heal the past. No wonder he went home angry, yet
quite as much in love as ever!
Preston and Kate often met after this, but they seemed destined
to misunderstand each other. Kate was really ignorant of the
mischief she had done. She had come down to meet him with a
heart full of the memories of other days, and, if truth must be told, a
little nervous and anxious how he, of whom she had so often
thought in secret, would receive her. His proud demeanor had chilled
her. Nor on subsequent occasions were their interviews more
satisfactory. Indeed Kate was puzzled and vexed at Preston’s
manner. No one could, at times, be more interesting; yet no one was
so often haughty and disagreeable. Kate sighed to think how
changed he had become; then she was angry at herself for sighing.
Kate was accordingly as wayward as Preston—and who, indeed,
had greater excuse? Rich and well born, beautiful and high-spirited,
she was positively the reigning belle in Charleston during the whole
of that gay winter. To a complexion delicately fair, and a person of
the most exquisite proportions, she united those graces of mind and
manner, which, in that courtly day, were considered the unerring
accompaniments of high breeding. Report awarded to her numbers
of unsuccessful suitors; but all had tacitly resigned their claims in
favor of Major Lindsay, an English officer of noble blood, between
whom and an earldom there was only a single life. Gay and splendid
in person and equipage, the Major no sooner laid siege to the heart
of the heiress, than her less favored suitors gave over in despair;
and what between lounging most of his mornings away in her parlor,
and attending her abroad on all occasions, he speedily came to have
the field nearly altogether to himself.
The arrival of the major anticipated that of Preston about a
month, and when our hero returned, he found his rival almost
domesticated at Mr. Mowbray’s house. Jealousy soon revealed to
Preston the secret of his own long hidden love; but it made him
heartily hate the major. The two gentlemen seemed perfectly to
understand each other. But the Englishman knew better than his
rival how to suppress his feelings, and accordingly possessed every
advantage over him in superior ease and self-command. Had Kate
wished otherwise, she could not but have given the larger share of
her attention to the graceful, brilliant and composed man of fashion,
rather than to his more irritable and wayward rival, whom a fancied
slight, in word or look, was sufficient to make dumb for a whole
evening. Depend on it, the worst possible use to which a lover can
put himself is to be sulky.
Perhaps it was the enmity he nourished against his more
successful rival; perhaps it was the natural indignation of a frank and
noble heart against oppression; perhaps, which is more natural, it
was both combined, but Preston had not been long at home before
he formed the resolution to take part with his countrymen in the war
then going on; and the sudden appearance of General Marion on the
Santee, where he began a partisan conflict with the invaders,
opened to him a favorable way for carrying out his design, which he
only postponed until he could part from Kate on better terms. He
flattered himself that she herself was secretly on the side of the
colonists, for her father had once held a commission under the
provisional government, although since the fall of Charleston and the
apparent conquest of the colony, he, like many others, had been
induced to take a royal protection, and ground his arms as a neutral.
One morning Preston found Kate alone in her little parlor. It was
rare that she was without visiters, for Major Lindsay, at least, was
usually at her side. Kate wore a pretty morning-dress, and was
sewing, her little tiny foot, that rested on a cushioned stool, peeping
provokingly out beneath the snowy muslin. A woman one admires
never looks lovelier than when occupied in this truly feminine
employment; and as Kate made room for Preston beside her, with
her sweetest smile, he thought she had never seemed half so
charming. Lovers can imagine how happy Preston soon was. He and
Kate talked of old times, she busily plying her needle, but every now
and then looking up with animation into his face. His heart beat
quicker, and he longed to tell her how he loved her; it would, I fear,
have set your head or mine, reader, topsy-turvy at once. A dozen
long forgotten incidents were called to mind: how Preston had once
rescued Kate from the river, how they both wept when her old nurse
died, and a score of other things. The color of both heightened, and
Preston felt every instant as if he could snatch the dear girl to his
arms. In the eagerness of conversation, all at once Kate placed her
hand familiarly on his.
“And do you remember,” she said, gazing up with sparkling eyes
into his face, “do you remember when the pony ran away with you?
Oh! I was half dead with fright, and screamed lustily. Those were
happy days—I wonder if we are ever as happy as in childhood. I
sometimes wish we were back again on that old lawn.” And she
sighed.
“Do you, indeed?” said Preston, his whole face lighting up, and
he took her hand by an impulse he could no longer resist.
At that moment the words which would have decided his fate
were rising to Preston’s lips, and Kate, as if secretly forewarned,
began to tremble and be confused, when the door was flung open
and the servant in a loud voice announced Major Lindsay.
If any of my readers has ever been interrupted when about to
declare himself, and had to come plump down from rapture to
foolishness, he can imagine Preston’s chagrin at the entrance of the
visiter. However, he had tact enough to think of Kate’s
embarrassment, and as he rose to make his bow, adroitly placed
himself so as to conceal her for a moment, and allow her time to
recover from her confusion. The major gave both parties, on the
instant, a suspicious glance, but his softest smile immediately
succeeded, and with easy assurance taking the seat Preston had
vacated, he glided into a strain of brilliant small talk, such as would
have done honor to any gallant of the day, incomparable at
compliments and snuff-boxes. Preston was angry at this
unceremonious supplanting, but even more angry to see how quickly
Kate recovered herself, and dashed out into the strife of repartee,
with a spirit and ease superior even to the major’s. Preston chafed,
and thought she might have been a little less interested. At first he
was silent and reserved, then he began to be uneasy, and once or
twice he yielded to his irritability in words. He cursed his folly for
imagining, as he did five minutes before, that she thought more of
him than she did of others. He fixed his eyes half frowningly, half
contemptuously on Kate. She colored immediately, he thought with
conscious guilt. The next instant she turned haughtily away and
addressed the major. Now, for the first time, Preston became
convinced of the existence of the engagement respecting which he
had heard so much. Burning with mortification, after sitting a few
seconds, during which Kate did not once address him, he arose and
abruptly took his leave.
“She loves him,” he exclaimed bitterly. “Dazzled by the glitter of a
coronet, she casts aside her old and tried friend like a worn-out
trinket. Oh! God, was it for this I hastened home? was it for this I
treasured her memory through long years?”
For hours he remained alone, now pacing his chamber with rapid
strides, now burying his face moodily in his hands. He recalled all his
various interviews with Kate, and strove to remember her every
word and look: the result was to curse himself for his egregious folly
in fancying for a moment that she loved him. But after awhile his
feelings grew less exasperated. He reflected on Kate’s manner that
morning, before the arrival of Major Lindsay, and hope once more
dawned in his bosom.
“I will lose no time,” he said, “in learning my fate decisively. I
shall see Kate at her aunt’s ball, and her manner there will
determine my suspense. If she is cold and haughty I will understand
that she wishes to rebuke my presumption this morning. In that
case, I will trifle here no longer, but at once join Gen. Marion.
Macdonald, my foster-brother, loves me too well to desert me, but
he has been crazy to be gone this fortnight past. I will order him to
get a pass and have every thing ready in case of the worst, which
my heart forebodes.”
It was after arriving at this determination, and receiving
Macdonald’s message, that Preston gave himself up to his
melancholy, nor did he rise from his desponding position until it was
time to dress for Mrs. Blakeley’s ball.
The sound of gay music, the flashing of diamonds and the
twinkling of light forms met his sight as he entered the ball-room;
but he had eyes only for one object: and he soon sought out Kate
amid her crowd of admirers. Never had she looked so transcendently
lovely. It is thought a mark of taste and fashion now-a-days to laugh
at the enormous hoops and powdered hair of our grandmothers: but
let us tell you, good reader, that a belle of the present age, with her
deformed tournure and Dutch amplitude of skirt, though she may
create a sort of matter-of-fact sensation, very suitable perhaps for
this money-making generation, never awakens that deep sentiment
of adoration, that respectful, awe-struck, Sir Charles Grandison
feeling, bestowed on the beauty of the last century, august in silver
tissue and high-heeled shoes. The veriest stickler for modern ease
would have given up the point at sight of Kate. She wore, as was
then the custom, a petticoat of rich brocade, a single yard of which
cost more than the twenty ells of lute-string flaunted by a beauty
now. Over this was a robe of white satin, made high on the
shoulders, but opening in front so as partially to reveal the swelling
bust, and expose the richly-gemmed stomacher and glittering
petticoat. The edge of this robe from the neck down was trimmed
with a quilling of blue ribbon, which was also continued around the
bottom. The tight sleeve, with bands like the trimming of the robe,
reached to the elbow: and the deep ruffle of Valenciennes lace
which nearly hid the round white arm, heightened with rare art the
beauties it affected to conceal. Her hair was gathered back from the
forehead, richly powdered, and trimmed coquettishly with blue
ribbon. Now, if there be any heretical repudiator of the past, denying
the brilliancy that powder gave a fair complexion, we wish he would
go and look at one of Copley’s portraits, or—what is better!—could
have seen Kate then! We trow his mouth would have watered. We
doubt if justice is done to those good old times. Ah! those were the
days of courtly dames and high-bred cavaliers—when the stately
minuet still held sway—when gentlemen bowed reverently over the
hand they scarcely dared to kiss—and when it was the crowning
felicity of a whole evening’s devotion to hand a partner to the table
by the tips of the fingers. Now-a-days people bounce through frisky
quadrilles, while gallants tuck the arm of a mistress under their own
as cozily as an old codger does his umbrella.
Preston was advancing toward Kate, when a buzz of admiration
announced that Major Lindsay was about to lead her forth to the
minuet. He won accordingly only a hasty curtsey in reply to his bow.
He was meanwhile subjected to the mortification of hearing from a
dozen bystanders the rumor of Kate’s engagement to the major; and
one or two officiously applied to him to confirm the rumor, knowing
his intimacy with the family. When the dance was concluded, which
attracted general admiration, Major Lindsay still remained at Kate’s
side. Never before had Preston noticed such meaning and delicate
assiduity in his attentions. Between the incidents of the morning and
those of the evening, no wonder Preston’s anger continued
unabated. Still he made several attempts to obtain a moment’s tête-
à-tête with Kate: but the crowd of her admirers frustrated this. At
length, toward the close of the ball, he approached her.
“I come to bid you farewell,” he said abruptly; “to-morrow I leave
Charleston.”
“Leave Charleston!” repeated a dozen voices in dismay. “What
shall we do without you?” Kate alone betrayed neither surprise nor
emotion. “Ah! indeed,” was her unconcerned reply.
Preston turned pale with suppressed mortification at this
indifference; mere friendship, he said to himself, demanded some
expression of regret at least. His feelings were not allayed by what
followed.
“You’re not going to join Marion, are you?” said Major Lindsay, in
a tone of triumphant banter, little imagining how near he was to the
truth. “Has he frightened you by the great oath he has sworn to
revenge his nephew, who was shot for a rebel? I hear he threatens
some mighty deed. Only think of his doing any thing with that
brigade of invincible tatterdemalions—Falstaff’s ragged regiment
over again!”
“Take care that you are not one of those to pay the penalty of
Marion’s oath,” retorted Preston, stung by the insolence of his
successful rival, and reckless what he said. “It was a foul deed, and
will be terribly revenged.”
Major Lindsay flushed to the brow, and his hand mechanically
sought his sword hilt; but he controlled himself immediately, and
said with a sneer—
“That might be called sedition, only we know you are a man of
peace, Mr. Preston. But he is certainly Marion-bit, is he not?” and he
turned to Kate.
Now Kate felt piqued at this unceremonious leave of her lover, as
well as at his haughty conduct in the morning. She fancied herself
trifled with, and answered cuttingly,
“Never fear Mr. Preston’s joining Marion. Our American
gentlemen, on both sides, are but carpet knights of late. They
resemble Sancho Panza, who, good soul, would not stir a step till a
rich island was promised for his share.”
Preston tingled in every vein at this speech, which he regarded
as aimed at himself. He bowed sarcastically to Kate, and glanced
angrily at Major Lindsay, as he replied,
“One might almost be tempted to join Marion after this, in order
to raise the reputation of American courage, since just now British
bravery has it dead hollow.”
“Oh! pray,” said Kate, laughingly, “play the Atlas for the patriots
then. That’s a good man: Be the St. George to destroy this British
dragon.”
Major Lindsay looked for a moment as if he thought there was
more in this than met the ear; but he contented himself with
retorting on Preston.
“Do, by all means,” he said, “and, if you take Bobadil’s plan, you
may defeat a whole army yourself. You know he proposed to
challenge a single enemy and slay him by duello: then challenge a
second, and slay him: then a third, and dispose of him also: and so
on until the whole army was annihilated.”
Kate, as well as the rest, laughed at this sally. Preston needed
but this to complete his anger and disgust. The field, he saw, was
his rival’s, and he was glad when other persons approached and
broke up the colloquy, which, to tell the truth, was growing too
personal. But Kate was piqued and Preston enraged: and as for the
major, seeing there was a quarrel between his rival and mistress, he
had striven to widen the breach.
Preston hurried from the ball-room, and taking time only to
change his dress, repaired to the rendezvous where Macdonald
awaited him. Without a word he flung himself into the saddle, and
his companion imitating his example, they were soon without the
city. They had passed the outposts for some time, when Macdonald,
pushing his horse close to Preston’s, opened the conversation.
“We’re clear of that confounded town at last, thank Heaven!” he
said, “and I, for one, aint sorry. Them Englishmen are as saucy as
princes, and think nobody has any courage but themselves. But I
know one stout fellow that can snuff a candle with his rifle at two
hundred yards, and before a week we’ll have a rap at ’em, for I
s’pose you go direct, sir, to Marion’s camp?”
Preston nodded a gloomy assent, for buried in his own thoughts
he cared not to be disturbed. Macdonald saw this, and, defeated in
his attempt to open a conversation, dropped back, but when out of
hearing muttered,
“I see how it is. Them women’s always getting a man into
trouble. For my part I’ll be a bachelor. Marrying’s like getting tipsy,
very pleasant except for the after repentance.”
——
CHAPTER II.
Grave men there are by broad Santee,
Grave men with hoary hairs,
Their hearts are all with Marion,
With Marion are their prayers.
Bryant.