100% found this document useful (3 votes)
146 views80 pages

Data Structures Through C in Depth 2nd Revised and Updated Edition by Srivastava, Deepali Srivastava ISBN 8176567418 9788176567411 Download

The document is a comprehensive guide on data structures and algorithms using C, covering various topics such as arrays, linked lists, stacks, queues, searching and sorting techniques, and tree data structures. It includes detailed explanations, basic operations, and example programs in C for each data structure. Additionally, it discusses algorithm analysis, complexity, and provides resources for further reading and digital downloads.

Uploaded by

croutdoerrak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
146 views80 pages

Data Structures Through C in Depth 2nd Revised and Updated Edition by Srivastava, Deepali Srivastava ISBN 8176567418 9788176567411 Download

The document is a comprehensive guide on data structures and algorithms using C, covering various topics such as arrays, linked lists, stacks, queues, searching and sorting techniques, and tree data structures. It includes detailed explanations, basic operations, and example programs in C for each data structure. Additionally, it discusses algorithm analysis, complexity, and provides resources for further reading and digital downloads.

Uploaded by

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

Data Structures Through C in Depth 2nd revised

and Updated Edition by Srivastava, Deepali


Srivastava ISBN 8176567418 9788176567411 install
download
https://ebookball.com/product/data-structures-through-c-in-
depth-2nd-revised-and-updated-edition-by-srivastava-deepali-
srivastava-isbn-8176567418-9788176567411-15716/

Explore and download more ebooks or textbooks


at ebookball.com
Get Your Digital Files Instantly: PDF, ePub, MOBI and More
Quick Digital Downloads: PDF, ePub, MOBI and Other Formats

Data Structures Algorithms and Applications in C With Microsoft


Compiler 2nd Edition by Sartaj Sahni ISBN 0929306325 9780929306322

https://ebookball.com/product/data-structures-algorithms-and-
applications-in-c-with-microsoft-compiler-2nd-edition-by-sartaj-
sahni-isbn-0929306325-9780929306322-15764/

Data Structures Using C 2nd Edition by Malik 0324782012 978-0324782011

https://ebookball.com/product/data-structures-using-c-2nd-
edition-by-malik-0324782012-978-0324782011-17222/

Data Structures and Problem Solving Using C++ 2nd edition by MALIK
ISBN 0324782012 978-0324782011

https://ebookball.com/product/data-structures-and-problem-
solving-using-c-2nd-edition-by-malik-
isbn-0324782012-978-0324782011-16350/

Data Structures and Other Objects Using C++ 2nd edition by Michael
Main ISBN 8129705826 978-8129705822

https://ebookball.com/product/data-structures-and-other-objects-
using-c-2nd-edition-by-michael-main-
isbn-8129705826-978-8129705822-16344/
Data Structures and Algorithms in C 1st edition by Adam Drozdek ASIN
B002WLXMBY

https://ebookball.com/product/data-structures-and-algorithms-
in-c-1st-edition-by-adam-drozdek-asin-b002wlxmby-25076/

Step by Step Oral Radiology 1st Edition by Ram Kumar Srivastava ISBN
B00INKKBK8 9789350250853

https://ebookball.com/product/step-by-step-oral-radiology-1st-
edition-by-ram-kumar-srivastava-
isbn-b00inkkbk8-9789350250853-6870/

Modern Pediatric Dentistry 1st Edition by Vinay Kumar Srivastava, Anil


Kohli ISBN 9350251892 9789350251898

https://ebookball.com/product/modern-pediatric-dentistry-1st-
edition-by-vinay-kumar-srivastava-anil-kohli-
isbn-9350251892-9789350251898-8190/

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/

Data Structures And Algorithm Analysis in C 4th Edition by Mark Weiss


013284737X 9780132847377

https://ebookball.com/product/data-structures-and-algorithm-
analysis-in-c-4th-edition-by-mark-
weiss-013284737x-9780132847377-15292/
Table of Contents
About the Tutorial
………………………………………………………………………………………………………
i
Audience………………………………………………………………………………………………
i
Prerequisites…………………………………………………………………………………………
i Copyright and Disclaimer
………………………………………………………………………………………………………
i Compile & Execute Online
………………………………………………………………………………………………………
ii Table of Contents
………………………………………………………………………………………………………
iii

BASICS…………………………………………………………………………………

1. Overview
………………………………………………………………………………………………………
Characteristics of a Data
Structure………………………………………………………………………………………………
2
Need for Data Structure
………………………………………………………………………………………………………
2
Execution Time Cases
………………………………………………………………………………………………………
3
Basic Terminology
………………………………………………………………………………………………………
3
2. Environment Setup
………………………………………………………………………………………………………
Try it Option Online
………………………………………………………………………………………………………
4
Local Environment
Setup…………………………………………………………………………………………………
4
Installation on
UNIX/Linux…………………………………………………………………………………………
5
Installation on Mac
OS……………………………………………………………………………………………………
5
Installation on
Windows………………………………………………………………………………………………
6

ALGORITHM…………………………………………………………………………
3. Algorithms ─ Basics
………………………………………………………………………………………………………
Characteristics of an Algorithm
………………………………………………………………………………………………………
8
How to Write an Algorithm?
………………………………………………………………………………………………………
9
Algorithm
Analysis………………………………………………………………………………………………
10
Algorithm
Complexity……………………………………………………………………………………………
11
Space Complexity
………………………………………………………………………………………………………
11
Time
Complexity……………………………………………………………………………………………
11
4. Asymptotic
Analysis………………………………………………………………………………………………
Asymptotic
Notations……………………………………………………………………………………………
12
Common Asymptotic Notations
……………………………………………………………………………………………………..
15
5. Greedy Algorithms
………………………………………………………………………………………………………
Counting
Coins…………………………………………………………………………………………………
16
6. Divide &
Conquer………………………………………………………………………………………………
18
Divide/Break
………………………………………………………………………………………………………
18
Conquer/Solve………………………………………………………………………………………
18
Merge/Combine
………………………………………………………………………………………………………
19
7. Dynamic
Programming………………………………………………………………………………………
iii

DATA STRUCTURES
…………………………………………………………………………………………
8. Basic Concepts
………………………………………………………………………………………………………
Data Definition
………………………………………………………………………………………………………
22
Data
Object…………………………………………………………………………………………………
22
Data
Type…………………………………………………………………………………………………
22
Basic
Operations……………………………………………………………………………………………
23
9. Arrays
………………………………………………………………………………………………………
Array Representation
………………………………………………………………………………………………………
24
Basic
Operations……………………………………………………………………………………………
25
Insertion Operation
………………………………………………………………………………………………………
25
Array Insertions
………………………………………………………………………………………………………
27
Insertion at the Beginning of an Array
…………………………………………………………………………………………….
28
Insertion at the Given Index of an Array
…………………………………………………………………………………………. 30
Insertion After the Given Index of an Array
…………………………………………………………………………………….. 32
Insertion Before the Given Index of an
Array…………………………………………………………………………………… 34
Deletion
Operation……………………………………………………………………………………………
36
Search
Operation……………………………………………………………………………………………
37
Update
Operation……………………………………………………………………………………………
39

LINKED
LIST……………………………………………………………………………………

10. Linked List ─


Basics…………………………………………………………………………………………………
Linked List Representation
………………………………………………………………………………………………………
42
Types of Linked List
………………………………………………………………………………………………………
42
Basic
Operations……………………………………………………………………………………………
43
Insertion Operation
………………………………………………………………………………………………………
43
Deletion
Operation……………………………………………………………………………………………
44
Reverse
Operation……………………………………………………………………………………………
45
Linked List Program in C
………………………………………………………………………………………………………
46
11. Doubly Linked List
………………………………………………………………………………………………………
Doubly Linked List Representation
………………………………………………………………………………………………….
55
Basic
Operations……………………………………………………………………………………………
55
Insertion Operation
………………………………………………………………………………………………………
56
Deletion
Operation……………………………………………………………………………………………
57
Insertion at the End of an
Operation……………………………………………………………………………………………
57
Doubly Linked List Program in C
……………………………………………………………………………………………………..
58
12. Circular Linked List
………………………………………………………………………………………………………
Singly Linked List as Circular
………………………………………………………………………………………………………
67
Doubly Linked List as Circular
………………………………………………………………………………………………………
67
Basic
Operations……………………………………………………………………………………………
67
Insertion Operation
………………………………………………………………………………………………………
68
Deletion
Operation……………………………………………………………………………………………
68
Display List
Operation……………………………………………………………………………………………
69
Circular Linked List Program in C
…………………………………………………………………………………………………….
69

