0% found this document useful (0 votes)
45 views

Full download Data structures and algorithms made easy in Java data structure and algorithmic puzzles 2nd Edition Narasimha Karumanchi pdf docx

puzzles

Uploaded by

zulmifagade47
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Full download Data structures and algorithms made easy in Java data structure and algorithmic puzzles 2nd Edition Narasimha Karumanchi pdf docx

puzzles

Uploaded by

zulmifagade47
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Download the full version of the ebook at

https://ebookgate.com

Data structures and algorithms made easy in


Java data structure and algorithmic puzzles
2nd Edition Narasimha Karumanchi

https://ebookgate.com/product/data-structures-and-
algorithms-made-easy-in-java-data-structure-and-
algorithmic-puzzles-2nd-edition-narasimha-
karumanchi/

Explore and download more ebook at https://ebookgate.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Data Structures Algorithms And Applications In C 2nd


Edition Sartaj Sahni

https://ebookgate.com/product/data-structures-algorithms-and-
applications-in-c-2nd-edition-sartaj-sahni/

ebookgate.com

Java Structures Data Structures in Java for the Principled


Programmer 2nd edition Duane Bailey

https://ebookgate.com/product/java-structures-data-structures-in-java-
for-the-principled-programmer-2nd-edition-duane-bailey/

ebookgate.com

Data structures and abstractions with Java 2nd ed Edition


Carrano

https://ebookgate.com/product/data-structures-and-abstractions-with-
java-2nd-ed-edition-carrano/

ebookgate.com

Data Structures and Algorithms in C 4th Edition Adam


Drozdek

https://ebookgate.com/product/data-structures-and-algorithms-in-c-4th-
edition-adam-drozdek/

ebookgate.com
Data Structures and Algorithms in C 1st Edition Michael
Mcmillan

https://ebookgate.com/product/data-structures-and-algorithms-in-c-1st-
edition-michael-mcmillan/

ebookgate.com

Data Structures and Algorithms Using C 1st Edition Michael


Mcmillan

https://ebookgate.com/product/data-structures-and-algorithms-
using-c-1st-edition-michael-mcmillan/

ebookgate.com

Java Software Structures Designing and Using Data


Structures 3rd Edition John Lewis

https://ebookgate.com/product/java-software-structures-designing-and-
using-data-structures-3rd-edition-john-lewis/

ebookgate.com

Java Foundations Introduction to Program Design and Data


Structures 2nd Edition John Lewis

https://ebookgate.com/product/java-foundations-introduction-to-
program-design-and-data-structures-2nd-edition-john-lewis/

ebookgate.com

Data Structures Outside In with Java 1st Edition Sesh


Venugopal

https://ebookgate.com/product/data-structures-outside-in-with-
java-1st-edition-sesh-venugopal/

ebookgate.com
Data Structures
And
Algorithms
Made Easy In JAVA
Data Structures and Algorithmic Puzzles

By
Narasimha Karumanchi

Concepts Problems Interview Questions


Copyright ©2020 by .
All rights reserved.
Designed by ℎ ℎ

©
Copyright 2020 CareerMonk Publications. All rights reserved.
All rights reserved. No part of this book may be reproduced in any form or by any electronic or mechanical means, including information
storage and retrieval systems, without written permission from the publisher or author.

This book has been published with all efforts taken to make the material error-free after the consent of the author. However, the author and
the publisher do not assume and hereby disclaim any liability to any party for any loss, damage, or disruption caused by errors or omissions,
whether such errors or omissions result from negligence, accident, or any other cause.

While every effort has been made to avoid any mistake or omission, this publication is being sold on the condition and understanding that
neither the author nor the publishers or printers would be liable in any manner to any person by reason of any mistake or omission in this
publication or for any action taken or omitted to be taken or advice rendered or accepted on the basis of this work. For any defect in printing
or binding the publishers will be liable only to replace the defective copy by another copy of this work then available.
Acknowledgements
ℎ and ℎ , it is impossible to thank you adequately for everything you have done, from loving me unconditionally to raising me in
a stable household, where your persistent efforts and traditional values taught your children to celebrate and embrace life. I could not have
asked for better parents or role-models. You showed me that anything is possible with faith, hard work and determination.

This book would not have been possible without the help of many people. I would like to express my gratitude to all of the people who
provided support, talked things over, read, wrote, offered comments, allowed me to quote their remarks and assisted in the editing,
proofreading and design. In particular, I would like to thank the following individuals:

 ℎ , IIT Bombay, Architect, dataRPM Pvt. Ltd.


 , Senior Consultant, Juniper Networks Inc.
 . ℎ ℎ , IIT Kanpur, Mentor Graphics Inc.

- ℎ ℎ
M-Tech,
Founder, .
Preface
Dear Reader,

Please hold on! I know many people typically do not read the Preface of a book. But I strongly recommend that you read this particular
Preface.

It is not the main objective of this book to present you with the theorems and proofs on and ℎ . I have followed
a pattern of improving the problem solutions with different complexities (for each problem, you will find multiple solutions with different,
and reduced, complexities). Basically, it’s an enumeration of possible solutions. With this approach, even if you get a new question, it will
show you a way to think about the possible solutions. You will find this book useful for interview preparation, competitive exams preparation,
and campus interview preparations.

As a , if you read the complete book, I am sure you will be able to challenge the interviewers. If you read it as an , it
will help you to deliver lectures with an approach that is easy to follow, and as a result your students will appreciate the fact that they have
opted for Computer Science / Information Technology as their degree.

This book is also useful for and during their academic preparations. In all the
chapters you will see that there is more emphasis on problems and their analysis rather than on theory. In each chapter, you will first read
about the basic required theory, which is then followed by a section on problem sets. In total, there are approximately 700 algorithmic
problems, all with solutions.

If you read the book as a preparing for competitive exams for Computer Science / Information Technology, the content covers
the topics in full detail. While writing this book, my main focus was to help students who are preparing for these exams.

In all the chapters you will see more emphasis on problems and analysis rather than on theory. In each chapter, you will first see the basic
required theory followed by various problems.

For many problems, solutions are provided with different levels of complexity. We start with the solution and slowly
move toward the possible for that problem. For each problem, we endeavor to understand how much time the algorithm takes
and how much memory the algorithm uses.

It is recommended that the reader does at least one complete reading of this book to gain a full understanding of all the topics that are
covered. Then, in subsequent readings you can skip directly to any chapter to refer to a specific topic. Even though many readings have been
done for the purpose of correcting errors, there could still be some minor typos in the book. If any are found, they will be updated
at . . . You can monitor this site for any corrections and also for new problems and solutions. Also, please provide
your valuable suggestions at: @ . .

I wish you all the best and I am confident that you will find this book useful.

- ℎ ℎ
M-Tech,
Founder, .
Other Books by Narasimha Karumanchi

IT Interview Questions
Elements of Computer Networking
Data Structures and Algorithmic Thinking with Python
Data Structures and Algorithms Made Easy (C/C++)
Coding Interview Questions
Data Structures and Algorithms for GATE
Peeling Design Patterns
Algorithm Design Techniques
Data Structure Operations Cheat Sheet
Space
Average Case Time Complexity Worst Case Time Complexity
Data Structure Complexity
Name Accessing Accessing
Search Insertion Deletion Search Insertion Deletion Worst Case
element element
Arrays O(1) O( ) O( ) O( ) O(1) O( ) O( ) O( ) O( )
Stacks O( ) O( ) O(1) O(1) O( ) O( ) O(1) O(1) O( )
Queues O( ) O( ) O(1) O(1) O( ) O( ) O(1) O(1) O( )
Binary Trees O( ) O( ) O( ) O( ) O( ) O( ) O( ) O( ) O( )
Binary Search
O( ) O( ) O( ) O( ) O( ) O( ) O( ) O( ) O( )
Trees
Balanced
Binary Search O( ) O( ) O( ) O( ) O( ) O( ) O( ) O( ) O( )
Trees
Hash Tables N/A O(1) O(1) O(1) N/A O( ) O( ) O( ) O( )

Note: For best case operations, the time complexities are O(1).

Sorting Algorithms Cheat Sheet


