100% found this document useful (1 vote)
9 views

(eBook PDF) Data Structures and Problem Solving Using Java 4th Edition pdf download

The document provides information about various eBooks related to data structures and problem-solving using Java, including their download links. It outlines the changes and unique approaches in the fourth edition of a specific textbook, emphasizing the use of the Java Collections API and the organization of the text into parts covering Java basics, algorithms, case studies, and data structure implementations. Additionally, it discusses prerequisites for students, the use of Java as the programming language, and the chapter dependencies within the textbook.

Uploaded by

mabeetoriiv6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
9 views

(eBook PDF) Data Structures and Problem Solving Using Java 4th Edition pdf download

The document provides information about various eBooks related to data structures and problem-solving using Java, including their download links. It outlines the changes and unique approaches in the fourth edition of a specific textbook, emphasizing the use of the Java Collections API and the organization of the text into parts covering Java basics, algorithms, case studies, and data structure implementations. Additionally, it discusses prerequisites for students, the use of Java as the programming language, and the chapter dependencies within the textbook.

Uploaded by

mabeetoriiv6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

(eBook PDF) Data Structures and Problem Solving

Using Java 4th Edition install download

https://ebookluna.com/product/ebook-pdf-data-structures-and-
problem-solving-using-java-4th-edition/

Download more ebook from https://ebookluna.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

(eBook PDF) Data Structures and Other Objects Using Java


4th Edition

https://ebookluna.com/product/ebook-pdf-data-structures-and-other-
objects-using-java-4th-edition/

ebookluna.com

(eBook PDF) Data Structures and Abstractions with Java 4th


Edition

https://ebookluna.com/product/ebook-pdf-data-structures-and-
abstractions-with-java-4th-edition/

ebookluna.com

(eBook PDF) Data Structures and Abstractions with Java 4th


Global Edition

https://ebookluna.com/product/ebook-pdf-data-structures-and-
abstractions-with-java-4th-global-edition/

ebookluna.com

(eBook PDF) Starting Out with Java: From Control


Structures through Data Structures 4th Edition

https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-data-structures-4th-edition/

ebookluna.com
(eBook PDF) Java: An Introduction to Problem Solving and
Programming 7th Edition

https://ebookluna.com/product/ebook-pdf-java-an-introduction-to-
problem-solving-and-programming-7th-edition/

ebookluna.com

(eBook PDF) Java: An Introduction to Problem Solving and


Programming 8th Edition

https://ebookluna.com/product/ebook-pdf-java-an-introduction-to-
problem-solving-and-programming-8th-edition/

ebookluna.com

Data Structures and Abstractions with Java 5th Edition


(eBook PDF)

https://ebookluna.com/product/data-structures-and-abstractions-with-
java-5th-edition-ebook-pdf/

ebookluna.com

(eBook PDF) Introduction to Programming with Java: A


Problem Solving Approach 3rd Edition

https://ebookluna.com/product/ebook-pdf-introduction-to-programming-
with-java-a-problem-solving-approach-3rd-edition/

ebookluna.com

(eBook PDF) Starting Out with Java: From Control


Structures through Data Structures 3rd Edition

https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-data-structures-3rd-edition/

ebookluna.com
summary of changes in the fourth edition

1. This edition provides additional discussion on using classes (Chapter 2),


writing classes (Chapter 3), and interfaces (Chapter 4).
2. Chapter 6 contains additional material discussing the running time of lists, the
use of maps, and the use of views in the Java Collections API.
3. The Scanner class is described, and code throughout the text makes use of the
Scanner class.
4. Chapter 9 describes and implements the 48-bit linear congruential generator that
is part of both the Java and many C++ libraries.
5. Chapter 20 has new material on separate chaining hash tables and the String
hashCode method.
6. There are numerous revisions to the text that improve on the prose in the
previous edition.
7. Many new exercises are provided in Parts I, II, and IV.

a unique approach

My basic premise is that software development tools in all languages come with
large libraries, and many data structures are part of these libraries. I envision an
eventual shift in emphasis of data structures courses from implementation to use. In this
book I take a unique approach by separating the data structures into their specification
and subsequent implementation and taking advantage of an already existing data
structures library, the Java Collections API.
A subset of the Collections API suitable for most applications is discussed in a
single chapter (Chapter 6) in Part Two. Part Two also covers basic analysis techniques,
recursion, and sorting. Part Three contains a host of applications that use the
Collections API’s data structures. Implementation of the Collections API is not shown
until Part Four, once the data structures have already been used. Because the
Collections API is part of Java, students can design large projects early on, using
existing software components.
Despite the central use of the Collections API in this text, it is neither a book on the
Collections API nor a primer on implementing the Collections API specifically; it
remains a book that emphasizes data structures and basic problem-solving techniques.
Of course, the general techniques used in the design of data structures are applicable to
the implementation of the Collections API, so several chapters in Part Four include
Collections API implementations. However, instructors can choose the simpler
implementations in Part Four that do not discuss the Collections API protocol. Chapter
6, which presents the Collections API, is essential to understanding the code in Part
Three. I attempted to use only the basic parts of the Collections API.
Many instructors will prefer a more traditional approach in which each data structure
is defined, implemented, and then used. Because there is no dependency between
material in Parts Three and Four, a traditional course can easily be taught from this
book.

prerequisites

Students using this book should have knowledge of either an object-oriented or


procedural programming language. Knowledge of basic features, including primitive
data types, operators, control structures, functions (methods), and input and output (but
not necessarily arrays and classes) is assumed.
Students who have taken a first course using C++ or Java may find the first four
chapters “light” reading in some places. However, other parts are definitely “heavy”
with Java details that may not have been covered in introductory courses.
Students who have had a first course in another language should begin at Chapter 1
and proceed slowly. If a student would like to use a Java reference book as well, some
recommendations are given in Chapter 1.
Knowledge of discrete math is helpful but is not an absolute prerequisite. Several
mathematical proofs are presented, but the more complex proofs are preceded by a
brief math review. Chapters 7 and 19–24 require some degree of mathematical
sophistication. The instructor may easily elect to skip mathematical aspects of the
proofs by presenting only the results. All proofs in the text are clearly marked and are
separate from the body of the text.

java

This textbook presents material using the Java programming language. Java is a
language that is often examined in comparison with C++. Java offers many benefits, and
programmers often view Java as a safer, more portable, and easier-to-use language than
C++.
The use of Java requires that some decisions be made when writing a textbook. Some
of the decisions made are as follows:
1. The minimum required compiler is Java 5. Please make sure you are using a
compiler that is Java 5-compatible.
2. GUIs are not emphasized. Although GUIs are a nice feature in Java, they seem
to be an implementation detail rather than a core Data Structures topic. We do
not use Swing in the text, but because many instructors may prefer to do so, a
brief introduction to Swing is provided in Appendix B.
3. Applets are not emphasized. Applets use GUIs. Further, the focus of the course
is on data structures, rather than language features. Instructors who would like
to discuss applets will need to supplement this text with a Java reference.
4. Inner classes are used. Inner classes are used primarily in the implementation
of the Collections API, and can be avoided by instructors who prefer to do so.
5. The concept of a pointer is discussed when reference variables are
introduced. Java does not have a pointer type. Instead, it has a reference type.
However, pointers have traditionally been an important Data Structures topic
that needs to be introduced. I illustrate the concept of pointers in other
languages when discussing reference variables.
6. Threads are not discussed. Some members of the CS community argue that
multithreaded computing should become a core topic in the introductory
programming sequence. Although it is possible that this will happen in the
future, few introductory programming courses discuss this difficult topic.
7. Some Java 5 features are not used. Including:
Static imports, not used because in my opinion it actually makes the code harder
to read.
Enumerated types, not used because there were few places to declare public
enumerated types that would be usable by clients. In the few possible places, it
did not seem to help the code’s readability.

text organization

In this text I introduce Java and object-oriented programming (particularly abstraction)