STACK &
QUEUE…………………………………………………………………………………
74

13. Stack
………………………………………………………………………………………………………
Stack
Representation………………………………………………………………………………………
75
Basic
Operations……………………………………………………………………………………………
76
peek()
………………………………………………………………………………………………………
76
isfull()
………………………………………………………………………………………………………
77
isempty()
………………………………………………………………………………………………………
77
Push
Operation……………………………………………………………………………………………
78
Pop Operation
………………………………………………………………………………………………………
79
Stack Program in
C………………………………………………………………………………………………………
81
14. Expression Parsing
………………………………………………………………………………………………………
Infix
Notation………………………………………………………………………………………………
84
Prefix Notation
………………………………………………………………………………………………………
84
Postfix
Notation………………………………………………………………………………………………
84
Parsing Expressions
………………………………………………………………………………………………………
85
Postfix Evaluation Algorithm
………………………………………………………………………………………………………
86
Expression Parsing Using
Stack…………………………………………………………………………………………………
86
15. Queue
………………………………………………………………………………………………………
Queue Representation
………………………………………………………………………………………………………
92
Basic
Operations……………………………………………………………………………………………
92
peek()
………………………………………………………………………………………………………
93
isfull()
………………………………………………………………………………………………………
93
isempty()
………………………………………………………………………………………………………
94
Enqueue Operation
………………………………………………………………………………………………………
95
Dequeue Operation
………………………………………………………………………………………………………
96
Queue Program in C
………………………………………………………………………………………………………
98

SEARCHING
TECHNIQUES…………………………………………………………………………

16. Linear Search


………………………………………………………………………………………………………
Linear Search Program in C
………………………………………………………………………………………………………
104
17. Binary Search
………………………………………………………………………………………………………
How Binary Search Works?
………………………………………………………………………………………………………
107
Binary Search Program in C
………………………………………………………………………………………………………
110
18. Interpolation Search
………………………………………………………………………………………………………
Positioning in Binary Search
………………………………………………………………………………………………………
113
Position Probing in Interpolation
Search………………………………………………………………………………………..
114
Interpolation Search Program in C
………………………………………………………………………………………………..
116
19. Hash Table
………………………………………………………………………………………………………
Hashing
………………………………………………………………………………………………………
118
Linear
Probing………………………………………………………………………………………………
119
Basic
Operations……………………………………………………………………………………………
120
Data
Item……………………………………………………………………………………………………
120
v Hash Method
………………………………………………………………………………………………………
120
Search
Operation……………………………………………………………………………………………
120
Insert Operation
………………………………………………………………………………………………………
121
Delete Operation
………………………………………………………………………………………………………
122
Hash Table Program in C
………………………………………………………………………………………………………
123

SORTING
TECHNIQUES…………………………………………………………………………
128
20. Sorting
Algorithm……………………………………………………………………………………………
In-place Sorting and Not-in-place Sorting
……………………………………………………………………………………… 129
Stable and Not Stable
Sorting………………………………………………………………………………………………
129
Adaptive and Non-Adaptive Sorting Algorithm
………………………………………………………………………………. 130
Important
Terms…………………………………………………………………………………………………
130
21. Bubble Sort Algorithm
………………………………………………………………………………………………………
How Bubble Sort Works?
………………………………………………………………………………………………………
132
Bubble Sort Program in C
………………………………………………………………………………………………………
136
22. Insertion Sort
………………………………………………………………………………………………………
How Insertion Sort Works?
………………………………………………………………………………………………………
140
Insertion Sort Program in C
………………………………………………………………………………………………………
143
23. Selection
Sort……………………………………………………………………………………………………
How Selection Sort Works?
………………………………………………………………………………………………………
147
Selection Sort Program in C
………………………………………………………………………………………………………
150
24. Merge Sort Algorithm
………………………………………………………………………………………………………
153
How Merge Sort Works?
………………………………………………………………………………………………………
153
Merge Sort Program in C
………………………………………………………………………………………………………
156
25. Shell Sort
………………………………………………………………………………………………………
How Shell Sort Works?
………………………………………………………………………………………………………
158
Shell Sort Program in C
………………………………………………………………………………………………………
162
26. Quick Sort
………………………………………………………………………………………………………
166
Partition in Quick Sort
………………………………………………………………………………………………………
166
Quick Sort Pivot Algorithm
………………………………………………………………………………………………………
166
Quick Sort Pivot Pseudocode
………………………………………………………………………………………………………
167
Quick Sort Algorithm
………………………………………………………………………………………………………
167
Quick Sort
Pseudocode……………………………………………………………………………………………
168
Quick Sort Program in C
………………………………………………………………………………………………………
168

GRAPH DATA STRUCTURE


…………………………………………………………………………………………

27. Graphs
………………………………………………………………………………………………………
Graph Data Structure
………………………………………………………………………………………………………
173
Basic
Operations……………………………………………………………………………………………
175
28. Depth First
Traversal……………………………………………………………………………………………
Depth First Traversal in C
………………………………………………………………………………………………………
179
29. Breadth First
Traversal……………………………………………………………………………………………
Breadth First Traversal in C
………………………………………………………………………………………………………
186

TREE DATA STRUCTURE


…………………………………………………………………………………………

30. Tree
………………………………………………………………………………………………………
193
Important
Terms…………………………………………………………………………………………………
193
Binary Search Tree Representation
……………………………………………………………………………………………….
194
Tree Node
………………………………………………………………………………………………………
194
BST Basic Operations
………………………………………………………………………………………………………
195
Insert Operation
………………………………………………………………………………………………………
195
Search
Operation……………………………………………………………………………………………
197
Tree Traversal in C
………………………………………………………………………………………………………
198
31. Tree Traversal
………………………………………………………………………………………………………
204
In-order Traversal
………………………………………………………………………………………………………
204
Pre-order
Traversal………………………………………………………………………………………………
205
Post-order Traversal
………………………………………………………………………………………………………
206
Tree Traversal in C
………………………………………………………………………………………………………
207
32. Binary Search Tree
………………………………………………………………………………………………………
Representation
………………………………………………………………………………………………………
213
Basic
Operations……………………………………………………………………………………………
214
Node
………………………………………………………………………………………………………
214
Search
Operation……………………………………………………………………………………………
214
Insert Operation
………………………………………………………………………………………………………
215
33. AVL Trees
………………………………………………………………………………………………………
AVL Rotations
………………………………………………………………………………………………………
218
34. Spanning Tree
………………………………………………………………………………………………………
222
General Properties of Spanning Tree
…………………………………………………………………………………………….
222
Mathematical Properties of Spanning
Tree……………………………………………………………………………………. 223
Application of Spanning Tree
………………………………………………………………………………………………………
223
Minimum Spanning Tree (MST)
…………………………………………………………………………………………………….
223
Minimum Spanning-Tree Algorithm
………………………………………………………………………………………………
223
Kruskal’s Spanning Tree
Algorithm……………………………………………………………………………………………
224
Prim’s Spanning Tree Algorithm
……………………………………………………………………………………………………
227
35.
Heaps…………………………………………………………………………………………………
Max Heap Construction Algorithm
………………………………………………………………………………………………..
232
Max Heap Deletion Algorithm
………………………………………………………………………………………………………
233

RECURSION…………………………………………………………………………