Space
Sorting Time Complexity
Complexity Is Sorting Class
Algorithm Remarks
Best Average Worst Stable? Type
Name Worst Case
Case Case Case
Bubble Sort O( ) O( ) O( ) O(1) Yes Comparison Not a preferred sorting algorithm.
In the best case (already sorted), every
Insertion Sort O( ) O( ) O( ) O(1) Yes Comparison
insert requires constant time
Even a perfectly sorted array requires
Selection Sort O( ) O( ) O( ) O(1) Yes Comparison
scanning the entire array
On arrays, it requires O( ) space; and on
Merge Sort O( ) O( ) O( ) O( ) Yes Comparison
linked lists, it requires constant space
By using input array as storage for the
Heap Sort O( ) O( ) O( ) O(1) No Comparison heap, it is possible to achieve constant
space
Randomly picking a pivot value can help
Quick Sort O( ) O( ) O( ) O( ) No Comparison avoid worst case scenarios such as a
perfectly sorted array.
Performing inorder traversal on the
Tree Sort O( ) O( ) O( ) O( ) Yes Comparison
balanced binary search tree.
Where is the range of the non-negative
Counting Sort O( + ) O( + ) O( + ) O( ) Yes Linear
key values.
Bucket sort is stable, if the underlying
Bucket Sort O( + ) O( + ) O( ) O( ) Yes Linear
sorting algorithm is stable.
Radix sort is stable, if the underlying
Radix Sort O( ) O( ) O( ) O( + ) Yes Linear
sorting algorithm is stable.
Table of Contents
1. Introduction -------------------------------------------------------------------------------------------------------------------------------------------------------------------- 15
1.1 Variables ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 15
1.2 Data Types --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 15
1.3 Data Structure ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- 16
1.4 Abstract Data Types (ADTs) ------------------------------------------------------------------------------------------------------------------------------------------------- 16
1.5 What is an Algorithm? ---------------------------------------------------------------------------------------------------------------------------------------------------------- 16
1.6 Why the Analysis of Algorithms? ------------------------------------------------------------------------------------------------------------------------------------------- 16
1.7 Goal of the Analysis of Algorithms ----------------------------------------------------------------------------------------------------------------------------------------- 17
1.8 What is Running Time Analysis? ------------------------------------------------------------------------------------------------------------------------------------------- 17
1.9 How to Compare Algorithms------------------------------------------------------------------------------------------------------------------------------------------------- 17
1.10 What is Rate of Growth? ----------------------------------------------------------------------------------------------------------------------------------------------------- 17
1.11 Commonly Used Rates of Growth --------------------------------------------------------------------------------------------------------------------------------------- 17
1.12 Types of Analysis ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 18
1.13 Asymptotic Notation ----------------------------------------------------------------------------------------------------------------------------------------------------------- 19
1.14 Big-O Notation ------------------------------------------------------------------------------------------------------------------------------------------------------------------- 19
1.15 Omega-Ω Notation [Lower Bounding Function] ------------------------------------------------------------------------------------------------------------------- 20
1.16 Theta- Notation---------------------------------------------------------------------------------------------------------------------------------------------------------------- 20
1.17 Why is it called Asymptotic Analysis?----------------------------------------------------------------------------------------------------------------------------------- 21
1.18 Guidelines for Asymptotic Analysis -------------------------------------------------------------------------------------------------------------------------------------- 21
1.20 Simplifying properties of asymptotic notations ---------------------------------------------------------------------------------------------------------------------- 22
1.21 Commonly used Logarithms and Summations ---------------------------------------------------------------------------------------------------------------------- 22
1.22 Master Theorem for Divide and Conquer Recurrences --------------------------------------------------------------------------------------------------------- 23
1.23 Divide and Conquer Master Theorem: Problems & Solutions ----------------------------------------------------------------------------------------------- 23
1.24 Master Theorem for Subtract and Conquer Recurrences------------------------------------------------------------------------------------------------------- 24
1.25 Variant of Subtraction and Conquer Master Theorem----------------------------------------------------------------------------------------------------------- 24
1.26 Method of Guessing and Confirming ----------------------------------------------------------------------------------------------------------------------------------- 24
1.27 Amortized Analysis ------------------------------------------------------------------------------------------------------------------------------------------------------------- 26
1.28 Algorithms Analysis: Problems & Solutions -------------------------------------------------------------------------------------------------------------------------- 26
2. Recursion and Backtracking --------------------------------------------------------------------------------------------------------------------------------------------- 36
2.1 Introduction ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 36
2.2 What is Recursion?--------------------------------------------------------------------------------------------------------------------------------------------------------------- 36
2.3 Why Recursion? ------------------------------------------------------------------------------------------------------------------------------------------------------------------- 36
2.4 Format of a Recursive Function --------------------------------------------------------------------------------------------------------------------------------------------- 36
2.5 Recursion and Memory (Visualization)----------------------------------------------------------------------------------------------------------------------------------- 37
2.6 Recursion versus Iteration ----------------------------------------------------------------------------------------------------------------------------------------------------- 37
2.7 Notes on Recursion -------------------------------------------------------------------------------------------------------------------------------------------------------------- 38
2.8 Example Algorithms of Recursion------------------------------------------------------------------------------------------------------------------------------------------ 38
2.9 Recursion: Problems & Solutions------------------------------------------------------------------------------------------------------------------------------------------- 38
2.10 What is Backtracking?--------------------------------------------------------------------------------------------------------------------------------------------------------- 39
2.11 Example Algorithms of Backtracking ----------------------------------------------------------------------------------------------------------------------------------- 39
2.12 Backtracking: Problems & Solutions------------------------------------------------------------------------------------------------------------------------------------- 39
3. Linked Lists--------------------------------------------------------------------------------------------------------------------------------------------------------------------- 41
3.1 What is a Linked List? ---------------------------------------------------------------------------------------------------------------------------------------------------------- 41
3.2 Linked Lists ADT----------------------------------------------------------------------------------------------------------------------------------------------------------------- 41
3.3 Why Linked Lists? --------------------------------------------------------------------------------------------------------------------------------------------------------------- 41
3.4 Arrays Overview ------------------------------------------------------------------------------------------------------------------------------------------------------------------- 41
3.5 Comparison of Linked Lists with Arrays & Dynamic Arrays ---------------------------------------------------------------------------------------------------- 42
3.6 Singly Linked Lists ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 42
3.7 Doubly Linked Lists ------------------------------------------------------------------------------------------------------------------------------------------------------------- 48
3.8 Circular Linked Lists------------------------------------------------------------------------------------------------------------------------------------------------------------- 54
3.9 A Memory-efficient Doubly Linked List--------------------------------------------------------------------------------------------------------------------------------- 59
3.10 Unrolled Linked Lists --------------------------------------------------------------------------------------------------------------------------------------------------------- 59
3.11 Skip Lists---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 67
3.11 Linked Lists: Problems & Solutions ------------------------------------------------------------------------------------------------------------------------------------- 70
4. Stacks ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 91
4.1 What is a Stack? ------------------------------------------------------------------------------------------------------------------------------------------------------------------- 91
4.2 How Stacks are used ------------------------------------------------------------------------------------------------------------------------------------------------------------- 91
4.3 Stack ADT --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 91
4.4 Applications ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 92
4.5 Implementation -------------------------------------------------------------------------------------------------------------------------------------------------------------------- 92
4.6 Comparison of Implementations ------------------------------------------------------------------------------------------------------------------------------------------- 97
4.8 Stacks: Problems & Solutions ------------------------------------------------------------------------------------------------------------------------------------------------ 97
5. Queues ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 115
5.1 What is a Queue? --------------------------------------------------------------------------------------------------------------------------------------------------------------- 115
5.2 How are Queues Used? ------------------------------------------------------------------------------------------------------------------------------------------------------ 115
5.3 Queue ADT----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 115
5.4 Exceptions-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 115
5.5 Applications ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 115
5.6 Implementation ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 116
5.7 Queues: Problems & Solutions -------------------------------------------------------------------------------------------------------------------------------------------- 121
6. Trees ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 125
6.1 What is a Tree? ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 125
6.2 Glossary ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 125
6.3 Binary Trees----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 126
6.4 Types of Binary Trees--------------------------------------------------------------------------------------------------------------------------------------------------------- 126
6.5 Properties of Binary Trees--------------------------------------------------------------------------------------------------------------------------------------------------- 126
6.4 Binary Tree Traversals -------------------------------------------------------------------------------------------------------------------------------------------------------- 128
6.5 Generic Trees (N-ary Trees)------------------------------------------------------------------------------------------------------------------------------------------------ 149
6.6 Threaded (Stack or Queue less) Binary Tree Traversals-------------------------------------------------------------------------------------------------------- 154
6.7 Expression Trees ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 158
6.10 XOR Trees ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- 160
6.9 Binary Search Trees (BSTs) ------------------------------------------------------------------------------------------------------------------------------------------------ 161
6.10 Balanced Binary Search Trees ------------------------------------------------------------------------------------------------------------------------------------------- 172
6.11 AVL (Adelson-Velskii and Landis) Trees --------------------------------------------------------------------------------------------------------------------------- 172
6.12 Other Variations on Trees ------------------------------------------------------------------------------------------------------------------------------------------------- 183
6.13 Supplementary Questions-------------------------------------------------------------------------------------------------------------------------------------------------- 186
7. Priority Queues and Heaps -------------------------------------------------------------------------------------------------------------------------------------------- 187
7.1 What is a Priority Queue? --------------------------------------------------------------------------------------------------------------------------------------------------- 187
7.2 Priority Queue ADT----------------------------------------------------------------------------------------------------------------------------------------------------------- 187
7.3 Priority Queue Applications ------------------------------------------------------------------------------------------------------------------------------------------------ 187
7.4 Priority Queue Implementations------------------------------------------------------------------------------------------------------------------------------------------ 187
7.5 Heaps and Binary Heaps----------------------------------------------------------------------------------------------------------------------------------------------------- 188
7.6 Binary Heaps---------------------------------------------------------------------------------------------------------------------------------------------------------------------- 189
7.7 Priority Queues [Heaps]: Problems & Solutions ------------------------------------------------------------------------------------------------------------------- 193
8. Disjoint Sets ADT --------------------------------------------------------------------------------------------------------------------------------------------------------- 203
8.1 Introduction ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 203
8.2 Equivalence Relations and Equivalence Classes -------------------------------------------------------------------------------------------------------------------- 203
8.3 Disjoint Sets ADT -------------------------------------------------------------------------------------------------------------------------------------------------------------- 203
8.4 Applications ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 203
8.5 Tradeoffs in Implementing Disjoint Sets ADT --------------------------------------------------------------------------------------------------------------------- 204
8.8 Fast UNION Implementation (Slow FIND) ------------------------------------------------------------------------------------------------------------------------- 204
8.7 Fast UNION Implementations (Quick FIND)---------------------------------------------------------------------------------------------------------------------- 206
8.8 Path Compression--------------------------------------------------------------------------------------------------------------------------------------------------------------- 207
8.9 Summary---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 208
8.10 Disjoint Sets: Problems & Solutions ----------------------------------------------------------------------------------------------------------------------------------- 208
9. Graph Algorithms ---------------------------------------------------------------------------------------------------------------------------------------------------------- 210
9.1 Introduction ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 210
9.2 Glossary ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 210
9.3 Applications of Graphs-------------------------------------------------------------------------------------------------------------------------------------------------------- 212
9.4 Graph Representation --------------------------------------------------------------------------------------------------------------------------------------------------------- 212
9.5 Graph Traversals ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 217
9.6 Topological Sort ----------------------------------------------------------------------------------------------------------------------------------------------------------------- 224
9.7 Shortest Path Algorithms ----------------------------------------------------------------------------------------------------------------------------------------------------- 226
9.8 Minimal Spanning Tree ------------------------------------------------------------------------------------------------------------------------------------------------------ 232
9.9 Graph Algorithms: Problems & Solutions----------------------------------------------------------------------------------------------------------------------------- 235
10. Sorting -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 249
10.1 What is Sorting? --------------------------------------------------------------------------------------------------------------------------------------------------------------- 249
10.2 Why is Sorting Necessary? ------------------------------------------------------------------------------------------------------------------------------------------------ 249
10.3 Classification of Sorting Algorithms ------------------------------------------------------------------------------------------------------------------------------------ 249
10.4 Other Classifications --------------------------------------------------------------------------------------------------------------------------------------------------------- 249
10.5 Bubble Sort ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- 250
10.6 Selection Sort-------------------------------------------------------------------------------------------------------------------------------------------------------------------- 251
10.7 Insertion Sort-------------------------------------------------------------------------------------------------------------------------------------------------------------------- 252
10.8 Shell Sort-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 254
10.9 Merge Sort------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 254
10.10 Heap Sort ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 257
10.11 Quick Sort ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- 257
10.12 Tree Sort ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 261
10.13 Comparison of Sorting Algorithms ----------------------------------------------------------------------------------------------------------------------------------- 261
10.14 Linear Sorting Algorithms------------------------------------------------------------------------------------------------------------------------------------------------ 261
10.15 Counting Sort------------------------------------------------------------------------------------------------------------------------------------------------------------------ 261
10.16 Bucket sort (Bin Sort)------------------------------------------------------------------------------------------------------------------------------------------------------ 262
10.17 Radix Sort----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 262
10.18 Topological Sort ------------------------------------------------------------------------------------------------------------------------------------------------------------- 263
10.19 External Sorting -------------------------------------------------------------------------------------------------------------------------------------------------------------- 263
10.20 Sorting: Problems & Solutions ----------------------------------------------------------------------------------------------------------------------------------------- 264
11. Searching----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 274
11.1 What is Searching? ----------------------------------------------------------------------------------------------------------------------------------------------------------- 274
11.2 Why do we need Searching?---------------------------------------------------------------------------------------------------------------------------------------------- 274
11.3 Types of Searching------------------------------------------------------------------------------------------------------------------------------------------------------------ 274
11.4 Unordered Linear Search -------------------------------------------------------------------------------------------------------------------------------------------------- 274
11.5 Sorted/Ordered Linear Search------------------------------------------------------------------------------------------------------------------------------------------- 274
11.6 Binary Search ------------------------------------------------------------------------------------------------------------------------------------------------------------------- 275
11.7 Interpolation Search---------------------------------------------------------------------------------------------------------------------------------------------------------- 275
11.8 Comparing Basic Searching Algorithms ------------------------------------------------------------------------------------------------------------------------------ 276
11.9 Symbol Tables and Hashing -------------------------------------------------------------------------------------------------------------------------------------------- 277
11.10 String Searching Algorithms ------------------------------------------------------------------------------------------------------------------------------------------ 277
11.11 Searching: Problems & Solutions-------------------------------------------------------------------------------------------------------------------------------------- 277
12. Selection Algorithms [Medians] -------------------------------------------------------------------------------------------------------------------------------------- 297
12.1 What are Selection Algorithms?----------------------------------------------------------------------------------------------------------------------------------------- 297
12.2 Selection by Sorting----------------------------------------------------------------------------------------------------------------------------------------------------------- 297
12.3 Partition-based Selection Algorithm ----------------------------------------------------------------------------------------------------------------------------------- 297
12.4 Linear Selection Algorithm - Median of Medians Algorithm ------------------------------------------------------------------------------------------------ 297
12.5 Finding the K Smallest Elements in Sorted Order --------------------------------------------------------------------------------------------------------------- 297
12.6 Selection Algorithms: Problems & Solutions ----------------------------------------------------------------------------------------------------------------------- 297
13. Symbol Tables --------------------------------------------------------------------------------------------------------------------------------------------------------------- 305
13.1 Introduction --------------------------------------------------------------------------------------------------------------------------------------------------------------------- 305
13.2 What are Symbol Tables? ------------------------------------------------------------------------------------------------------------------------------------------------- 305
13.3 Symbol Table Implementations ----------------------------------------------------------------------------------------------------------------------------------------- 305
13.4 Comparison Table of Symbols for Implementations ----------------------------------------------------------------------------------------------------------- 306
14. Hashing ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 307
14.1 What is Hashing?-------------------------------------------------------------------------------------------------------------------------------------------------------------- 307
14.2 Why Hashing?------------------------------------------------------------------------------------------------------------------------------------------------------------------ 307
14.3 Hash Table ADT-------------------------------------------------------------------------------------------------------------------------------------------------------------- 307
14.4 Understanding Hashing ----------------------------------------------------------------------------------------------------------------------------------------------------- 307
14.5 Components of Hashing ---------------------------------------------------------------------------------------------------------------------------------------------------- 308
14.6 Hash Table----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 308
14.7 Hash Function ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 309
14.8 Load Factor ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- 309
14.9 Collisions-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 310
14.10 Collision Resolution Techniques-------------------------------------------------------------------------------------------------------------------------------------- 310
14.11 Separate Chaining ----------------------------------------------------------------------------------------------------------------------------------------------------------- 310
14.12 Open Addressing ------------------------------------------------------------------------------------------------------------------------------------------------------------ 311
14.13 Comparison of Collision Resolution Techniques -------------------------------------------------------------------------------------------------------------- 312
14.14 How Hashing Gets O(1) Complexity -------------------------------------------------------------------------------------------------------------------------------- 312
14.15 Hashing Techniques-------------------------------------------------------------------------------------------------------------------------------------------------------- 312
14.16 Problems for which Hash Tables are not suitable -------------------------------------------------------------------------------------------------------------- 312
14.17 Bloom Filters ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 312
14.18 Hashing: Problems & Solutions---------------------------------------------------------------------------------------------------------------------------------------- 314
15. String Algorithms ----------------------------------------------------------------------------------------------------------------------------------------------------------- 322
15.1 Introduction --------------------------------------------------------------------------------------------------------------------------------------------------------------------- 322
15.2 String Matching Algorithms ----------------------------------------------------------------------------------------------------------------------------------------------- 322
15.3 Brute Force Method --------------------------------------------------------------------------------------------------------------------------------------------------------- 322
15.4 Rabin-Karp String Matching Algorithm ------------------------------------------------------------------------------------------------------------------------------ 323
15.5 String Matching with Finite Automata--------------------------------------------------------------------------------------------------------------------------------- 323
15.6 KMP Algorithm ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 324
15.7 Boyer-Moore Algorithm ---------------------------------------------------------------------------------------------------------------------------------------------------- 326
15.8 Data Structures for Storing Strings-------------------------------------------------------------------------------------------------------------------------------------- 327
15.9 Hash Tables for Strings ----------------------------------------------------------------------------------------------------------------------------------------------------- 327
15.10 Binary Search Trees for Strings ---------------------------------------------------------------------------------------------------------------------------------------- 327
15.11 Tries------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 327
15.12 Ternary Search Trees ------------------------------------------------------------------------------------------------------------------------------------------------------ 329
15.13 Comparing BSTs, Tries and TSTs ----------------------------------------------------------------------------------------------------------------------------------- 332
15.14 Suffix Trees -------------------------------------------------------------------------------------------------------------------------------------------------------------------- 332
15.15 String Algorithms: Problems & Solutions -------------------------------------------------------------------------------------------------------------------------- 334
16. Algorithms Design Techniques --------------------------------------------------------------------------------------------------------------------------------------- 344
16.1 Introduction --------------------------------------------------------------------------------------------------------------------------------------------------------------------- 344
16.2 Classification--------------------------------------------------------------------------------------------------------------------------------------------------------------------- 344
16.3 Classification by Implementation Method--------------------------------------------------------------------------------------------------------------------------- 344
16.4 Classification by Design Method ---------------------------------------------------------------------------------------------------------------------------------------- 345
16.5 Other Classifications --------------------------------------------------------------------------------------------------------------------------------------------------------- 345
17. Greedy Algorithms--------------------------------------------------------------------------------------------------------------------------------------------------------- 346
17.1 Introduction --------------------------------------------------------------------------------------------------------------------------------------------------------------------- 346
17.2 Greedy Strategy----------------------------------------------------------------------------------------------------------------------------------------------------------------- 346
17.3 Elements of Greedy Algorithms ----------------------------------------------------------------------------------------------------------------------------------------- 346
17.4 Does Greedy Always Work? --------------------------------------------------------------------------------------------------------------------------------------------- 346
17.5 Advantages and Disadvantages of Greedy Method -------------------------------------------------------------------------------------------------------------- 346
17.6 Greedy Applications---------------------------------------------------------------------------------------------------------------------------------------------------------- 346
17.7 Understanding Greedy Technique ------------------------------------------------------------------------------------------------------------------------------------- 347
17.8 Greedy Algorithms: Problems & Solutions ------------------------------------------------------------------------------------------------------------------------- 349
18. Divide and Conquer Algorithms ------------------------------------------------------------------------------------------------------------------------------------- 354
18.1 Introduction --------------------------------------------------------------------------------------------------------------------------------------------------------------------- 354
18.2 What is the Divide and Conquer Strategy? ------------------------------------------------------------------------------------------------------------------------- 354
18.3 Does Divide and Conquer Always Work? -------------------------------------------------------------------------------------------------------------------------- 354
18.4 Divide and Conquer Visualization -------------------------------------------------------------------------------------------------------------------------------------- 354
18.5 Understanding Divide and Conquer----------------------------------------------------------------------------------------------------------------------------------- 355
18.6 Advantages of Divide and Conquer ------------------------------------------------------------------------------------------------------------------------------------ 355
18.7 Disadvantages of Divide and Conquer -------------------------------------------------------------------------------------------------------------------------------- 355
18.8 Master Theorem --------------------------------------------------------------------------------------------------------------------------------------------------------------- 355
18.9 Divide and Conquer Applications -------------------------------------------------------------------------------------------------------------------------------------- 356
18.10 Divide and Conquer: Problems & Solutions --------------------------------------------------------------------------------------------------------------------- 356
19. Dynamic Programming -------------------------------------------------------------------------------------------------------------------------------------------------- 368
19.1 Introduction --------------------------------------------------------------------------------------------------------------------------------------------------------------------- 368
19.2 What is Dynamic Programming Strategy?--------------------------------------------------------------------------------------------------------------------------- 368
19.3 Properties of Dynamic Programming Strategy --------------------------------------------------------------------------------------------------------------------- 368
19.4 Greedy vs Divide and Conquer vs DP -------------------------------------------------------------------------------------------------------------------------------- 368
19.5 Can DP solve all problems?----------------------------------------------------------------------------------------------------------------------------------------------- 369
19.6 Dynamic Programming Approaches----------------------------------------------------------------------------------------------------------------------------------- 369
19.7 Understanding DP Approaches ----------------------------------------------------------------------------------------------------------------------------------------- 369
19.8 Examples of DP Algorithms ---------------------------------------------------------------------------------------------------------------------------------------------- 372
19.9 Longest Common Subsequence----------------------------------------------------------------------------------------------------------------------------------------- 372
19.10 Dynamic Programming: Problems & Solutions ----------------------------------------------------------------------------------------------------------------- 374
20. Complexity Classes -------------------------------------------------------------------------------------------------------------------------------------------------------- 396
20.1 Introduction --------------------------------------------------------------------------------------------------------------------------------------------------------------------- 396
20.2 Polynomial/Exponential Time ------------------------------------------------------------------------------------------------------------------------------------------- 396
20.3 What is a Decision Problem? -------------------------------------------------------------------------------------------------------------------------------------------- 396
20.4 Decision Procedure----------------------------------------------------------------------------------------------------------------------------------------------------------- 396
20.5 What is a Complexity Class?---------------------------------------------------------------------------------------------------------------------------------------------- 396
20.6 Types of Complexity Classes --------------------------------------------------------------------------------------------------------------------------------------------- 397
20.7 Reductions------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 398
20.8 Complexity Classes: Problems & Solutions ------------------------------------------------------------------------------------------------------------------------- 400
21. Miscellaneous Concepts ------------------------------------------------------------------------------------------------------------------------------------------------- 402
21.1 Introduction --------------------------------------------------------------------------------------------------------------------------------------------------------------------- 402
21.2 Hacks on Bitwise Programming ----------------------------------------------------------------------------------------------------------------------------------------- 402
21.3 Other Programming Questions ------------------------------------------------------------------------------------------------------------------------------------------ 405
References ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 412
Data Structures and Algorithms Made Easy in Java Introduction