in Part One. I discuss primitive types, reference types, and some of the predefined
classes and exceptions before proceeding to the design of classes and inheritance.
In Part Two, I discuss Big-Oh and algorithmic paradigms, including recursion and
randomization. An entire chapter is devoted to sorting, and a separate chapter contains
a description of basic data structures. I use the Collections API to present the interfaces
and running times of the data structures. At this point in the text, the instructor may take
several approaches to present the remaining material, including the following two.
1. Discuss the corresponding implementations (either the Collections API versions
or the simpler versions) in Part Four as each data structure is described. The
instructor can ask students to extend the classes in various ways, as suggested in
the exercises.
2. Show how each Collections API class is used and cover implementation at a
later point in the course. The case studies in Part Three can be used to support
this approach. As complete implementations are available on every modern
Java compiler, the instructor can use the Collections API in programming
projects. Details on using this approach are given shortly.
Part Five describes advanced data structures such as splay trees, pairing heaps, and
the disjoint set data structure, which can be covered if time permits or, more likely, in a
follow-up course.

chapter-by-chapter text organization

Part One consists of four chapters that describe the basics of Java used throughout the
text. Chapter 1 describes primitive types and illustrates how to write basic programs in
Java. Chapter 2 discusses reference types and illustrates the general concept of a
pointer—even though Java does not have pointers—so that students learn this important
Data Structures topic. Several of the basic reference types (strings, arrays, files, and
Scanners) are illustrated, and the use of exceptions is discussed. Chapter 3 continues
this discussion by describing how a class is implemented. Chapter 4 illustrates the use
of inheritance in designing hierarchies (including exception classes and I/O) and
generic components. Material on design patterns, including the wrapper, adapter, and
decorator patterns can be found in Part One.
Part Two focuses on the basic algorithms and building blocks. In Chapter 5 a
complete discussion of time complexity and Big-Oh notation is provided. Binary search
is also discussed and analyzed. Chapter 6 is crucial because it covers the Collections
API and argues intuitively what the running time of the supported operations should be
for each data structure. (The implementation of these data structures, in both
Collections API-style and a simplified version, is not provided until Part Four). This
chapter also introduces the iterator pattern as well as nested, local, and anonymous
classes. Inner classes are deferred until Part Four, where they are discussed as an
implementation technique. Chapter 7 describes recursion by first introducing the notion
of proof by induction. It also discusses divide-and-conquer, dynamic programming, and
backtracking. A section describes several recursive numerical algorithms that are used
to implement the RSA cryptosystem. For many students, the material in the second half
of Chapter 7 is more suitable for a follow-up course. Chapter 8 describes, codes, and
analyzes several basic sorting algorithms, including the insertion sort, Shellsort,
mergesort, and quicksort, as well as indirect sorting. It also proves the classic lower
bound for sorting and discusses the related problems of selection. Finally, Chapter 9 is
a short chapter that discusses random numbers, including their generation and use in
randomized algorithms.
Part Three provides several case studies, and each chapter is organized around a
general theme. Chapter 10 illustrates several important techniques by examining games.
Chapter 11 discusses the use of stacks in computer languages by examining an algorithm
to check for balanced symbols and the classic operator precedence parsing algorithm.
Complete implementations with code are provided for both algorithms. Chapter 12
discusses the basic utilities of file compression and cross-reference generation, and
provides a complete implementation of both. Chapter 13 broadly examines simulation
by looking at one problem that can be viewed as a simulation and then at the more
classic event-driven simulation. Finally, Chapter 14 illustrates how data structures are
used to implement several shortest path algorithms efficiently for graphs.
Part Four presents the data structure implementations. Chapter 15 discusses inner
classes as an implementation technique and illustrates their use in the ArrayList
implementation. In the remaining chapters of Part Four, implementations that use simple
protocols (insert, find, remove variations) are provided. In some cases, Collections
API implementations that tend to use more complicated Java syntax (in addition to
being complex because of their large set of required operations) are presented. Some
mathematics is used in this part, especially in Chapters 19–21, and can be skipped at
the discretion of the instructor. Chapter 16 provides implementations for both stacks
and queues. First these data structures are implemented using an expanding array, then
they are implemented using linked lists. The Collections API versions are discussed at
the end of the chapter. General linked lists are described in Chapter 17. Singly linked
lists are illustrated with a simple protocol, and the more complex Collections API
version that uses doubly linked lists is provided at the end of the chapter. Chapter 18
describes trees and illustrates the basic traversal schemes. Chapter 19 is a detailed
chapter that provides several implementations of binary search trees. Initially, the basic
binary search tree is shown, and then a binary search tree that supports order statistics
is derived. AVL trees are discussed but not implemented, but the more practical red–
black trees and AA-trees are implemented. Then the Collections API TreeSet and
TreeMap are implemented. Finally, the B-tree is examined. Chapter 20 discusses hash
tables and implements the quadratic probing scheme as part of HashSet and HashMap,
after examination of a simpler alternative. Chapter 21 describes the binary heap and
examines heapsort and external sorting.
Part Five contains material suitable for use in a more advanced course or for general
reference. The algorithms are accessible even at the first-year level. However, for
completeness, sophisticated mathematical analyses that are almost certainly beyond the
reach of a first-year student were included. Chapter 22 describes the splay tree, which
is a binary search tree that seems to perform extremely well in practice and is
competitive with the binary heap in some applications that require priority queues.
Chapter 23 describes priority queues that support merging operations and provides an
implementation of the pairing heap. Finally, Chapter 24 examines the classic disjoint
set data structure.
The appendices contain additional Java reference material. Appendix A lists the
operators and their precedence. Appendix B has material on Swing, and Appendix C
describes the bitwise operators used in Chapter 12.

chapter dependencies

Generally speaking, most chapters are independent of each other. However, the
following are some of the notable dependencies.
Part One (Tour of Java): The first four chapters should be covered in their
entirety in sequence first, prior to continuing on to the rest of the text.
Chapter 5 (Algorithm Analysis): This chapter should be covered prior to
Chapters 6 and 8. Recursion (Chapter 7) can be covered prior to this chapter,
but the instructor will have to gloss over some details about avoiding inefficient
recursion.
Chapter 6 (The Collections API): This chapter can be covered prior to or in
conjunction with material in Part Three or Four.
Chapter 7 (Recursion): The material in Sections 7.1–7.3 should be covered
prior to discussing recursive sorting algorithms, trees, the Tic-Tac-Toe case
study, and shortest-path algorithms. Material such as the RSA cryptosystem,
dynamic programming, and backtracking (unless Tic-Tac-Toe is discussed) is
otherwise optional.
Chapter 8 (Sorting Algorithms): This chapter should follow Chapters 5 and 7.
However, it is possible to cover Shellsort without Chapters 5 and 7. Shellsort
is not recursive (hence there is no need for Chapter 7), and a rigorous analysis
of its running time is too complex and is not covered in the book (hence there is
little need for Chapter 5).
Chapter 15 (Inner Classes and Implementations of ArrayLists): This material
should precede the discussion of the Collections API implementations.
Chapters 16 and 17 (Stacks and Queues/Linked Lists): These chapters may be
covered in either order. However, I prefer to cover Chapter 16 first because I
believe that it presents a simpler example of linked lists.
Chapters 18 and 19 (Trees/Binary Search Trees): These chapters can be
covered in either order or simultaneously.

separate entities

The other chapters have little or no dependencies:


Chapter 9 (Randomization): The material on random numbers can be covered
at any point as needed.
Part Three (Applications): Chapters 10–14 can be covered in conjunction with
or after the Collections API (in Chapter 6) and in roughly any order. There are a
few references to earlier chapters. These include Section 10.2 (Tic-Tac-Toe),
which refers to a discussion in Section 7.7, and Section 12.2 (cross-reference
generation), which refers to similar lexical analysis code in Section 11.1
(balanced symbol checking).
Chapters 20 and 21 (Hash Tables/A Priority Queue): These chapters can be
covered at any point.
Part Five (Advanced Data Structures): The material in Chapters 22–24 is self-
contained and is typically covered in a follow-up course.