vii
36. Recursion ─
Basics…………………………………………………………………………………………………
235
Properties
………………………………………………………………………………………………………
235
Implementation………………………………………………………………………………………
236
Analysis of
Recursion……………………………………………………………………………………………
236
Time
Complexity……………………………………………………………………………………………
236
Space Complexity
………………………………………………………………………………………………………
237
37. Tower of Hanoi
………………………………………………………………………………………………………
Rules
………………………………………………………………………………………………………
238
Algorithm……………………………………………………………………………………………
242
Tower of Hanoi in C
………………………………………………………………………………………………………
245
38. Fibonacci Series
………………………………………………………………………………………………………
249
Fibonacci Iterative Algorithm
………………………………………………………………………………………………………
250
Fibonacci Interactive Program in
C………………………………………………………………………………………………..
250
Fibonacci Recursive Algorithm
……………………………………………………………………………………………………..
252
Fibonacci Recursive Program in
C………………………………………………………………………………………………….
252
viii
Basics
1. Overview Data Structures &
Algorithms
Data Structure is a systematic way to organize data in order to use it efficiently. Following
terms are the foundation terms of a data structure.
Interface − Each data structure has an interface. Interface represents the set of operations
that a data structure supports. An interface only provides the list of supported operations,
type of parameters they can accept and return type of these operations.
Implementation − Implementation provides the internal representation of a data structure.
Implementation also provides the definition of the algorithms used in the operations of the
data structure.
Characteristics ofa Data Structure
Correctness − Data structure implementation should implement its interface correctly.
Time Complexity − Running time or the execution time of operations of data structure
must be as small as possible.
Space Complexity − Memory usage of a data structure operation should be as little as
possible.
Need for Data Structure
As applications are getting complex and data rich, there are three common problems that
applications face now-a-days.
Data Search − Consider an inventory of 1 million(106) items of a store. If the application
is to search an item, it has to search an item in 1 million(106) items every time slowing
down the search. As data grows, search will become slower.
Processor Speed − Processor speed although being very high, falls limited if the data
grows to billion records.
Multiple Requests − As thousands of users can search data simultaneously on a web
server, even the fast server fails while searching the data.
To solve the above-mentioned problems, data structures come to rescue. Data can be
organized in a data structure in such a way that all items may not be required to be
searched, and the required data can be searched almost instantly.
ExecutionTimeCases
There are three cases which are usually used to compare various data structure’s execution
time in a relative manner.
Worst Case − This is the scenario where a particular data structure operation takes
maximum time it can take. If an operation’s worst case time is ƒ(n) then this operation will
not take more than ƒ(n) time, where ƒ(n) represents function of n.
Average Case − This is the scenario depicting the average execution time of an operation
of a data structure. If an operation takes ƒ(n) time in execution, then m operations will
take mƒ(n) time.
Best Case − This is the scenario depicting the least possible execution time of an
operation of a data structure. If an operation takes ƒ(n) time in execution, then the actual
operation may take time as the random number which would be maximum as ƒ(n).
Basic Terminology
Data − Data are values or set of values.
Data Item − Data item refers to single unit of values.
Group Items − Data items that are divided into sub items are called as Group Items.
Elementary Items − Data items that cannot be divided are called as Elementary Items.
Attribute and Entity − An entity is that which contains certain attributes or properties,
which may be assigned values.
Entity Set − Entities of similar attributes form an entity set.
Field − Field is a single elementary unit of information representing an attribute of an
entity.
Record − Record is a collection of field values of a given entity. File − File is a collection
of records of the entities in a given entity set.
2. Environment SetupData Structures &
Algorithms
Tryit Option Online
You really do not need to set up your own environment to start learning C programming
language. Reason is very simple, we already have set up C Programming environment
online, so that you can compile and execute all the available examples online at the same
time when you are doing your theory work. This gives you confidence in what you are
reading and to check the result with different options. Feel free to modify any example and
execute it online.
Try the following example using the Try it option available at the top right corner of the
sample code box −
#include <stdio.h>
int main(){
/* My first program in C */ printf(“Hello, World! \n”);
return 0; }
For most of the examples given in this tutorial, you will find Try it option, so just make
use of it and enjoy your learning.
LocalEnvironment Setup
If you are still willing to set up your environment for C programming language, you need
the following two tools available on your computer, (a) Text Editor and (b) The C
Compiler.

Text Editor

This will be used to type your program. Examples of few editors include Windows
Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi.
The name and the version of the text editor can vary on different operating systems. For
example, Notepad will be used on Windows, and vim or vi can be used on Windows as
well as Linux or UNIX.
The files you create with your editor are called source files and contain program source
code. The source files for C programs are typically named with the extension “.c“.
Before starting your programming, make sure you have one text editor in place and you
have enough experience to write a computer program, save it in a file, compile it, and
finally execute it.

The C Compiler

The source code written in the source file is the human readable source for your program.
It needs to be “compiled”, to turn into machine language so that your CPU can actually
execute the program as per the given instructions.
This C programming language compiler will be used to compile your source code into a
final executable program. We assume you have the basic knowledge about a programming
language compiler.
Most frequently used and free available compiler is GNU C/C++ compiler. Otherwise, you
can have compilers either from HP or Solaris if you have respective Operating Systems
(OS).
The following section guides you on how to install GNU C/C++ compiler on various OS.
We are mentioning C/C++ together because GNU GCC compiler works for both C and
C++ programming languages.
Installation on UNIX/Linux
If you are using Linux or UNIX, then check whether GCC is installed on your system by
entering the following command from the command line −
$ gcc -v
If you have GNU compiler installed on your machine, then it should print a message such
as the following −
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure —prefix=/usr ……. Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)
If GCC is not installed, then you will have to install it yourself using the detailed
instructions available at http://gcc.gnu.org/install/
This tutorial has been written based on Linux and all the given examples have been
compiled on Cent OS flavor of Linux system.
Installation on Mac OS
If you use Mac OS X, the easiest way to obtain GCC is to download the Xcode
development environment from Apple’s website and follow the simple installation
instructions. Once you have Xcode setup, you will be able to use GNU compiler for
C/C++.
Xcode is currently available at developer.apple.com/technologies/tools/
Installation onWindows
To install GCC on Windows, you need to install MinGW. To install MinGW, go to the
MinGW homepage, www.mingw.org, and follow the link to the MinGW download page.
Download the latest version of the MinGW installation program, which should be named
MinGW<version>.exe.
While installing MinWG, at a minimum, you must install gcc-core, gcc-g++, binutils, and
the MinGW runtime, but you may wish to install more.
Add the bin subdirectory of your MinGW installation to your PATH environment
variable, so that you can specify these tools on the command line by their simple names.
When the installation is complete, you will be able to run gcc, g++, ar, ranlib, dlltool, and
several other GNU tools from the Windows command line.
Algorithm
3. Algorithms─ BasicsData Structures &
Algorithms
Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in
a certain order to get the desired output. Algorithms are generally created independent of
underlying languages, i.e. an algorithm can be implemented in more than one
programming language.
From the data structure point of view, following are some important categories of
algorithms −
Search − Algorithm to search an item in a data structure.
Sort − Algorithm to sort items in a certain order.
Insert − Algorithm to insert item in a data structure.
Update − Algorithm to update an existing item in a data structure. Delete − Algorithm to
delete an existing item from a data structure.
Characteristics ofanAlgorithm
Not all procedures can be called an algorithm. An algorithm should have the following
characteristics −
Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or
phases), and their inputs/outputs should be clear and must lead to only one meaning.
Input − An algorithm should have 0 or more well-defined inputs.
Output − An algorithm should have 1 or more well-defined outputs, and should match the
desired output.
Finiteness − Algorithms must terminate after a finite number of steps.
Feasibility − Should be feasible with the available resources.
Independent − An algorithm should have step-by-step directions, which should be
independent of any programming code.
How toWriteanAlgorithm?
There are no well-defined standards for writing algorithms. Rather, it is problem and
resource dependent. Algorithms are never written to support a particular programming
code.
As we know that all programming languages share basic code constructs like loops (do,
for, while), flow-control (if-else), etc. These common constructs can be used to write an
algorithm.
We write algorithms in a step-by-step manner, but it is not always the case. Algorithm
writing is a process and is executed after the problem domain is well-defined. That is, we
should know the problem domain, for which we are designing a solution.

Example

Let’s try to learn algorithm-writing by using an example.