Chapter

INTRODUCTION 1
The objective of this chapter is to explain the importance of the analysis of algorithms, their notations, relationships and solving as many
problems as possible. Let us first focus on understanding the basic elements of algorithms, the importance of algorithm analysis, and then
slowly move toward the other topics as mentioned above. After completing this chapter, you should be able to find the complexity of any
given algorithm (especially recursive functions).

1.1 Variables
Before getting in to the definition of variables, let us relate them to an old mathematical equation. Many of us would have solved many
mathematical equations since childhood. As an example, consider the equation below:
+2 −2 =1
We don’t have to worry about the use of this equation. The important thing that we need to understand is that the equation has names ( and
), which hold values (data). That means the ( and ) are placeholders for representing data. Similarly, in computer science
programming we need something for holding data, and is the way to do that.

1.2 Data Types


In the above-mentioned equation, the variables and can take any values such as integral numbers (10, 20), real numbers (0.23, 5.5), or
just 0 and 1. To solve the equation, we need to relate them to the kind of values they can take, and is the name used in computer
science programming for this purpose. A in a programming language is a set of data with predefined values. Examples of data
types are: integer, floating point, unit number, character, string, etc.
Computer memory is all filled with zeros and ones. If we have a problem and we want to code it, it’s very difficult to provide the solution in
terms of zeros and ones. To help users, programming languages and compilers provide us with data types. For example, takes 2
bytes (actual value depends on compiler), takes 4 bytes, etc. This says that in memory we are combining 2 bytes (16 bits) and calling it
an . Similarly, combining 4 bytes (32 bits) and calling it a . A data type reduces the coding effort. At the top level, there are two
types of data types:
 System-defined data types (also called data types)
 User-defined data types.

System-defined data types (Primitive data types)


Data types that are defined by system are called data types. The primitive data types provided by many programming languages
are: int, float, char, double, bool, etc. The number of bits allocated for each primitive data type depends on the programming languages, the
compiler and the operating system. For the same primitive data type, different languages may use different sizes. Depending on the size of the
data types, the total available values (domain) will also change. For example, “ ” may take 2 bytes or 4 bytes. If it takes 2 bytes (16 bits),
then the total possible values are minus 32,768 to plus 32,767 (-2 2 -1). If it takes 4 bytes (32 bits), then the possible values are between
−2,147,483,648 and +2,147,483,647 (-2 2 -1). The same is the case with other data types.

User-defined data types


If the system-defined data types are not enough, then most programming languages allow the users to define their own data types, called
− . Good examples of user defined data types are: structures in / + + and classes in . For example, in
the snippet below, we are combining many system-defined data types and calling the user defined data type by the name “ ”. This
gives more flexibility and comfort in dealing with computer memory.
public class newType {
public int data1;
public int data 2;
private float data3;

1.1 Variables 15
Data Structures and Algorithms Made Easy in Java Introduction


private char data;
//Operations
}

1.3 Data Structure


Based on the discussion above, once we have data in variables, we need some mechanism for manipulating that data to solve problems.
is a particular way of storing and organizing data in a computer so that it can be used efficiently. A is a
special format for organizing and storing data. General data structure types include arrays, files, linked lists, stacks, queues, trees, graphs and
so on.
Depending on the organization of the elements, data structures are classified into two types:
1) : Elements are accessed in a sequential order but it is not compulsory to store all elements sequentially
(say, Linked Lists). : Linked Lists, Stacks and Queues.
2) − : Elements of this data structure are stored/accessed in a non-linear order. : Trees and
graphs.

1.4 Abstract Data Types (ADTs)