mathematics

I have attempted to provide mathematical rigor for use in Data Structures courses that
emphasize theory and for follow-up courses that require more analysis. However, this
material stands out from the main text in the form of separate theorems and, in some
cases, separate sections or subsections. Thus it can be skipped by instructors in courses
that deemphasize theory.
In all cases, the proof of a theorem is not necessary to the understanding of the
theorem’s meaning. This is another illustration of the separation of an interface (the
theorem statement) from its implementation (the proof). Some inherently mathematical
material, such as Sections 7.4 (Numerical Applications of Recursion), can be skipped
without affecting comprehension of the rest of the chapter.

course organization

A crucial issue in teaching the course is deciding how the materials in Parts Two–Four
are to be used. The material in Part One should be covered in depth, and the student
should write one or two programs that illustrate the design, implementation, testing of
classes and generic classes, and perhaps object-oriented design, using inheritance.
Chapter 5 discusses Big-Oh notation. An exercise in which the student writes a short
program and compares the running time with an analysis can be given to test
comprehension.
In the separation approach, the key concept of Chapter 6 is that different data
structures support different access schemes with different efficiency. Any case study
(except the Tic-Tac-Toe example that uses recursion) can be used to illustrate the
applications of the data structures. In this way, the student can see the data structure and
how it is used but not how it is efficiently implemented. This is truly a separation.
Viewing things this way will greatly enhance the ability of students to think abstractly.
Students can also provide simple implementations of some of the Collections API
components (some suggestions are given in the exercises in Chapter 6) and see the
difference between efficient data structure implementations in the existing Collections
API and inefficient data structure implementations that they will write. Students can
also be asked to extend the case study, but again, they are not required to know any of
the details of the data structures.
Efficient implementation of the data structures can be discussed afterward, and
recursion can be introduced whenever the instructor feels it is appropriate, provided it
is prior to binary search trees. The details of sorting can be discussed at any time after
recursion. At this point, the course can continue by using the same case studies and
experimenting with modifications to the implementations of the data structures. For
instance, the student can experiment with various forms of balanced binary search trees.
Instructors who opt for a more traditional approach can simply discuss a case study
in Part Three after discussing a data structure implementation in Part Four. Again, the
book’s chapters are designed to be as independent of each other as possible.

exercises

Exercises come in various flavors; I have provided four varieties. The basic In Short
exercise asks a simple question or requires hand-drawn simulations of an algorithm
described in the text. The In Theory section asks questions that either require
mathematical analysis or asks for theoretically interesting solutions to problems. The In
Practice section contains simple programming questions, including questions about
syntax or particularly tricky lines of code. Finally, the Programming Projects section
contains ideas for extended assignments.

pedagogical features

Margin notes are used to highlight important topics.

The Key Concepts section lists important terms along with definitions and page
references.
The Common Errors section at the end of each chapter provides a list of
commonly made errors.

References for further reading are provided at the end of most chapters.

supplements

A variety of supplemental materials are available for this text. The following resources
are available at http://www.aw.com/cssupport for all readers of this textbook:

Source code files from the book. (The On the Internet section at the end of each
chapter lists the filenames for the chapter’s code.)
In addition, the following supplements are available to qualified instructors. To access
them, visit http://www.pearsonhighered.com/cs and search our catalog by title for Data
Structures and Problem Solving Using Java. Once on the catalog page for this book,
select the link to Instructor Resources.
PowerPoint slides of all figures in the book.
Instructor’s Guide that illustrates several approaches to the material. It includes
samples of test questions, assignments, and syllabi. Answers to select exercises
are also provided.

acknowledgments

Many, many people have helped me in the preparation of this book. Many have already
been acknowledged in the prior edition and the related C++ version. Others, too
numerous to list, have sent e-mail messages and pointed out errors or inconsistencies in
explanations that I have tried to fix in this edition.
For this edition I would like to thank my editor Michael Hirsch, editorial assistant
Stephanie Sellinger, senior production supervisor Marilyn Lloyd, and project manager
Rebecca Lazure and her team at Laserwords. Thanks also go to Allison Michael and
Erin Davis in marketing and Elena Sidorova and Suzanne Heiser of Night & Day
Design for a terrific cover.
Some of the material in this text is adapted from my textbook Efficient C
Programming: A Practical Approach (Prentice Hall, 1995) and is used with
permission of the publisher. I have included end-of-chapter references where
appropriate.
My World Wide Web page, , will contain
updated source code, an errata list, and a link for receiving bug reports.

M. A. W.
Miami, Florida
contents

part one Tour of Java

chapter 1 primitive java

1.1 the general environment

1.2 the first program


1.2.1 comments

1.2.2

1.2.3 terminal output

1.3 primitive types


1.3.1 the primitive types

1.3.2 constants

1.3.3 declaration and initialization of primitive types

1.3.4 terminal input and output

1.4 basic operators


1.4.1 assignment operators

1.4.2 binary arithmetic operators

1.4.3 unary operators

1.4.4 type conversions

1.5 conditional statements


1.5.1 relational and equality operators

1.5.2 logical operators

1.5.3 the statement

1.5.4 the statement

1.5.5 the statement

1.5.6 the statement

1.5.7 and

1.5.8 the statement

1.5.9 the conditional operator

1.6 methods
1.6.1 overloading of method names

1.6.2 storage classes

summary

key concepts

common errors

on the internet

exercises

references

chapter 2 reference types

2.1 what is a reference?

2.2 basics of objects and references


2.2.1 the dot operator (.)

2.2.2 declaration of objects

2.2.3 garbage collection

2.2.4 the meaning of =

2.2.5 parameter passing

2.2.6 the meaning of ==

2.2.7 no operator overloading for objects

2.3 strings
2.3.1 basics of string manipulation

2.3.2 string concatenation

2.3.3 comparing strings

2.3.4 other methods

2.3.5 converting other types to strings

2.4 arrays
2.4.1 declaration, assignment, and methods

2.4.2 dynamic array expansion

2.4.3

2.4.4 multidimensional arrays

2.4.5 command-line arguments

2.4.6 enhanced loop

2.5 exception handling


2.5.1 processing exceptions
2.5.2 the clause

2.5.3 common exceptions

2.5.4 the and clauses

2.6 input and output


2.6.1 basic stream operations

2.6.2 the type

2.6.3 sequential files

summary

key concepts

common errors

on the internet

exercises

references

chapter 3 objects and classes

3.1 what is object-oriented programming?

3.2 a simple example

3.3 javadoc

3.4 basic methods


3.4.1 constructors

3.4.2 mutators and accessors

3.4.3 output and


3.4.4

3.4.5

3.5 example: using

3.6 additional constructs


3.6.1 the reference

3.6.2 the shorthand for constructors

3.6.3 the operator

3.6.4 instance members versus static members

3.6.5 static fields and methods

3.6.6 static initializers

3.7 example: implementing a class

3.8 packages
3.8.1 the directive

3.8.2 the statement

3.8.3 the environment variable

3.8.4 package visibility rules

3.9 a design pattern: composite (pair)

summary

key concepts

common errors
on the internet

exercises

references

chapter 4 inheritance

4.1 what is inheritance?


4.1.1 creating new classes

4.1.2 type compatibility

4.1.3 dynamic dispatch and polymorphism

4.1.4 inheritance hierarchies

4.1.5 visibility rules

4.1.6 the constructor and super

4.1.7 methods and classes

4.1.8 overriding a method

4.1.9 type compatibility revisited

4.1.10 compatibility of array types

4.1.11 covariant return types

4.2 designing hierarchies


4.2.1 abstract methods and classes

4.2.2 designing for the future

4.3 multiple inheritance

4.4 the interface


4.4.1 specifying an interface
4.4.2 implementing an interface

4.4.3 multiple interfaces

4.4.4 interfaces are abstract classes

4.5 fundamental inheritance in java


4.5.1 the Object class