Problem − Design an algorithm to add two numbers and display the result.
step 1 − START
step 2 − declare three integers a, b & c
step 3 − define values of a & b
step 4 − add values of a & b
step 5 − store output of step 4 to c
step 6 − print c
step 7 − STOP
Algorithms tell the programmers how to code the program. Alternatively, the algorithm
can be written as −
step 1 − START ADD
step 2 − get values of a & b
step 3 − c ← a + b
step 4 − display c
step 5 − STOP
In design and analysis of algorithms, usually the second method is used to describe an
algorithm. It makes it easy for the analyst to analyze the algorithm ignoring all unwanted
definitions. He can observe what operations are being used and how the process is
flowing.
Writing step numbers, is optional.
We design an algorithm to get a solution of a given problem. A problem can be solved in
more than one ways.
Hence, many solution algorithms can be derived for a given problem. The next step is to
analyze those proposed solution algorithms and implement the best suitable solution.
AlgorithmAnalysis
Efficiency of an algorithm can be analyzed at two different stages, before implementation
and after implementation. They are the following −
A Priori Analysis − This is a theoretical analysis of an algorithm. Efficiency of an
algorithm is measured by assuming that all other factors, for example, processor speed, are
constant and have no effect on the implementation.
A Posterior Analysis − This is an empirical analysis of an algorithm. The selected
algorithm is implemented using programming language. This is then executed on target
computer machine. In this analysis, actual statistics like running time and space required,
are collected.
We shall learn about a priori algorithm analysis. Algorithm analysis deals with the
execution or running time of various operations involved. The running time of an
operation can be defined as the number of computer instructions executed per operation.
AlgorithmComplexity
Suppose X is an algorithm and n is the size of input data, the time and space used by the
algorithm X are the two main factors, which decide the efficiency of X.
Time Factor – Time is measured by counting the number of key operations such as
comparisons in the sorting algorithm.
Space Factor − Space is measured by counting the maximum memory space required by
the algorithm.
The complexity of an algorithm f(n) gives the running time and/or the storage space
required by the algorithm in terms of n as the size of input data.
SpaceComplexity
Space complexity of an algorithm represents the amount of memory space required by the
algorithm in its life cycle. The space required by an algorithm is equal to the sum of the
following two components −
A fixed part that is a space required to store certain data and variables, that are
independent of the size of the problem. For example, simple variables and constants used,
program size, etc.
A variable part is a space required by variables, whose size depends on the size of the
problem. For example, dynamic memory allocation, recursion stack space, etc.
Space complexity S(P) of any algorithm P is S(P) = C + SP(I) where C is the fixed part
and S(I) is the variable part of the algorithm, which depends on instance characteristic I.
Following is a simple example that tries to explain the concept −
Algorithm: SUM(A, B) Step 1 START
Step 2 C ← A + B + 10 Step 3 Stop
Here we have three variables A, B, and C and one constant. Hence S(P) = 1+3. Now,
space depends on data types of given variables and constant types and it will be multiplied
accordingly.
TimeComplexity
Time complexity of an algorithm represents the amount of time required by the algorithm
to run to completion. Time requirements can be defined as a numerical function T(n),
where T(n) can be measured as the number of steps, provided each step consumes constant
time.
For example, addition of two n-bit integers takes n steps. Consequently, the total
computational time is T(n) = c*n, where c is the time taken for the addition of two bits.
Here, we observe that T(n) grows linearly as the input size increases.
4. Asymptotic AnalysisData Structures &
Algorithms
Asymptotic analysis of an algorithm refers to defining the mathematical
boundation/framing of its run-time performance. Using asymptotic analysis, we can very
well conclude the best case, average case, and worst case scenario of an algorithm.
Asymptotic analysis is input bound i.e., if there’s no input to the algorithm, it is concluded
to work in a constant time. Other than the “input” all other factors are considered constant.
Asymptotic analysis refers to computing the running time of any operation in
mathematical units of computation. For example, the running time of one operation is
computed as f(n) and may be for another operation it is computed as g(n2). This means the
first operation running time will increase linearly with the increase in n and the running
time of the second operation will increase exponentially when n increases. Similarly, the
running time of both operations will be nearly the same if n is significantly small.
Usually, the time required by an algorithm falls under three types −
Best Case − Minimum time required for program execution.
Average Case − Average time required for program execution. Worst Case − Maximum
time required for program execution.
AsymptoticNotations
Following are the commonly used asymptotic notations to calculate the running time
complexity of an algorithm.
Ο Notation
Ω Notation θ Notation

Big Oh Notation, Ο

The notation Ο(n) is the formal way to express the upper bound of an algorithm’s running
time. It measures the worst case time complexity or the longest amount of time an
algorithm can possibly take to complete.

For example, for a function f(n)


Ο(f(n)) = { g(n) : there exists c > 0 and n0 such that g(n) ≤ c.f(n) for all n > n0. }

Omega Notation, Ω

The notation Ω(n) is the formal way to express the lower bound of an algorithm’s running
time. It measures the best case time complexity or the best amount of time an algorithm
can possibly take to complete.

For example, for a function f(n)


Ω(f(n)) ≥ { g(n) : there exists c > 0 and n0 such that g(n) ≤ c.f(n) for all n > n0. }

Theta Notation, θ
The notation θ(n) is the formal way to express both the lower bound and the upper bound
of an algorithm’s running time. It is represented as follows −

θ(f(n)) = { g(n) if and only if g(n) = Ο(f(n)) and g(n)


= Ω(f(n)) for all n > n0. }
CommonAsymptotic Notations
Following is a list of some common asymptotic notations:
constant − Ο(1)
logarithmic − Ο(log n)
linear − Ο(n)
n log n − Ο(n log n)
quadratic − Ο(n2)
cubic − Ο(n3)
polynomial − nΟ(1) exponential − 2Ο(n)
5. Greedy AlgorithmsData Structures &
Algorithms
An algorithm is designed to achieve optimum solution for a given problem. In greedy
algorithm approach, decisions are made from the given solution domain. As being greedy,
the closest solution that seems to provide an optimum solution is chosen.
Greedy algorithms try to find a localized optimum solution, which may eventually lead to
globally optimized solutions. However, generally greedy algorithms do not provide
globally optimized solutions.
Counting Coins
This problem is to count to a desired value by choosing the least possible coins and the
greedy approach forces the algorithm to pick the largest possible coin. If we are provided
coins of € 1, 2, 5 and 10 and we are asked to count € 18 then the greedy procedure will be

1 − Select one € 10 coin, the remaining count is 8
2 − Then select one € 5 coin, the remaining count is 3
3 − Then select one € 2 coin, the remaining count is 1
3 − And finally, the selection of one € 1 coins solves the problem
Though, it seems to be working fine, for this count we need to pick only 4 coins. But if we
slightly change the problem then the same approach may not be able to produce the same
optimum result.
For the currency system, where we have coins of 1, 7, 10 value, counting coins for value
18 will be absolutely optimum but for count like 15, it may use more coins than necessary.
For example, the greedy approach will use 10 + 1 + 1 + 1 + 1 + 1, total 6 coins. Whereas
the same problem could be solved by using only 3 coins (7 + 7 + 1)
Hence, we may conclude that the greedy approach picks an immediate optimized solution
and may fail where global optimization is a major concern.

Examples

Most networking algorithms use the greedy approach. Here is a list of few of them −
Travelling Salesman Problem
Prim’s Minimal Spanning Tree Algorithm
Kruskal’s Minimal Spanning Tree Algorithm
Dijkstra’s Minimal Spanning Tree Algorithm
Graph - Map Coloring
Graph - Vertex Cover
Knapsack Problem
Job Scheduling Problem
There are lots of similar problems that uses the greedy approach to find an optimum
solution.
6. Divide & ConquerData Structures &
Algorithms
In divide and conquer approach, the problem in hand, is divided into smaller sub-problems
and then each problem is solved independently. When we keep on dividing the
subproblems into even smaller sub-problems, we may eventually reach a stage where no
more division is possible. Those “atomic” smallest possible sub-problem (fractions) are
solved. The solution of all sub-problems is finally merged in order to obtain the solution
of an original problem.