Before defining abstract data types, let us consider the different view of system-defined data types. We all know that, by default, all primitive
data types (int, float, etc.) support basic operations such as addition and subtraction. The system provides the implementations for the primitive
data types. For user-defined data types we also need to define operations. The implementation for these operations can be done when we
want to actually use them. That means, in general, user defined data types are defined along with their operations.
To simplify the process of solving problems, we combine the data structures with their operations and we call this
(ADTs). An ADT consists of parts:
1. Declaration of data
2. Declaration of operations
Commonly used ADTs include: Linked Lists, Stacks, Queues, Priority Queues, Binary Trees, Dictionaries, Disjoint Sets (Union and Find),
Hash Tables, Graphs, and many others. For example, stack uses a LIFO (Last-In-First-Out) mechanism while storing the data in data
structures. The last element inserted into the stack is the first element that gets deleted. Common operations are: creating the stack, push an
element onto the stack, pop an element from the stack, finding the current top of the stack, finding the number of elements in the stack, etc.
While defining the ADTs do not worry about the implementation details. They come into the picture only when we want to use them.
Different kinds of ADTs are suited to different kinds of applications, and some are highly specialized to specific tasks. By the end of this
book, we will go through many of them and you will be in a position to relate the data structures to the kind of problems they solve.

1.5 What is an Algorithm?


Let us consider the problem of preparing an . To prepare an omelette, we follow the steps given below:
1) Get the frying pan.
2) Get the oil.
a. Do we have oil?
i. If yes, put it in the pan.
ii. If no, do we want to buy oil?
1. If yes, then go out and buy.
2. If no, we can terminate.
3) Turn on the stove, etc...
What we are doing is, for a given problem (preparing an omelette), we are providing a step-by-step procedure for solving it. The formal
definition of an algorithm can be stated as:
An algorithm is the step-by-step unambiguous instructions to solve a given problem.
In the traditional study of algorithms, there are two main criteria for judging the merits of algorithms: correctness (does the algorithm give
solution to the problem in a finite number of steps?) and efficiency (how much resources (in terms of memory and time) does it take to
execute the).
Note: We do not have to prove each step of the algorithm.

1.6 Why the Analysis of Algorithms?


To go from city “ ” to city “ ”, there can be many ways of accomplishing this: by flight, by bus, by train and also by bicycle. Depending on
the availability and convenience, we choose the one that suits us. Similarly, in computer science, multiple algorithms are available for solving
the same problem (for example, a sorting problem has many algorithms, like insertion sort, selection sort, quick sort and many more).
Algorithm analysis helps us to determine which algorithm is most efficient in terms of time and space consumed.

1.3 Data Structure 16


Data Structures and Algorithms Made Easy in Java Introduction

1.7 Goal of the Analysis of Algorithms


The analysis of an algorithm can help us understand it better and can suggest informed improvements. The main and important role of
analysis of algorithm is to predict the performance of different algorithms in order to guide design decisions. The goal of the
ℎ is to compare algorithms (or solutions) mainly in terms of running time but also in terms of other factors (e.g.,
memory, developer effort, etc.).
In theoretical analysis of algorithms, it is common to estimate their complexity in the asymptotic sense, i.e., to estimate the complexity function
for arbitrarily large input. The term "analysis of algorithms" was coined by Donald Knuth.
Algorithm analysis is an important part of computational complexity theory, which provides theoretical estimation for the required resources
of an algorithm to solve a specific computational problem. Most algorithms are designed to work with inputs of arbitrary length. Analysis of
algorithms is the determination of the amount of time and space resources required to execute it.
Usually, the efficiency or running time of an algorithm is stated as a function relating the input length to the number of steps, known as time
complexity, or volume of memory, known as space complexity.

1.8 What is Running Time Analysis?


It is the process of determining how processing time increases as the size of the problem (input size) increases. Input size is the number of
elements in the input, and depending on the problem type, the input may be of different types. The following are the common types of inputs.
 Size of an array
 Polynomial degree
 Number of elements in a matrix
 Number of bits in the binary representation of the input
 Vertices and edges in a graph.

1.9 How to Compare Algorithms


To compare algorithms, let us define a few :
Execution times? as execution times are specific to a particular computer.
Number of statements executed? , since the number of statements varies with the programming language as well as the
style of the individual programmer.
Ideal solution? Let us assume that we express the running time of a given algorithm as a function of the input size (i.e., ( )) and compare
these different functions corresponding to running times. This kind of comparison is independent of machine time, programming style, etc.

1.10 What is Rate of Growth?


The rate at which the running time increases as a function of input is called ℎ. Let us assume that you go to a shop to buy a
car and a bicycle. If your friend sees you there and asks what you are buying, then in general you say . This is because the cost
of the car is high compared to the cost of the bicycle (approximating the cost of the bicycle to the cost of the car).
= _ _ + _ _
≈ _ _ ( )
For the above-mentioned example, we can represent the cost of the car and the cost of the bicycle in terms of function, and for a given function
ignore the low order terms that are relatively insignificant (for large value of input size, ). As an example, in the case below, , 2 , 100
and 500 are the individual costs of some function and approximate to since is the highest rate of growth.
+ 2 + 100 + 500 ≈

1.11 Commonly Used Rates of Growth


Below is the list of growth rates you will come across in the following chapters.
Time Complexity Name Description
1 Constant Whatever is the input size , these functions take a constant amount of time.
Logarithmic These are slower growing than even linear functions.
Linear These functions grow linearly with the input size .
Linear Logarithmic Faster growing than linear but slower than quadratic.
Quadratic These functions grow faster than the linear logarithmic functions.
Cubic Faster growing than quadratic but slower than exponential.
2 Exponential Faster than all of the functions mentioned here except the factorial functions.
! Factorial Fastest growing than all these functions mentioned here.

1.7 Goal of the Analysis of Algorithms 17


Data Structures and Algorithms Made Easy in Java Introduction

The diagram below shows the relationship between different rates of growth.

4 D
e
c
2 r
e
a
s
i
log n
g
log ( !)
R
a
t
e
s
2
O
f

G
r
o
w
t
h
log log

1.12 Types of Analysis


To analyze the given algorithm, we need to know with which inputs the algorithm takes less time (performing well) and with which inputs the
algorithm takes a long time. We have already seen that an algorithm can be represented in the form of an expression. That means we represent
the algorithm with multiple expressions: one for the case where it takes less time and another for the case where it takes more time.
In general, the first case is called the and the second case is called the for the algorithm. To analyze an algorithm we
need some kind of syntax, and that forms the base for asymptotic analysis/notation. There are three types of analysis:
 Worst case
o Defines the input for which the algorithm takes a long time (slowest time to complete).
o Input is the one for which the algorithm runs the slowest.
 Best case
o Defines the input for which the algorithm takes the least time (fastest time to complete).
o Input is the one for which the algorithm runs the fastest.
 Average case
o Provides a prediction about the running time of the algorithm.
o Run the algorithm many times, using many different inputs that come from some distribution that generates these
inputs, compute the total running time (by adding the individual times), and divide by the number of trials.
o Assumes that the input is random.
<= <=
For a given algorithm, we can represent the best, worst and average cases in the form of expressions. As an example, let ( ) be the function
which represents the given algorithm.
( )= + 500, for worst case
( )= + 100 + 500, for best case
Similarly for the average case. The expression defines the inputs with which the algorithm takes the average running time (or memory).

1.12 Types of Analysis 18


Data Structures and Algorithms Made Easy in Java Introduction

1.13 Asymptotic Notation


Having the expressions for the best, average and worst cases, for all three cases we need to identify the upper and lower bounds. To represent
these upper and lower bounds, we need some kind of syntax, and that is the subject of the following discussion. Let us assume that the given
algorithm is represented in the form of function ( ).

1.14 Big-O Notation


This notation gives the ℎ upper bound of the given function. Generally, it is represented as ( ) = O( ( )). That means, at larger
values of , the upper bound of ( ) is ( ). For example, if ( ) = + 100 + 10 + 50 is the given algorithm, then is ( ).
That means ( ) gives the maximum rate of growth for ( ) at larger values of .

( )
( )

Rate of growth

Input size,

Let us see the O−notation with a little more detail. O−notation defined as O( ( )) = { ( ): there exist positive constants and such
that 0 ≤ ( ) ≤ ( ) for all ≥ }. ( ) is an asymptotic tight upper bound for ( ). Our objective is to give the smallest rate of
growth ( ) which is greater than or equal to the given algorithms’ rate of growth ( ).
Generally, we discard lower values of . That means the rate of growth at lower values of is not important. In the figure, is the point
from which we need to consider the rate of growth for a given algorithm. Below , the rate of growth could be different. is called threshold
for the given function.

Big-O Visualization
O( ( )) is the set of functions with smaller or the same order of growth as ( ). For example; O( ) includes O(1), O( ), O( ), etc.

O(1): 100,1000, 200,1,20, . O( ):3 + 100, 100 , 2 − 1, 3, .

O( ): 5 , 3 − 100, 2 − O( ): , 5 − 10, 100, −


1, 100, 100 , . 2 + 1, 5, .

Note: Analyze the algorithms at larger values of only. What this means is, below we do not care about the rate of growth.

Big-O Examples
Example-1 Find upper bound for ( ) = 3 + 8
Solution: 3 + 8 ≤ 4 , for all ≥ 8
∴ 3 + 8 = O( ) with c = 4 and =8
Example-2 Find upper bound for ( ) = + 1
Solution: + 1 ≤ 2 , for all ≥ 1
∴ + 1 = O( ) with = 2 and = 1
Example-3 Find upper bound for ( ) = + 100 + 50
Solution: + 100 + 50 ≤ 2 , for all ≥ 11
∴ + 100 + 50 = O( ) with = 2 and = 11
Example-4 Find upper bound for ( ) = 2 − 2
Solution: 2 − 2 ≤ 2 , for all ≥ 1
∴ 2 − 2 = O( ) with = 2 and =1
Example-5 Find upper bound for ( ) =
Solution: ≤ , for all ≥ 1

1.13 Asymptotic Notation 19


Data Structures and Algorithms Made Easy in Java Introduction

∴ = O( ) with = 1 and =1
Example-6 Find upper bound for ( ) = 410
Solution: 410 ≤ 410, for all ≥ 1
∴ 410 = O(1 ) with = 1 and =1

No Uniqueness?
There is no unique set of values for and in proving the asymptotic bounds. Let us consider, 100 + 5 = O( ). For this function there
are multiple and values possible.
Solution1: 100 + 5 ≤ 100 + = 101 ≤ 101 , for all ≥ 5, = 5 and = 101 is a solution.
Solution2: 100 + 5 ≤ 100 + 5 = 105 ≤ 105 , for all ≥ 1, = 1 and = 105 is also a solution.

1.15 Omega-Ω Notation [Lower Bounding Function]


Similar to the O discussion, this notation gives the tighter lower bound of the given algorithm and we represent it as ( ) = ( ( )). That
means, at larger values of , the tighter lower bound of ( ) is ( ). For example, if ( ) = 100 + 10 + 50, ( ) is ( ).

( )
( ))

Rate of growth

Input size,

The Ω notation can be defined as Ω( ( )) = { ( ): there exist positive constants c and such that 0 ≤ ( ) ≤ ( ) for all ≥
}. ( ) is an asymptotic tight lower bound for ( ). Our objective is to give the largest rate of growth ( ) which is less than or equal to
the given algorithm’s rate of growth ( ).

Ω Examples
Example-1 Find lower bound for ( ) = 5 .
Solution:  , Such that: 0  5  5  = 5 and =1
∴5 = ( ) with = 5 and =1
Example-2 Prove ( ) = 100 + 5 ≠ ( ).
Solution:  c, Such that: 0   100 + 5
100 + 5  100 + 5 (  1) = 105
 105  ( – 105)  0
Since is positive  – 105  0   105/
 Contradiction: cannot be smaller than a constant
Example-3 2 = ( ), = ( ), = ( ).

1.16 Theta- Notation


c ( )
( )

Rate of growth c ( )

Input size,

1.15 Omega-Ω Notation [Lower Bounding Function] 20


Another random document with
no related content on Scribd:
CHAPTER XIV
THE UNIVERSITY OF LEE-HIGGINSON

There is a saying that when you go to Philadelphia they ask you


