Data Structures and Algorithms Made Easy Data Structure and Algorithmic Puzzles 5th Edition by Careermonk Publications, Narasimha Karumanchi ISBN 9788193245279 - Download the ebook now for an unlimited reading experience
Data Structures and Algorithms Made Easy Data Structure and Algorithmic Puzzles 5th Edition by Careermonk Publications, Narasimha Karumanchi ISBN 9788193245279 - Download the ebook now for an unlimited reading experience
com
OR CLICK BUTTON
DOWLOAD EBOOK
https://ebookball.com/product/javascript-data-structures-and-
algorithms-an-introduction-to-understanding-and-implementing-core-
data-structure-and-algorithm-fundamentals-1st-editon-by-sammie-bae-
isbn-1484239873-9781484239872-15798/
ebookball.com
https://ebookball.com/product/data-structures-and-algorithms-1st-
edition-by-alfred-aho-isbn-0201000237-9780201000238-25072/
ebookball.com
https://ebookball.com/product/data-structures-and-algorithms-in-
java-1st-edition-by-peter-drake-isbn-0131469142-9780131469143-12422/
ebookball.com
https://ebookball.com/product/data-structures-and-algorithms-in-c-1st-
edition-by-adam-drozdek-asin-b002wlxmby-25076/
ebookball.com
Data Structures Algorithms and Applications in C++ 1st
edition by Adam Drozdek ISBN 1133608426 9781133608424
https://ebookball.com/product/data-structures-algorithms-and-
applications-in-c-1st-edition-by-adam-drozdek-
isbn-1133608426-9781133608424-17250/
ebookball.com
https://ebookball.com/product/the-tomes-of-delphi-algorithms-and-data-
structures-1st-edition-by-julian-bucknall-
isbn-1556227361-9781556227363-10344/
ebookball.com
https://ebookball.com/product/think-data-structures-algorithms-and-
information-retrieval-in-java-1st-edition-by-allen-downey-
isbn-9781491972311-1491972319-15760/
ebookball.com
https://ebookball.com/product/problem-solving-in-data-structures-and-
algorithms-using-c-1st-edition-by-hemant-jain-
isbn-9352655915-9789352655915-15768/
ebookball.com
https://ebookball.com/product/problem-solving-in-data-structures-and-
algorithms-using-c-1st-edition-by-hemant-jain-
isbn-1540407306-9781540407306-15866/
ebookball.com
Data Structures
And
Algorithms
Made Easy
By
Narasimha Karumanchi
Copyright© 2017 by CareerMonk.com
All rights reserved.
Designed by Narasimha Karumanchi
All rights reserved. No part of this book may be reproduced in any form or by any electronic or mechanical means, including
information storage and retrieval systems, without written permission from the publisher or author.
Acknowledgements
Mother and Father, it is impossible to thank you adequately for everything you have done, from
loving me unconditionally to raising me in a stable household, where your persistent efforts and
traditional values taught your children to celebrate and embrace life. I could not have asked for
better parents or role-models. You showed me that anything is possible with faith, hard work and
determination.
This book would not have been possible without the help of many people. I would like to express
my gratitude to all of the people who provided support, talked things over, read, wrote, offered
comments, allowed me to quote their remarks and assisted in the editing, proofreading and design.
In particular, I would like to thank the following individuals:
▪ Mohan Mullapudi, IIT Bombay, Architect, dataRPM Pvt. Ltd.
▪ Navin Kumar Jaiswal, Senior Consultant, Juniper Networks Inc.
▪ A. Vamshi Krishna, IIT Kanpur, Mentor Graphics Inc.
▪ Cathy Reed, BA, MA, Copy Editor
–Narasimha Karumanchi
M-Tech, IIT Bombay
Founder, CareerMonk.com
Preface
Dear Reader,
Please hold on! I know many people typically do not read the Preface of a book. But I strongly
recommend that you read this particular Preface.
It is not the main objective of this book to present you with the theorems and proofs on data
structures and algorithms. I have followed a pattern of improving the problem solutions with
different complexities (for each problem, you will find multiple solutions with different, and
reduced, complexities). Basically, it’s an enumeration of possible solutions. With this approach,
even if you get a new question, it will show you a way to think about the possible solutions. You
will find this book useful for interview preparation, competitive exams preparation, and campus
interview preparations.
As a job seeker, if you read the complete book, I am sure you will be able to challenge the
interviewers. If you read it as an instructor, it will help you to deliver lectures with an approach
that is easy to follow, and as a result your students will appreciate the fact that they have opted for
Computer Science / Information Technology as their degree.
This book is also useful for Engineering degree students and Masters degree students during
their academic preparations. In all the chapters you will see that there is more emphasis on
problems and their analysis rather than on theory. In each chapter, you will first read about the
basic required theory, which is then followed by a section on problem sets. In total, there are
approximately 700 algorithmic problems, all with solutions.
If you read the book as a student preparing for competitive exams for Computer Science /
Information Technology, the content covers all the required topics in full detail. While writing
this book, my main focus was to help students who are preparing for these exams.
In all the chapters you will see more emphasis on problems and analysis rather than on theory. In
each chapter, you will first see the basic required theory followed by various problems.
For many problems, multiple solutions are provided with different levels of complexity. We start
with the brute force solution and slowly move toward the best solution possible for that problem.
For each problem, we endeavor to understand how much time the algorithm takes and how much
memory the algorithm uses.
It is recommended that the reader does at least one complete reading of this book to gain a full
understanding of all the topics that are covered. Then, in subsequent readings you can skip
directly to any chapter to refer to a specific topic. Even though many readings have been done for
the purpose of correcting errors, there could still be some minor typos in the book. If any are
found, they will be updated at www.CareerMonk.com. You can monitor this site for any
corrections and also for new problems and solutions. Also, please provide your valuable
suggestions at: [email protected].
I wish you all the best and I am confident that you will find this book useful.
–Narasimha Karumanchi
M-Tech, I IT Bombay
Founder, CareerMonk.com
Other Books by Narasimha Karumanchi
IT Interview Questions
1. Introduction
1.1 Variables
1.2 Data Types
1.3 Data Structures
1.4 Abstract Data Types (ADTs)
1.5 What is an Algorithm?
1.6 Why the Analysis of Algorithms?
1.7 Goal of the Analysis of Algorithms
1.8 What is Running Time Analysis?
1.9 How to Compare Algorithms
1.10 What is Rate of Growth?
1.11 Commonly Used Rates of Growth
1.12 Types of Analysis
1.13 Asymptotic Notation
1.14 Big-O Notation [Upper Bounding Function]
1.15 Omega-Q Notation [Lower Bounding Function]
1.16 Theta-Θ Notation [Order Function]
1.17 Important Notes
1.18 Why is it called Asymptotic Analysis?
1.19 Guidelines for Asymptotic Analysis
1.20 Simplyfying properties of asymptotic notations
1.21 Commonly used Logarithms and Summations
1.22 Master Theorem for Divide and Conquer Recurrences
1.23 Divide and Conquer Master Theorem: Problems & Solutions
1.24 Master Theorem for Subtract and Conquer Recurrences
1.25 Variant of Subtraction and Conquer Master Theorem
1.26 Method of Guessing and Confirming
1.27 Amortized Analysis
1.28 Algorithms Analysis: Problems & Solutions
3. Linked Lists
3.1 What is a Linked List?
3.2 Linked Lists ADT
3.3 Why Linked Lists?
3.4 Arrays Overview
3.5 Comparison of Linked Lists with Arrays & Dynamic Arrays
3.6 Singly Linked Lists
3.7 Doubly Linked Lists
3.8 Circular Linked Lists
3.9 A Memory-efficient Doubly Linked List
3.10 Unrolled Linked Lists
3.11 Skip Lists
3.12 Linked Lists: Problems & Solutions
4. Stacks
4.1 What is a Stack?
4.2 How Stacks are used
4.3 Stack ADT
4.4 Applications
4.5 Implementation
4.6 Comparison of Implementations
4.7 Stacks: Problems & Solutions
5. Queues
5.1 What is a Queue?
5.2 How are Queues Used?
5.3 Queue ADT
5.4 Exceptions
5.5 Applications
5.6 Implementation
5.7 Queues: Problems & Solutions
6. Trees
6.1 What is a Tree?
6.2 Glossary
6.3 Binary Trees
6.4 Types of Binary Trees
6.5 Properties of Binary Trees
6.6 Binary Tree Traversals
6.7 Generic Trees (N-ary Trees)
6.8 Threaded Binary Tree Traversals (Stack or Queue-less Traversals)
6.9 Expression Trees
6.10 XOR Trees
6.11 Binary Search Trees (BSTs)
6.12 Balanced Binary Search Trees
6.13 AVL (Adelson-Velskii and Landis) Trees
6.14 Other Variations on Trees
9. Graph Algorithms
9.1 Introduction
9.2 Glossary
9.3 Applications of Graphs
9.4 Graph Representation
9.5 Graph Traversals
9.6 Topological Sort
9.7 Shortest Path Algorithms
9.8 Minimal Spanning Tree
9.9 Graph Algorithms: Problems & Solutions
10. Sorting
10.1 What is Sorting?
10.2 Why is Sorting Necessary?
10.3 Classification of Sorting Algorithms
10.4 Other Classifications
10.5 Bubble Sort
10.6 Selection Sort
10.7 Insertion Sort
10.8 Shell Sort
10.9 Merge Sort
10.10 Heap Sort
10.11 Quick Sort
10.12 Tree Sort
10.13 Comparison of Sorting Algorithms
10.14 Linear Sorting Algorithms
10.15 Counting Sort
10.16 Bucket Sort (or Bin Sort)
10.17 Radix Sort
10.18 Topological Sort
10.19 External Sorting
10.20 Sorting: Problems & Solutions
11. Searching
11.1 What is Searching?
11.2 Why do we need Searching?
11.3 Types of Searching
11.4 Unordered Linear Search
11.5 Sorted/Ordered Linear Search
11.6 Binary Search
11.7 Interpolation Search
11.8 Comparing Basic Searching Algorithms
11.9 Symbol Tables and Hashing
11.10 String Searching Algorithms
11.11 Searching: Problems & Solutions
14. Hashing
14.1 What is Hashing?
14.2 Why Hashing?
14.3 HashTable ADT
14.4 Understanding Hashing
14.5 Components of Hashing
14.6 Hash Table
14.7 Hash Function
14.8 Load Factor
14.9 Collisions
14.10 Collision Resolution Techniques
14.11 Separate Chaining
14.12 Open Addressing
14.13 Comparison of Collision Resolution Techniques
14.14 How Hashing Gets O(1) Complexity?
14.15 Hashing Techniques
14.16 Problems for which Hash Tables are not suitable
14.17 Bloom Filters
14.18 Hashing: Problems & Solutions
References
The objective of this chapter is to explain the importance of the analysis of algorithms, their
notations, relationships and solving as many problems as possible. Let us first focus on
understanding the basic elements of algorithms, the importance of algorithm analysis, and then
slowly move toward the other topics as mentioned above. After completing this chapter, you
should be able to find the complexity of any given algorithm (especially recursive functions).
1.1 Variables
Before going to the definition of variables, let us relate them to old mathematical equations. All of
us have solved many mathematical equations since childhood. As an example, consider the below
equation:
We don’t have to worry about the use of this equation. The important thing that we need to
understand is that the equation has names (x and y), which hold values (data). That means the
names (x and y) are placeholders for representing data. Similarly, in computer science
programming we need something for holding data, and variables is the way to do that.
In the above-mentioned equation, the variables x and y can take any values such as integral
numbers (10, 20), real numbers (0.23, 5.5), or just 0 and 1. To solve the equation, we need to
relate them to the kind of values they can take, and data type is the name used in computer science
programming for this purpose. A data type in a programming language is a set of data with
predefined values. Examples of data types are: integer, floating point, unit number, character,
string, etc.
Computer memory is all filled with zeros and ones. If we have a problem and we want to code it,
it’s very difficult to provide the solution in terms of zeros and ones. To help users, programming
languages and compilers provide us with data types. For example, integer takes 2 bytes (actual
value depends on compiler), float takes 4 bytes, etc. This says that in memory we are combining
2 bytes (16 bits) and calling it an integer. Similarly, combining 4 bytes (32 bits) and calling it a
float. A data type reduces the coding effort. At the top level, there are two types of data types:
• System-defined data types (also called Primitive data types)
• User-defined data types
Data types that are defined by system are called primitive data types. The primitive data types
provided by many programming languages are: int, float, char, double, bool, etc. The number of
bits allocated for each primitive data type depends on the programming languages, the compiler
and the operating system. For the same primitive data type, different languages may use different
sizes. Depending on the size of the data types, the total available values (domain) will also
change.
For example, “int” may take 2 bytes or 4 bytes. If it takes 2 bytes (16 bits), then the total possible
values are minus 32,768 to plus 32,767 (-215 to 215-1). If it takes 4 bytes (32 bits), then the
possible values are between -2,147,483,648 and +2,147,483,647 (-231 to 231-1). The same is the
case with other data types.
If the system-defined data types are not enough, then most programming languages allow the users
to define their own data types, called user – defined data types. Good examples of user defined
data types are: structures in C/C + + and classes in Java. For example, in the snippet below, we
are combining many system-defined data types and calling the user defined data type by the name
“newType”. This gives more flexibility and comfort in dealing with computer memory.
Based on the discussion above, once we have data in variables, we need some mechanism for
manipulating that data to solve problems. Data structure is a particular way of storing and
organizing data in a computer so that it can be used efficiently. A data structure is a special
format for organizing and storing data. General data structure types include arrays, files, linked
lists, stacks, queues, trees, graphs and so on.
Depending on the organization of the elements, data structures are classified into two types:
1) Linear data structures: Elements are accessed in a sequential order but it is not
compulsory to store all elements sequentially. Examples: Linked Lists, Stacks and
Queues.
2) Non – linear data structures: Elements of this data structure are stored/accessed in a
non-linear order. Examples: Trees and graphs.
Before defining abstract data types, let us consider the different view of system-defined data
types. We all know that, by default, all primitive data types (int, float, etc.) support basic
operations such as addition and subtraction. The system provides the implementations for the
primitive data types. For user-defined data types we also need to define operations. The
implementation for these operations can be done when we want to actually use them. That means,
in general, user defined data types are defined along with their operations.
To simplify the process of solving problems, we combine the data structures with their operations
and we call this Abstract Data Types (ADTs). An ADT consists of two parts:
1. Declaration of data
2. Declaration of operations
Commonly used ADTs include: Linked Lists, Stacks, Queues, Priority Queues, Binary Trees,
Dictionaries, Disjoint Sets (Union and Find), Hash Tables, Graphs, and many others. For
example, stack uses LIFO (Last-In-First-Out) mechanism while storing the data in data structures.
The last element inserted into the stack is the first element that gets deleted. Common operations
of it are: creating the stack, pushing an element onto the stack, popping an element from stack,
finding the current top of the stack, finding number of elements in the stack, etc.
While defining the ADTs do not worry about the implementation details. They come into the
picture only when we want to use them. Different kinds of ADTs are suited to different kinds of
applications, and some are highly specialized to specific tasks. By the end of this book, we will
go through many of them and you will be in a position to relate the data structures to the kind of
problems they solve.
Let us consider the problem of preparing an omelette. To prepare an omelette, we follow the
steps given below:
1) Get the frying pan.
2) Get the oil.
a. Do we have oil?
i. If yes, put it in the pan.
ii. If no, do we want to buy oil?
1. If yes, then go out and buy.
2. If no, we can terminate.
3) Turn on the stove, etc...
What we are doing is, for a given problem (preparing an omelette), we are providing a step-by-
step procedure for solving it. The formal definition of an algorithm can be stated as:
In the traditional study of algorithms, there are two main criteria for judging the merits of
algorithms: correctness (does the algorithm give solution to the problem in a finite number of
steps?) and efficiency (how much resources (in terms of memory and time) does it take to execute
the).
The goal of the analysis of algorithms is to compare algorithms (or solutions) mainly in terms of
running time but also in terms of other factors (e.g., memory, developer effort, etc.)
It is the process of determining how processing time increases as the size of the problem (input
size) increases. Input size is the number of elements in the input, and depending on the problem
type, the input may be of different types. The following are the common types of inputs.
• Size of an array
• Polynomial degree
• Number of elements in a matrix
• Number of bits in the binary representation of the input
• Vertices and edges in a graph.
Execution times? Not a good measure as execution times are specific to a particular computer.
Number of statements executed? Not a good measure, since the number of statements varies
with the programming language as well as the style of the individual programmer.
Ideal solution? Let us assume that we express the running time of a given algorithm as a function
of the input size n (i.e., f(n)) and compare these different functions corresponding to running
times. This kind of comparison is independent of machine time, programming style, etc.
The rate at which the running time increases as a function of input is called rate of growth. Let us
assume that you go to a shop to buy a car and a bicycle. If your friend sees you there and asks
what you are buying, then in general you say buying a car. This is because the cost of the car is
high compared to the cost of the bicycle (approximating the cost of the bicycle to the cost of the
car).
For the above-mentioned example, we can represent the cost of the car and the cost of the bicycle
in terms of function, and for a given function ignore the low order terms that are relatively
insignificant (for large value of input size, n). As an example, in the case below, n4, 2n2, 100n
and 500 are the individual costs of some function and approximate to n4 since n4 is the highest
rate of growth.
The diagram below shows the relationship between different rates of growth.
Below is the list of growth rates you will come across in the following chapters.
1.12 Types of Analysis
To analyze the given algorithm, we need to know with which inputs the algorithm takes less time
(performing wel1) and with which inputs the algorithm takes a long time. We have already seen
that an algorithm can be represented in the form of an expression. That means we represent the
algorithm with multiple expressions: one for the case where it takes less time and another for the
case where it takes more time.
In general, the first case is called the best case and the second case is called the worst case for
the algorithm. To analyze an algorithm we need some kind of syntax, and that forms the base for
asymptotic analysis/notation. There are three types of analysis:
• Worst case
○ Defines the input for which the algorithm takes a long time (slowest
time to complete).
○ Input is the one for which the algorithm runs the slowest.
• Best case
○ Defines the input for which the algorithm takes the least time (fastest
time to complete).
○ Input is the one for which the algorithm runs the fastest.
• Average case
○ Provides a prediction about the running time of the algorithm.
○ Run the algorithm many times, using many different inputs that come
from some distribution that generates these inputs, compute the total
running time (by adding the individual times), and divide by the
number of trials.
○ Assumes that the input is random.
Similarly for the average case. The expression defines the inputs with which the algorithm takes
the average running time (or memory).
Having the expressions for the best, average and worst cases, for all three cases we need to
identify the upper and lower bounds. To represent these upper and lower bounds, we need some
kind of syntax, and that is the subject of the following discussion. Let us assume that the given
algorithm is represented in the form of function f(n).
This notation gives the tight upper bound of the given function. Generally, it is represented as f(n)
= O(g(n)). That means, at larger values of n, the upper bound of f(n) is g(n). For example, if f(n)
= n4 + 100n2 + 10n + 50 is the given algorithm, then n4 is g(n). That means g(n) gives the
maximum rate of growth for f(n) at larger values of n.
Let us see the O–notation with a little more detail. O–notation defined as O(g(n)) = {f(n): there
exist positive constants c and n0 such that 0 ≤ f(n) ≤ cg(n) for all n > n0}. g(n) is an asymptotic
tight upper bound for f(n). Our objective is to give the smallest rate of growth g(n) which is
greater than or equal to the given algorithms’ rate of growth /(n).
Generally we discard lower values of n. That means the rate of growth at lower values of n is not
important. In the figure, n0 is the point from which we need to consider the rate of growth for a
given algorithm. Below n0, the rate of growth could be different. n0 is called threshold for the
given function.
Big-O Visualization
O(g(n)) is the set of functions with smaller or the same order of growth as g(n). For example;
O(n2) includes O(1), O(n), O(nlogn), etc.
Note: Analyze the algorithms at larger values of n only. What this means is, below n0 we do not
care about the rate of growth.
Big-O Examples
No Uniqueness?
There is no unique set of values for n0 and c in proving the asymptotic bounds. Let us consider,
100n + 5 = O(n). For this function there are multiple n0 and c values possible.
Solution1: 100n + 5 ≤ 100n + n = 101n ≤ 101n, for all n ≥ 5, n0 = 5 and c = 101 is a solution.
Solution2: 100n + 5 ≤ 100n + 5n = 105n ≤ 105n, for all n > 1, n0 = 1 and c = 105 is also a
solution.
Similar to the O discussion, this notation gives the tighter lower bound of the given algorithm and
we represent it as f(n) = Ω(g(n)). That means, at larger values of n, the tighter lower bound of
f(n) is g(n). For example, if f(n) = 100n2 + 10n + 50, g(n) is Ω(n2).
The Ω notation can be defined as Ω(g(n)) = {f(n): there exist positive constants c and n0 such that
0 ≤ cg(n) ≤ f(n) for all n ≥ n0}. g(n) is an asymptotic tight lower bound for f(n). Our objective is
to give the largest rate of growth g(n) which is less than or equal to the given algorithm’s rate of
growth f(n).
Ω Examples
This notation decides whether the upper and lower bounds of a given function (algorithm) are the
same. The average running time of an algorithm is always between the lower bound and the upper
bound. If the upper bound (O) and lower bound (Ω) give the same result, then the Θ notation will
also have the same rate of growth.
As an example, let us assume that f(n) = 10n + n is the expression. Then, its tight upper bound
g(n) is O(n). The rate of growth in the best case is g(n) = O(n).
In this case, the rates of growth in the best case and worst case are the same. As a result, the
average case will also be the same. For a given function (algorithm), if the rates of growth
(bounds) for O and Ω are not the same, then the rate of growth for the Θ case may not be the same.
In this case, we need to consider all possible time complexities and take the average of those (for
example, for a quick sort average case, refer to the Sorting chapter).
Now consider the definition of Θ notation. It is defined as Θ(g(n)) = {f(n): there exist positive
constants c1,c2 and n0 such that 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n) for all n ≥ n0}. g(n) is an asymptotic
tight bound for f(n). Θ(g(n)) is the set of functions with the same order of growth as g(n).
Θ Examples
Example 1 Find Θ bound for
For analysis (best case, worst case and average), we try to give the upper bound (O) and lower
bound (Ω) and average running time (Θ). From the above examples, it should also be clear that,
for a given function (algorithm), getting the upper bound (O) and lower bound (Ω) and average
running time (Θ) may not always be possible. For example, if we are discussing the best case of
an algorithm, we try to give the upper bound (O) and lower bound (Ω) and average running time
(Θ).
In the remaining chapters, we generally focus on the upper bound (O) because knowing the lower
bound (Ω) of an algorithm is of no practical importance, and we use the Θ notation if the upper
bound (O) and lower bound (Ω) are the same.
From the discussion above (for all three notations: worst case, best case, and average case), we
can easily understand that, in every case for a given function f(n) we are trying to find another
function g(n) which approximates f(n) at higher values of n. That means g(n) is also a curve
which approximates f(n) at higher values of n.
In mathematics we call such a curve an asymptotic curve. In other terms, g(n) is the asymptotic
curve for f(n). For this reason, we call algorithm analysis asymptotic analysis.
There are some general rules to help us determine the running time of an algorithm.
1) Loops: The running time of a loop is, at most, the running time of the statements
inside the loop (including tests) multiplied by the number of iterations.
2) Nested loops: Analyze from the inside out. Total running time is the product of the
sizes of all the loops.
4) If-then-else statements: Worst-case running time: the test, plus either the then part
or the else part (whichever is the larger).
Note: Similarly, for the case below, the worst case rate of growth is O(logn). The same
discussion holds good for the decreasing sequence as well.
• Transitivity: f(n) = Θ(g(n)) and g(n) = Θ(h(n)) ⇒ f(n) = Θ(h(n)). Valid for O and Ω
as well.
• Reflexivity: f(n) = Θ(f(n)). Valid for O and Ω.
• Symmetry: f(n) = Θ(g(n)) if and only if g(n) = Θ(f(n)).
• Transpose symmetry: f(n) = O(g(n)) if and only if g(n) = Ω(f(n)).
• If f(n) is in O(kg(n)) for any constant k > 0, then f(n) is in O(g(n)).
• If f1(n) is in O(g1(n)) and f2(n) is in O(g2(n)), then (f1 + f2)(n) is in O(max(g1(n)),
(g1(n))).
• If f1(n) is in O(g1(n)) and f2(n) is in O(g2(n)) then f1(n) f2(n) is in O(g1(n) g1(n)).
Logarithms
Arithmetic series
Geometric series
Harmonic series
All divide and conquer algorithms (also discussed in detail in the Divide and Conquer chapter)
divide the problem into sub-problems, each of which is part of the original problem, and then
perform some additional work to compute the final answer. As an example, a merge sort
algorithm [for details, refer to Sorting chapter] operates on two sub-problems, each of which is
half the size of the original, and then performs O(n) additional work for merging. This gives the
running time equation:
The following theorem can be used to determine the running time of divide and conquer
algorithms. For a given program (algorithm), first we try to find the recurrence relation for the
problem. If the recurrence is of the below form then we can directly give the answer without fully
solving it. If the recurrence is of the form , where a ≥ 1,b >
1,k ≥ 0 and p is a real number, then:
1) If a > bk , then
2) If a= bk
a. If p > –1, then
b. If p = –1, then
c. If p < –1, then
3) If a < bk
a. If p ≥ 0, then T(n) = Θ(nk logpn)
b. If p < 0, then T(n) = O(nk )
For each of the following recurrences, give an expression for the runtime T(n) if the recurrence
can be solved with the Master Theorem. Otherwise, indicate that the Master Theorem does not
apply.
for some constants c,a > 0,b ≥ 0,k ≥ 0, and function f(n). If f(n) is in O(nk ), then
The solution to the equation T(n) = T(α n) + T((1 – α)n) + βn, where 0 < α < 1 and β > 0 are
constants, is O(nlogn).
Now, let us discuss a method which can be used to solve any recurrence. The basic idea behind
this method is:
In other words, it addresses the question: What if the given recurrence doesn’t seem to match with
any of these (master theorem) methods? If we guess a solution and then try to verify our guess
inductively, usually either the proof will succeed (in which case we are done), or the proof will
fail (in which case the failure will help us refine our guess).
As an example, consider the recurrence . This doesn’t fit into the form
required by the Master Theorems. Carefully observing the recurrence gives us the impression that
it is similar to the divide and conquer method (dividing the problem into subproblems each
with size ). As we can see, the size of the subproblems at the first level of recursion is n. So,
let us guess that T(n) = O(nlogn), and then try to prove that our guess is correct.
The last inequality assumes only that 1 ≥ k. .logn. This is incorrect if n is sufficiently large and
for any constant k. From the above proof, we can see that our guess is incorrect for the lower
bound.
From the above discussion, we understood that Θ(nlogn) is too big. How about Θ(n)? The lower
bound is easy to prove directly:
From the above induction, we understood that Θ(n) is too small and Θ(nlogn) is too big. So, we
need something bigger than n and smaller than nlogn. How about ?
The last step doesn’t work. So, Θ( ) doesn’t work. What else is between n and nlogn?
How about nloglogn? Proving upper bound for nloglogn:
From the above proofs, we can see that T(n) ≤ cnloglogn, if c ≥ 1 and T(n) ≥ knloglogn, if k ≤ 1.
Technically, we’re still missing the base cases in both proofs, but we can be fairly confident at
this point that T(n) = Θ(nloglogn).
The motivation for amortized analysis is to better understand the running time of certain
techniques, where standard worst case analysis provides an overly pessimistic bound. Amortized
analysis generally applies to a method that consists of a sequence of operations, where the vast
majority of the operations are cheap, but some of the operations are expensive. If we can show
that the expensive operations are particularly rare we can change them to the cheap operations,
and only bound the cheap operations.
The general approach is to assign an artificial cost to each operation in the sequence, such that the
total of the artificial costs for the sequence of operations bounds the total of the real costs for the
sequence. This artificial cost is called the amortized cost of an operation. To analyze the running
time, the amortized cost thus is a correct way of understanding the overall running time – but note
that particular operations can still take longer so it is not a way of bounding the running time of
any individual operation in the sequence.
Example: Let us consider an array of elements from which we want to find the kth smallest
element. We can solve this problem using sorting. After sorting the given array, we just need to
return the kth element from it. The cost of performing the sort (assuming comparison based sorting
algorithm) is O(nlogn). If we perform n such selections then the average cost of each selection is
O(nlogn/n) = O(logn). This clearly indicates that sorting once is reducing the complexity of
subsequent operations.
Note: From the following problems, try to understand the cases which have different
complexities (O(n), O(logn), O(loglogn) etc.).
Problem-21 Find the complexity of the below recurrence:
Solution: Let us try solving this function with substitution.
T(n) = 3T(n – 1)
Note: We can use the Subtraction and Conquer master theorem for this problem.
Problem-22 Find the complexity of the below recurrence:
∴ Time Complexity is O(1). Note that while the recurrence relation looks exponential, the
solution to the recurrence relation here gives a different result.
Problem-23 What is the running time of the following function?
Solution: Consider the comments in the below function:
We can define the ‘s’ terms according to the relation si = si–1 + i. The value oft’ increases by 1
for each iteration. The value contained in ‘s’ at the ith iteration is the sum of the first ‘(‘positive
integers. If k is the total number of iterations taken by the program, then the while loop terminates
if:
In the above-mentioned function the loop will end, if i2 > n ⇒ T(n) = O( ). This is similar to
Problem-23.
Problem-25 What is the complexity of the program given below:
Solution: The while loop will terminate once the value of ‘k’ is greater than or equal to the value
of ‘n’. In each iteration the value of ‘k’ is multiplied by 3. If i is the number of iterations, then ‘k’
has the value of 3i after i iterations. The loop is terminated upon reaching i iterations when 3i ≥ n
↔ i ≥ log3 n, which shows that i = Ω(logn).
Solution: By iteration:
Note: We can use the Subtraction and Conquer master theorem for this problem.
Problem-34 Consider the following program:
Solution: The recurrence relation for the running time of this program is: T(n) = T(n – 1) + T(n –
2) + c. Note T(n) has two recurrence calls indicating a binary tree. Each step recursively calls the
program for n reduced by 1 and 2, so the depth of the recurrence tree is O(n). The number of
leaves at depth n is 2n since this is a full binary tree, and each leaf takes at least O(1)
computations for the constant factor. Running time is clearly exponential in n and it is O(2n).
Problem-35 Running time of following program?
Solution: Consider the comments in the function below:
In the above code, inner loop executes n/i times for each value of i. Its running time is
.
Problem-36 What is the complexity of
Solution: Using the logarithmic property, logxy = logx + logy, we can see that this problem is
equivalent to
Problem-38 What is the running time of the following recursive function (specified as a
function of the input value n)? First write a recurrence formula, and show its solution using
induction.
The if statement requires constant time [O(1)]. With the for loop, we neglect the loop overhead
and only count three times that the function is called recursively. This implies a time complexity
recurrence:
Using the Subtraction and Conquer master theorem, we get T(n) = Θ(3n).
Problem-39 Write a recursion formula for the running time T(n) of the function whose code
is below.
The recurrence for this piece of code is T(n) = T(.8n) + O(n) = T(4/5n) + O(n) =4/5 T(n) + O(n).
Applying master theorem, we get T(n) = O(n).
Problem-40 Find the complexity of the recurrence: T(n) = 2T( ) + logn
Solution: The given recurrence is not in the master theorem format. Let us try to convert this to the
master theorem format by assuming n = 2m. Applying the logarithm on both sides gives, logn =
mlogl ⇒ m = logn. Now, the given function becomes:
For the above code, the recurrence function can be given as: T(n) = T( ) + 1. This is same as
that of Problem-41.
Problem-44 Analyze the running time of the following recursive pseudo-code as a function of
n.
Solution: Consider the comments in below pseudo-code and call running time of function(n) as
T(n).
Another Random Document on
Scribd Without Any Related Topics
They arrived at the broad gulley that Bambi had never been across.
The elder climbed down into it, Bambi tried to follow but it took him
a lot of effort to climb up the steep slope on the other side.
The fierce pain he felt began once more to go through him. He fell
over, pulled himself back up, fell over again and began to gasp for
breath.
“I can’t help you here,” said the elder, “you’ve got to get up here
yourself!” And Bambi did get up to the top. He began once more to
feel the hot band of pain that shot down his shoulder and felt for the
second time that he was losing his strength.
“You’re bleeding again,” said the elder, “that’s what I expected. It’s
not too much, though ... and ...,” he added in a whisper, “it doesn’t
matter any more.”
They made their way very slowly through a grove of beech trees, as
high as the sky. The ground was soft and smooth. It did not take too
much effort to go through it. Bambi yearned to just lay himself down
here, to stretch himself out and not to move a finger. He just could
not go any further. His head hurt, there was a buzzing in his ears,
his nerves were quivering and his fever began to shake him. His
eyes went dim. There was nothing more inside him than the
yearning for rest and a vague astonishment at how his life had
suddenly been interrupted and altered, at how he had once used to
go through the forest in good health and without injury ... just that
morning ... just an hour earlier ... it seemed to him now like the
happiness of a distant time that had long since vanished.
They passed through a low thicket of oaks and dogwood. The fallen
trunk of a beech tree lay across their path, deeply embedded in the
bushes. It was very big and they could see no way of getting past it.
“Now we’ve got there ...” Bambi heard the elder say. He walked the
length of the beech trunk and Bambi followed him, nearly falling into
a hole in the ground.
“Alright!” said the elder. “You can lie down here.”
Bambi sank down and did not try to move any more.
He saw that the hole in the ground under the fallen beech trunk was
deeper than it had seemed, creating a small chamber. The bushes at
the edge of it closed over him as he entered so that nobody could
see in. Once he was down there it was as if he had disappeared.
“You’ll be safe here,” said the elder. “Stay here and don’t go
anywhere.”
Bambi lay in the warm earth, the bark of the fallen tree slowly
rotting above him, it listened to his pain as it grew inside his body,
became stronger, then abated, became weaker and went down,
steadily softer and softer. Sometimes he would struggle outside
where he would stand, weak and unsteady, on his tired and
unreliable legs, and take a few steps to look for food. He began to
eat herbs that he had never before noticed. Now they had suddenly
begun to offer themselves to him, called to him with their scent that
had a strange and tempting sharpness. What he had until then
despised, what he would have thrown away if he inadvertently got it
between his lips, now seemed tasty and spicy. Many little leaves,
many short stalks continued to seem unappetizing even now, but he
nonetheless ate them under some kind of compulsion, and his
wounds healed more quickly and he could feel how his strength was
coming back to him.
He had been saved. But he still did not leave his chamber. He would
only come out at night and take a few steps around, but in the
daytime he would remain quietly in his bed. It was only now, when
his body was feeling no more pain, that Bambi realized all that had
happened to him, he was able to think once more, and a feeling of
great horror arose within him, his character had been shattered. He
was not able to simply wipe it away, not able to stand up and run
about as he had before. He lay there and felt many emotions,
alternately disgusted, ashamed, astonished, disheartened, but soon
afterwards full of melancholy, soon afterwards full of happiness.
The elder was nearby at all times. At first he was at Bambi’s side day
and night. Then there were times when he left him alone for short
periods, especially when he saw that Bambi was lost in his thoughts.
But there was no time when he was not close by.
One day there had been storm and thunder and lightning, the sky
had been swept clean and that evening the sun, as it went down,
shone over a sky that was blue. The blackbirds sang out loudly from
the tree tops, the finches flapped their wings, the tits whispered in
the undergrowth, in the grass and under the bushes close to the
ground the metallic bursts of the pheasants’ cries could be heard,
the woodpecker laughed in loud celebration and the pigeons cooed
from the yearning for love that was inside them.
Bambi stepped out from his underground chamber. Life was good.
The elder was standing there as if he had been waiting.
But Bambi never went back across that gulley, never went back to
see the others.
CHAPTER 23
One night, when the autumn leaves were falling and whispering
through the whole of the forest, the tawny owl gave his shrill cry
through the tree tops. Then he waited.
But Bambi had already seen him in the distance through the now
sparse foliage and now he kept still.
The owl flew closer and gave his shrill cry even louder. Then he
waited. But this time too, Bambi said nothing.
The owl could not hold back any longer. “Aren’t you startled, then?”
he asked discontentedly.
“Well ...,” the owl grumbled, “only a little bit? You always used to be
terribly shocked. It was always such a pleasure to see how shocked
you were. What’s happened then, what’s happened that means your
only a little bit shocked ...?”
The owl had grown old, and that had made him even more vain and
even more sensitive than he had been.
Bambi could not resist. What harm could there be in it? Let the little
old boy have some pleasure.
The owl puffed up his feathers, turned himself into a soft, brown and
light grey, fluffy ball, and he was very pleased. “That’s very nice of
you to have been thinking about me ... very nice indeed ...” he
cooed gently. “It’s such a long time since we saw each other.”
“Maybe it’s that you don’t go along the same old paths any more?”
enquired the owl.
“No ...,” Bambi spoke slowly, “I don’t go along the same old paths
any more.”
“I’ve been seeing a lot more of the world too lately,” remarked the
owl, puffing his chest out. He did not tell Bambi that he had been
driven out of the old territory he had inherited from his ancestors by
a young and reckless lad. “You can’t always stay on the same spot,”
he added. Then he waited for Bambi’s reply.
But Bambi had gone. By now he had learned the art of disappearing
in silence almost as well as the elder.
The owl was dismayed. “Shameless ...” he grumbled. He shook
himself, buried his beak into his plumage and philosophized to
himself; “You should never think you could make friends with these
posh types. They might seem ever so likeable ... but one day they’ll
shamelessly ... and then you sit there looking stupid, just like I am
now ...”
The storm blew through the woods for many days, tearing the last
of the leaves from the twigs and branches. The trees now stood
there naked.
In the grey of morning twilight Bambi was making his way home in
order to sleep together with the elder in their chamber.
Bambi lowered his head in sadness. It really did hurt his soul to hear
about the wonderful ancient tree.
“It all happened so quickly,” the squirrel told him. “All of us who lived
on the old tree, we all ran away and we could only watch as He bit
through it with an enormous blinking tooth. The tree screamed out
loud from his wound. He just kept on screaming, and the tooth
screamed too ... it was horrible to hear it. Then that poor, lovely tree
fell over. Out onto the meadow ... it made all of us cry.”
“Yes ...” said the squirrel with a sigh, “He can do anything ... He’s
omnipotent ...” He looked at Bambi with eyes wide open and pricked
up his ears, but Bambi was silent.
“We’ve all got nowhere to live now ...” the squirrel continued, “I
don’t even have any idea of where the others have got to ... I came
over here ... but it’ll take me ages to find another tree like that.”
“The old oak tree ...,” muttered Bambi to himself, “I’ve known it
since I was a child.”
“No ... but it’s good to see that it’s really you!” The squirrel became
quite contented. “We all thought you must have died a long time
ago. But there were some who said you were still alive ... some said
that someone or other had seen you ... but we couldn’t find out
anything definite, so we just supposed it was an empty rumour ...”
The squirrel looked at him searchingly. “Well, that was ... that was
because you didn’t come back.”
He sat there waiting for an answer, you could see that he was very
keen to know what had happened.
Bambi was silent. But he, too, felt a slight, anxious curiosity. He
wanted to ask. About Faline, about Aunt Ena, about Ronno and
Karus, about everyone he had known as a child. But he was silent.
The squirrel nodded his head vigorously. “It really is!” he said in
astonishment. “Really. You’re beginning to go grey.”
The squirrel saw that the discussion was at an end and swung up
into the branches. “Bye then,” he called down. “Look after yourself! I
enjoyed seeing you again. If I see any of your old friends I’ll tell
them you’re still alive ... they’ll all be glad to hear it.”
Bambi heard this and once again felt those slight stirrings in his
heart. But it said nothing. You have to stay alone, the elder had
taught him when Bambi was still a child. And the elder had shown
him many things, told him many secrets, and continued doing so up
to the present day. But of all the things he had been taught, this was
the most important: You have to stay alone. If you’re going to
preserve your life, if you want to understand existence, if you want
to become wise, you have to stay alone!
“But,” asked Bambi one time, “but what about the two of us, we’re
always together nowadays ...?”
One morning the deep quiet was torn apart by the barking of dogs.
In the chamber under the fallen beech trunk Bambi raised his head
and looked at the elder who was lying next to him.
The elder answered Bambi’s look. “It’s nothing, nothing that need
concern us.”
They lay in their chamber, they had the old beech trunk as a
protective roof over them, icy draughts were kept out by the height
of the snow, and the tangle of bushes hid them like a dense grid
from any spying eye.
It came ever nearer. Now they could hear the gasping for breath at
twice the speed, and through the angry barking they heard a gentle
growling, as if from pain. Bambi became uneasy, but the elder again
said, “It’s nothing that need concern us.”
The rustling in the twigs came ever nearer, snow fell from the
boughs as they were suddenly run past, a dust of snow was kicked
up from the ground.
Through snow and bushes, through roots and twigs there came,
jumping and creeping and sliding, the old fox.
Immediately after him the dog broke through. It was a very small
dog on short legs.
One of the fox’s front legs was broken and just above the break his
fur was ripped open. He held the broken leg high up in front of him,
blood was spurting from his wounds, his breath was wheezy, his
eyes were staring far ahead because of his horror and the efforts he
was having to make. He was beside himself with terror and panic, he
was confused and exhausted. He swung round in a swiping
movement, which startled the dog so that he stepped back a few
paces.
The fox sat down on his hind legs. He could go no further. He held
the shot foreleg up in a way that was pitiful, his mouth was open,
sucking in his cheeks he spat at the dog.
He, though, was not quiet for a moment. His high, shrill voice now
became fuller and deeper. “Here!” he shouted. Here! Here he is!
Here! Here! Here!” He was not shouting at the fox, at that moment
he was not speaking to him at all but was clearly calling to
somebody else who was still a long way away.
Bambi and the elder were both aware that it was Him whom the dog
was calling.
The fox knew it too. The blood was now gushing down from his
breast and into the snow and built up a gently steaming, scarlet
stain on the icy-white layer.
The fox seemed to be having a mild fit. His shattered foreleg had no
strength in it and it sank down, but when it touched the cold snow a
burning pain shot through it. Arduously, he raised it up and held it,
jittering, in the air in front of him.
“No! No! No!” the dog threw back at him in a malevolent howl.
“I beg of you ...” said the fox, “I can’t go any further ... I’ve had it ..
just let me go ... let me go home ... at least let me die in peace ...”
The fox begged him even harder. “But we’re related ...” he lamented,
“we’re almost brothers ... let me go home ... let me die among my
own folk ... we ... we’re almost brothers ... you and me ...”.
Now the fox sat upright. His lovely pointed snout sank down to his
bloodied breast, his eyes rose up and stared at the dog right into his
face . In a quite different voice, in control of himself, sad and bitter,
he snarled, “Aren’t you ashamed of yourself ...? You traitor!”
The fox, however went on. “You turncoat ... you defector!” His
lacerated body became stiff with hatred and contempt. “You’re just
His henchman,” he hissed. “You miserable ... you seek us out where
He couldn’t find us ... you persecute us in places that He can’t get to
... you turn us in ..., and all of us are your relatives ... you turn me
in, and you and I are nearly brothers ... and you just stand there
...are you not ashamed of yourself?”
Shrill hisses and screeches came out from all the trees and bushes,
and from the air came the screeching of the crows, “henchman!” All
had hurried close, all had listened to the quarrel from the trees
above or from a safe hiding place on the ground. The disgust
expressed by the fox released the old, bitter disgust that they all felt,
and the blood steaming in sight of them on the snow made them
furious and made them lose all their reserve.
The dog looked around him. “You!” he called. “What do you want?
What do you know about it? What are you talking about? All o’ you
belong to ‘Im, just like I belong to ‘Im! But me ... well I love ‘Im, I
pray to ‘Im! I serve ‘Im! But you, you don’t know that ‘E’s in charge
‘ere. You’re pitiful you are, you can’t rebel against ‘Im? ‘E’s the
almighty! ‘E’s above all of us! Ev’rything you’ve got comes from ‘Im!
E’vrything that grows and lives, it all comes from ‘Im.” The dog was
shaking in his outrage.
“Yes!” hissed the fox. “You’re a traitor. Nobody but you ... you’re the
only one ...!”
They danced about in self-righteous anger. “I’m the only one ...? You
liar! D’you think there aren’t loads and loads of others who are with
‘Im ...? The ‘orse ... the cows ... the lamb ... the chickens ... and
some of all of you, all your species, there are loads who are with
‘Im, who pray to ‘im ... and serve ‘Im!”
The dog could control himself no longer and hurled himself at the
fox’s throat. A snarling, spitting, gasping bundle, wild and whirring
they rolled in the snow, snapping at each other, hair flew up, snow
flew up, fine drops of blood flew up. But the fox was not able to
maintain the fight for long. After just a few seconds he lay there on
his back, showed his pale belly, twitched, stretched himself out, and
died.
The dog shook him a few more times, then dropped him into the
churned up snow, stood there with his legs wide apart and once
more called out in a full, deep voice, “There! There! There he is!”
“Worst of all,” the elder replied, “is that they believe in what the dog
just said. They believe it, they live a life full of fear, they hate Him
and they hate themselves ... and they kill themselves for his sake.”
CHAPTER 25
There came a break in the cold and a pause in the middle of winter.
The Earth drank in the melting snow in great draughts, so that broad
stretches of naked earth could be seen everywhere. The blackbirds
were not singing yet but when they flew up from the ground where
they had been hunting for worms, or when they flapped from tree to
tree, they let out a long, shrill, cheerful cry which was almost like
birdsong. The woodpecker began to laugh here and there, magpies
and crows became more chatty, the tits talked gaily with each other,
and the pheasants, when they had swung down from the trees
where they had been sleeping, now remained in one spot for almost
as long as they would in the good times, they would shake their
plumage in the morning sunshine and continually burst out with
their metallic cry.
On mornings like this Bambi would range out further afield than he
normally would. When the sun had barely risen he arrived at his
chamber under the beech tree. Over on the other side, there where
he had used to live, there was something moving. Bambi remained
hidden in the undergrowth and watched. He was right, someone of
his own species was moving about there, seeking out the patches
that were free of snow and setting about the early-risen grasses.
At first, Bambi wanted to turn round and go away, but then he saw
that it was Faline. His first urge was to jump forward and call to her.
But he stayed where he was as if rooted to the spot. It was so long
since he had last seen Faline. His heart began to beat hotly. Faline
was walking slowly, as if she were tired or sad. She looked like her
mother now, looked like Aunt Ena, and when Bambi noticed this it
was with painful astonishment.
Faline raised her head and looked in his direction, as if she could feel
that he was near.
Again, Bambi felt the urge to go toward her, but, again, he stayed
where he was, powerless and lame, he was unable to move.
Over there, Faline was walking away with her head sunk down to the
ground, slow, tired and sad. At that moment Bambi loved her with a
gush of tender pity, he wanted to cross through the hole under the
beech trunk, which for so long had separated him from her and from
the others, wanted to fetch her back, to talk to her about the time
when they had been children, above all to talk about the past.
That was here, on this side of the hole. Not very close, but here, on
the side where he was.
Bambi made a few steps deeper back into the thicket, where he kept
still and listened. Everything was quiet. He crept carefully home.
The elder was already there, but had not gone down into their
chamber, he just stood next to the fallen beech trunk as if he had
been waiting.
“Where have you been all this time?” he asked, and he was so
serious that Bambi remained silent. “Did you hear that, just now?”
the elder went on after a pause.
“Over there,” said the elder, and his voice was heavy. “Over there
where He is now.”
“Don’t be frightened,” the elder went on. “Come with me now and
don’t be afraid. I’m glad I’ve got the chance to take you there and
let you see it ...” He hesitated and gently added, “before I go.”
Bambi was taken aback at this and stared at the elder. He suddenly
became aware of how frail he looked; his head was now entirely
white, his face had become very gaunt, his beautiful eyes had lost
their sparkle, they had taken on a dull green appearance and
seemed to be somehow broken.
Bambi and the elder did not go far, they could feel the first winds of
a heavy storm blowing at them, a storm that was capable of putting
so much threat and dread into their hearts.
Two steps away from them, He lay there on the ground on bent and
broken bushes and in churned up snow.
“Stop!” he heard the elder call. He looked back and saw that the
elder was calmly standing there where He was lying on the ground.
Beside himself in astonishment, Bambi stepped closer, compelled by
his obedience, by his boundless curiosity, by his quaking anticipation.
There He lay, his pale uncovered face looking upwards, His hat a
little to the side of him in the snow, and Bambi, who knew nothing
about hats, thought that that awful head had been struck into two
pieces.
Bambi looked down at Him as he lay there, His form, His limbs, His
hair all seemed to Bambi to be something gruesome but puzzling.
He looked into those broken eyes that stared sightlessly back up at
him, and he did not understand.
“Bambi,” the elder continued, “do you remember what Gobo said,
what the dog said, about what everyone believed ... do you
remember?”
“You can see him there, Bambi,” the elder went on, “you can see
Him lying there like any one of us. Listen to me, Bambi, He is not
almighty like they say he is. He is not the source from which
everything comes, everything that grows and lives. He is not our
superior! He is beside us, He is like us, and just like us He knows
fear and need and sorrow. He can be overcome just like us and now
He lies helpless on the ground, just like the rest of us, just as you
see Him now.”
Bambi blushed and quaked and said, “There’s someone else who is
above all of us, ... above us and above Him.”
“The time has come, then, when I can go,” the elder said.
He turned round and the two of them wandered on for a little while.
At a tall ash tree the elder stopped. “Don’t come with me any more,
Bambi,” he began, in a calm voice, “my time is up. Now I need to
find a place for the end ...”
“No,” the elder stopped him. “No ... at the time I am now
approaching each of us is alone. Fare well, my son ... I have loved
you very much.”
The summer’s day started being hot as soon as the sun had risen,
no wind, no chill of twilight. The sun seemed to be in more of a
hurry that day. It rose quickly into the sky and broke out its dazzling
flames like a dreadful blaze.
The dew on the meadow and on the bushes quickly evaporated; the
earth became very dry and crumbly. In the woods it became quiet
before its usual time. Only the woodpecker could be heard laughing
here and there, and only the pigeons cooed in tireless, fervent
tenderness.
“Did you see him ...?” the midges asked each other. “That’s the
elder,” said one of them. And the others sang, “All of his relatives are
already dead, but he’s still alive.”
A couple of very small midges asked, “How long do you think he’s
going to live?” The others sang their answer, “We don’t know. He’s
outlived all of his family ... he’s very old ... very old.”
Bambi walked on. The song of midges, he thought, song of midges
... A tender, anxious call came through to him. The voice of
somebody of his own species. “Mother! ... mother!”
Bambi turned away, slipped into the nearest bush and disappeared,
even before two of them could understand what had happened. He
walked on. “I like that lad ...” he thought. “Maybe I’ll meet him again
when he’s a bit bigger ...” He walked on. “And the little lass,” he
thought,” she’s nice too ... that’s what Faline looked like when she
was a child.”
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E. Unless you have removed all references to Project Gutenberg:
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
ebookball.com