Broadly, we can
understand divide-and-conquer approach in a three-step process.
Divide/Break
This step involves breaking the problem into smaller sub-problems. Sub-problems should
represent a part of the original problem. This step generally takes a recursive approach to
divide the problem until no sub-problem is further divisible. At this stage, sub-problems
become atomic in nature but still represent some part of the actual problem.
Conquer/Solve
This step receives a lot of smaller sub-problems to be solved. Generally, at this level, the
problems are considered ‘solved’ on their own.
Merge/Combine
When the smaller sub-problems are solved, this stage recursively combines them until
they formulate a solution of the original problem. This algorithmic approach works
recursively and conquer & merge steps works so close that they appear as one.

Examples

The following computer algorithms are based on divide-and-conquer programming


approach −
Merge Sort
Quick Sort
Binary Search
Strassen’s Matrix Multiplication
Closest Pair (points)
There are various ways available to solve any computer problem, but the mentioned are a
good example of divide and conquer approach.
7. Dynamic ProgrammingData Structures
& Algorithms
Dynamic programming approach is similar to divide and conquer in breaking down the
problem into smaller and yet smaller possible sub-problems. But unlike, divide and
conquer, these sub-problems are not solved independently. Rather, results of these smaller
sub-problems are remembered and used for similar or overlapping sub-problems.
Dynamic programming is used where we have problems, which can be divided into
similar sub-problems, so that their results can be re-used. Mostly, these algorithms are
used for optimization. Before solving the in-hand sub-problem, dynamic algorithm will try
to examine the results of the previously solved sub-problems. The solutions of sub-
problems are combined in order to achieve the best solution.
So we can say −
The problem should be able to be divided into smaller overlapping sub-problem.
An optimum solution can be achieved by using an optimum solution of smaller
subproblems.
Dynamic algorithms use memorization.

Comparison

In contrast to algorithms are motivated for an overall optimization of the problem. greedy
algorithms, where local optimization is addressed, dynamic
In contrast to divide and conquer algorithms, where solutions are combined to achieve an
overall solution, dynamic algorithms use the output of a smaller sub-problem and then try
to optimize a bigger sub-problem. Dynamic algorithms use memorization to remember the
output of already solved sub-problems.

Example

The following computer problems can be solved using dynamic programming approach −
Fibonacci number series
Knapsack problem
Tower of Hanoi
All pair shortest path by Floyd-Warshall
Shortest path by Dijkstra
Project scheduling
Dynamic programming can be used in both top-down and bottom-up manner. And of
course, most of the times, referring to the previous solution output is cheaper than
recomputing in terms of CPU cycles.
Data Structures
8. Basic ConceptsData Structures &
Algorithms
This chapter explains the basic terms related to data structure.
Data Definition
Data Definition defines a particular data with the following characteristics. Atomic −
Definition should define a single concept.
Traceable − Definition should be able to be mapped to some data element.
Accurate − Definition should be unambiguous. Clear and Concise − Definition should
be understandable.
Data Object
Data Object represents an object having a data.
Data Type
Data type is a way to classify various types of data such as integer, string, etc. which
determines the values that can be used with the corresponding type of data, the type of
operations that can be performed on the corresponding type of data. There are two data
types −
Built-in Data Type Derived Data Type

Built-in Data Type

Those data types for which a language has built-in support are known as Built-in Data
types. For example, most of the languages provide the following built-in data types.
Integers
Boolean (true, false)
Floating (Decimal numbers) Character and Strings

Derived Data Type

Those data types which are implementation independent as they can be implemented in
one or the other way are known as derived data types. These data types are normally built
by the combination of primary or built-in data types and associated operations on them.
For example −
List
Array
Stack Queue
Basic Operations
The data in the data structures are processed by certain operations. The particular data
structure chosen largely depends on the frequency of the operation that needs to be
performed on the data structure.
Traversing
Searching
Insertion
Deletion
Sorting Merging
Other documents randomly have
different content
SALLY. And all day too.

MARTHA. You hold your hush, Sally Teale. Am I to come in here to


be insulted by your servant, Zack?

ZACK. Nay, I've got no servant that I ever heard of.

MARTHA. Sally.

ZACK. Eh, Martha, Sally's a decent body. She'd never insult


nobody.

MARTHA. Are you going to take her side against me? Zack. I've
not seen anything to take anybody's side about as yet.

SALLY. She says I'm jealous and she'll take it back.

MARTHA. I won't. As true as true, you are.

SALLY. I'm not.

MARTHA. You are.

SALLY. I'm not. I'm not. I'm not.

(Zack rises, comes between, puts finger in mouth and whistles.)

SALLY. I'm not.

ZACK. That's enough, lass. Whistle's gone. I'm referee and I look
at it like this. You can't both be right.

SALLY. No, I'm——

ZACK. And you can't both be wrong.

MARTHA. She's——
ZACK. So it's a draw.

MARTHA. That doesn't help. She called me a liar. Zack


(impressed). No. Did you, Sally?

SALLY. Yes, I did, and——

ZACK. I'm sorry to hear that of you, Sally.

SALLY (contrite). Well, she shouldn't have said——

ZACK. Maybe she spoke beyond her meaning. You did, didn't you,
Martha?

MARTHA. I spoke hasty.

ZACK (to Sally). And you answered hasty, didn't you?

SALLY. I might.

ZACK. I thought so. Haste! It's the cause of half the trouble in the
world. I never hurry. It's a principle with me.

MARTHA (tearfully). Zack, I'm sorry I put on airs. I won't do it


again. (Comes to him. He puts arm round her).

SALLY. I'll—I'll not lose my temper again, Zack. (Comes to him. He


puts his other arm round her.)

ZACK. There, there, Martha. There, there, Sally. I never did


believe in arguing. It's wear and tear for nothing, and——-

(Virginia and Mrs. Munning enter, Virginia in light dress, with hat
and gloves.)

VIRGINIA. Oh!
MRS. MUNNING. Going in for being a Mormon, Zack?

ZACK. No, mother. I dunno how it is, cousin Virginia, but the
awkwardest things do keep happening to me. I was only reconciling
them like.

MRS. MUNNING. You haven't done the bedrooms for the night,
Sally.

SALLY. I'm on my way there now.

MRS. MUNNING. You'll arrive a lot sooner if you'll try going


upstairs.

(Sally is about to reply, thinks better of it and goes out.)

ZACK. I'm the unluckiest chap alive, Virginia. I'd give the world to
have you thinking well of me, and things fall out wrong road every
time.

MRS. MUNNING. That'll do, Zack. Martha's waiting to speak to me.


What is it, Martha?

MARTHA (opening her bag). This is what I came in for, Mrs.


Munning. Your invitation to the wedding. Oh! (She drops some
cards.)

MRS. MUNNING. Pick them up, Zack.

(Zack picks them up.)

MARTHA. I thought Zack and me might go round tonight


delivering them.

(Zack, on his knee picking up cards, reverently kisses the hem of


Virginia's skirt.)
MRS. MUNNING. Oh yes. (Sharply.) What are you doing, Zack?

ZACK (scrambling up). Picking up cards. (Giving them to Mrs.


Munning.)

MRS. MUNNING. Why, you've had cards printed. (Returns cards to


Martha.)

MARTHA. They are stylish, aren't they? (Giving a card). That's


yours, Mrs. Munning. And I brought you one, Miss Virginia.

VIRGINIA. Thanks.

MRS. MUNNING. Waste of money.

MARTHA. You can't be genteel without spending a bit of money. A


wedding's a wedding, Mrs. Munning, and folk have to spread
themselves sometimes. Are you ready, Zack?

ZACK. I'm not so anxious, Martha. It'll mean a lot of walking.

MRS. MUNNING. I suppose you'd rather good money went on


postage?

ZACK. All right, mother. I'll go. Only you know, Martha, you're
tying this knot firm. A printed card's an awful binding thing.

MARTHA. My father's got to see there's no mistake.

ZACK. He's doing pretty well so far.

MARTHA. Yes. My wedding-dress is coming home tonight, too. I'll


show it you if you like.

ZACK (swallowing, then), I'm like a cat on hot bricks till I see that
dress.
(Martha and Zack go out.)

VIRGINIA. Poor Zack!

MRS. MUNNING. Fools pay for their folly. Did you come down for
your walk with Paul?

VIRGINIA. Yes. It's about the usual time.