who your grandfather was, and when you go to New York they ask
you what you are worth, and when you go to Boston they ask you
what you know. We are now going to the hub of America’s
intellectual life, and make ourselves familiar with our most highly
cultured university.
We shall begin, as before, by investigating those who run it; and
straightway we shall get a shock. We shall find not merely the
interlocking directorate—the princes, and the dukes, and the barons;
we shall find the emperor himself, none other than J. Pierpont
Morgan! I was puzzled when I studied the affairs of Columbia, for I
knew that the elder Morgan had been on the board until his death,
and I could not imagine how President Butler managed to overlook
his son and heir. When I came to study Harvard I discovered the
reason; the younger Morgan was graduated from Harvard in 1889.
The purpose of such interchanges of royalty is, of course, to cement
the bonds of empire.
The house of J. P. Morgan & Company is closely allied with the
Boston banking house of Lee, Higginson & Company. Mr. Morgan
was reelected to the Harvard board in 1917, along with Francis Lee
Higginson, Jr., of Lee, Higginson & Company; Eliot Wadsworth,
representative of Stone & Webster, an allied banking house; Howard
Elliott, then president and now chairman of the New Haven, a
Morgan railroad; and, finally, a prominent corporation lawyer in San
Francisco, representing the interlocking directorate in that city.
In his discussion of the Pujo report Justice Brandeis wrote that
“Concentration of banking capital has proceeded even farther in
Boston than in New York.” He goes on to tell of three great banking
concerns, with their interlocking directorates, controlling ninety-two
per cent of Boston’s money resources. These concerns competed in
minor and local matters, said Mr. Brandeis, but they were all allied
with Morgan. “Financial concentration seems to have found its
highest exemplification in Boston.” And exactly the same thing is
true of the concentration of control of Harvard University and the
Massachusetts Institute of Technology, and the group of smaller
colleges located in Eastern Massachusetts. They are all “State
Street”—this being the Boston equivalent of “Wall Street.”
In 1916 the New York Evening Post, at that time in rebellion
against the House of Morgan, published an interesting study of the
financial connections of the governing board of Harvard. There are
six members of the Harvard corporation, known as the “fellows,” and
these are appointed for life. In addition, there are thirty “overseers,”
elected by the whole body of graduates. The New York “Evening
Post” examined these latter, and found eleven capitalists and seven
lawyers, a generous majority for the plutocracy. Nor was there much
danger to the plutocracy from some of the others; those classified as
“public men” including Senator Lodge and F. A. Delano, ex-president
of several railroads.
A year later the “Evening Post” made a further examination,
considering not merely the fellows and the overseers, but the nine
directors of the Harvard Alumni Association, the nine members of
the Association’s nominating committee, twenty candidates for
overseers who had just been called, and six who had just been
called as candidates for directors of the Association. That made a
body of eighty Harvard graduates, forty of them Boston men, and
twenty-nine of these forty being financial men, or attorneys for the
State Street houses. All but six were connected with the three
interlocked financial institutions; twenty were connected with Lee,
Higginson & Company or its institutions—nine with the Old Colony
Trust Company, the great Lee-Higginson bank, five with Lee,
Higginson & Company itself, four directors in another Lee-Higginson
bank, six directors in a Lee-Higginson savings bank, six in another
Lee-Higginson savings bank, four in a Lee-Higginson insurance
company, and six attorneys for these. “State Street,” you see, is like
Virginia; the old families have been intermarrying for so long that
everybody is related to everybody else.
A Harvard graduate wrote to the New York “Evening Post,”
“Harvard has assets to be invested of about thirty-four million
dollars. Is that the reason why practically five-sixths of the Boston
business representation (of Harvard) is affiliated with investment
banking concerns, or is it because they wish to use Harvard as a
knighthood for their friends?” The “Evening Post” went on politely to
say that it did not believe this was the case; the financial domination
of Harvard had resulted by accident! But this bit of humor did not
save the “Evening Post” from the wrath of the interlocking
directorate. The paper offended also by opposing America’s entry
into the war—and so the valuable advertising business of Lee,
Higginson & Co. was withdrawn, and shortly afterwards the owner of
the paper was forced to sell out to Mr. Lamont, a partner of the
House of Morgan. This story is in “The Brass Check,” page 248. To
complete it we should note the part played by Harvard in the
swallowing. It was a Harvard overseer who bought the “Evening
Post”; another overseer is now president and trustee of the “Evening
Post” company, and a third overseer is also a trustee of the “Evening
Post” company!
Also, it will be worth while to notice the Massachusetts Institute of
Technology, until recently a part of Harvard. This is one of the most
marvelous collections of plutocrats ever assembled in the world; it
includes the president of the Powder Trust, and his cousin Mr.
Coleman du Pont, who is emperor of the State of Delaware; also Mr.
Eastman, the kodak king; two of our greatest international bankers,
Mr. Otto Kahn and Mr. Frank Vanderlip; Mr. Howard Elliott, chairman
of the New Haven, Mr. Elisha Lee, vice-president of the
Pennsylvania; both members of the firm of Stone and Webster, with
all of its enormous electrical interests; also nine other electrical
bankers, two officials of the General Electric Company, one big
electrical manufacturer, and six others who are interested in electric
railways. Make particular note of this mass of electrical connections,
because in succeeding chapters you will find several amusing
instances of the influence of electric light and electric railway
interests upon the policy and teaching of both Harvard and
Massachusetts Tech.
As we have seen, the endowment of Harvard was estimated at
thirty-four millions of dollars in 1917, and since then there has been
a campaign in which nearly fifteen millions was raised. This money is
under the direction of the Morgan-Lee-Higginson directorate, and
needless to say is largely invested in Morgan-Lee-Higginson
enterprises. We are told by some friends of Harvard that Harvard
stands for “liberalism” in American education; do you suppose that
Harvard stands for “liberalism” in American industry? Do you
suppose that the votes of Harvard administrators are cast for policies
of justice and democracy in the enterprises it exploits? If you
suppose that, you are extremely naive. The Harvard votes are cast,
just as any other votes of any other business concerns are cast, for
the largest amount of dividends for Harvard. For example, Harvard
owns twenty-five hundred shares in a Boston department store; has
Harvard done anything to humanize the management of that store?
It has not. Harvard likewise operates a mine. Harvard has a graduate
business school and trains executives to run mines—on the basis of
getting the maximum production at the lowest cost, and maintaining
the present system of industrial feudalism.
I take these facts concerning the Harvard investments from a
paper by Harry Emerson Wildes, a Harvard graduate. It is interesting
to note that Mr. Wildes at the time he made this study was doing
voluntary publicity work for the alumni group which was raising
Harvard funds in Philadelphia; and Mr. Wildes was “dropped”
immediately after this study saw the light!
We have seen how Columbia owns stocks and bonds in American
railroads, public service corporations, and industrial corporations of
all sorts. Exactly the same thing is true of Harvard. Says Mr. Wildes:

Twelve separate cities feed the Harvard purse from their traction
lines, and more than half a hundred pay tribute from their lighting,
heating, gas and power plants. Harvard has two million dollars in the
traction game. The two-cent transfer charge on New York City
trolleys goes to pay the interest on three-quarters of a million
dollars’ worth of traction bonds in Harvard ownership, and Boston
ten-cent fare goes partially to Harvard’s third of a million in Boston
traction bonds.

Mr. Wildes goes on to study the effect of these investments upon


Harvard, and the effect which Harvard, through the power of these
investments, might have upon the industrial life of the country. I
cannot present the subject better than he has done, so I quote his
words:

With rapid transit lines throughout the nation in a state of rising


fares, and continual labor strife taking place, the intervention of a
conciliatory investor holding any such amounts might aid in bringing
better harmony between the companies on the one hand and the
public and the workmen on the other. But nothing has been done by
Harvard University, nor by any educational body in the land, to work
for the friendship of either public or labor towards the transit lines....
How strenuously the influence of Harvard will be thrown on the
side of limitation of armaments and the ending of war may be
gauged by the total of more than a million dollars’ worth of ordnance
bonds and munitions stock owned by the corporation. And, as these
are largely in great steel corporations such as Bethlehem, Midvale
and Illinois, the attitude of the college heads towards the move for
unionizing workers can be clearly understood.
When railroad brotherhoods put forth a plan for guild operation of
the lines, they face a mighty opposition from security investors. The
eight million dollars which Harvard holds in railroad stock and bonds
would be affected by victory for the Plumb Plan. The professors of
economics and particularly of railroad operation and finance can
scarcely be expected to imbue their scholars with a holy zeal for the
securing of the Brotherhood aims....
Evidence of the patriotic ardor of the financiers directing Harvard’s
investments may be readily seen in the fact that only one per cent of
the funds of the university is invested in the Liberty Loans. The total
of United States bonds held is less than half of that spent for bonds
of five foreign nations. Intervention in Mexico would perhaps be
pleasing to the authorities, since they hold a total of nearly one
hundred thousand dollars in Mexican government bonds. So, also, is
the pacification of Central America through the stationing of
American marines and blue-jackets in those lands. Meddling of our
State Department in the internal affairs of Costa Rica, Honduras, San
Salvador and the rest helps to uphold the value of another one
hundred thousand dollars’ worth of United Fruit Company bonds.[B]
This company notoriously controls entire nations in Central America
and sets up or deposes presidents at its whim. There is scarcely a
large community north of Panama that is not in some degree tapped
by the Harvard treasury. The American college is becoming the
strongest single force in the world. Its management is almost
entirely in the hands of international bankers or men dependent
upon that group.

B. These bonds have just been paid off, but the ability to pay them
off was of course assured by American intervention.

Such are the business facts underlying Harvard University; such


are the roots of the plant, and we shall now examine its flowers.
CHAPTER XV
THE HARVARD TRADITION

Harvard has a tradition, which is a part of the tradition of New