4.5.2 the hierarchy of exceptions

4.5.3 i/o: the decorator pattern

4.6 implementing generic components using inheritance


4.6.1 using Object for genericity

4.6.2 wrappers for primitive types

4.6.3 autoboxing/unboxing

4.6.4 adapters: changing an interface

4.6.5 using interface types for genericity

4.7 implementing generic components using java 5 generics


4.7.1 simple generic classes and interfaces

4.7.2 wildcards with bounds

4.7.3 generic static methods

4.7.4 type bounds

4.7.5 type erasure

4.7.6 restrictions on generics

4.8 the functor (function objects)


4.8.1 nested classes

4.8.2 local classes

4.8.3 anonymous classes

4.8.4 nested classes and generics

4.9 dynamic dispatch details

summary

key concepts

common errors

on the internet

exercises

references
part two Algorithms and Building Blocks

chapter 5 algorithm analysis

5.1 what is algorithm analysis?

5.2 examples of algorithm running times

5.3 the maximum contiguous subsequence sum problem


5.3.1 the obvious O(N3) algorithm

5.3.2 an improved O(N2) algorithm

5.3.3 a linear algorithm

5.4 general big-oh rules

5.5 the logarithm


Other documents randomly have
different content
a conclusion with their own forces, before the reinforcements
arrived.
Pertau’s command was not numerous, but it was composed of
the most loyal of the Sultan’s troops; for Solyman had taken care to
select his most faithful colonels, captains, and cavalry officers. There
was, indeed, serious apprehension of Pertau’s forces being induced
to go over to the enemy in a body, as it was impossible to say how
far they had been tampered with, or to what length their party
feeling might carry them. The rank and file of the Janissaries,
excited by the idea of a revolution with Mustapha at its head, were
well inclined towards the insurgents, and eager for the rising to
become general. There were, therefore, serious reasons for anxiety.
On receiving Solyman’s commands, the Sanjak-beys felt the
necessity of vigorous action, and, with many mutual exhortations,
set to work in all haste to oppose and check the pretender’s plans,
doing their utmost to cut off the bands that were coming up, and to
break up the force which he had already collected, whilst they
cowed the whole country side with threats of the Sultan’s
vengeance.
Meanwhile, the column of Pertau Pasha was advancing towards
the scene of insurrection. The effect produced by the approach of
the regular troops was such as might have been expected. The raw
levies of the pretender were panic-stricken when they saw that they
were out-generalled and attacked on every side. At first small parties
dropped away; after a while the whole army, throwing honour and
obligation to the winds, deserted their leader, and scattered in every
direction. The pretender, with his chief officers and advisers,
attempted to follow the example of his men, but was stopped by the
Sanjak-beys, and taken alive. They were all handed over to Pertau
Pasha, and sent off to Constantinople with a guard of picked troops.
On their arrival, Solyman had them carefully examined under
torture. Their confession established the guilt of Bajazet, and made
his father acquainted with his treasonable designs. He had intended,
it appears, as soon as the forces of the insurgents had reached a
certain size, to join them with a strong body of troops, and either to
lead them straight against Constantinople, or to fall with all his
strength upon his brother, according as circumstances might favour
either attempt; but whilst he hesitated, his designs were nipped in
the bud by the prompt action of his father. Solyman, having satisfied
himself on these points, ordered them all to be drowned in the sea
at dead of night, deeming it most inexpedient that any of these
transactions should be noised abroad, and his family misfortunes
become the gazing-stock of neighbouring princes. The Sultan, who
was grievously displeased with Bajazet for this audacious attempt,
was debating in his mind how he should punish him; but his wife
being a clever woman, his intentions were not long a secret to her.
Having allowed a few days to elapse, in order to give time for his
anger to cool, she alluded to the subject in Solyman’s presence, and
spoke of the thoughtlessness of young men, quoting similar acts
which had been done by his forefathers. She reminded the Sultan
that ‘natural instinct teaches everyone to protect himself and his
family, and that death is welcome to none; that the mind of a young
man can easily be seduced from the right path by the suggestions of
unscrupulous advisers. It was only fair,’ she said, ‘to pardon a first
fault, and if his son came to his senses he would have saved him to
his own great benefit as a father; but if Bajazet should go back to
his former ways, it would then be time to punish him, as he
deserved, for both his misdeeds. If he would not grant this mercy to
his erring son, she implored him to grant it to a mother’s prayers.
She begged for the life of the son she had borne, and entreated him
to spare their common child. What must be her feelings,’ she
continued, ‘if, of the two sons whom God had spared her, one should
be reft away by his unrelenting father. He ought to control his wrath,
and lean to mercy rather than severity, however just that severity
might be; for the Deity, whose power and justice were infinite, did
not clothe himself always in severity, but to a great extent allowed
mercy to prevail, otherwise the human race could not suffice to
supply victims for his vengeance. To whom ought a man to extend
mercy, if not to his children? Henceforth Bajazet would be a dutiful
son, and, freed by this great act of grace from his present fears,
overflow with love and obedience towards his father; there was no
surer bond for noble souls than kind and generous treatment; the
recollection of the pardon he had received would prevent Bajazet
from repeating his offence. She pledged her word for him, and
undertook that he should henceforth be a good and dutiful son.’
By these words, accompanied as they were with tears and
caresses, Solyman was softened; and being at all times too much
under his wife’s influence, he changed his resolve, and determined
to spare Bajazet, on condition of his coming and receiving his
commands in person. The mother was equal to the occasion, and
wrote secretly to Bajazet, telling him not to be afraid to come when
he was sent for, he would be perfectly safe; she had obtained his
restoration to his father’s favour, from whose mind all displeasure
had been removed. On receiving this message his hopes rose, and
he determined to trust himself in his father’s hands; but he was not
without fears, as he thought every now and then of his brother
Mustapha, whose fate testified pretty clearly to the magnitude of the
danger he was incurring. Accordingly, he came to the place
appointed for the conference, which was a public inn a few miles
from Constantinople, called Carestran. This was in accordance with a
rule of the Turkish Court, that no grown-up son of the Sultan should
during his father’s lifetime set foot within the walls of
Constantinople, lest he should tamper with the household troops,
and endeavour to seize the throne. On dismounting, he found his
father’s slaves waiting for him with an order to lay aside his sword
and dagger. Nor was there anything unusual in this, as it is the
general rule for those who are admitted to an audience with the
Sultan; still it was a precaution which was not calculated to allay the
fears of his conscience-stricken son. But his mother, foreseeing how
frightened he would be when entering his father’s presence, had
stationed herself in a chamber close to the entrance of the house, by
which Bajazet must pass. As he went by, he could hear his mother
calling to him through a little canvas-covered window, and saying,
‘Corcoma, oglan, corcoma’; i.e., Do not fear, my son, do not fear.
These words from his mother gave Bajazet no little comfort. On
entering, his father bade him take a seat by his side, and proceeded
to lecture him most seriously on the rashness of his conduct in
venturing to take up arms under circumstances which made it not
improbable that he himself was the object of his attack; and
granting that his attempt was directed only against his brother, it
was even then an outrageous crime.
‘He had done what he could towards destroying the very
foundations of the Moslem faith, by bringing to the verge of ruin
through family feuds that which was nowadays its only support—the
imperial power of the house of Othman; this consideration alone
ought to prevent a true believer from entertaining such a design.
‘On the wrong and insult to himself,’ continued the Sultan, ‘he
would not dwell, though he had attempted to seize the throne
during his lifetime, and thus committed an unpardonable offence, for
which no possible punishment could ever atone; in spite of all this,
he had determined to spare him, and deal with him rather as a kind
father than as a strict judge, in the hope that he would
henceforward leave the care of the future in the hands of God; none
of these matters depended on man’s pleasure, it was by God’s
decree that kingdoms went and kingdoms came. If fate ordained
that after his death he (Bajazet) should reign, the matter was
settled, the realm would come to him without any effort on his part;
no human means could avail to hinder that which was appointed
from on high; but if God had decreed otherwise, it was mere
madness to toil and strive against His will, and, as it were, to fight
against God. In short, he must leave off fomenting disorders, cease
to attack a brother who did nothing to provoke him, and refrain from
troubling his aged father. But if he returned to his old courses, and
stirred up another storm, it should break on his own head, and there
should be no pardon for a second offence; in that case he would not
find in him a gentle father, but a stern judge.’
When he had thus spoken, and Bajazet had made a short and
judicious reply, apologising for his fault rather than palliating it, and
promising submission for the future to his father’s will, Solyman
ordered the national beverage to be brought in, and handed to his
son—it was a compound of sugar and water, flavoured with the juice
of certain herbs. Bajazet, longing, but not daring, to refuse it, drank
as much as appearances required, with misgiving in his heart that
this might be the last cup he should ever taste. But presently his
father removed his anxiety by taking a draught from the same cup.
Bajazet therefore was more fortunate than Mustapha in his interview
with his father, and was allowed to return to his government.158
I have a few things to tell you about Achmet’s death. Some think
he was accused of a secret leaning towards Mustapha, or at any rate
of negligence in not detecting the conspiracy of the pretender and
Bajazet till it was almost too late. Others think that he had long
before been sentenced to death for robberies and depredations
committed by him at a time when he was without official rank, and
fighting for his own hand; and that this sentence, which, on account
of his gallantry and military skill, had been postponed, though never
actually remitted, was now to be put into execution. Others, again,
think that the wish to restore Roostem to his old position was the
one and only reason for putting Achmet to death. Solyman was
believed to have promised Achmet never to deprive him of the seal
of office so long as he lived. When circumstances necessitated the
restoration of the seal to Roostem, he was obliged, in order to keep
his pledge and avoid a breach of faith, to put Achmet to death, and
hence the order for his execution. They declare also that Solyman
said, it was better for him to die once than to die a thousand times,
as would be the case, if he survived to be perpetually tormented
with vain regret for the power that had been snatched from his
hands and given to another. However that may be, one morning
when he had gone to the Divan (which I have already explained to
be the council chamber), without the slightest knowledge of what
was about to happen, a messenger came to sentence him to death
in the Sultan’s name. Achmet, being a man of marvellous courage,
received the announcement with almost as much composure as if it
were no concern of his. All he did was to repulse the hangman, who
was preparing to perform his office, deeming it unfitting that one
who had but lately held so exalted a position, should be touched by
his polluted hands. Glancing round on the bystanders, he begged as
a favour of a gentleman, with whom he was on friendly terms, to act
as his executioner, telling him that it was a kindness he should
greatly value, and the last he would ever be able to do to him; after
many entreaties, his friend acceded to his request. When this was
settled, Achmet enjoined him, after putting the bowstring round his
neck, not to strangle him at the first pull, but to slacken it and allow
him to draw one breath; after which he was to tighten the string
until he was dead; this fancy of his was duly complied with. A
strange wish, methinks, to pry at such a time into the mystery of
death, and pay one visit to the threshold of the king of terrors
before passing his portals for ever!
After his death the badges of his former office and the post of
Chief Vizier were restored to Roostem. As to your inquiry about my
return, I may answer in the words of the famous quotation, ‘Facilis
descensus Averni.’ Well, He who guided me on my way hither will
bring me back in His own good time. In the meanwhile, I shall
console myself in my loneliness and troubles with my old friends, my
books; friends who have never failed me hitherto, but have done
their master true and loyal service by night and day. Farewell.
Constantinople, July 14, 1556.159
LETTER III.
Introduction—Departure of Busbecq’s colleagues and preceding negotiations—
Turkish hawking—Busbecq summoned to Adrianople—Earthquake there—
Account of earthquake at Constantinople—Busbecq returns to Constantinople—
Hires a house there—Is forced to go back to his former abode—Description of
it—Anecdotes of animals in it—Busbecq’s menagerie—How Busbecq’s friend
availed himself of the Turkish abhorrence of pigs—Stories of a lynx, a crane, a
stag—Turkish mendicants—Turkish slaves—Busbecq’s kite-shooting—His tame
partridges from Chios—Mode of keeping them—Artificial egg-hatching in Egypt
—Turkish horses—Camels—Their use in war—Turkish commissariat—Turkish
and Christian soldiers contrasted—Their clothing and equipment—Illustration
from Cæsar of Turkish tactics—Turkish kindness to animals—Cats preferred to
dogs—Mahomet and his cat—Narrow escape of a Venetian who ill-treated a
bird—Turkish fondness for birds—Tame nightingales and goldfinches—Turkish
women and marriage laws—Divorces—Baths for women—Extraordinary story of
an old woman—Busbecq’s letters intercepted—Pashas puzzled by supposed
cipher—Conversations with Roostem—Hungarian affairs—Ali Pasha appointed
commander there—His character and appearance—Besieges Szigeth
unsuccessfully—Turkish army preserved by advice of a Sanjak-bey—His
subsequent treatment—Retreat and death of Ali Pasha—Capture of Gran—
Skirmishes and raids in Croatia—Turkish and Persian dread of fire-arms—Story
of Roostem’s corps of musketeers—Turkish opinion of duelling—Arslan bey—
Account of the Mingrelians and their king—Busbecq’s life and occupations—
Turkish archery—Turkish readiness to adopt foreign inventions and customs—
Lemnian earth—Why some Turks have their children baptised—Parthian tactics
of the Turks—Busbecq’s acquaintances of various nations—Rudeness of a
Cavasse and Busbecq’s retaliation—Story of Roostem—Turkish treatment of
ambassadors—Story of a Venetian ambassador—Emblematic present from
Roostem—Beginning of Bajazet’s rebellion—Removal of him and Selim to new
governments—Reluctance of Bajazet to obey—Selim marches on Ghemlik—
Bajazet’s remonstrances and his father’s reply—Missions of Mehemet and
Pertau Pashas to Selim and Bajazet—Reluctance of Solyman’s troops—The
Mufti consulted—Message of Bajazet to Solyman—His preparations at Angora—
Characters of the rival brothers—Address of Bajazet to his army—His defeat at
Koniah and retreat to Amasia—Reputation he gains by 193his conduct—
Solyman crosses to Asia—His motives—Busbecq a spectator of his departure—
Description of the procession—Busbecq summoned to Solyman’s camp—
Description of it—Turkish observance of Ramazan—Impression made on a Turk
by the carnival—Why wine was forbidden by Mahomet—Turkish military
punishments—Quarrel of Busbecq’s servants with some Janissaries—Light in
which the Janissaries are regarded by the Sultan—Albert de Wyss—Bajazet’s
proceedings at Amasia—Description of Persia—Characters of Shah Tahmasp
and his son—Solyman’s policy towards Bajazet—Flight of Bajazet to Persia—
Description of the celebration of Bairam by the army—Return of Busbecq to
Constantinople—Incidents of Bajazet’s flight—Solyman is dissuaded from
marching against Persia—Disaffection among his troops—Bajazet’s arrival in
Persia—His reception by the Shah—Duplicity of the Shah—His probable motives
—Bajazet’s troops separated and massacred in detail—He and his family are
thrown into prison—Opinions as to his probable fate—Influence of these events
on Busbecq’s negotiations—His course of policy—Conclusion.