MRS. MUNNING. He'll be late this evening. He'd to go to Bollington


this afternoon, but he'll bring you back a fairing, Jenny. He mostly
went on your account.

VIRGINIA. On mine?

MRS. MUNNING. Paul's fretting because the roses he's putting in


your room each day aren't good enough for you. He's gone to
Bollington to see if he can't find better at the flower shop there.

VIRGINIA (coldly). He needn't have troubled, aunt.

MRS. MUNNING. Paul doesn't count it trouble to do things for you.

VIRGINIA. So he's told me.

MRS. MUNNING. Well, truth's truth, and I'm not bound to hide it.
He's missed his proper bedtime every night with seeking roses here
to suit him. They've got to be so fine and large before they'll do for
Paul.

(Sally enters with a vase of very faded roses in her hand.)

SALLY. Do you want these leaving in your room any longer, Miss
Virginia? They're that faded and done they'll stink the place out
soon.

VIRGINIA. I think they might be thrown away now, Sally.


SALLY. I'd think so, too. Been there a week if it's a minute. Some
one used to change them every day, but they've seemingly got tired
of the job.

VIRGINIA. Yes. Put them away, please.

(Sally nods and goes out.)

MRS. MUNNING (making the best of it). I didn't know he'd given it
up here altogether.

VIRGINIA. I expect he preferred a proper night's rest, aunt.

MRS. MUNNING. Not he. But that's Paul all over. If he can't get the
best he'll have none. Look at the engagement ring he gave you.

VIRGINIA. Yes. It's—an engagement ring.

MRS. MUNNING. Ah, but you're like myself, Jenny. You don't value
things for their appearance, but for what they mean to you.

VIRGINIA (doubtfully, fingering the ring). Yes.

(Paul enters, with hat and coat on.)

PAUL. Good evening.

MRS. MUNNING. Why, you're sooner than I expected.

PAUL. Well, I've settled it. I've done my business. I've got them
mother. How are you, Jenny? (Comes round and kisses her.)

MRS. MUNNING. Have you brought them with you, Paul?

PAUL. I'll show you. Let me get my coat off.

MRS. MUNNING. The roses, I mean.


PAUL (blankly). Oh the roses.

MRS. MUNNING (quickly). They'll be sending them, I suppose.

PAUL. Well——

VIRGINIA. I'm just going upstairs.

MRS. MUNNING. You needn't run away from him the moment he
comes back.

VIRGINIA. No. But I shan't be going out for a walk to-night, aunt.
I'll take my hat off. (Exit Virginia.)

MRS. MUNNING. Have you no sense at all? Couldn't you tell her
the roses were coming?

PAUL. They're not.

MRS. MUNNING. Not coming? And me just telling her they were all
you went to Bollington for!

PAUL. You shouldn't tell her lies. You know they weren't all I went
for.

MRS. MUNNING. She liked to think they were. You've got a


memory like a sieve.

PAUL. I didn't forget. I went to the shop and asked the price. They
wanted sixpence each. Sixpence for a single rose. Have you any idea
what a lot of roses it takes to make a decent-looking bunch?

MRS. MUNNING. Will you never get it into your thick head that it's
worth spending money to gain money?

PAUL. You've got the spending habit lately. There's no need to


spend for the sake of spending. I'm engaged to Virginia. What more
do you want?

MRS. MUNNING. I want you to keep engaged till you're married.


You're growing careless and neglecting her.

PAUL. Neglecting! I gave her a kiss just now.

MRS. MUNNING. That cost you nothing. What made you stop
putting flowers in her room?

PAUL. I'm not marrying a wife to stand at her heels with silly
flowers. And there isn't a woman on earth worth buying roses for at
sixpence a bloom.

MRS. MUNNING. Virginia's five hundred a year's worth it.

PAUL. It's not. Selling flowers at that price is robbery, and I'll be
robbed by no one. Look at Joe Wrigley.

MRS. MUNNING. That won't last long.

PAUL. You're right. It won't. Zack will be married on Wednesday


and off to Canada on Saturday. Just let Joe Wrigley come here after
that. I'll teach him something.

MRS. MUNNING. You've got their tickets?

PAUL (showing them). I told you I had.

MRS. MUNNING. Steerage, I see.

PAUL. Of course they're steerage. Why, do you know we've to give


them a matter of ten pounds before they'll let them load?

MRS. MUNNING. Well, we have to start them off with something,


Paul.
PAUL. Ten pounds isn't something. It's a thundering lot.

MRS. MUNNING. In a good cause.

PAUL. A good cause is a better cause when it's cheap, and this is
coming out a bit expensive.

(Enter Sally.)

MRS. MUNNING. What is it, Sally?

SALLY. The door bell, Mrs. Munning.

(Sally crosses and exit.)

PAUL. An order, if we're lucky.

MRS. MUNNING. Well, you are lucky, lately, aren't you? Everything
you can think of 's going right, (Sally re-enters.)

SALLY. It's Mr. Wrigley and some friends.

(Wrigley enters with Thomas Mowatt and Harry Shoe-bridge.


Mowatt is a fat, red-faced dairyman and Shoe-bridge is a farmer, tall,
with brown face and mutton-chop whiskers. Wrigley has a large jug
of ale and puts it on table.)

(Exit Sally.)

WRIGLEY. Good evening, Mrs. Munning. Come in, Thomas, Harry.


You see, Mrs. Munning, you've been so amazing good to me lately
over a bit of supper at nights that I thought I'd bring a friend or two
this time to test the vittles.

MRS. MUNNING. You——


WRIGLEY. Ay, and you needn't tire your tongue with welcoming
words. I can read your genial thoughts. And knowing you hadn't got
it here, we brought our own ale with us. (Lifting jug.) It's a real drop
of stimulant is this. Now sit down, Thomas. There you are, Harry.
(Places chairs.) Well, now what shall it be? (Sits.) Seeing we're
unexpected like, I think a bit of bread and cheese, eh Thomas?

THOMAS. It'll go sweetly with the ale.

WRIGLEY. So it will. Bread and cheese, Mrs. Munning. I'd not say
"no" to biscuits myself.

PAUL (advancing). Joe Wrigley——

WRIGLEY. Eh, Paul, I didn't just notice you, but you're the man we
want. We've really come on business, but we'll get on better when
we're fortified with a bite and a sup. You know what Thomas and
Harry are, don't you?

PAUL (surrendering). You'd better get the bread and cheese out,
mother.

(Mrs. Munning goes reluctantly and opens door.)

MRS. MUNNING. Sally! Sally!

(Exit Mrs. Munning.)

WRIGLEY. That's right, Paul. When the Executive Committee of the


Little Hulton Savings Club pay a call upon you it's a matter of
common sense for you to make them feel at home.

PAUL. Mr. Mowatt and Mr. Shoebridge are on the Executive and
they're welcome here, but you——

WRIGLEY. I'm on as well.


HARRY. Since last night.

WRIGLEY. As you say, Harry, since last night. I'm coopted under
rule 17. Cost me a gallon of beer, but I'm co-opted. We're the
Executive and we're here on a matter of business concerned with
the work of the Society.

PAUL (with deference). What can I do for you, Mr. Shoebridge?

HARRY. Well, I'll tell you, Mr. Munning.

(Mrs. Munning and Sally enter. They put food and glasses on
table. Wrigley pours ale. They eat and drink during the ensuing. Exit
Sally.)

HARRY. You do the catering for our annual picnic, and there's a
resolution standing on our minute book, recommending our
members to employ you at times of private merrymaking. Thank
you, Mrs. Munning.

PAUL. We've done all catering for your members at contract prices
for many years.

THOMAS. That's so. And no one likes to break an old connection


without warning.

PAUL. Break?

THOMAS. I reckon first to last you've made a pretty penny by us.

PAUL. I'm sure our charges to you are moderate, Mr. Mowatt.

THOMAS. They'll do. They'll do—so long as you're giving us what


we want.

HARRY. It's not the charges that we're here about exactly.
MRS. MUNNING. Then what is it?

HARRY. I'm telling you as fast as I can. This is a tasty bit of


cheese, Mrs. Munning.

WRIGLEY. Aye. I thought you'd relish it. It's full-flavoured but it