England; it is one of scholarship, of respect for the dignity of
learning. Money counts in New England, but money is not enough,
so you will be told; you must have culture also, and the prestige of
the intellectual life. More than that, in New England is found that
quality which must necessarily go with belief in the intellectual life,
the quality of open-mindedness, the willingness to consider new
ideas.
Such is the tradition; and first, it will pay us to ask, how did the
tradition originate? Was it made by Harvard University? Or was it
made by Charles Sumner, anti-slavery senator from Massachusetts,
who was found unfit to be a professor in the Harvard Law School,
and wrote to his brother: “I am too much of a reformer in law to be
trusted in a post of such commanding influence as this has now
become.” Was it made by Harvard, or by Wendell Phillips, who,
according to his biographer, Sears, denounced “the restraint of
Harvard, which he attributed to affiliation with the commercial
interests of Boston, and the silence they imposed on anti-slavery
sentiments.” Was it made by Harvard or by William Lloyd Garrison,
who was dragged through the streets of Boston with a rope about
his neck, by a silk-hatted mob of State Streeters, many of them of
course from Harvard?
Sumner, Phillips and Garrison were extremists, you may say; and
the best traditions are not made by such. They are made by
scholars, who lead retired lives and guide others by the power of
thought. Very well; New England has had no more revered scholar,
no more keen thinker than Emerson. Emerson was gentle, Emerson
was dignified, and you will find Emerson a part of the Harvard
tradition—one of its halls bears his name. So let us see what
Emerson had to report about the Harvard of his time; how much
credit he gives it for progress in the anti-slavery days. Writing in
1861, in “The Celebration of the Intellect,” Emerson said: “Harvard
College has no voice in Harvard College, but State Street votes it
down on every ballot. Everything will be permitted there, which goes
to adorn Boston Whiggism—is it geology, astronomy, poetry,
antiquities, art, rhetoric? But that which it exists for, to be a fountain
of novelties out of heaven, a Delphos uttering warning and ravishing
oracles to lift and lead mankind—that it shall not be permitted to do
or to think of. On the contrary, every generosity of thought is
suspect and has a bad name. And all the youths come out decrepit
citizens; not a prophet, not a poet, not a daimon, but is gagged and
stifled or driven away.”
And precisely that is what we have to report about the Harvard of
the time of capitalistic reaction, which is 1922. For thirteen years
Harvard has been under the administration of a cultured corporation
lawyer of Boston, who has generally carried out the politics of his
State Street associates in all essential matters, and has preserved
just as much reputation for liberalism as can be preserved—safely.
A. Lawrence Lowell is not, like Nicholas Murray Butler, a climber
and a toady; he could not be a climber, because he was born on a
mountaintop, and there was no place to climb to—he could only stay
where he was or descend. He belongs to the Lowell family, who are
among the Boston Brahmins, and it would not occur to him that any
millionaire could confer a favor upon Harvard University, or upon the
president of Harvard University. On the other hand, it does occur to
him that Harvard is a close corporation, a family affair of the vested
interests of New England, which cover an enormous financial power
with a decorous coating of refined exclusiveness.
Before the days of President Lowell, Harvard was presided over by
Charles W. Eliot, a scholar who believed to some extent in a safe and
reasonable freedom of opinion—using his own freedom to glorify the
“great American hero” known as the “scab.” President Lowell has
inherited the Eliot tradition, and in my travels about the country I
heard many rumors as to how he had stood by his professors in time
of stress. When I got to Harvard, and turned these rumors into fact,
I found an amusing situation. No circus rider who keeps his footing
on two horses has ever done a more deft and delicate feat of
balancing than President Lowell, with one foot on the Eliot tradition
and the other foot on the House of Lee-Higginson.
They will tell you proudly that professors are not let out of Harvard
because of their opinions; and that is sometimes true. One reason is,
because the Harvard teaching staff is selected with meticulous care,
and because, when the new man comes to Harvard he comes under
the influence of a subtle but powerful atmosphere of good form. It is
not crude materialism, as in Columbia; it is cleverly compounded of
high intellectual and social qualities, and it is brought to the young
educators’ attention with humor and good fellowship. A friend of
mine, a Harvard man who knows the game, described to me from
personal experience how the State Street pressure operates.
Somebody in Lee-Higginson calls President Lowell on the telephone
and says: “How can we get So-and-so to put up the money for that
chair, if young This-or-that gets his name in the newspapers as
lecturing to workingmen?” President Lowell smiles and says he will
see about it, and the young instructor is invited to dinner and
amiably shown how the most liberal university in America cannot run
entirely without money. The young instructor sees the point, and the
president goes away, thinking to himself: “Thank God we are not as
Columbia!”
Even down to the humblest freshman such pressure is conveyed.
There are things that “are not done” at Harvard; and you would be
surprised to know how minute is the supervision. You might not
think it was a grave offense for a student, wearing a soft shirt in
summer-time, to leave the top button unfastened; but a student
friend of mine, who had ideas of the simple life—going back to
nature and all that—was coldly asked by Dean Gay: “Is the button of
your shirt open by mistake, or is the button missing?” And when he
did not take this delicate hint, Professor Richard C. Cabot told
another student that he might help the young man by advising him
to close the top button of his shirt. I am advised that Harvard men
will call this story “rot”; therefore I specify that I have it in writing
from the man to whom it happened.
And if they are so careful about shirt-buttons, they would hardly
be careless about public speeches. A couple of years ago the
Harvard Liberal Club made so bold as to invite Wilfred Humphries, a
mild little gentleman who served with the Y. M. C. A., to tell about
his experiences in Russia; whereupon the president of the Liberal
Club received a letter from the secretary to the Corporation of
Harvard, politely pointing out that there was likely to be
embarrassment to the university, and would the president of the club
kindly call upon the secretary, in order to provide him with
arguments, “in case the press takes the thing up in a way which
might embarrass the progress of the Endowment Fund Campaign.”
Just as deftly as that, you see!
I found that Harvard’s reputation for liberalism was based upon
the custom of President Lowell to take into his institution men who
had been expelled from other colleges. I was impressed by this, until
Harvard men explained to me how it is managed. The basis of it is a
painstaking inquiry into the character and opinions of those men, to
make sure there is nothing really dangerous about them. In some
cases they are men who have offended local interests, with which
“State Street” has little concern. Others are men of ability who have
offended religious prejudices in the provinces; the tradition of
Harvard is Unitarian, and nobody is shocked by the idea that his
ancestors swung from the tree-tops by their tails. The State of Texas
has just passed a law providing for the expulsion of professors who
teach that idea, so in due course you may hear of Harvard taking
over some Texas scholar.
How men are investigated before they are taken into Harvard is a
matter about which I happen to know from a man who underwent
the ordeal. I will call my informant Professor Smith, and he was head
of a department in a leading university. Appointed on a public
service commission, he discovered that the local gas company was
engaged in swindling the city. The facts got into the newspapers,
and this public spirited professor was on the verge of being expelled
by his trustees, several of whom were “in gas.” Some friends of his
put the matter before President Lowell, and Lowell made inquiry,
and ascertained that Smith was a liberal of the very mildest sort,
well connected and affable, in every way worthy to associate with
the best families, and to train their sons; so Professor Smith received
a letter, asking him if he would come to Cambridge and make the
acquaintance of President Lowell. He made the journey, and found
himself a guest at a dinner party in the home of one of the
interlocking directorate. President Lowell was seated next to him,
and they chatted on many subjects, but only once did they touch on
the subject of Smith and his qualifications.
“By the way,” said Lowell (I reproduce the conversation from
careful notes). “I understand you had some little unpleasantness in
your home city.”
“Quite a good deal of it,” replied Smith.
“I’m not quite clear about it,” said Lowell. “It had something to do
with the gas company, did it not?”
“Yes,” replied Smith.
“It was merely gas? It had nothing to do with electricity?”
“Oh, no,” said Smith. “Nothing whatever.”
“You are sure the electric light company was not involved?”
“Quite sure. They are separate concerns.”
“I see,” said Lowell, and talked about the European situation.
So Professor Smith went home, and told a friend about the
matter; the friend made him repeat it over, word for word, and then
burst out laughing. “Don’t you see the point?” he asked; but Smith
saw no point whatever.
“Don’t you know that gas companies and electric light companies
are sometimes rivals?” inquired the friend. “You can light your house
with either gas or electricity; you can cook with either gas or
electricity, you can heat with either gas or electricity.”
“Yes, of course,” said Smith, still unenlightened.
“Well, you attacked the gas company,” said the friend. “You did
not attack the Edison Electric Company of your city, which happens
to be a part of the electric trust which covers the entire United
States. Harvard is all tied up with this electrical trust, and
Massachusetts Tech still more so, and Lee, Higginson & Company
are its bankers. President Lowell was perfectly willing for you to fight
your local gas company, but he wanted to make sure that you hadn’t
trod on the toes of Harvard’s leading industry! You will get your
invitation to Harvard, I’ll wager.”
And, sure enough, the invitation came a few days later! To
complete the humor of the story, the fact of the invitation became
known at once among the faculty of Professor Smith’s university, and
had the effect of instantly killing the talk of Professor Smith’s being
asked to resign!
I tell this incident as it was told to me. Standing by itself it might
not mean much; but before we finish with Harvard we shall have
plenty of evidence to prove that when the electric men play a tune,
the Lee-Higginson university dances. President Lowell, I am told, did
not know the difference between a mathematician and an
astronomer; when Pickering died, he proposed to put in a
mathematician, and was naively surprised when it was explained to
him that modern astronomy has gone so far that an observatory
cannot be run by a mathematician, however expert. But ignorant as
our Boston Brahmin may be about the stars of the milky way, it is
certain that he knows all about the stars of State Street, he has
them carefully charted and plotted, and neither he nor any member
of his faculty ever bumps into them.
CHAPTER XVI
FREE SPEECH BUT—

We have referred to the Harvard Liberal Club, an organization