Of course you have heard of the last arrangements. Well, my


colleagues left me some time ago, and I am alone at Constantinople.
A strange fancy, I think I hear you say. What on earth can have
induced him to stay among savages, an exile from his dear native
land? But while you exclaim at my choice, you do not forget to ask
for every scrap of news I have to give, solemnly promising to accept
it all—good, bad, and indifferent—just as it comes. You have other
questions which you wish answered. What books am I reading?
What am I doing? How do I get through the day? Do I ever go out?
Come, come, what you are plaguing me for is, I see, not a letter but
a diary. Again, you are specially anxious for information about
Bajazet’s fortunes, touching which, you say, there are many rumours
at home. You assert that I am under an engagement to give you
news of him, and you demand heavy damages for breach of
contract! I believe you intend dragging me into court, and are
already preparing your pleadings! Pray do not be so hard! Restrain
your passion, my friend; or if nothing else194 will serve, take the full
sum; I will pay interest as well, in fact do or pay anything sooner
than be brought into court, though indeed a demurrer would
probably lie to your claim, for surely after so long an interval I might
set up the Statute of Limitations.
When my colleagues, with whom my former letters have made
you acquainted, saw that we had already wasted three years here,
and that no progress had been made towards peace, or even
towards an armistice of any duration, and there appeared hardly any
hope of gaining anything if they stayed, they sought leave to return.
Now I must tell you that it is easy enough to get here; the difficult
thing is to get away!160 and they had much trouble before they
could obtain Solyman’s consent. After this we had to decide whether
we should all three leave, or I should remain behind, while my two
colleagues, who had been longer at Constantinople, returned home.
For this point Solyman had left for our decision, as he was afraid, if
he kept one of us, that people would think that he was anxious for
peace. My colleagues considered it was essential to the Emperor’s
interest that one of us should remain. This was tolerably obvious;
but, while I shared their opinion, I thought it politic to dissemble,
and so, whenever the subject was mentioned in the presence of
Turks, I took care to express my dissatisfaction with any
arrangement which kept me at Constantinople. ‘Admitting that I had
come to discharge the duties of an ambassador in ordinary, yet such
a position implied that peace had been concluded. While this was
uncertain, I did not see how I could remain at the Sultan’s court
without disobeying my instructions, or at any rate going beyond
them. The proper course,’ I added, ‘would be for one and all of us to
receive our passports.’
I took this line in order to make them press me to stay, knowing
that it would make a material difference in my position whether I
remained at the request of the Turkish Government or of my own
free will. I was fully alive to the fact that if none of us remained to
represent his Majesty, there was a probability, or rather a certainty,
of war; whereas if I stayed, the prospects of a peaceful arrangement
would not be prejudiced. While communications were being
exchanged between Vienna and Constantinople, a long time would
elapse, in which many things might occur to improve our position.
Finally, anything was better than needlessly to plunge into the
horrors of war. These considerations did not blind me to the fact,
that, as far as my own personal interest was concerned, I was acting
imprudently in remaining behind. I foresaw the additional
responsibility I must undertake, and the risks and dangers of the
position I was to occupy, which, great as they must be in any case,
would become extremely serious if the negotiations ended in war.
But men who take upon themselves the onerous office of
ambassador must not allow considerations of this kind to come
between them and their duty to the State.
Roostem, in his excessive anxiety to keep me, played as it were
into my hands. No doubt he understood how much the chances of
peace would be diminished by our departure in a body, and the
rupture of the negotiations which were pending. His chief reason for
dreading an outbreak of hostilities was the effect it would probably
have on Solyman’s sons, who would be sure to take up arms as soon
as their father marched for Hungary. However quiet Selim might be,
he knew that Bajazet would be certain to attack him; and the deep
interest which he, his wife, and his mother-in-law took in the
younger prince, made him anxious that nothing should occur to
provoke a step on his part which he foresaw would be his
destruction. Therefore, having summoned us to his house, he
communicated at great length to my colleagues the considerations
he wished to be brought before his Majesty to induce him to agree
to the terms the Sultan offered. But he urged me to stay at my post,
and to persevere in my efforts for the re-establishment of peace.
There was no doubt, he said, that the course he recommended
would meet with the Emperor’s approval, as he had never shown
himself averse to peace. I, on the other hand, expressed annoyance
at his proposals, and made objections to them, as far as I could do
so with decency and safety. On this Roostem grew eager, and
begged me not to take a step which must necessarily put an end to
all prospect of peace, saying that his Emperor161 was eager to lead
his army into Hungary, and would have done so long ago, if he
himself had not through the influence of certain ladies162 (meaning
his wife and mother-in-law) prevented him. To use his own
expression, they had detained him by seizing the hem of his
garment. He implored us not to go on teasing and provoking against
ourselves the rage of a sleeping lion. I began to be less decided in
my refusals, and to say that I would stay, did I not fear that the
Pashas would be unreasonable in their treatment of me. I felt sure, I
added, that if anything occurred to displease them they would hold
me responsible for it, and make me the scapegoat, even for matters
totally out of my power to prevent. Roostem told me not to be
afraid, saying that whatever turn things might take, nothing should
be laid to my charge; if I would only remain he would undertake to
protect me, and, to use his own expression, would regard me as his
brother. I replied that I would think it over, and so we departed.
The next day we were summoned to the Divan,163 or Council of
State, where almost the same scene was enacted, except that
Roostem, on account of the presence of the other Pashas was more
guarded in his language. Before I finally agreed to remain, I
deposited a protest with the Pashas, in which I put on record that I
was remaining without knowing what my master’s wishes might be,
and therefore reserved all questions for his decision without
prejudice. I undertook nothing, and did not engage to be responsible
for the result which God had foreordained. This protest was
afterwards of great service to me when affairs looked gloomy, and
the Pashas were inclined to treat me harshly. I have now given you
my reasons for remaining.
The departure of my colleagues took place towards the end of
August 1557. In the following winter the Sultan, according to his
usual custom, removed to Adrianople, with the double object of
making a demonstration against Hungary and of enjoying the good
hawking and the bracing climate, which he thought were beneficial
to his health. At the junction of the rivers near Adrianople are wide
tracts of flooded lands, on which there are great quantities of wild
ducks, geese, herons, eagles, cranes, and buzzards. To capture
these he generally uses a small species of eagle; these birds are
trained to seek their quarry in the clouds, and bring it down, or to
seize it as it flies beneath them, and with one swoop dash it to the
ground.164 I hear he has falcons so well trained that they can bring
down a crane, striking it under the wing in such a way as to keep
clear of its beak, on which they would otherwise be impaled. Their
boldness, however, is not always successful, for if they make the
least mistake, they immediately suffer for it; the crane’s beak goes
through them like an arrow, and they tumble lifeless to the ground.
For the reasons I have mentioned, the Sultan makes a practice
every year of repairing to Adrianople at the beginning of the winter,
and of not returning to Constantinople till the frogs drive him away
with their croaking.
Shortly after the departure of the Court, I received a letter from
Roostem ordering me to follow. Some horsemen were attached to
me as an escort, and also sixteen Janissaries, either as a mark of
honour or to prevent my escaping. As I was directed to come with
all speed, at first we travelled by long stages, but we had scarcely
commenced our third day’s journey when the Janissaries began to
grumble. It was winter, and they had to trudge along muddy roads,
so our long marches were not at all to their liking; they declared that
when they were campaigning with the Sultan they did not march
more than half the distance, and said they could not stand it. This
troubled me, as I did not wish to be hard on them. At last, while I
was considering with my attendants what to do for them, one of
them suggested that they were very fond of a sort of omelette,
which my cook compounded of wine and eggs with plenty of sugar
and spices. ‘Possibly,’ said he, ‘if they were served with this for
breakfast every day, they would make fewer complaints of fatigue
and be more obliging.’ Queer as the suggestion was, I determined to
try it, and the result was a most complete success, for they were so
charmed with the omelette, and so merry with the wine with which I
plied them, that they were ready to start before the order came, and
volunteered to follow me to Buda if I would always treat them so.
Travelling thus, I arrived at Adrianople, where I was obliged to
listen to the complaints, not to say abuse, of Roostem about the
raids and robberies of the Hungarians. To these, however, the
answer was not far to seek, for I was able to tell him of the
numerous wrongs which our people daily received from Turkish
soldiers. He could not be surprised, I added, if the Christians
retaliated.
I was enabled to answer him thus by the arrival of a courier with
despatches from the Emperor, in which he narrated the outrages
perpetrated every day by the Turks in our territory, in violation of the
armistice which we had made for a fixed period on the departure of
my colleagues; how they harried the miserable peasantry with their
ceaseless raids, plundered their property, and carried off into
captivity themselves, their wives, and their children.
I must not omit to mention that on the day of the courier’s arrival
at Adrianople there was a great earthquake, à propos of which he
related, that he had felt an earthquake, which he considered to be
the same, at Nisch and Sofia, and many other places through which
he had journeyed, so that the air enclosed in the caverns of the
earth seemed to have run a race with him and to have travelled
almost as fast as he had ridden. In confirmation of this theory, I
must tell you that a similar earthquake was felt four days later at
Constantinople; here are the data and you can make your own
deductions.
I may remark that Constantinople is very subject to earthquakes,
and I remember that once, a little after midnight, our lodging began
to shake so violently that we thought the house would fall. I had
been sound asleep, but when it woke me and I could see by my
night-light books and cups tumbling about, laths and stones falling
from the wall, and the whole room shaking violently, for a moment I
was dumbfoundered and knew not what to make of it. At last, when
it occurred to me that it was an earthquake, I jumped up and ran
out, for fear the house should tumble in upon me. The same
earthquake continued for some days, though the shocks were not so
violent. All through the city, and especially in our lodging and in St.
Sophia, even where the walls are most solid, may be seen huge
cracks caused by settlements from earthquakes.
I stayed at Adrianople about three months, and then, after
concluding a seven months’ armistice, I was taken back to
Constantinople in March. As I was tired of being confined in the
same lodging, I had recourse to the cavasse who acted as my
keeper (for among the various duties which, as I have already told
you, are assigned to men of this profession amongst the Turks, is
the custody of ambassadors), and asked him to allow me, like other
ambassadors, to hire a house with a little bit of garden or pleasure-
ground, at my own expense. The cavasse made no objection, as it
would be a saving for his master of 400 gold ducats a year if I took
a house for myself, this being the price which the Sultan paid for my
present lodgings; so I hired a house, or rather block of buildings,
with some land about it, where I intended to lay out a garden,
hoping by this means to divert my mind from the cares and anxieties
of my position.
When, however, my cavasse found it was impossible to watch me
in a house, which was furnished with several means of egress and
lay in its own ample grounds, as strictly as in a caravanserai (a word
with which I think my former letters have made you familiar), where
all the windows were closely barred, and to which there was only
one entrance, he changed his mind, and induced the Pashas, who
had now returned from Adrianople, to shut me up once more within
the walls of our old lodging. Thankful, indeed, was I that I did not
get worse treatment, for some of the Pashas held that, now that I
was alone, it was a needless extravagance to give me such a roomy
lodging. The majority, however, of the council were more
considerate, and I was allowed to return to my old prison-house.
I will take the opportunity of giving you a description of my
abode. The house is situated on high ground in the most populous
quarter of Constantinople. From the back windows there is a lovely
view of the sea; though we are at some distance from the shore we
can distinguish the gambols of the dolphins in the water, while the
prospect is bounded by Mount Olympus in Asia, white with perpetual
snow. On every side it is open to the breezes, and is on this account
considered a peculiarly healthy residence. So airy a situation the
Turks appear to think too good for foreigners, as they have not only
put iron bars on our windows, to the discomfort of our eyes, but
have built up parapets which prevent our getting fresh air or a good
view. This was done to meet the complaints of our neighbours, who
declared that their houses, which stood on lower ground, were
completely exposed to the gaze of the Christians. In the centre there
is a large open space or court in which is a well. No one lives on the
ground-floor, but on the upper storey there is a verandah running
round the court, out of which open the chambers which form the
outer part of the building, and which consist of a great number of
small rooms, all built after the same pattern, like the cells of a
monastery. The front windows open on the public street leading to
the palace; and from them the ambassadors have an opportunity,
nearly every Friday (which answers to our Sunday) of seeing the
Sultan on his way to his devotions. As he passes, the cavasse and
Janissaries make their bow, or rather return his, for among the Turks
it is the custom for the man of higher rank to bow first. In
conformity with this rule, the Sultan himself does not wait for the
people in the street to bow to him, but first bows himself, and they
return his salute amid loyal shouts and blessings. The ground-floor
of the edifice is intended for a stable. The vaulted roofs, which are
universal throughout the building, render it safe from fire on the
inside; while on the outside it is protected by a covering of lead.
While the house has many advantages, it must be allowed that it
has corresponding inconveniences. Everything in it is constructed for
use, and nothing for ornament or comfort; it has no beauty or
novelty of design to render it attractive. It has no garden to take a
walk in; not so much as a tree, or shrub, or patch of grass to refresh
the eye, while it swarms with different kinds of vermin, such as
weasels, snakes, lizards, and scorpions. Sometimes when a man
goes to fetch his hat in the morning, he has the unpleasant surprise
of finding a snake coiled round it. However, to let you into the secret
of our diversions, we contrive to extract some amusement from
these creatures. Sometimes a weasel has a battle-royal with a
snake, with my whole household standing round, and in spite of its
struggles drags it off in triumph to its hole; sometimes again a
weasel changes its abode, and moves its young elsewhere. For
instance, the other day, when my friends and I were still at dinner,
one of them jumped down on the middle of the table from her nest
in the roof with a young one in her mouth. On our pulling her away,
she left it there, and stationed herself at the door to see what would
happen to the cub. After amusing ourselves with the ugly little beast
we placed it on the floor, whereupon the mother darted in, caught it
up, and carried it off to its new home.
We also had an opportunity of inspecting a strange, reptile from
the stables, which had been trodden on by the horses and killed; it
was either a snake or a python. Its stomach appeared to be very
much swollen, so I ordered my people to cut it open, and there we
found three good-sized mice. I could not make out how an animal
that crawled so slowly could catch such nimble creatures; nor could I
understand how it contrived to swallow them whole, when its jaws
were, as it seemed, so narrow. But my difficulty was solved by my
finding another snake in the act of swallowing a toad or poisonous
frog. It had seized it by the hind legs, and had already sucked them
and a good part of its body down its throat. The toad was still alive,
and kept endeavouring to get away from its enemy, struggling as
hard as it could with its front feet. When I first saw it I was
thoroughly puzzled. I thought the creature was some strange
abortion, for it appeared to me to be a two-footed beast, with an
enormous tail. When I saw what it was, I began beating it with a
stick, and tried to make it release its victim. It was frightened, and
did its best to disgorge its prey in order to escape; but it was some
time before it could succeed in getting rid of the toad, for it had
sucked it in so far that the creature stuck in its throat. At last, after
much difficulty, it managed to disgorge; but then it could not shut its
mouth, and gaped hideously with its open jaws until we killed it. My
stick, if Pliny is to be believed, would be serviceable to women in
childbirth.
Besides the creatures that breed in the building, I keep a good
many animals, which furnish my people with employment and
amusement. I am heartily glad to have something for them to do, as
otherwise they would get terribly homesick. For what better resource
is left us in our isolation than seeking to forget our cares in the
society of animals? There is not much amusement to be had, I
warrant you, in a great stone prison-house like ours. The chief
favourites are the monkeys, on account of their strange tricks, which
are very amusing. You may generally see round their cage a group
of admiring bystanders, who watch their mischievous pranks with
the keenest interest. I have also wolves, bears, broad-horned stags
—which are frequently but incorrectly called fallow deer—and
common deer, likewise gazelles, lynxes, ichneumons, and of the
weasel kind the varieties called martens and sables; also, if you care
to know, a pig as well, whose companionship I am told by my
grooms is wholesome for horses. I certainly ought to have given him
a place in my catalogue, as he attracts numbers of Asiatics to my
lodging. They come to see this unclean animal, which the laws of
their religion forbid their tasting. The beast is all the more
interesting to them, because pigs are never kept, or even seen, in
their country. Indeed, a Turk would as lief touch one of them as I
would touch a man with the plague.
I will tell you a capital story of a friend of mine, who took
advantage of this prejudice. He wished to send me a private parcel,
so he got a little pig, and put it with the parcel in a sack, which he
then told his servant to take to me. When he came to the door my
cavasse met him, and asked him what he had got in the sack. The
servant whispered in his ear, ‘It is a little pig, a present from a
friend.’ The cavasse gave the sack a poke with his stick, on which
the little pig began to squeak. The moment he heard it he made a
hasty retreat, crying out, ‘Well, take your nasty dirty present in, if
you must, and be hanged to you.’ Then, with a look of intense
disgust, he turned to his fellow Mussulmans, and said, ‘How
extraordinarily fond the Christians are of the flesh of that filthiest of
animals; they positively cannot live without it.’ Thus the servant was
admitted, and brought in the secret parcel.
I have also many kinds of birds, such as eagles, ravens,
jackdaws, foreign kinds of ducks, Balearic cranes, and partridges.
From this you will see that my house is full of animals, ‘A Noah’s ark,
in short,’ as one of my friends observed.
Not only is the menagerie a great resource for my people by
keeping them from fretting, but I also derive advantage from it
myself, as I am able to verify the wonderful stories I have read in
various authors of the great affection beasts are capable of
entertaining towards human beings. I never ventured to accept
these statements for facts, until I saw an Assyrian lynx so attach
himself to one of my people after only a few days’ acquaintance,
that one could only explain it by the theory that he had fallen in love
with him. When he was present the lynx would give him many
caresses that plainly showed his affection, hugging and all but
kissing him. When he wished to go, the animal would try to detain
him by placing its claws gently on the hem of his garment, and
would cast wistful looks after him as he went away. During his
absence the lynx was in a state of the deepest melancholy,
constantly gazing at the door till the man returned; on which the
creature, strange to say, recovered his spirits and welcomed his
friend. When I took the man away with me to the Turkish camp
across the water, the poor beast was inconsolable, refused its food,
and after a few days pined away. I was much annoyed at this, for I
had intended to make him, with a very tame ichneumon I had, a
present to the Emperor, on account of the remarkable beauty of his
coat; it was indeed so handsome, that if a common lynx were set by
his side you would hardly think that they both belonged to the same
species. It is in Assyria that the handsomest lynxes are found, and
their skins are worth fifteen or sixteen golden crowns. I have no
doubt that they are the same as the Babylonian skins considered so
valuable in former days, which are mentioned in the Digest in the
chapter on Farmers of the Revenue.165
Here is another story, which relates to a bird. Among other
cranes I have a Balearic one. This species is distinguished from the
common kinds by a white tuft of feathers hanging down from either
ear, and also by the black feathers which cover the front of its neck.
These last the Turks are wont to stick in their caps. It also differs in
size from common cranes. This Balearic crane I speak of showed
most distinct signs of affection for a Spanish soldier, whom I
ransomed from captivity, being so attached to him that it used to
march beside him for many hours as he walked, to halt when he
stopped, and to stay by him when he sat down; and it allowed itself
to be stroked and patted by him, though it could not bear to be
touched by any one else. When he was away, it used to go to his
room and knock at the door with its beak. If it was opened, it pried
about to see if it could find him. When it found itself disappointed, it
used to go all over the house and disturb us all with cries so loud
and shrill that we were obliged in self-defence to shut it up; but
when he returned, it would run to meet him with outspread wings
and queer comical gestures, as if it were practising some outlandish
jig, or preparing to do battle with a pygmy.166 To be short, at last it
made a custom of sleeping under his bed; and one day actually
presented him with an egg.167
You have heard the marks of affection for men displayed by two
animals. I will now give you an instance of an ungrateful beast,
which proved itself both savage and treacherous. I had a tame stag
which lived with us for many months and seemed quite
domesticated. When the rutting season arrived, however, he
suddenly became so frantic, that, forgetful of the ties of hospitality
and kindness, he as it were declared war on us and treated us all
like enemies, attacking with his horns everyone he met, so that we
were obliged to shut him up. One night he broke out in spite of bars
and bolts, and frightened the horses, which, after the Turkish
fashion, were passing the night in the open air in the courtyard.
When the grooms ran out to quiet the disturbance, and tried to drive
the stag back to his prison, he not only refused to go in, but turned
on the men and wounded several of them. Excited by this they drove
the foe into the stable, which, as I said, was very spacious, and
there with my permission attacked him with lances, hunting spears,
and every weapon that came to hand. At first he made a gallant
defence, but at last, overcome by numbers, he fell pierced with
wounds in every limb; for more than forty men were arrayed against
him, and he was all alone. Thus he atoned for his bad conduct to his
hosts. All the ambassadors at Constantinople had a share of the
fruits of that night’s chase, for I had the stag cut up and sent them
each a present of venison.
The stag was one of very large size, like those that are in the
habit of going up from Hungary to Austria at the beginning of
autumn for the purpose of mating with their kind. I got him from
beggars who made a profit of him. They went about collecting alms,
and before asking for money they repeated a prayer, in which there
was frequent mention of the name of God. As often as it occurred
they bowed their heads, and they had trained the stag to do the
same. By this the lower orders were led to imagine that the animal
recognised the name of God, and gave many a penny to its owners.
As the stag was an unusually fine specimen of its kind, I had
intended bringing him to the Emperor.
Now that we are talking of Turkish beggars, I may as well give
you some account of their ways. They are not so numerous as with
us, and for the most part consist of religious impostors of one kind
or another, wandering from place to place. Some feign madness or
idiocy as an excuse for their begging, for lunatics and crazy folk are
considered sure of salvation by the Turks, and therefore regarded as
saints whilst still on earth. There are Arabs too among them, who
carry about with them banners, under which they declare their
ancestors fought to extend the Moslem religion. They do not beg
indiscriminately or from everybody, but force upon the passers-by in
the evening a tallow candle, a lemon, or a pomegranate, for which
they expect double or treble its value, that so by a pretence of
selling they may avoid the disgrace of asking.
But the people who among us are beggars among them are
slaves, for when a slave has lost the use of his limbs his master is
still bound to maintain him; besides, however feeble a slave may be,
they manage to get some service from him. I remember ransoming
a Spanish gentleman, who had been an officer in his own army.
Though he was completely crippled by his wounds, yet the Turk who
had bought him managed to make some profit of him. He took him
over to Asia, where flocks of geese are kept, and hired him out as
goose-herd, by which he turned a nice little penny.
I have my doubts as to whether the man who first abolished
slavery is to be regarded as a public benefactor. I know that slavery
brings with it various disadvantages, but these are counterbalanced
by corresponding advantages. If a just and mild form of slavery,
such as the Roman laws ordained, especially with the State for
master, had continued, perhaps fewer gallows and gibbets would be
needed to keep those in order who, having nothing but life and
liberty, are driven by want into every conceivable crime. Freedom
when combined with extreme poverty has made many a man a
rascal; it causes temptation such as few can resist. Nature has
denied to many the power of self-control, and the knowledge which
is indispensable for acting aright; they need the support and
guidance of a superior as the only means of stopping them in their
career of vice. They are like savage animals, and require chains to
prevent their becoming dangerous.
In Turkey the class which is likely to go astray is controlled by a
master’s authority, while the master is supported by the slave’s
labour. Both publicly and privately the Turks derive great advantages
from this institution. Slave labour enables them to live both
comfortably and economically; indeed they have a proverb to the
effect that no one can be considered poor as long as he is master of
a single slave. So also in the department of public works, if there is
any building, removing, clearing, or breaking up to be done, there is
a constant supply of slave labour to execute the work. We never
attain the grandeur of the works of antiquity. What is the reason?
Hands are wanting, or, in other words, slave labour. I need not
mention what means of acquiring every kind of knowledge the
ancients possessed in learned and educated slaves. Well, well, you
must not put down all this as my serious opinion; it is a mere fancy
which I should be sorry you should take in sober earnest.168
Slave-hunting is the chief source of profit to the Turkish soldier. If
he brings back from a campaign nothing except one or two slaves,

You might also like