doesn't rasp the tongue. It's mellow.

THOMAS. Meller's a great word, Joe. I like things to be meller. I


like meller women and meller cheese and meller ale and meller
festivals.

HARRY. Did you go to see Mr. Abbott married the other day?

THOMAS. Did I go? I'd say so. That was a proper meller occasion.

HARRY. It was that. Mellow right through. He married his wife with
port wine, did Mr. Abbott.

THOMAS. I'm not partial to port wine myself. I favour ale at all
times and all occasions. Ale's a beverage.

WRIGLEY. And Mr. Abbott's wedding isn't the point to-night.

THOMAS. It was a meller wedding and we want things meller


always.

HARRY. That's it in a nutshell, Mr. Munning.

PAUL. I'm sure we make no differences, Mr. Shoebridge.

HARRY. Oh yes, you do. You may not know it, but you do. You
have two sorts of catering, and our members want the best, or the
Executive will pass a resolution advising all to patronize Wilson's of
Norton.

MRS. MUNNING. I hope you won't do that, Mr. Shoebridge.


HARRY. Well, if you want to keep our connection, you'll have to do
the thing our way.

PAUL. But you don't tell us what your way is. What is it we do
wrong?

HARRY. I'm coming to it, lad. I'm going to touch the spot. From
what we hear, your Zack's a-wedding Martha Wrigley.

PAUL. Yes?

HARRY. Well, I've nowt against it. Martha's doing unexpected well,
but if Zack's satisfied I'm sure I am. But Joe Wrigley tells me that it
doesn't stop at that, and being her father he ought to know. You
want to emigrate them off to Canada. Now where's the sense in
that?

PAUL. It seems best to us.

THOMAS. Well, I think it's rotten.

PAUL. You must allow us to be judges.

MRS. MUNNING. I think that's our business and nobody else's.

WRIGLEY (pushing back chair and rising). Come on, let's be


getting over to Wilson's and making our arrangements with him.

THOMAS (rising). Yes, that's the only thing if they're going to talk
that road.

PAUL. But I do wish you'd explain. What has Zack's going to


Canada to do with it?

HARRY. You want a lot of telling. You have two sorts of


jollifications here. Jollifications with Zack Munning and jollifications
without. We want them with.
MRS. MUNNING. With Zack?

HARRY. He's the difference I've been telling you about.

MRS. MUNNING. Zack is! He never does anything.

HARRY. He does enough. I know what you mean. He's a bit of a


fool at doing most things is Zack, but he's got a gift for jollifications.
I couldn't point to where it is myself. Zack's just to come and moon
about and drop a word into an ear there and take a woman's arm
here and the thing's done. You might call it a knack he has.

THOMAS. He mellers things. That's where it is. It's like this, Mrs.
Munning. You can eat cheese without supping ale to it, but you don't
get satisfaction. And Paul can run a wedding without Zack being
there, but it's not hearty—not what I'd call a jollification. It's stiff and
hard. No feeling in it. No mellerness.

HARRY. Zack's got a way with him. He's an artist. If the talk's
going flat, or anybody recalls a subject that's not fit to be recalled at
a wedding—an old quarrel or such like,—what does Zack do but
break a plate? and smiles that smile of his, and all's well in a
moment.

MRS. MUNNING. Well, this is a revelation to me. I don't know


what to say.

PAUL. I do. He'll go to Canada.

WRIGLEY. Is that your last word?

MRS. MUNNING. No. We'll talk this over, Paul.

PAUL. It's gone too far for talking now. I've bought their tickets.

WRIGLEY. They'll do to light a fire with.


MRS. MUNNING. We'll let you have your answer later, Mr.
Shoebridge.

HARRY (by door). All right, Mrs. Munning. You're wise enough to
know a hasty temper doesn't pay in business. I could give a good
guess at your answer.

WRIGLEY. I'm not fond of guessing myself, so I'll stay here to get
it. I'm concerned twice over. As a member of the Executive and as
father of the bride to be.

THOMAS. We'll leave it to you, Joe.

WRIGLEY. I reckon you can.

HARRY. Good evening, Mrs. Munning.

MRS. MUNNING. Good evening to you.

(Exeunt Thomas and Harry.)

MRS. MUNNING. I suppose we can put this down to you, Joe


Wrigley.

WRIGLEY. You might be farther out.

PAUL. You'd nothing to say against emigrating them when I


mentioned it.

WRIGLEY. No, but I thought a lot. I'd a father's feelings, and they
went too deep for words.

MRS. MUNNING. What have you done this for, Joe?

WRIGLEY. Two reasons, and I don't know which is bigger of the


two. Zack's worth good money here. If I'd a mind to ruin your trade
I'd let him go, and make you find out what you've missed. But that's
not Joseph Wrigley's way. I kill no geese that lay me golden eggs.
And reason number two. Aye, and this weighs heaviest. I want the
pleasure of knowing they're living in the village here and the
satisfaction of watching your face look sour and sourer for the sight
of them. I'll teach you something for sacking me.

(Virginia enters, during this speech.)

PAUL. Will you, Joe? You've given me two reasons why you think
you will. I'll give you two why you won't.

WRIGLEY. You will?

MRS. MUNNING. Be careful, Paul. (She puts hand on his arm.)

PAUL (shaking her off). The first's Zack isn't married yet to Martha
and the second is he isn't going to be. Their engagement's served
my purpose.

VIRGINIA. What was your purpose, Paul?

PAUL. Oh! I didn't see you, Jenny.

WRIGLEY. Never mind her. You're speaking to me. Zack shall


marry Martha or I'll make your name a stink in Little Hutton.

PAUL. Get out.

WRIGLEY. You'll eat a lot of dirt for this, Paul Munning. Banns
called and wedding fixed and people asked. (By door, then turns). Is
Zack to marry Martha?

PAUL. He's not.

WRIGLEY. Then the band is going to play and, by George, I'll


make you dance to it.
(Exit Wrigley.)

VIRGINIA (quietly). You must tell me what this is, Paul.

PAUL. It's Joe Wrigley making a mistake. Thinks he can bounce


me, does he?

MRS. MUNNING. You'd better be careful, Paul. Joe Wrigley's one


thing when he's one of our men, but he's another now he's got on
that committee.

PAUL. I'd like to wring his neck. The cunning swine.

MRS. MUNNING. Zack's not to go to Canada.

PAUL. All right. He's not. I'll go to Bollington tomorrow and get the
money back on the tickets. But he shan't marry Martha either. I'll get
even with Joe Wrigley there.

VIRGINIA. What does Zack say?

PAUL. Zack? What's Zack to do with it?

VIRGINIA. It's his marriage, you know.

PAUL. Zack 'll do as he's told. He wasn't marrying her because he


wanted to.

VIRGINIA. Why was he marrying?

PAUL. Because I wanted it. I don't want it now.

MRS. MUNNING. We're in a ticklish corner with Joe Wrigley, Paul.

PAUL. Do you want me to hold my hands up to Joe Wrigley?


MRS. MUNNING. You'll take care what you do? I don't want my
business damaged worse than it is.

PAUL. Your business?

MRS. MUNNING. It is my business, I believe. You're only my


manager, and I warn you to be careful or I'll set about making a
change. I've learnt something to-night.

VIRGINIA. So have I.

PAUL. Mother, you don't believe Joe's tales of Zack!

MRS. MUNNING. I'd not believe a sacked man's tales of anything,


but I believe Mowatt and Shoebridge, and I know who it is they
want at the weddings. It's been a shock to me to find they favour
Zack, but it's Zack they want and Zack they're going to get.

PAUL. A nice mess he'll make of things.

MRS. MUNNING. That remains to be seen. He's never had his


chance till now, but he's just as much my son as you are, Paul.

VIRGINIA. Yes, he was just as much your son when you neglected
him and kept him down and gave Paul all your love. And just as
much when you and Paul let Zack walk into Wrigley's trap and never
raised a hand to save him, and when you schemed to send him out
to Canada to save your pride from being hurt, and when you
changed your mind about him now—not from regret or any love for
Zack, but when you found your business would do better with him
here. Oh, I've been stupid too. I let myself be blinded by the dust
you both threw in my eyes, but I'm not blinded now and——