formed by some graduates who sympathized with the cause of social
justice. This club brought speakers to Harvard, and got itself into the
newspapers several times; for example, during the anti-red hysteria
they heard an address from Federal Judge Anderson, who
denounced the Palmer raids as crimes against the constitution. This
caused President Lowell great annoyance, but he could not control
the club, because it was a graduate organization. He demanded that
it abandon the name Harvard, saying it might cause people to get a
wrong idea of the university. Inquiries were made to ascertain if
legal measures could be taken; and when he found that such
measures wouldn’t work, he came to one of its meetings, very
courteous and deeply interested, trying to steer it into ways of
academic propriety. “We are all liberals at Harvard,” he said—an old,
old formula! For a generation the British labor party has been
hearing from the Tories: “We are all Socialists in England.”
Just how much of a liberal President Lowell is, of his own impulse
and from his own conviction, was shown at the time that Louis D.
Brandeis was nominated by President Wilson for the Supreme Court.
Brandeis is a graduate of the Harvard Law School, and was a
prosperous corporation lawyer in Boston; a man of European culture
and charming manners, he was the darling of Harvard, in spite of
the fact that he is a Jew. The Lees and the Higginsons took him up—
until suddenly he ran into the New Haven railroad! Then the other
crowd, the Kidders and the Peabodys, took him up—until he ran into
the gas company! After that everybody dropped him, and if he had
not been a man of wealth he would have been ruined. When he was
proposed for the Supreme Court, a committee of lawyers, with
Austen G. Fox, a Harvard man, at their head, took up the fight
against him in the United States Senate. This fight didn’t involve
Harvard, and there was no reason for President Lowell to meddle in
it; but he made it his personal fight, and a fight of the most
determined and bitter character.
In 1918 there was a great strike in the Lawrence textile mills, and
this made a delicate situation, because Harvard holds six hundred
thousand dollars’ worth of woolen mill loans and mortgages, and an
equal amount of bonds and stocks. It seemed natural, therefore, to
the overseers that Harvard students should go out as militiamen to
crush this strike; it did not seem natural to them that members of
the Liberal Club should call meetings and invite strike leaders to tell
the students of the university their side of the case. But the
members of this Liberal Club persisted, and when the district
attorney accused the strikers of violence, they appointed a
committee to interview him and get his facts. They gave a dinner, to
which they invited the directors of the mills to meet the strike-
leaders; they appointed a committee to consider terms of
settlement, and in the end they forced a compromise.
Things like this caused most intense annoyance to the interlocking
directorate. This was voiced to a Harvard man of my acquaintance,
one of the organizers of the Liberal Club, by a Harvard graduate
whose father has been a Harvard overseer, and is one of
Massachusetts’ most distinguished jurists. In the Harvard Club of
Boston my friend was challenged to say what he meant by a liberal;
and when his definition was not found satisfactory, the Harvard
graduate exclaimed: “A liberal? I’ll tell you what a liberal is! A liberal
is a —- —— —— —— —— ——!” In order to reproduce the scene
you will have to fill these blanks, not with the ordinary terms of
abuse used by longshoremen and lumber-jacks, but with the most
obscene expletives which your imagination can invent.
Such is the present attitude of the ruling class of Harvard toward
the issue of free speech. The attitude of the students was
delightfully set forth by an editorial in the Harvard “Crimson,” at the
time of the Liberal Club lecture of Wilfred Humphries, Y. M. C. A.
worker from Russia. The “Crimson” was for Free Speech—But! What
the “Crimson” wished to forbid was “propaganda”; and it made clear
that by this term it meant any and all protest against things
established. Said the cautious young editor: “Not prohibited by law,
propaganda creeps in and is accepted by many as an almost
essential part of freedom of speech!” This is as persuasive as the
communications of the Harvard Union to the liberal students, barring
various radicals from the platform, on the ground that the Union did
not permit “partisan” speakers: the Union’s idea of non-partisan
speakers being such well-poised and judicious conservatives as
Admiral Sims and Detective Burns! As the old saying runs:
“Orthodoxy is my doxy, heterodoxy is your doxy!” There is a
standing rule at Harvard barring “outside” speakers who discuss
“contentious contemporaneous questions of politics or economics”;
and this rule was used to bar Mrs. Pankhurst!
I tell you of these petty incidents of discrimination; and yet, if we
are to keep our sense of proportion, we must state that in the
totality of American universities, Harvard ranks, from the point of
view of academic liberalism, among the three or four best. There
was no interference with its professors during the war hysteria—and
I found but one other large institution, the University of Chicago, of
which this statement may be made. Also, Harvard has to its credit
one post-war case, in which academic freedom was gravely involved,
and in which the Harvard tradition proved itself still alive. This is a
curious and dramatic story, and I will tell it in detail.
In the summer of 1918 the United States Army invaded Archangel
in Northern Russia, and Vladivostok in Eastern Siberia, seizing the
territory of a friendly people and killing its inhabitants without the
declaration of war required by the constitution of the United States.
This invasion was the blackest crime in American public history, and
was denounced by many of our leading thinkers. Also it was
denounced by five obscure Russian Jews, mere children in age, living
in the East-side slums of New York City. Four boys and a girl printed
a leaflet, asking the American people not to kill their Russian
compatriots, and they distributed these leaflets in public—for which
crime they were arrested, taken to prison, and beaten and tortured
so severely that one of them died a few days later. The surviving
four were placed on trial, and after a hideous travesty of justice
were given sentences of from fifteen to twenty years in prison.
This is known as the “Abrams case,” and it stood as one of our
greatest judicial scandals. Among others who protested was
Professor Zechariah Chafee, Jr., of the Harvard Law School. He
published in the “Harvard Law Review,” April, 1920, an article
entitled “A Contemporary State Trial”; and subsequently he
embodied this article as a chapter in his book on “Freedom of
Speech.” Dean Pound of the Harvard Law School, with Professors
Frankfurter, Chafee and Sayre (President Wilson’s son-in-law), also
the librarian of the Law School, signed a petition for executive
clemency in this Abrams case. These actions excited great
indignation among the interlocking directorates, and Mr. Austen G.
Fox, a Harvard graduate and Wall Street lawyer, drew up a protest to
the Harvard board of overseers, which protest was signed by twenty
prominent corporation lawyers, all Harvard men, including Mr. Peter
B. Olney, a prominent Tammany politician; Mr. Beekman Winthrop,
ex-governor of Porto Rico, and Mr. Joseph H. Choate, Jr., recently
notorious in connection with the scandals of the Alien Property
Custodian. The overseers referred the matter to the “Committee to
Visit the Law School,” which consists of fourteen prominent servants
of the plutocracy, including a number of judges. The result was a
“conference,” in reality a solemn trial, which occupied an entire day
and evening, May 22, 1921, at the Harvard Club in Boston. Mr. Fox
appeared, with a committee of his supporters and a mass of
documents in the case; also the United States attorney and his
assistant, serving as witnesses.
President Lowell’s attitude on this occasion is described to me as
that of “a hen protecting her brood against an old Fox.” Professor
Chafee himself tells me that President Lowell stood by him all
through the “conference,” and made Mr. Fox uncomfortable by well-
directed inquiries. Mr. Fox’s principal charge was that Professor
Chafee had taken his quotations of testimony at the Abrams trial
from the official record submitted to the Supreme Court in the
defendant’s appeal, instead of going to the prosecuting attorney and
getting the complete stenographic record. And lo and behold, when
Mr. Fox came to confront the fourteen Harvard judges, it transpired
that he himself had committed a similar blunder, only far worse! He
accused the five professors at the Law School of having made false
representations in their petition to President Wilson; but instead of
going to the office of his friend the government prosecutor, and
getting a photographic reproduction of the petition as signed by the
professors, Mr. Fox presented in evidence a four-page circular,
printed by the Abrams defense, containing a fac-simile of the
petition, with the signatures of the five professors; the statements
which Mr. Fox claimed were inaccurate were printed on the reverse
side of this circular. But it was easy for the professors to show that
they had nothing to do with the circular or its statements. The
document had been compiled by the Abrams defense some time
after the professors signed the petition. Mr. Fox, champion of strict
legal accuracy, had based his charge upon a piece of propaganda
literature, for which the professors had been no more responsible
than he!
It is interesting to note how the interlocking newspapers of Boston
handled this incident. It was, as you can understand, a most
sensational piece of news; but it was an “inside” story, a family
dispute of the interlocking directorate. The only newspaper which
gave any account of the indictment of the professors was the Hearst
paper, which is to a certain extent an outlaw institution, and
publishes sensational news concerning the plutocracy, when the
interests of Mr. Hearst and his group are not involved. But no other
Boston newspaper published the news about this trial at the time
that it took place; the first account was in the Boston “Herald,”
nearly two months later, after the story was stale!
It was an amazing demonstration of the power of the Boston
plutocracy; and it affords us curious evidence of the consequences
of news suppression. I heard about the Chafee trial all the way from
California to Massachusetts, and back again; and every time I heard
it, I heard a different version—and always from some one who knew
it positively, on the very best authority. These guardians of the
dignity of Harvard thought that by keeping the story quiet they were
helping the cause of academic freedom; but what they really did was
to set loose a flood of wild rumors, for the most part discreditable to
themselves. Of course, they may say that they do not care about
gossip; but why is it not just as important to educate people about
Harvard, as to educate them about the ancient Egyptians and
Greeks?
CHAPTER XVII
INTERFERENCE

We have seen President Lowell’s behavior when a group of Wall


Street lawyers attempted to dictate to his university. We have next
to investigate his attitude when it is his own intimates and financial
supporters who are being attacked; when it is, not Wall Street, but
State Street, which calls to him for help. Here again our Boston
Brahmin has put himself on record, with exactly the same self-will
and decisiveness—but, unfortunately, on the other side! We were
promised some more evidence on the subject of Harvard in relation
to Lee-Higginson and Edison Electric. Now we are to have it.
I am indebted for the details of the incident to Mr. Morris Llewellyn
Cooke, an engineer of Philadelphia who was Director of Public Works
under a reform administration. For a series of five years Mr. Cooke
had been a regular lecturer at the Graduate School of Business
Administration of Harvard University. He prepared two lectures on
the public utility problem in American cities, which he gave at a
number of universities, and was invited to give at Harvard. Mr. Cooke
took the precaution to inquire whether he would be free “to discuss
conditions exactly as they exist in the public utility field.” The reply
was, in the magnificent Harvard manner: “I am desirous that your
lectures be both specific and frank. I am anxious for the students to
see clearly the real relation of local public utilities to the
municipalities, and vice versa, and am not considering whether your
remarks may hurt any one’s feelings.”
Mr. Cooke came and delivered his two lectures, and was
announced to give them again; but four months later came a letter
from the dean of the Graduate School, saying: “Mr. Lowell feels, and
I agree with him, that in view of the use you made of your invitation
to come here this last year, we cannot renew the invitation.” Mr.
Cooke then wrote to President Lowell to find out what was the
matter, and was told that he had violated academic ethics by giving
to the press an abstract of his lectures. In answering President
Lowell, Mr. Cooke pointed out that six weeks prior to giving the
lectures he had written on three separate occasions to the Graduate
School, giving notice of his intention to publish an abstract of his
remarks, because officials in other cities wished the information on
public utilities which he had accumulated. “Trusting that if this is not
entirely satisfactory to you, you will so advise me at your
convenience,” etc. The reply from the Business School had been: “I
note that you intend to publish these two lectures later, which will be
perfectly satisfactory to us.”
President Lowell now condescended to explain to Mr. Cooke
wherein he had offended; he had violated “academic customs ... not
in the least peculiar to Harvard, but true in all universities.” Mr.
Cooke thereupon wrote to universities all over the United States; he
obtained statements from a score or two of university professors,
deans and presidents, showing that not only was there no such
custom, but that it was a quite common custom for lecturers at
universities to make abstracts of their lectures and furnish these to
the press. The authorities quoted include the president of the
University of Wisconsin, and a dean who is now president; Professor
Dewey of Columbia, Hoxie of Chicago—and Frankfurter of President
Lowell’s own university! Theodore Roosevelt wrote:

Until I received your letter, I knew nothing whatever of any rule


prohibiting the remarks of academic lecturers from being published
in the periodical press or in other ways being quoted as material
used in the lecture room.

If you really want to test the sincerity of President Lowell’s


statement, here is the way to do it: Imagine Theodore Roosevelt,
distinguished Harvard alumnus, coming to his alma mater to deliver
a lecture on “The Duties of the College Man as a Citizen,” and
preparing a summary of his lecture and giving it to the press; and
then imagine him receiving from President Lowell a letter rebuking
him for his action, and informing him that because of it he would not
again be invited to speak at Harvard!
No, we shall have to examine Mr. Cooke’s lectures, for some other
reason why his career as a Harvard lecturer was so suddenly cut
short. Mr. Cooke has printed the lectures in pamphlet form under the
title “Snapping Cords.” On page 9 I find a statement of the over-
valuation of public utilities in Philadelphia, and note that the
Philadelphia Electric Company has securities to the amount of over
fifty million dollars upon an actual valuation of less than twenty-five
million. And this is an Edison concern, allied with Boston Edison and
Lee Higginson! I turn to page 12, and learn how the National Electric
Light Association, the society of electrical engineers, is being used as
a dummy by the electric light interests. I turn to page 14, and find
the American Electric Railway Association shown up as planning to
corrupt American education, creating a financed Bureau of Public
Relations for the self-stated purpose of “influencing the sources of
public education particularly by (a) lectures on the Chautauqua
circuit and (b) formation of a committee of prominent technical
educators to promote the formation and teaching of correct
principles on public service questions in technical and economic
departments at American colleges, through courses of lectures and
otherwise.”
The tactless Mr. Cooke goes on to examine the activities of
“prominent technical educators” who have lent themselves to this
program. Among the names I find—can such a thing be possible?—
George F. Swain, professor of civil engineering in the Graduate
School of Applied Science of Harvard University! Professor Swain, it
appears, has done “valuation work” for Mr. Morgan’s New Haven
Railroad—our interlocking directorate, you perceive! You may not
know what “valuation work” consists of; it is the job of determining
how much money you shall pay for your water, light, gas and
transportation, and needless to say, the utility corporations want the
valuation put as high as possible. Mr. Cooke, since the incidents here
narrated, put through a rate case whereby the Philadelphia Electric
Company collects from the city and the people of that city one
million dollars less per year. So you see just what an ornery cuss Mr.
Cooke is!
Professor Swain lays out “principles” for the doing of this ticklish
“valuation work.”[C] One of his “principles” is that when anything has
increased in value, the increased valuation shall be allowed the
corporations, but when anything has decreased in value there shall
be no corresponding decrease in the valuation! (We used to play this
game when we were children; we called it “Heads I win and tails you
lose.”) Another of Professor Swain’s “principles” is that when states,
counties or cities have helped to pay the cost of grade crossings, the
railroads shall be credited with the full value of these grade
crossings. (We used to play that game also when we were children;
we called it “Findings is keepings.”) Needless to say, a man who is so
clever as to get away with things like that regards himself as
superior to the rest of us, who let him get away with it. So, as
president of the American Society of Civil Engineers, Professor Swain
voices his distrust of democratic ideals, and informs the engineers
that “present-day humanitarianism leads to race degeneracy.”

C. See record of hearing, May 3, 1920, at State House, Trenton, N.


J., before Governor Edwards, on motion of City of Jersey City for
removal of Public Service Commission.
And then I turn on to page 35 of the pamphlet, and stumble on
still more tactless conduct on the part of this dreadful Mr. Cooke. He
tells us about Dugald C. Jackson, professor of electrical engineering
at Harvard University,[D] who also does this fancy “valuation work.”
Says Mr. Cooke: “Professor Jackson has never really been so much a
university professor as a corporate employe giving courses in
universities. While he probably receives five thousand dollars from
his present teaching post he must receive at least four times this
amount from his corporate clients—charging as he does one
hundred dollars a day for his own time and a percentage on the time
of his assistants!”
D. Professor Jackson, in qualifying as an expert before the
Pennsylvania Public Service Commission, introduced himself by the
single statement that he was “professor of engineering at the
Massachusetts Institute of Technology and head of the Department
of Electrical Engineering and professor of electrical engineering at
Harvard University.” It should be explained that he held the last two
positions only ex-officio, by virtue of the affiliation of the two
institutions which existed for a few years.

Mr. Cooke goes on to show that before taking up teaching,


