Data Structures and Algorithms With C Pal Debdutta Halder Suman Instant Download
Data Structures and Algorithms With C Pal Debdutta Halder Suman Instant Download
https://ebookbell.com/product/data-structures-and-algorithms-
with-c-pal-debdutta-halder-suman-10525336
Data Structures And Algorithms With The C Stl A Guide For Modern C
Practitioners 1 Converted John Farrier
https://ebookbell.com/product/data-structures-and-algorithms-with-the-
c-stl-a-guide-for-modern-c-practitioners-1-converted-john-
farrier-55889290
https://ebookbell.com/product/data-structures-and-algorithms-with-go-
create-efficient-solutions-and-optimize-your-go-coding-skills-duan-
stojanovi-56153732
https://ebookbell.com/product/handson-data-structures-and-algorithms-
with-kotlin-chandra-sekhar-nayak-11063708
https://ebookbell.com/product/handson-data-structures-and-algorithms-
with-rust-claus-matzinger-57017412
Handson Data Structures And Algorithms With Rust Claus Matzinger
https://ebookbell.com/product/handson-data-structures-and-algorithms-
with-rust-claus-matzinger-170505490
Data Structures And Algorithms With Python 100 Coding Qa Code Of Code
Converted Yasin Cakal
https://ebookbell.com/product/data-structures-and-algorithms-with-
python-100-coding-qa-code-of-code-converted-yasin-cakal-54845986
Handson Data Structures And Algorithms With Python Write Complex And
Powerful Code Using The Latest Features Of Python 37 2nd Edition 2nd
Edition Dr Basant Agarwal
https://ebookbell.com/product/handson-data-structures-and-algorithms-
with-python-write-complex-and-powerful-code-using-the-latest-features-
of-python-37-2nd-edition-2nd-edition-dr-basant-agarwal-10684212
https://ebookbell.com/product/data-structures-and-algorithms-with-
python-with-an-introduction-to-multiprocessing-undergraduate-topics-
in-computer-science-2nd-ed-2023-lee-55038848
https://ebookbell.com/product/learn-data-structures-and-algorithms-
with-golang-level-up-your-go-programming-skills-to-develop-faster-and-
more-efficient-code-bhagvan-kommadi-10903012
Data Structures and
Algorithms with C
Data Structures and
Algorithms with C
Debdutta Pal
Suman Halder
α
Alpha Science International Ltd.
Oxford, U.K.
Data Structures and Algorithms with C
352 pages
Debdutta Pal
Suman Halder
Department of Computer Science and Engineering
Calcutta Institute of Engineering and Management
Kolkata
Copyright © 2018
A L P H A S C I E N C E I N T E R N AT I O N A L LT D .
7200 The Quorum, Oxford Business Park North
Garsington Road, Oxford OX4 2JZ, U.K.
www.alphasci.com
ISBN 978-1-78332-368-5
E-ISBN 978-1-78332-427-9
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system,
or transmitted in any form or by any means, electronic, mechanical, photocopying, recording
or otherwise, without prior written permission of the publisher.
Dedicated
to
Our Parents
Preface
This book is designed as a stepping stone for the students to enter into the world of computer science
and engineering. All the students irrespective of different domain of technology if want to build carrier
in the Computer Science and Engineering domain have to have enough knowledge in data structures.
The Data structure is a course that helps students to accumulate knowledge about how data are stored
and manipulated in the memory of any computing device. This book is written for the students who have
knowledge about C and now are going to open their eyes in the domain of data structure. Hence, the
prospective audience for this book consists primarily of sophomores and juniors majoring in computer
science or computer engineering.
Chapter 1, in this book is designed in such a way that the students having no knowledge in data
structure can boldly step forward into the zone of data structure. This chapter has a detail overview on a
data structure that includes definition of data structure, the categorisation of data structure. Operation on
different data structure is also included in this chapter. The chapter ends with application of data structure.
Chapter 2, can be defined as a soul of this book. This chapter includes details of the algorithm.
Definition of algorithm, life cycle of algorithm. Time complexity and space complexity measurement is
explained in this chapter. Students will come to know about asymptotic notation and the manipulation
of asymptotic notation in this chapter. Classification of the algorithm is also a major part of this chapter.
In the chapter 3, array is defined in broad way. The chapter includes details of one dimensional (1-D)
array. Multidimensional array is also explained here. Address calculations of one and two dimensional
array are shown in this chapter. Representation of a sparse matrix is given here. Manipulation of string
is a major part of this chapter.
Chapter 4 can be defined as a heart of this chapter. This includes classification of pointers and array
of pointers. Dynamic memory allocation (DMA) is one of the major contributions in this chapter. Stu-
dents will learn about different predefined functions that are used for DMA. They will also build their
knowledge about need of DMA and the shortcomings of DMA. Dynamically allocated spaces are how
to de-allocate that is also explained here. Creation of one dimensional and two dimensional arrays using
dynamic memory allocation is explained here.
In the chapter 5, detail of another a linear data structure is described. The name of this data structure
is “Link List”. This chapter initiates with linear link list and finally it concludes with a doubly link list.
Creation, traversal, insertion, deletion, reverse operations on the single link list, circular link list and the
doubly link list are explained in broad way. Both algorithms and programs are given for each operation
to make this chapter more student approachable. This chapter is application of DMA.
Chapter 6 deals with different aspects of Stack and Queue. The first part of this chapter explains
Stack definition and basic operations on Stack. It is followed by the application of Stack in POSTFIX,
PREFIX expression. Implementations of Stack using link list and array are also included in this chapter.
Second part of this chapter is all about Queue. Definition of the Queue and basic operations on queue are
specified here. Then categorisation of Queue is also given here. Different types of Queues like circular
queue, de-queue and priority queue are explained with example. Each operation on Stack and Queue is
accompanied with algorithm and programs.
viii Preface
In chapter 7, recursion is explained in a comprehensive way. When students reach at this chapter
they have acquired knowledge about non recursive functions. After completion of this chapter, students
will come to know about recursive function. This chapter deals with the need of recursion, depth of
recursion, type of recursion and the shortcomings of recursive functions. This chapter concludes with
bags of programs on recursion that make students more familiar with recursion.
Chapter 8 involves a non-linear data structure. Until now the students accumulate their knowledge
about the linear data structure. With this chapter they will reveal another look of data structure. This
chapter focuses on Tree structure. This chapter initiates with binary tree followed by a binary search tree
and end with multi way search tree. Each type of tree structure is explained with some basic operations
on tree like creation, insertion of node, traversal, and deletion of nodes. Height balance tree is one of the
major contributions of this chapter.
Chapter 10 focuses on another very important part of data structure that is Graph. Here, the graph is
explained in detail. The chapter introduces the different terminology of graph like nodes, link, adjacent
node, complete graph, path, circuit, walk, degree of vertex, etc.; it is followed by the memory repre-
sentation of the graph. Then memory representation of a graph is explained in terms of the adjacency
matrix, adjacency list, multi list, incident matrix. Then different graph traversal algorithm is explained.
Spanning tree formation is also shown here by the means of Prim’s algorithm and Kruskal algorithm.
The chapter also includes some algorithm to find shortest path using Bellman-Ford algorithm, Dijkstra’s
algorithm, and Floyed-Warshall algorithm. The chapter concludes with different application of graph in
different aspects of computer science and engineering fields. To make it easy -for student programs are
also written for all the algorithm explain in this chapter. Some lemmas are written for students who are
going to study design analysis and algorithm.
In chapter 10, different types of searching and sorting algorithms are explained. For each searching
and sorting algorithm recurrence relation is also derived using different approaches. The algorithms are
explained with the help of examples in each case. Each sorting and searching algorithm is accompanied
with programs so that the students can easily understand the algorithm and run the program without any
difficulties. This chapter includes some basic sorting algorithm like bubble sort, insertion sort, merge
sort, quick sort and also some advance sorting technique like radix sort, heap sort and shell sort.
Chapter 11 deals with hashing technique. It explains different terminology relates to hashing like
hash function, hash table. This chapter also describes different types of hashing procedure with examples.
Collision resolution techniques are also described in this chapter. Here, creation of hash table, insert in
a hash table and delete from a hash table is explained with algorithm and program.
Chapter 12, the concluding chapter of this book gives a glimpse on file handling. Here, different
ways of storing records in a file are explained. Indexing of records and searching of records from a file
are also described in this chapter.
Debdutta Pal
Suman Halder
Acknowledgement
I am grateful to the Almighty, whose grace and blessings empowered me at every juncture. This book
would not be completed without the contribution and support that I have acquired from many people. I
would like to take the opportunity to express my heartfelt thanks to these individuals.
I would like to thank my co-author Mr. Suman Halder, who encourage me to contribute in this book.
I am very grateful to my colleagues Mrs. Smita Basu, Mr. MD.Sahid Ahmed and Mr, Sudipta Basak for
their valuable suggestions. I wish to acknowledge my student whose feedback helps me to make this
book student centric.
Narosa Publishing House deserves my sincere thanks for providing me such a platform to share my
knowledge with the universe.
Last but not the least, a word of thanks goes to my parent’s in law, my beloved father Dipak Barman
Roy and mother Mala Barman Roy, my husband Supriyo Pal and my little daughter Ishaani . Without
their love, patience and continuous encouragements I would never be able to complete this book.
Debdutta Pal
The successful completion of any task would be incomplete without giving gratitude to the people who
made it possible and whose constant encouragement made these efforts with success. The acknowledge-
ment transcends with my deep gratitude to all the people, who inspired, supported and helped me in the
completion of this book.
I express my deep-felt thanks to the co-author Dr. Debdutta Pal, who continuously inspires me in
the completion of this book. I am very grateful to my colleagues at Calcutta Institute of Engineering and
Management, Mrs. Smita Basu, Mr. MD.Sahid Ahmed and Mr, Sudipta Basak for their valuable construc-
tive suggestions and genuine feedback. I extend my thanks to Mr. Surjakanta Sasmal who provided me
valuable materials.that helped me in writing this book.
I would like to thank the management, editorial and production unit of Narosa Publishing House,
for publishing this book in time. Suggestions and queries are most welcome through publishers.
Last but not the least, a word of thanks goes to my beloved parents, my elder sister, wife Rupa and
my little son Avinaba for their love, constant encouragement and blessings.
Suman Halder
Contents
Preface vii
Acknowledgments
ix
Appendix A A.1
Solved GATE Question Papers SP.1
Glossary G.1
Bibliography B.1
Index I.1
CHAPTER 1
INTRODUCTION
“Those who wise succeed must ask the right preliminary questions”. – Aristotle
I
n Computer Science, one of the core fields that belongs to its
foundations, with the design, analysis, and implementation of K E Y F E A T U R E S
algorithms for the efficient solutions of the problem Data and Information
concerned. The data structure is one of the subjects that
Data Structure
intrinsically connected with the design and implementations of
efficient algorithms. Data Type
The subject ‗Data Structure‘ deals with the study of methods, Abstract Data Type
techniques, and tools to organize or structure data in computer
Classification of Data Structure
memory.
Now before defining Data Structure, we should know ― what is data?‖ and ―
what is the difference
between data and information?‖
Data and Information
Data is a plural of datum, which is originally a Latin noun meaning ― something given.‖
The Oxford dictionary meaning of data is:
i) Facts or statistics used for reference or analysis.
ii) The quantities, characters or symbols operated by a computer.
For our purpose, the second meaning is more important. Therefore, we can say that:
The data represent quantities, characters, or symbols on which operations are performed by
a computer, stored and recorded on either magnetic, optical, or mechanical recording media, and
transmitted in the form of digital electrical signals.
Definition: Data is the basic entity or fact that is used in a calculation or manipulation process.
Data is commonly processed by some stages. Unprocessed data or raw data is a collection of
numbers, characters, that may be considered as an input of a stage and processed data is the output of
the stage.
There are two types of data, such as numerical and alphanumerical data. Data may be a single
value or a set of values and it is to be organized in a particular fashion. This organization or structuring
of data will have a profound impact on the efficiency of the program.
Most of the individuals consider that the terms "Data" and "Information" are interchangeable and
mean the same thing. However, there is a distinct difference between the two words. Data are raw
facts without context, whereas Information is data with context. Data are an abstraction of Information
in a problem-solving system. Data requires interpretation to become an Information.
Data can be any character, text, words, number, pictures, sound, or video and if not put into
context means nothing to a human or computer. For example, 10409 is a data, whereas information
1.2 | Data Structures and Algorithms with C
may be 1/04/09-the date of birth of Avinaba, 10409 a zip code of somewhere or Rs. 10409 is the salary
of someone.
Raw Data Information
Processing
Figure 1.1: Data and Information
Representation of Data
Almost all the high-level languages, e.g. FORTRAN, COBOL, C, Pascal, C++, Java, etc. allow data to
be represented in computer memory of mainly two types:
i) Numerical Data
ii) Alphanumerical Data
Most of the high-level languages classified numerical data into two types:
i) Integer
ii) Floating-point
In C language, the following Data types are used to represent numerical data.
Table 1.1: Ranges of numerical data types
Character
The characters may be alphabets, digits, special characters and white spaces. In C language, characters
are represented by char data type and one-byte memory space is used for storing the same. The ASCII
format has been used in C language to represent the characters. While storing character ‗C‘ in the
computer, ASCII value 67 is stored in memory.
String
The string is a sequence of characters may consist of any number and any combination of characters.
The characters may be alphabets, digits, special characters and white spaces. In C language, the string
can be defined as an array of character terminated with a null character.
Data Type
Generally, computer programs do exist for a single purpose: how to process data. The type of data, the
format of data that is going to be returned and the correctness of the processing are the primary
concerns of a computer program. When a program is written, how the computer handles the data
internally is usually a secondary concern.
Definition: A data type refers to the type of data that variables hold.
Now, depending on the representation of different forms of data, different data types are used. The
data types are names given to a set of variables, which have common properties. A data type refers to
the type of data that variables hold.
Data types
Data
Structure
Non -
Primitive
primitive
Non -
int float char pointer Linear
Linear
Operation Description
Allocation of memory for the data structure, the creation of data structure
Creation
may take place either during compile-time or during run-time.
Insertion Insert a data item in the data structure.
Deletion Delete a data item from the data structure.
Traversing Accessing and processing each data item of the data structure exactly once.
Searching Find the location of the key value within the data structure.
Arranging all the data items in a data structure either in ascending or in
Sorting
descending order or in lexicographical order (for Strings).
Merging Combining the data items of two different sorted lists into a single sorted list.
Linked List
A linked list is an ordered collection of finite homogeneous data elements called node where the linear
order is maintained by means of links or pointers. In linked list, data items may be scattered arbitrarily
all over the memory. In a linked list, there is no relationship between the addresses of elements; each
element of a linked list must store explicitly the address of the element, next to it.
Tree
The tree is a non-linear data structure. A Tree may be defined as a non-empty finite set of nodes, such
that
i) There is a specially designated node called the root,
ii) The remaining nodes are partitioned into zero or more disjoint trees T 1, T2, … Tn are called the
subtrees of the root R.
Graph
The graph is another non-linear data structure. A Graph G is defined as an ordered set G = (V, E),
consists of finite non-empty set of objects V, where V (G) = {v1, v2, v3, … vn} called vertices (or nodes
or points) and another set E where E (G) = {e1, e2, e3, …em} whose elements are called edges, that
connects these vertices.
Summary
Data is the basic entity or fact that is used in the calculation or manipulation process.
Data are raw facts without context, whereas information is data with context.
Data Structure is defined as a mathematical or logical model of the particular organization of data
items in computer memory so that it can be used efficiently.
An Abstract Data Type (ADT) describes the data objects, which constitute the data structure, and
the fundamental operations supported on them.
Exercises
1. What are the differences between linear and non-linear data structures?
2. What are the operations can be performed on data structures?
3. What is an Abstract Data Type? What do you mean by a Dynamic Data Structure?
4. Choose the correct alternatives for the following:
i) Which of the following data structure is a linear data structure?
a) Trees b) Graphs c) Arrays d) None of these
ii) The operation of processing each element in the list is known as
a) Sorting b) Merging c) Inserting d) Traversal
iii) Finding the location of the element with a given key in the list is known as
a) Traversal b) Searching c) Sorting d) None of these
iv) Representation of data structure in memory is known as
a) Recursion b) Abstract data type c) Storage structure d) File structure
v) An ADT is defined to be a mathematical model of a user-defined type along with the collection
of all__________operations on that model
a) Cardinality b) Assignment c) Primitive d) Structured
*****
CHAPTER 2
ANALYSIS OF ALGORITHM
“Programming is the art of telling another human being what one wants the computer to do”. –
Donald Knuth
cg(n)
f(n)
n
no
f(n)=O(g(n))
Figure 2.1: Big-O Notation
If f (n) and g (n) are functions defined for positive integers, then we write f (n) = O (g (n)) if there
exist positive constants n0 and c such that | f (n) | ≤ c | g (n |, for all n ≥ n0.
In general, O (g (n)) = {f (n): there exist positive constants c and n0 such that 0 ≤ f (n) ≤ cg (n) for
all n, where n ≥ n0}.
That is the right of n0, the value of f (n) always lies on or below cg (n). This notation gives an
upper bound for a function to within a constant factor.
Example:
Suppose f (n) = 3n + 2
Now we can write f (n) = 3n + 2 ≤ 4n, for all n≥2, here g (n) = n, c = 4, n0 = 2
Hence, we can write f (n) = O (g (n)) = O (n)
Example:
Suppose f (n) = 10n2 + 4n + 2
Now we can write f (n) = 10n2 + 4n + 2 ≤ 11n2, for all n ≥ 5, here g (n) = n2, c = 11, n0 = 5
Hence, we can write f (n) = O (g (n)) = O (n2)
2.8 | Data Structures and Algorithms with C
Example:
Suppose f (n) = 2n3 + n2 + 2n
Now we can write f (n) = 2n3 + n2 + 2n ≤ 3n3, for all n ≥ 2, here g (n) = n3, c = 3, n0 = 2
Hence, we can write f (n) = O (g (n)) = O (n3)
Big-Ω (Omega) Notation (Lower Bound)
Big-Ω notation is the formal method of expressing the lower bound on an algorithm's running time. It
describes the best that can happen for a given data size. If f (n) and g (n) are functions defined for
positive integers, then we write f (n) = Ω (g (n)) if there exist positive constants n0 and c such that
| f (n) | ≥ c | g (n) |, for all n≥ n0.
f(n)
cg(n)
n
no f(n)=Ω(g(n))
Figure 2.2: Omega Notation
In general, Ω (g (n)) = {f (n): there exist positive constants c and n0 such that 0≤ cg (n) ≤ f (n) for
all n, where n≥ n0}.
That is the right of n0, the value of the function f (n) always lies on or above cg (n). This notation
gives a lower bound for a function to within a constant factor.
Example:
Suppose f (n) = 3n + 2
Now we can write f (n) = 3n + 2 ≥ 3n, for all n ≥ 1, here g (n) = n, c = 3, n0 = 1
Hence, we can write f (n) = Ω (g (n)) = Ω (n)
Example:
Suppose f (n) = 10n2 + 4n + 2
Now we can write f (n) = 10n2 + 4n + 2 ≥ 10n2, for all n≥1, here g (n) = n2 , c = 10, n0 = 5
Hence, we can write f (n) = Ω (g (n)) = Ω (n2)
Example:
Suppose f (n) = 2n3 + n2 + 2n
Now we can write f (n) = 2n3 + n2 + 2n ≥ 2n3, for all n ≥ 1, here c = 2, n0 = 1
Hence, we can write f (n) = Ω (g (n)) = Ω (n3)
Analysis of Algorithm | 2.9
Θ (Theta) -Notation (Tight Bound)
If f (n) & g (n) are functions defined for positive integers, then we say f (n) = Θ (g (n)) if there exists
positive constants n0, c1 and c2 such that
c1 | g (n) |, ≤ | f (n) | ≤ c2 | g (n) |, for all n ≥ n0
In general, Θ (g (n)) = {f (n): there exist positive constants c1, c2 and n0 such that c1 g (n) ≤ f (n) ≤
c2 g (n) for all n, where n≥ n0}.
That is the right of n 0 the value of the function f (n) always lies between c1 g (n) and c2 g (n)
inclusive. This notation bounds a function to within constant factors. This is saying that the function, f
(n) is bounded from both the top and bottom by the same function, g (n).
c2g(n)
f(n)
c1g(n)
n
no
f(n)=Ө(g(n))
Figure 2.3: Theta Notation
Example:
Suppose f (n) = 3n + 2
Now we can write 3n ≤ 3n + 2 ≤ 4n, for all n ≥ 2, here g (n) = n, c1 = 3, c2 = 4, n0 = 1
Hence, we can write f (n) = Θ (g (n)) = Θ (n)
Example:
Suppose f (n) = 10n2 + 4n + 2
Now we can write 10n2 ≤ 10n2 + 4n + 2 ≤ 11n2, for all n ≥ 5
Here g (n) = n2, c1 = 10, c2 = 11, n0 = 5
Hence, we can write f (n) = Θ (g (n)) = Θ (n2)
Example:
Suppose f (n) = 2n3 + n2 + 2n
Now we can write 2n3 ≤ 2n3 + n2 + 2n ≤ 3n3 for all n ≥ 2, here, c1 =2, c2 = 3, n0 = 2
Hence, we can write f (n) = Θ (g (n)) = Θ (n3)
o (“little oh”) - Notation
For non-negative functions, f(n) and g(n), f(n) is little o of g(n) if and only if f(n) = O(g(n)), but f(n) ≠
Θ(g(n)). This is denoted as "f(n) = o(g(n))".
2.10 | Data Structures and Algorithms with C
This represents a loose bounding version of Big O; g(n) bounds from the top, but it does not bound
the bottom. Little-o notation represents a loose bounding version of Big O, g (n) bounds from the top,
but it does not bound the bottom.
If f (n) & g (n) are functions defined for positive integers, then we say f (n) = o (g (n)) iff
f(n)
lim
― =0
n→∞
g(n)
Example:
Suppose f (n) =2n3 + 3n2 + n + 10
lim f(n)
― =∞
n→∞
g(n)
Example:
Suppose f (n) = 4n3 + 2n + 3
lim 4n3+2n+3
Now we can write, ――― =∞
n→∞
n2
Here g (n) = n2
Hence we can write f (n) = ω (g (n)) = ω (n2)
Growth Functions of Algorithm
The big-O notation is used to classify algorithms by how they respond in their processing time or
working space requirements to changes in the input size. Order of growth in algorithm means how the
time or space for computation increases with input size, i.e. how the growth function grows with the
input size. Now, based on growth functions, the algorithm can be categorized as follows:
Analysis of Algorithm | 2.11
1. Constant time algorithms [ O(1) ]:
This means that the algorithm requires the same fixed number of steps regardless of the size
of the task.
Example: Array access, Push and pop operations for a stack, enqueue and dequeue operations
for a queue, other atomic operations.
2. Logarithmic time algorithms [ O ( ) ]:
Logarithm time algorithms mean that T(n) is upper bounded by logarithmic of the input size,
i.e. T(n) = .
Example: Binary search in a sorted list of n elements, Insert and Find operations for a binary
search tree with n nodes, Insert and Remove operations for a heap with n nodes, etc.
3. Linear time algorithms [ O (n) ]:
Linear time algorithm means that for large enough input sizes the running time increases
linearly with the size of the input.
Example: Array traversal
4. Linearithmic time algorithm [ O (n ) ]:
An algorithm is said to run in linearithmic time when T(n) = O (n ). Thus, a linearithmic
term grows faster than a linear term, but slower than any polynomial in n with degree greater
than 1.
Example: Merge sort, Heap sort
5. Polynomial time algorithms [O (nk), for k > 1 ]:
i) Quadratic time (O (n2)) algorithm: The number of operations is proportional to the
size of the task squared.
Example: Slow sorting algorithms, for example, selection sort of n elements.
ii) Cubic time (O (n3)) algorithm: The number of operations is proportional to the size
of the task cubed.
Example: Matrix multiplication
6. Exponential time algorithms [ O (kn), for k>1 ]:
Exponential time algorithm means that T(n) is upper bounded by exponential expression of
input size, i.e. T(n) = kn
Example: Towers of Hanoi, implementation of recursive Fibonacci, generating all
permutations of n symbols.
7. Factorial time algorithms [ O (n!) ]:
Polynomial time algorithm means that T (n) is upper bounded by the factorial of the input
size, i.e. T(n) = n!.
Example: Non-attacking n queen problem, traveling salesman problem by brute-force search
The best time in the above list is obviously constant time, and the worst is exponential time,
which, as we have seen, quickly overwhelms even the fastest computers even for relatively small n.
Polynomial growth (linear, quadratic, cubic, etc.) is considered manageable as compared to
2.12 | Data Structures and Algorithms with C
exponential growth.
Table 2.1: Values for different growth functions
n log2n nlog2n n2 n3 2n
1 0 0 1 1 2
2 1 2 4 8 4
4 2 8 16 64 16
8 3 24 64 512 256
16 4 64 256 4096 65536
32 5 160 1024 32768 2147483648
Order of asymptotic behavior of the functions from the above list, we can compare among time
complexities:
O (1) < O ( ) < O (n) < O (nk) < O (kn) < O (n!)
= 2i(2i 1) + 2i
2
= 2i2 + 3i
Finally, the out-most for loop, it is executed i = 1, 2, 3. . . n. Let T (n) be running time of the entire
algorithm:
n
T (n) = M (i)
i 1
n 2
= (2i 3i)
i 1
n 2 n
= 2i + 3i
i 1 i 1
3 2
= 2 2n 3n n + 3 n (n 1)
6 2
3 2
= 4n 15n 11n
6
= O (n3)
Answer: The complexity is O (n3)
Example:
T (n) = 4n2 + 3n , express T (n) in Big-O notation
Ta = 4n2 = O (n2) and
Tb = 3n = O (n )
Now, T (n) = O (max (Ta, Tb))
= O (max (O (n2), O (n )))
= O (n2) [because n > , hence n2 > n ]
Summary
The algorithm is a finite sequence of instructions/steps, each of which is very elementary that must
be followed to solve a problem.
The space complexity of a program is the amount of memory it needed to run to completion.
The time complexity of a program is the amount of computer time needs to run to completion.
The asymptotic notations commonly used in performance analysis to characterize the complexity
of an algorithm.
The big-O notation is the formal method of expressing the upper bound of an algorithm's running
time.
Exercises
1. Show that the function f (n) defined by
f (1) = 1
f (n) = f (n-1) + for n > 1
has a time complexity O( ).
2. Define Big-O notation, Θ notation, Ω notations.
2.16 | Data Structures and Algorithms with C
3. The designer of an algorithm needs to balance between space complexity and time complexity.‖-
Comment on the validity of the statement in the context of recursion algorithms.
4. Choose the correct alternatives for the following:
i) Which of the following is the best time for an algorithm?
a) O (n) b) O ( ) c) O (2n) d) O (n )
ii) Which of the following algorithm should execute the slowest for large value of N
a) O (n) b) O (n2) c) O ( ) d) None of these
iii) Let us consider a function f (n) = 1000n + 500 n4 + 0.52n. We can say that f (n) is
a) O (n4) b) O (n ) c) O (2n) d) None of the above
iv) An algorithm is made up of two independent time complexities f(n) and g(n). Then the
complexities of the algorithm is in the order of
a) f(n) ×g(n) b) Max(f(n), g(n)) c) Min(f(n),g(n)) d) f(n) + g(n)
v) Two main measures of the efficiency of an algorithm are
a) complexity and capacity b) Processor and memory
c) Time and space d) Data and space
vi) Which of the following shows the correct relationship between some of the more common
computing time for the algorithm?
a) O ( ) < O (n) < O (n* ) < O (2n) < O (n2)
b) O (n) < O ( ) < O (n* ) < O (2n) < O (n)
c) O (n) < O ( ) < O (n* ) < O (n2) < O (2n)
d) O ( ) < O (n) < O (n* ) < O (n2) < O (2n)
*****
CHAPTER 3
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
a:
Figure 3.1: Array of size 10
Sometimes symbolic constant can be used to define array size rather than an integer number.
Example:
#define N 10
int a[N];
In C, arrays are zero-based, that means the index of an array starts from zero. The ten elements of
a 10-element array are numbered from 0 to 9. The subscript, which specifies a single element of an
array, is simply an integer expression in square brackets. The first element of the array is a[0], the
second element is a[1], etc.
Example:
a[0] = 10;
a[1] = 20;
a[2] = a[0] + a[1];
Notice that the subscripted array references (i.e. expressions such as a[0] and a[1]) can appear on
either side of the assignment operator.
The subscript does not have to be a constant like 0 or 1; it can be any integral expression; it is
common to loop over all elements of an array:
Example:
int i;
for(i = 0; i < 10; i++)
a[i] = 0;
This loop sets 0 to all ten elements of the array a[0] to a[9] .
Arrays are a real convenience for many problems, but there is not a lot that C will do with them
automatically. In particular, you can neither set all elements of an array at once, nor assign one array to
another; both of the assignments are illegal.
Example:
int a[10];
a = 0; /* illegal */
and
int b[10];
b = a; /* illegal*/
To set all of the elements of an array to some value, you must do so one by one, as shown in the
loop example above. To copy the contents of one array to another, you must again do so one by one.
Example:
int b[10];
for(i = 0; i < 10; i++)
b[i] = a[i];
Remember that for an array declared
Array And String | 3.3
int a[10];
there is no element a [10]; the end element is a [9].
Arrays are not limited to type int; you can have arrays of char or float or double or any other type.
Example:
char name[30];
float x[10];
double d[100];
There are some important points about arrays. These are as follows:
Arrays are always stored in consecutive memory locations.
An array can store multiple values that can be referenced by a single name.
An array name is actually an address of the first element of the array.
An array can be either an integer, character or floating-point data type can be initialized only
during declaration.
In C, array index starts from zero.
There is no bound checking concept for arrays in C.
Size of One-Dimensional Array
The one-dimensional array can be declared as:
data_type array_name[size];
The total size of the array in bytes can be calculated by using the following expression:
sizeof(data_type)*size
where data_type is the data type of the array and size specifies the total number of elements of the
array.
Another way to calculate the total size of the array in bytes is simpler; that uses the following
expression
sizeof(array_name)
where array_name is the name of the array.
Initialization of One-Dimensional Array
Although it is not possible to assign values to all elements of an array at once using an assignment
expression, it is possible to initialize some or all elements of an array when the array is defined.
The syntax looks like this:
int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
The list of values, enclosed in braces {}, separated by commas, provides the initial values for
successive elements of the array. The individual array elements are as follows:
a[0] = 0
a[1] = 1
a[2] = 2
a[3] = 3
a[4] = 4
a[5] = 5
a[6] = 6
a[7] = 7
3.4 | Data Structures and Algorithms with C
a[8] = 8
a[9] = 9
If there are fewer initializers than elements in the array, the remaining elements are automatically
initialized to 0.
Example:
int a[10] = {0, 1, 2, 3, 4, 5, 6};
would initialize a[7], a[8], and a[9] to 0. When an array definition includes an initializer, the array
dimension may be omitted, and the compiler will infer the dimension from the number of initializers.
For example,
int b[] = {10, 11, 12, 13, 14};
would declare, define, and initialize an array b of 5 elements (i.e. just as if you'd typed int b[5]).
Only the dimension is omitted; the brackets [ ] remain to indicate that b is an array.
Reading array elements
As an array may contain more than one element, so to read all the elements, a single call to the scanf
function will not serve our purpose.
Example:
If we have an array declared as
int a[10];
to read all the elements we can use the following statements:
for(i = 0; i < 10; i++)
scanf (“%d”, &a[i]);
When the value of i is 0 then scanf() will read the value of a[0] element, if i is 1 it will read the
value of a[1] and so on.
Writing array elements
Similarly, to print all the array elements of an array we can use the printf statement within a loop.
Considering the above array declaration int a [10]. We can use the following statements:
Example:
for(i = 0; i < 10; i++)
printf (“%d\t”, a[i]);
Program 3.1: Find out the minimum and maximum of n given numbers.
#include<stdio.h>
main()
{
int a[10], max, min, i, n;
printf(“\nEnter the number of elements:”);
scanf (“%d”,&n);
printf(“\nEnter %d elements:”,n);
for( i = 0 ; i < n; i++ )
scanf(“%d”, &a[i]);
/* Initialization */
Array And String | 3.5
max = a[0];
min = a[0];
/* Finding Maximum and Minimum element */
for(i = 0; i < n; i++) {
if(a[i] > max) max = a[i];
if(a[i] < min) min = a[i];
}
printf (“\n The maximum element is: %d”, max);
printf (“\n The minimum element is: %d”, min);
}
Output:
Enter the number of elements: 5
Enter 5 elements: 3 2 9 5 4
The maximum element is: 9
The minimum element is: 2
GRETCHEN
Dorothy awoke from troubled dreams to find that it was another day.
Through the open window she saw the swirl of snowflakes driven in
a high wind. The bedroom was cold and in the grey light of the
winter morning it had lost its cheerful air.
She heard a knock on the door.
“Who’s there?” she called drowsily.
“It’s the maid, miss. Mrs. Lawson thought you might be wanting
your breakfast now.”
Dorothy looked at her wrist watch. The hands marked ten-thirty. She
jumped out on the rug, which felt cold and clammy under her bare
feet, went to the door and unlocked it. Then she scampered back to
bed and snuggled under the warm covers.
In walked a trim little figure wearing the small white apron and gray
uniform of a chambermaid. Dorothy saw a round merry face, and a
pair of big blue eyes beneath the white lawn cap, and thick flaxen
braids were coiled round the neat head. She was surprised and
somehow pleased to discover that this attractive member of the
household staff could not be much more than sixteen, just her own
age.
The little maid shut the door softly, crossed to the window and
closed it, turned on the steam heat and came to the bedside. “Good
morning, Miss Jordan.” She smiled engagingly. “I’m Gretchen, miss.
Will you have your breakfast in bed?”
“Why, thank you, Gretchen—that will be cozy. But if it’s going to give
you any trouble, don’t bother.” With the covers drawn up to her
eyes, Dorothy smiled back at the girl.
“Oh, no, miss—it’s no trouble at all.” Gretchen was insistent. “It’s all
ready now. I’ll run down and bring it up.”
She whisked out of the room and Dorothy rolled over for another
cat-nap.
“If you’ll be good enough to sit up now, Miss Jordan—I have your
breakfast here.”
Dorothy awoke again, yawned and stretched luxuriously. Gretchen
stood beside her bed with the breakfast tray.
“If you’ll be good enough to sit up, miss?” she repeated.
Dorothy punched the pillows into position behind her, slipped the
quilted gown about her shoulders and leaned back. Gretchen moved
nearer—then almost dropped the tray.
“Why—why—miss—”
Dorothy leaned over and steadied the tray. “What’s the matter,
Gretchen?” The little maid was staring at her open-mouthed, her big
blue eyes as round as saucers.
“Oh, I—I beg your pardon, but it’s—it’s the resemblance, miss—Miss
Jordan.” She set the tray over Dorothy’s knees and drew back still
with that astonished look. “I couldn’t see you very well before, miss,
with the covers up to your eyes. But when you sat up, it sure did
give me a start.”
“What do you mean, Gretchen? The resemblance to whom?”
Dorothy, outwardly calm, fingered her glass of orange juice, but her
thoughts raced toward this new complication.
“Why, you look so much like Dorothy Dixon—the flyer, you know,
miss. She’s my hero—I mean, heroine, Miss Jordan. I’ve read
everything the newspapers printed about her and Bill Bolton. You
must have read about them too, everybody has?”
“Oh, yes, I’ve heard about them.” Dorothy hoped her tone sounded
indifferent. “But you know, Gretchen, newspaper pictures are often
very poor likenesses.”
The girl smiled and nodded. “I know that, Miss Jordan. I’ve got them
all and there isn’t no two of the pictures that looks alike.”
“Then how—?”
“You see, it wasn’t the newspaper pictures I was thinking of, miss,
but Dorothy Dixon herself. You see I know Miss Dixon,” she went on
proudly, “and you two are certainly the spittin’ images of each other,
if you don’t mind my saying so.”
Dorothy minded very much, but it was not consistent with the part
she was playing to admit it. Here was a contretemps not even
Ashton Sanborn had foreseen. Yet, of course, New Canaan was only
ten miles away. She had many friends in Ridgefield, and she’d been
there hundreds of times. But she simply couldn’t remember having
seen Gretchen in any of their homes. Her answer was but a feeble
stall for time.
“So you know her then?” she said lamely.
“Oh, yes, miss. Not well, you understand. I saw her and Mr. Bill
Bolton first when they finished the endurance test on the Conway
motor this fall. Then a few days later, I drove over to her house in
our flivver—over to New Canaan, you know, and I called on Miss
Dixon. I wanted her to autograph a picture of herself I’d cut out of
the Sunday paper.”
“And you met her?” Dorothy remembered the incident perfectly now.
But the maid’s uniform—and her hair—when she had seen her,
Gretchen had worn two braids over her shoulders, very much the
schoolgirl. No wonder she hadn’t recognized her. But now what
should she do? Would it be possible to keep up this camouflage with
a girl whom she had met and with whom she would come in daily
contact? Gretchen was talking again.
“Yes indeed, I met her. And she was just darling to me, Miss Jordan.
She even gave me one of her own photographs and wrote on it, too.
You see, us Schmidts came over from Germany about a hundred
years ago, but we’re honest-to-goodness Americans just the same.
Father was in the American army during the war. He was an aviation
mechanic. He found one of them Iron Crosses of the Germans on
some battlefield in France and kept it for a mascot. And would you
believe it, miss, Father never even got wounded once, the whole
time he was over there! Perhaps it was the little Iron Cross, and
perhaps it wasn’t. Anyway, he thought a lot of his mascot. When I
was ten years old, he had it fixed on a thin gold chain for me to
wear around my neck, and gave it to me on my birthday. Well, when
I went to see Miss Dixon this fall, I took it with me. She goes up in
her airplane so much and does so many other exciting things, I
wanted her to have it. She didn’t want to take the cross at first, but
I persuaded her to, just the same. And you don’t know how nice she
was to me, Miss! Took me out to see Will-o-the-Wisp—that’s her
plane, you know—she calls it Wispy for short. And I had a perfectly
grand time. She’s my heroine, all right. And you, miss—I hope you’ll
excuse me for talking so much about it—but you look exactly like
her, and your voices are just the same, too. It’s wonderful!”
“So you are Margaret Schmidt,” Dorothy said slowly.
“Yes, miss, that is so, though everybody calls me Gretchen. How did
you know my given name, Miss Jordan? Is Miss Dixon a friend of
yours? Did she tell you about me? But that’s silly—she wouldn’t
remember me.”
Dorothy looked the little maid straight in the eyes. “She remembers
you, Gretchen. Would you be willing to do something for her—to
keep a secret, a very important and maybe a dangerous one? Do
you think you could do it?”
Gretchen looked awestruck, then she smiled. “Mother says I’m the
closest-mouthed girl she ever saw, miss. They could cut me in pieces
before I ever let out any secret of Dorothy Dixon’s. I’d never tell—
not me! You can trust me, Miss Jordan.”
“I’m sure I can, Gretchen. And I’m going to.” Dorothy slipped her
hand into the V-neck of her pajamas. “Remember this?”
“Why—it’s—it’s my Iron Cross—that I gave Dorothy Dixon. How in
the world—?”
“I am Dorothy Dixon.” Dorothy broke into laughter at the bewildered
expression on the girl’s face.
“But—but I don’t understand!” Gretchen stammered as though her
tongue was half-paralyzed. “I knew the resemblance was wonderful
—but—they said you were Miss Janet Jordan—and—”
“You sit down on the end of the bed,” said Dorothy, “I’ll go on with
my breakfast before it gets cold, and explain at the same time. We
won’t be disturbed, will we?”
“Oh, no, miss.”
“How about your work, Gretchen? Will you be wanted downstairs?”
“Mr. Tunbridge told me to unpack your trunk, miss—Miss Dixon—and
to make myself generally useful.”
“Fine,” smiled Dorothy, pouring out a cup of coffee. “But keep on
calling me Miss Jordan—otherwise you’ll be making slips in the name
in front of other people and that would be fatal.”
“Yes, Miss Jordan,” Gretchen grinned happily.
“After this beastly business is over,” Dorothy went on, “we’ll be
Gretchen and Dorothy to each other.”
The other girl looked a trifle embarrassed. “But I’m only a
chambermaid, Miss Jordan,” she said shyly.
“Don’t be silly!” Dorothy waved away the argument with a sweep of
her spoon. “You’re proving yourself a real friend—and that’s that.”
“Very well, Miss Jordan.”
“Now pin back your ears, Gretchen.” Dorothy lifted the cover from
her scrambled eggs. “I am taking my cousin, Janet Jordan’s place as
Mrs. Lawson’s secretary. Nobody in this house knows who I am
except Mr. Tunbridge, nor must they be given the slightest hint that I
am anybody but Janet Jordan. As you’ve probably guessed, Janet
and I look almost exactly alike. Our mothers were twins and that
probably accounts for it.”
“Gee—” breathed Gretchen. “It’s just like a story in a book!”
Dorothy bit into a slice of buttered toast. “Maybe it is,” she admitted,
speaking with her mouth full. “But the point is that you and I are
living this story and it may come to a very abrupt and unpleasant
ending unless we’re both terribly careful. Let’s see—where was I?
Oh, yes. Mr. Tunbridge and I are working together on this case,
working for the United States Government.”
“Secret Service?” asked Gretchen in an awed whisper.
“Yes.”
“Then I’ll be working for the secret service too?” Dorothy could see
that the girl was very much impressed with the idea.
“You will, Gretchen—that is, you are—under me. But don’t get too
pepped up about it. The work we are on is serious and it is
extremely dangerous into the bargain. I wouldn’t have brought you
into it unless I had to. Right now I haven’t the slightest notion how
you are going to be fitted into the picture. But I couldn’t have you
going around, talking about how much Janet Jordan looks like
Dorothy Dixon, could I? Doctor Winn and the Lawsons have no idea
of either the resemblance or the relationship. If that came out and
they got wind of it—well, there’s no telling what might happen.”
“Especially,” chimed in Gretchen, “after all the detective work you did
in those three big cases over to New Canaan this summer and fall.”
“You’ve got it,” declared Dorothy, and sipped her coffee. “A robbery
is being planned here, Gretchen, a robbery of some very valuable
papers from Doctor Winn’s safe. The thieves will probably try to pull
it off tonight. These papers, which have to do with an invention of
the Doctor’s are worth a million dollars or more to any number of
people. So you see the thieves are playing for big stakes, and I
might as well tell you that they aren’t the kind that would let a thing
like murder stop them. And now that you know the facts, are you
willing to go on with it?”
Gretchen seemed horrified that Dorothy should doubt her. “Oh, Miss
Jordan, I don’t want to get murdered any more than anybody else—
but, I’m not afraid—honest I’m not!”
“I knew you were true blue,” smiled Dorothy. “So we’ll call it a deal,
shall we?”
“You bet!” The two girls solemnly shook hands. “What do you want
me to do first, Miss Jordan?” Gretchen asked eagerly.
“Move this tray onto the chair over there, please. Then while I’m
taking a bath and dressing you might unpack Janet Jordan’s clothes.
I’ll choose something to wear later.”
“Very good, Miss Jordan.” The little maid took the tray, then stopped
short, her round blue eyes very serious. “But what about the secret
service work?”
“Just carry on as usual for the present.” Dorothy slipped out of bed.
“And remember—not a word to anyone about what I’ve told you—
not even Mr. Tunbridge. I don’t know myself exactly what I’m to do
yet. Mrs. Lawson expects me downstairs in about half an hour, so
I’ve got to hustle. If I need your help later on, I’ll get word to you
somehow.”
“I hope you will need me, Miss Jordan.” Gretchen was taking Janet’s
frocks from the wardrobe trunk.
“And I hope I shan’t!” said Dorothy, and she disappeared into the
bathroom.
Chapter XII
TESTS
Dorothy came down the wide staircase a few minutes before eleven-
thirty. She wore a dark blue morning frock of her cousin’s, its
simplicity relieved only by the soft white collar and deep cuffs.
Except for being rather tight across the shoulders it fitted her as
though she had been poured into it. She had selected this dress
because she knew it was just the sort of thing a new secretary
would be expected to wear.
She crossed the broad hall to the open door of the library, and there
found Mrs. Lawson standing before a window staring into the storm.
Although Dorothy’s footsteps made practically no sound on the thick
pile of the handsome Bokhara rug, the woman turned like a flash at
her entrance.
“Oh, good morning, Janet.” The frown on her face gave way to a
pleasant smile. “I hope you were comfortable last night. Did you
sleep well?”
“I dropped off as soon as my head touched the pillow,” she
answered, taking Mrs. Lawson’s outstretched hand. Dorothy did not
believe in telling a lie unless it was in a good cause; but when
necessary, she invariably made the lie a good one.
“I hope the storm didn’t wake you,” smiled Laura, holding Dorothy’s
hand.
Dorothy did not reply at once. Two long fingers were lightly pressing
her wrist, and she saw that Mrs. Lawson’s eyes had strayed to the
grandfather’s clock in the corner of the room. “Test number one,”
she said to herself. “Mrs. du Val, alias Lawson is counting my pulse.
Well, I’ve got a clear conscience, perhaps I can give her a shock.”
She drew her hand away and answered the woman’s question in her
normal voice. “Oh, the storm! No, I never heard it, Mrs. Lawson. If
that hot lemonade had been drugged, I couldn’t have slept any
sounder!”
“What makes you say that?” snapped her employer, and beneath the
velvet tone, Dorothy sensed the ring of steel.
She dropped her eyes, and turning toward the open hearth, held out
her hands to the crackling blaze. “Oh, I don’t know,” she said
sweetly and like the clever little strategist that she was, opened her
own offensive in the enemy’s territory. “I have the bad habit of
occasionally walking in my sleep, Mrs. Lawson—and especially when
I spend the night in a strange bed. Perhaps it’s nervousness—I don’t
know.”
Mrs. Lawson threw her a sharp glance. “Sit down, Janet,” she
suggested, pointing to a chair near the fire, and taking one herself
across the hearth. “You’re—I mean, you don’t seem to be at all
nervous this morning.”
“Good old pulse!” thought Dorothy. Then aloud—“No, I feel
splendidly, thank you. But, you see, I didn’t walk in my sleep last
night.”
“But surely you can’t tell when you do it!”
“Oh, yes, I can.” Dorothy’s manner and tone were those of the
simple schoolgirl proud of an unusual accomplishment.
“You don’t expect me to believe that you know what you’re doing
when you walk in your sleep, Janet. That’s impossible!”
“Not while I’m sleepwalking, Mrs. Lawson. That wasn’t what I said—
but when I have been sleepwalking—there’s a difference, you see?”
“Well?” The lady of the house objected to being contradicted and
took no trouble to hide it.
“It’s really very simple,” explained Dorothy, painstakingly, as though
she were speaking to a rather stupid child. “I found out how to do it.
You see, I’ve been walking in my sleep ever since I was a little thing.
When I get in bed at night I leave my slippers on the floor beside it
pointed outward—away from the bed. We all leave them that way, I
guess. It’s the natural thing to do.”
“But what have slippers got to do with it?” Laura was becoming
impatient.
“Everything, so far as I’m concerned, Mrs. Lawson. When I’ve been
walking at night, I always find them in the morning beside the bed,
but pointing toward it. I evidently slip them off before I get back into
bed, and—”
“I’m beginning to think you are quite a clever girl, Janet.”
“Oh, thank you,” said Dorothy with a guilelessness that was sheer
camouflage. “Has anybody been saying I’m stupid? I’ve always stood
high in my classes at school.”
“Oh, not stupid, child—but nervous—perhaps a little unbalanced,
especially this past week.”
Dorothy raised her heavy lashes and looked Mrs. Lawson squarely in
the face. This might be a test she was undergoing and it probably
was; but here was a heaven sent chance to stir up discord in the
enemy’s camp. She must work up to it gradually.
“I know that I was nervous and upset past all endurance.” She
leaned forward, her hands on the arms of the chair. “How would you
like your father to lock you in your bedroom for a week, without ever
coming to see you, or giving you any explanation for such
outrageous treatment? Am I a child to be handled like that? To be
shipped up here to strangers, whether I wanted to go or not? How
would you feel about it, Mrs. Lawson, if you were me? Don’t say you
would submit to it sitting down.”
“But I am taking you on as my secretary,” the lady hedged. “Offering
you a good position for which you’ll be paid twenty dollars a week.
That’s not to be thought of lightly, especially in these times.”
“But it doesn’t seem to strike you that I might like to have
something to say about it,” Dorothy replied calmly. “As for the salary
—that’s no inducement. My mother left me five thousand a year. I
came into the income on my last birthday, so you see I have nearly a
hundred dollars a week, whether I work or not.”
“I didn’t know that, of course,” Mrs. Lawson admitted and none too
graciously. “Your father wants you to be here while he’s away. I hope
you aren’t going to be difficult, Janet.”
“I hope not, Mrs. Lawson. I shall be glad to stay here for a while and
do the work you’d planned for me; but if I do, it must be as a guest
and not as a paid dependant.”
“But you are a guest, Janet.”
“I shall not accept a salary, Mrs. Lawson.”
“Very well, my dear, if you wish it that way.”
“Thank you very much.”
“To get back to our former topic,” Mrs. Lawson said, and lit a
cigarette. “I can understand that your father’s conduct in confining
you to your room might be exasperating—but why should it make
you nervous? And my husband tells me that when he visited you in
your room you acted as though you were in deadly fear of
something or somebody every time he saw you. What was the
trouble, Janet? Was anything worrying you?”
“Yes, there was, Mrs. Lawson.”
Dorothy looked down at the andirons, and her hands on the chair
arms twisted embarrassedly. From the corner of her eye she saw a
smile of satisfaction light up the older woman’s face. She knew she
was playing with fire and that Mrs. Lawson was watching her as a
hawk watches its defenseless prey before it strikes. But all unknown
to her inquisitor, Dorothy had been leading her into this trap as a
move forward in her own game. Genuine dislike for the woman as
well as a mischievous impulse on her part drew her to make the
scene as dramatic and convincing as possible.
“Yes—I—I—was afraid,” she went on, dragging out the words slowly.
“Then don’t you think you’d better tell me about it, Janet? I’m nearly
old enough to be your mother. Let me take your mother’s place,
dear. Give me your confidence. I feel sure I’ll be able to help you,
child.”
This reference to Janet’s dead mother by a woman who was the
vilest kind of a hypocrite swept away Dorothy’s last compunction.
She herself was going to commit justifiable libel. Mrs. Lawson, on
the other hand, was attempting to lead Janet Jordan into a
confession of shamming sleep at the fateful meeting a week ago.
And such a confession meant a sentence of death from this beautiful
siren who gazed at her so winningly, who puffed a cigarette so
nonchalantly while she waited for an unsuspecting girl to commit
herself.
“Well, I don’t know—I can’t help hesitating to tell you, Mrs. Lawson,”
Dorothy began timidly.
“There’s no need to be afraid of anything,” replied the woman, only
half veiling the sneer that went with the words.
“Oh, but you see, there is, Mrs. Lawson!” Dorothy’s manner was still
indecisive. “I don’t want—in fact, I hate awfully to hurt you this
way.”
“Hurt me!” Mrs. Lawson’s cigarette snapped into the fireplace like a
miniature comet. “Hurt me, child? What in the wide world are you
talking about?”
“Just what I say, Mrs. Lawson.”
Mrs. Lawson sniffed. “Don’t be ridiculous, Janet. Out with it now.
What did you fear when you were locked in your room?”
“Your husband, Mrs. Lawson.”
“My husband!”
“Yes.”
“But—why—I don’t believe you.”
“Oh, very well. You asked the question, I was trying to answer it,
that’s all.”
Mrs. Lawson bit her lip. She was furious. “As long as you’ve said
what you have, you’d better go on with it,” she said acidly.
“There isn’t any more,” returned Dorothy. “That’s all there is.”
“But surely he must have given you reasons for your assertion.” Mrs.
Lawson had walked beautifully into Dorothy’s trap. Her own plan to
snare an unsuspecting girl had been blotted out by the shadow of
the Green Goddess, Jealousy. “Tell me what my husband did or said
to make you fear him, and tell me at once.”
“It wasn’t what he did, Mrs. Lawson—it was the way he looked.”
“What do you mean—the way he looked?”
Dorothy had thrust a painful knife into the mental cosmos of her
adversary. Now she deliberately turned it in the wound. “Very
probably,” she said quietly, looking her straight in the eyes, “you can
remember how Mr. Lawson looked when he first made love to you. I
don’t want to be made love to, and I don’t like him, Mrs. Lawson.”
“What did you do?”
“I told him to leave me—and when he would not go, I simply walked
into my bathroom and locked the door.”
“But what happened the next time he came? Martin went in to see
you every day, didn’t he?”
“He did. But he talked to me through the bathroom door. Just as
soon as I heard the key turn in the lock I’d hop in there.”
The man she had been talking about must have been listening just
outside in the hall, for now he strode into the room and up to
Dorothy. “That,” he said menacingly, “is a deliberate lie, Miss Janet
Jordan!”
Chapter XIII
WINNITE
PROFESSOR
Dorothy, upon finishing the article on Winnite, laid the original and
first carbon copy of the typewritten sheets on Mrs. Lawson’s desk.
The almost transparent sheets of the second carbon copy she folded
carefully as though she meant to place them in an envelope. But
instead of this, her right foot slipped out of its walking pump, the
sheer silk stocking followed it. Then she put on the stocking again,
but now the soft papers rested between the stocking and the sole of
her foot. The pump fitted more snugly than before, although not
uncomfortably so. Content with her morning’s work, she had closed
the typewriter and was studying the effect of a new shade of
powder in her compact mirror when Mrs. Lawson came into the
room.
“I take it you’ve finished the work?”
“The original and copy are beside the longhand manuscript on your
desk,” said Dorothy, toning down her efforts with the puff. “I’ve read
it over and I don’t think you’ll find any mistakes.”
Mrs. Lawson ran her eyes over the typewritten sheets. “They are
without a fault,” she declared, placing them in a drawer. “If you take
dictation as accurately as you type, Janet, you’ll be the perfect
secretary.”
“Thank you,” said Dorothy demurely and slipped the compact into
the pocket of her frock. “It is very nice of you to say that.”
“Then we’ll go in to luncheon, shall we? That is, if you’re ready?”
Dorothy stood up. “Quite ready, Mrs. Lawson, and good and hungry,
too.”
“Splendid!” enthused her hostess, as they walked down the corridor
toward the entrance hall. “Doctor Winn declares this Connecticut
Ridge country is the most healthful section of the United States. And
even if some people have other ideas on the subject, I can testify
that it is a great appetite builder.”
Dorothy smiled, but said nothing. She was wondering how healthful
she was going to find this particular spot in the Ridge country after
what she had to do tonight.
“Doctor Winn always lunches in his study,” continued Mrs. Lawson.
“That is the room just beyond my office. My husband has been
called to New York on business. He won’t be back until after dinner
tonight, so we will be alone at luncheon.”
For some reason of her own, Laura Lawson had become affability
itself. And for this Dorothy gave thanks. That she disliked this truly
beautiful creature was only natural. But it is much more pleasant to
lunch with a person who puts herself out to be charming and
affable, no matter what your private opinion of the other’s character
may be.
The dining room proved to be a low-ceiled apartment paneled in
white pine; heavy beams of the satin-finished wood overhead, and
on the walls several colorful landscapes in oils, evidently the works
of artists who knew and loved this Ridge country. A cheerful log fire
burned brightly on the open hearth beneath a high mantelpiece.
Outside, the heavy snow continued to drive past frosted window-
panes, but within all was warmth and coziness.
Dorothy enjoyed the meal thoroughly. Like most girls, she revelled in
luxury when it came her way. Not only was her hostess an
interesting and entertaining conversationalist, the delicious food
served by Tunbridge and a second man in plum-colored knee
breeches, added materially to her pleasure. She was really sorry
when the butler lighted his mistress’ cigarette and Mrs. Lawson rose
from the table.
“I have no work for you this afternoon, Janet,” said the lady, as they
strolled into the spacious hall with its suits of polished armor and
trophies of war and the chase decorating the walls. “I have some
work to complete with Doctor Winn, so I won’t be free to entertain
you. There are periodicals and novels in the library. If it weren’t such
a beastly day, I would suggest a walk.”
“Oh, I don’t mind a snowstorm!” Dorothy smiled at her. “I’d love to
be out in it for a while.”
“But I’m afraid you might get lost. The blizzard is driving out of the
northeast—and that means something in this country. You’ll find it
more disagreeable than you think.”
“I’m not afraid to walk in a blizzard,” Dorothy argued, “we used to do
it a lot at school—I love it.”
“Oh, very well, then,” went on Mrs. Lawson. “I used to enjoy that
sort of thing myself. Somebody had better go with you, though. Let
me see—” She hesitated. “Oh, yes—Gretchen will be just the person.
She’s a nice little thing—a native of Ridgefield, you know. Gretchen
can show you round the place, and there’ll be no chance of your
getting lost.”
Dorothy was amused by this pretended concern for her safety. She
knew that Mrs. Lawson feared she might take it into her head to
walk to the railroad station and board the first train back to town.
Gretchen as guide and chaperone would be able to forestall anything
like that. Mrs. Lawson was not yet sure of the new secretary!
Dorothy’s features betrayed no sign of her thoughts. “That will be
ever so much pleasanter than going alone,” she agreed. “Gretchen
seems to be a sweet girl. I saw her this morning when she brought
my breakfast and unpacked my clothes. I’m sorry, though, that you
can’t come too.” Deception, she found, was becoming a habit when
treating with her hostess.
“Thank you, my dear—I’m sorry, too.” Mrs. Lawson went toward the
tasselled bell rope that hung beside the fireplace. “Run upstairs now
and get into warm things. I’ll ring for Gretchen and have her meet
you down here in quarter of an hour.”
Fifteen minutes afterward, warmly dressed in whipcord jodhpurs, a
heavy sweater and knee-length leather coat of dark green, Dorothy
came out of her room onto the gallery, pulling a white wool skating
cap well down over her ears. With a white wool scarf twisted about
her throat, the long ends thrown back over her shoulders, she
looked ready for any winter sport as she ran lightly down the stairs,
the rubber soles of her high arctics making no sound on the broad
oaken steps.
Gretchen, well bundled up in sweater and heavy tweed skirt was
waiting for her.
“You certainly do look like a picture on a Christmas magazine cover,
Miss Jordan,” the girl exclaimed, while they walked to the front door.
“I’m glad you’ve got warm gauntlets. It’s mighty cold out—you’ll
need them.”
Dorothy laughed gaily and swung open the door. “Nothing could be
more becoming than your own costume, Gretchen. That light blue
skating set is just the color of your eyes.”
“That,” chuckled Gretchen, “is the real reason I bought it.”
They were outside now and standing under the wide porte-cochere
of glass and wrought iron.
“It’s glorious out here, and not too cold, either.” Dorothy sniffed the
sharp air enthusiastically. “I hate staying indoors on a wild day like
this. Look at those big flakes spinning down and sideslipping into the
drifts. It makes one glad to be alive.”
“You said it, Miss Jordan. I love it myself—though I never thought of
snowflakes being like airplanes before. Which way do you want to
go?”
“You’re the leader, Gretchen. Anywhere you say suits me.”
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
ebookbell.com