PAUL. Will you be quiet, Virginia?

MRS. MUNNING. If I made a mistake; Jenny, I've owned to it.


VIRGINIA. You've owned to it! Does that make up to Zack for all
the years you've slighted him, for the chances that he might have
had and Paul has robbed him of? For——

PAUL. Robbed! I think you're forgetting whose ring you're wearing


on your finger.

VIRGINIA. Your ring? Yes. There's your ring.

(She takes it off and throws it at him. Zack and Martha enter.
Martha is in a stupidly elaborate wedding-dress. The ring misses
Paul, hits Zack and falls.)

ZACK. I think I heard something drop.

VIRGINIA. Yes. I've dropped Paul.

MRS. MUNNING. Jenny!

PAUL. You might have damaged that ring badly. It cost me thirty
shillings.

VIRGINIA. You are having an expensive time, lately.

MARTHA (picking up ring). Oh, it's a beautiful ring.

PAUL. Yes. Give it to me.

VIRGINIA. No. Put it on, Martha.

PAUL. What!

VIRGINIA. Put it on.

(Martha puts it on.)

Do you like the look of it on your finger?


MARTHA It's a vision.

VIRGINIA. Is it? Do you like the man that goes with that ring?

PAUL. That's my ring, Virginia.

VIRGINIA. I'm quite aware of that. Do you like Paul, Martha? Will
you take Paul Munning for your lawful wedded husband?

ZACK. I'm not very quick at thinking, Virginia, but I think you're
getting things mixed up like.

PAUL. She's gone mad.

VIRGINIA. Have I aunt?

MRS. MUNNING. I don't know, Jenny.

VIRGINIA. You do know. You know Joe Wrigley has the power to
ruin you unless Martha becomes Mrs. Munning. She's going to
become Mrs. Munning, but not Mrs. Zack Munning.

ZACK. But I've passed my word to Martha. We've had banns called
in church.

VIRGINIA. Are you in love with Martha, Zack?

ZACK. Well——

VIRGINIA. Are you or are you not?

ZACK. You do ask the awkwardest questions, Virginia.

VIRGINIA. That's good enough for me. Martha, it's a pity to waste
that wedding-dress. Would you rather marry Zack or Paul?

MARTHA. I've never dared to lift my eyes as high as Mr. Paul.


VIRGINIA. It's not so high. Stand on a chair if it'll make you feel
easier. It's like this, Martha. Paul's missing something by not
marrying me, but there's a matter of five hundred pounds that I'll
give him in the vestry on his wedding-day with you. Of course if he
doesn't marry you there's no five hundred pounds, and there is your
father.

MRS. MUNNING. And a new manager for my business too.

PAUL. Mother!

VIRGINIA. So you've got it all three ways, Paul. Martha, you


needn't be afraid. Canada with Zack was the riskiest gamble a
woman ever thought of, but England with Paul is something solid.
You'll have friends to Watch you and to watch Paul, too.

PAUL. But—but——

VIRGINIA. That's all right, Paul. You needn't thank me now. And if
you'd like to take Martha out for a walk, I shan't prevent you.

MARTHA. Me walk through Little Hulton by the side of Mr. Paul!


Oh, Miss Virginia, I'd never have the face.

VIRGINIA. I've told you you're bringing him good money. You give
and he takes.

PAUL. Do I take?

VIRGINIA. Don't you?

PAUL. Mother, have you nothing to say?

VIRGINIA. She's come down on the right side of the fence at last,
Paul.

MRS. MUNNING. I'll not pretend I'm pleased, but it's a way out.
PAUL. You'd see me sacrificed like this?

MRS. MUNNING. You'll not forget that Martha's in the room, will
you?

ZACK. I suppose I'll do wrong thing if I open my mouth, but I'll


speak my mind for once and chance it.

VIRGINIA. What's the matter, Zack? You didn't want to marry


Martha?

ZACK. I didn't and I did. I've no right to be selfish, and I didn't like
the thought of it at first. I'm the wrong sort of husband for her as I
am.

VIRGINIA. Very well, then———

ZACK. Aye. As I am I'm wrong, and I know I'm wrong. But I might
not be so wrong in Canada. I've never had a chance afore, and this
thing's grown on me a bit. I've wanted my chance, and it looked like
I was getting it. You never know what a foreign country will do for a
man, and Canada began to look a chance to me. I'd hopes of
Canada. And now you say I'm not to marry Martha, and I'll never get
a chance again.

MARTHA. I'd rather marry Mr. Paul, if he's willing, Zack.

VIRGINIA. He's willing.

ZACK. Maybe you're right, Martha. Paul's a bigger man than me


and I mustn't be selfish. But I'd begun to be hopeful, and I own this
is a blow to me. I'll go out for a breath of air.

VIRGINIA. Stay where you are, Zack. Paul and Martha are going
out together.
PAUL. That's advertising it a bit, and her in her wedding-gown and
all.

VIRGINIA. It's meant to advertise it, Paul. There's your hat. Give
her your arm now.

MARTHA. Oh, Mr. Paul!

(They go up to door, arm in arm.)

VIRGINIA. And I'll tell you something, Paul. You're great at talking
of the cost of things. A pleasant look costs no more than a sour one,
so see what you can do.

(Exeunt Paul and Martha. Virginia closes door.)

Now then, aunt, is there anything you'd like to say to Zack?

MRS. MUNNING. He's the cause of more trouble than he's worth,
and has been since the day he was born.

ZACK. Yes, mother. I knew it must be all my fault some road.

VIRGINIA. I suppose that way of speaking to him is force of habit,


aunt. But it's time you changed your habits now. Don't you think
you'd feel better if you apologized to Zack?

MRS. MUNNING. Apologized!

VIRGINIA. I've a belief myself in paying debts.

MRS. MUNNING. I don't owe Zack for much.

VIRGINIA. Only thirty years' neglect.

ZACK. You mustn't talk like that to mother, Jenny. You can't expect
a great soft thing like me to get same care taken of him as she took
of Paul. You don't treat carthorses like you'd treat a racer.

VIRGINIA (to Mrs. Munning, ignoring Zack). So you've nothing to


say to him?

MRS. MUNNING. I don't know that I have.

VIRGINIA. You're leaving quite a lot to me.

MRS. MUNNING. We know what's good for Zack. Some folk don't
pay for kindness.

VIRGINIA. Some never get a chance. Zack's had your method long
enough. We'll try mine now.

MRS. MUNNING. And what is yours?

VIRGINIA. Bring me some hot water and a towel, Zack.

ZACK. Hot water?

VIRGINIA. In a jug.

ZACK. Yes, Jenny. I knew there'd be hot water in it somewhere.


(Exit Zack.)

MRS. MUNNING. What's this for?

VIRGINIA. A clean start and a clean chin and Zack's first lesson in
the art of self-respect.

MRS. MUNNING. Meaning you're going to swell his head.

VIRGINIA. No, aunt. Only to shave his beard. I'm going to talk to
Zack and a lather-brush will be a handy thing to stop his mouth with
if he tries to answer back before I've done.
(Zack re-enters with steaming jug and a towel.)

ZACK. It's very hot. I found the kettle on the boil.

VIRGINIA. All the better.

ZACK (apprehensively). Yes, Jenny.

MRS. MUNNING. And you think I'll stay here and watch you do it?

VIRGINIA. Well, aunt, I rather hoped you wouldn't.

MRS. MUNNING. You're taking charge of things, young lady.

VIRGINIA. I've come to the conclusion that it's time. (Mrs.


Munning meets her eye, quails and goes out.) Zack, go upstairs and
bring me down the birthday present that I gave you.

ZACK. It's not upstairs, Jenny.

VIRGINIA. Where is it, then? I want it.

ZACK. I keep it in my pocket.

VIRGINIA. No wonder your coat fits like a sack. Give it me.

ZACK. You're not going to take it off me because I didn't use it,
are you?

VIRGINIA. I'm going to use it. Sit down. (She pushes him into
chair and puts towel round his neck.) Tell me why you carried this
about with you.

ZACK. It's because I——— (hesitates.)

VIRGINIA. Well?
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookball.com

You might also like