Professor Jackson was a chief engineer for the Edison General
Electric Company. In 1910, while a professor at Harvard, he
rendered a report showing that the Chicago Telephone Company
was running behind over eight hundred thousand dollars per year;
but two years later it was proven that the company could afford a
reduction in rates of seven hundred thousand dollars per year!
Again, Professor Jackson rendered a report showing that the Buffalo
General Electric Company had a valuation of $4,966,000; but the
state commission subsequently fixed the valuation at $3,194,000. He
valued three thousand municipal arc lamps at $21.70 each, but the
New York commission showed that the actual cost of these lamps
was $13.53. Says Mr. Cooke:
“What constitutes being employed by a corporation? Professor
Jackson is to all intents and purposes consulting engineer in chief as
to rates and valuations to the entire electrical industry in the United
States. He has made inventories of the Boston Edison Company and
the New York Edison Company. He is now engaged in doing similar
work for the Philadelphia Electric Company. These three companies
have a combined gross annual income of thirty-five million dollars.”
Do you see the “nigger in the woodpile” now? If you are a mine
guard or strike-breaking gunman, experienced in shooting up the
tent-colonies of striking miners, the corporations will pay you five
dollars a day and board for your services. If you are a “prominent
technical educator,” with a string of university degrees and titles,
who can enable the great corporations to swindle the public out of
tens of millions of dollars every year, then you can command a
salary of a hundred dollars a day, with a percentage on the time of
your assistants. That is what a college education is for; and if you
think that an over-cynical statement, I ask you to read the whole of
this book before you decide!
And what is a college president for? A college president is paid by
the interlocking directorate to take their “consulting engineers” and
“valuation experts” and cover them with a mantle of respectability,
enabling them to do their dirty work in the name of education and
public service. And if any freak individual comes along, trying to
break in and spoil the game, the function of a college president is to
furnish what the college football player knows as “interference“—
tripping the fellow up, slugging him, maiming him. In football there
are strict rules against fouls; but in this game of plutocratic
education “everything goes.”
CHAPTER XVIII
THE LASKI LAMPOON

A more recent test of Harvard University was made by Harold J.


Laski, a brilliant young writer whom President Lowell in an
unguarded moment admitted to teach political science. Laski holds
unorthodox ideas concerning the modern capitalist state; he thinks it
may not be the divinely appointed instrument which it considers
itself. Laski raised this question in his Harvard classes, which caused
tremendous excitement in State Street. The Harvard “drive” for
sixteen millions was on, and a number of people wrote that they
would give no money to Harvard while Laski was on its teaching
staff. On the other hand, a Chicago lawyer wrote that his son had
never taken any interest in his studies previously, but that since he
had come under Laski’s influence he had become a serious student;
this lawyer sent fifty thousand dollars to make up the losses. The
controversy got into the Boston newspapers, and President Lowell
stood by Laski; no Harvard professor should be driven out because
of his opinions. “Thank God we are not as Columbia!”
I asked a Cambridge friend about President Lowell’s heroism, and
he took a cynical view of it. Lowell is the author of a book
interpreting the British constitution, and has a reputation in England
based on this book; he has received an Oxford degree, and hopes
some day to be ambassador. In England people really believe in free
speech, and practice their beliefs; and Laski, it happens, is a
Manchester Jew, his family associated with the present ruling group
in England. Also, Laski himself wields a capable pen, and is not the
sort of man one chooses for an enemy. If Laski were to go home
and state that he had been expelled from President Lowell’s
university because of disbelief in the modern state, what would
become of Lowell’s English reputation? Said my friend: “If Laski had
been a German Jew, or a Russian Jew”—and he smiled.
As to the overseers and their handling of the case, Professor Laski
writes me that they were very nice to him. “I was simply invited to a
dinner at which we exchanged opinions in a friendly fashion. My only
doubt there was a doubt whether the committee realized how very
conservative my opinions really were in this changing social world.
Like most business men, they had little or no knowledge of the
results of modern social science.”
The climax came with the Boston police strike in the fall of 1919.
This was a very curious illustration of the part which the Harvard
plutocracy plays in the public life of Boston, so pardon me if I tell the
story in some detail. You know how the cost of living doubled all
over the country, while the wages of public servants increased very
little. The policemen of Boston were not able to live on their wages;
they begged for an increase, and the police commissioner promised
them the increase if they would wait until after the war. They
waited; and then the police commissioner tried to keep his promise,
and the mayor and the Democratic administration worked out a
settlement. But the Harvard plutocracy, which runs the government
of the state, decided not to permit that settlement, but to force a
strike of the policemen, so that they could smash the policemen’s
union. The late Murray Crane, senator and millionaire, holder of a
Harvard LL. D., planned the job in the Union Club of Boston,
together with Kidder, Peabody & Co., the bankers. Governor
Coolidge, the tool of Crane, upset the arrangements made by the
mayor of Boston, and the mayor was so furious that he “pasted the
governor one in the eye”—the inside reason why Coolidge
disappeared so mysteriously during the strike. But the newspapers
of the interlocking directorate celebrated him as the hero of the
affair, and he became vice-president of the United States on a wave
of glory!
The strike came, and according to the standard American
technique of strike-breaking, hoodlums were turned loose at the
right moment, to throw stones and terrify the public. The whole
affair was obviously stage-managed; nothing was stolen, and no real
harm was done. Insiders assured me that all the time the “riots”
were going on, there was a safe reserve of police locked up in the
police-station, waiting in case things should go too far. The Boston
policemen were represented as traitors to society, and a wave of
fury swept the country—including Harvard, which holds hundreds of
thousands of dollars’ worth of Boston city bonds, also securities of
Boston public service corporations. These properties must be
protected; so a “Harvard Emergency Committee” was formed,
headed by the professor who had first reported to the overseers
Professor Laski’s too great zeal in outside activities. Needless to say,
no one complained about the “outside activities” of this anti-strike
professor; on the contrary, President Lowell issued a resounding call
to Harvard men to help smash the policemen’s strike.
Incidentally, Harvard men smashed Harold J. Laski, who had the
temerity to interject himself into this class war. Laski went to Boston
and made a speech to the strikers’ wives, expressing sympathy with
their cause; whereat all Boston raged. “I would like to ask you
something, Mr. Laski,” said President Lowell, at a dinner party. “Why
did you make that speech?” “Why, Mr. Lowell,” said Laski, smiling, “I
made it because there is a general impression throughout the labor
world that Harvard is a capitalistic institution, and I wanted to show
that it is not true.” Laski was only twenty-six years old at the time,
and it took some nerve, you must admit. How to get this young
incendiary out of Harvard was the next job of the interlocking
directorate.
Meet Mr. James Thomas Williams, Jr., of Boston. Mr. Williams was
graduated from Columbia University in the same year that I quit it;
he then joined the Associated Press, and now serves the interlocking
directorate as editor of the Boston “Evening Transcript,” the paper
which is read by every Tory in New England. You may learn more
about this paper by consulting pages 284, 306, 307 and 379 of “The
Brass Check.” Also, perhaps I should tell you a little incident which
happened after “The Brass Check” came out. Desiring to test the
capitalist newspapers, I made up a dignified advertisement of the
book—nothing abusive or sensational, merely opinions from leading
journals of Europe. I sent this advertisement, with a perfectly good
check, to the Boston “Evening Transcript,” and the check was
returned to me, with the statement that the “Transcript” thought it
best not to publish the advertisement, because of the possibility of
being sued for libel.
I was puzzled at first, wondering what paper might sue the Boston
“Evening Transcript” for publishing an advertisement of “The Brass
Check.” Then I remembered that in the book I had accused a Boston
newspaper of having shared in the slush funds of the New York, New
Haven, and Hartford Railroad; also of having suppressed reports of
Justice Brandeis’ exposures of the Boston Gas Company, at the same
time publishing page advertisements from this gas company; also of
having published advertisements of “Harvard Beer, 1,000 Pure,” at
the same time suppressing news of the fact that the federal
government was prosecuting the manufacturers of Harvard Beer for
violation of the pure food laws. So I understood that the Boston
“Evening Transcript” was afraid of being sued by the Boston
“Evening Transcript.”
Now behold the editor of this fine old Tory newspaper rushing to
the defense of his interlocking directorate. Mr. Laski must be driven
from Harvard, and Mr. Williams knows exactly how to do it. He
interviews the editors of the Harvard “Crimson” and “Advocate;”
finally in the editors of the “Lampoon,” he finds a group who will
carry out his ideas. The result is an issue of that paper, January 16,
1920, known to history as the “Laski Lampoon.” If ever there was a
fouler product of class venom, it has not yet come under my eye.
I have never had the pleasure of meeting Harold J. Laski, but I
form an idea of him from a score of pictures in this publication. From
a painting on the cover I gather he is a short, thin, naked young
skeleton with a paunch; he wears large glasses, and has a fringe of
whiskers, or long hair, and a red dawn behind him, serving as a halo.
From another picture, a piece of clay modelling, I am puzzled about
the whiskers, or hairs, because I do not know whether they are little
worms or pieces of spaghetti. From other cartoons I gather that
Professor Laski sometimes wears clothes, and does not wear them
entirely in the Harvard manner; that is, his clothes do not fit him,
and his hat has too broad a brim, and is not worn entirely straight
on his head. I gather that he sometimes smokes cigarettes, a vice
entirely unknown in refined undergraduate circles.
Also Mr. Laski is described to me in a hundred or so sketches,
verses and witticisms. He is “the great indoor agitator”; he is “a
member of the firm of Lenin, Trotski and Laski.” This evil young man,
you must understand, holds the idea that the people of Russia
should be permitted to work out their own revolution in their own
way, and that American troops should not be sent in to attack them
in Archangel and Siberia without a declaration of war. This makes
him a “Bolshevik”; this makes him “Laski de Lenin,” and “Ivan
Itchykoff,” and the author of “The Constitution of the Russian
Itchocracy,” and of the “Autobiographia Laskivia.” “Love had to go.
One love was bad enough, but thirty or forty were insupportable. I
had tried it and I knew.” He is invited to “sing a song of Bolsheviks,”
and he tells us that “Comrade Lenin has a hundred and forty-eight
motor cars, and Comrade Trotsky has fifty-two.” He is “Cataline,” and
again he is “Professor Moses Smartelikoff”—the “Moses” meaning
that he is a Jew, and the rest that he thinks differently from Harvard.
Such thinking must not be allowed to get a start, say our cautious
young undergraduates:

The moral, oh ye masters, is, without a doubt,


Stop infection early; kick the first one out.

And here are more verses, addressed to our unpopular professor:

As you sit there, growing prouder,


With your skillful tongue awag,
As your piping voice grows louder,
Preaching Socialistic gag—
Stop a moment, let us warn you,
Nature’s freak,
That we loathe you and we scorn you, Bolshevik!
Harold Laski was scheduled to give a lecture at Yale, and when he
got there he found this copy of the “Lampoon” on sale all over town,
together with a reprint of an editorial in the “Transcript” denouncing
him. He was young, and rather sensitive, and naturally it occurred to
him that he was wasting his talents upon Harvard. He would be
allowed to stay there, he told a friend of mine, but he would never
be promoted, he would have no career. On the other hand, the
University of London offered him a full professorship at a higher
salary, in a part of the world where men may think what they please
about the capitalist state. Laski resigned; and so cleverly the job had
been managed—he had quit of his own free will, and the great
university could go on boasting that its professors are not forced out
because of their opinions! As a commentary on this story, I am sure
you will be interested in an extract from a letter from Laski, dated
August 16, 1922:

The results of the American atmosphere are quite clear.


1. Many men deliberately adopt reactionary views to secure
promotion.
2. Many more never express opinions lest the penalty be exacted.
3. Those who do are penalized when the chance of promotion
comes.
I am very much impressed by the contrast between the general
freedom of the English academic atmosphere and the illiberalism of
America. Three of my colleagues at the London School of Economics
are labor candidates; business men predominate on the governing
body; but interference is never dreamed of. At Oxford and
Cambridge the widest range of view prevails. But alumni do not
protest, and if they do, they are told to mind their own business. In
America, one always feels hampered by the sense of a control
outside; in England you never feel that it is necessary to watch your
tongue. No ox treads upon it.

You might also like