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

Data Structures and Applications: A Simple and Systematic Approach Padma Reddy - Instantly access the full ebook content in just a few seconds

The document provides an overview of data structures, including their definitions, classifications, and operations. It distinguishes between data and information, explaining how data is represented in computers using binary systems. Additionally, it introduces primitive and non-primitive data structures, detailing their characteristics and examples in programming languages like C.

Uploaded by

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

Data Structures and Applications: A Simple and Systematic Approach Padma Reddy - Instantly access the full ebook content in just a few seconds

The document provides an overview of data structures, including their definitions, classifications, and operations. It distinguishes between data and information, explaining how data is represented in computers using binary systems. Additionally, it introduces primitive and non-primitive data structures, detailing their characteristics and examples in programming languages like C.

Uploaded by

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

Visit ebookmass.

com to download the full version and


explore more ebook or textbook

Data Structures and Applications: A Simple and


Systematic Approach Padma Reddy

_____ Click the link below to download _____


https://ebookmass.com/product/data-structures-and-
applications-a-simple-and-systematic-approach-padma-reddy/

Explore and download more ebook or textbook at ebookmass.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

A Textbook of Data Structures and Algorithms, Volume 2:


Mastering Nonlinear Data Structures Vijayalakshmi Pai

https://ebookmass.com/product/a-textbook-of-data-structures-and-
algorithms-volume-2-mastering-nonlinear-data-structures-vijayalakshmi-
pai/

Data Structures and Algorithms in C++ 2nd Edition

https://ebookmass.com/product/data-structures-and-algorithms-in-c-2nd-
edition/

Data Structures E. Balagurusamy

https://ebookmass.com/product/data-structures-e-balagurusamy/

Organofluorine Chemistry - Synthesis and Applications 1st


Edition Reddy V. Prakash

https://ebookmass.com/product/organofluorine-chemistry-synthesis-and-
applications-1st-edition-reddy-v-prakash/
A Textbook of Data Structures and Algorithms, Volume 1 G.
A. Vijayalakshmi Pai

https://ebookmass.com/product/a-textbook-of-data-structures-and-
algorithms-volume-1-g-a-vijayalakshmi-pai/

A Textbook of Data Structures and Algorithms, Volume 2 G.


A. Vijayalakshmi Pai

https://ebookmass.com/product/a-textbook-of-data-structures-and-
algorithms-volume-2-g-a-vijayalakshmi-pai/

Kanski's Clinical Ophthalmology: A Systematic Approach 9th


Edition John Salmon

https://ebookmass.com/product/kanskis-clinical-ophthalmology-a-
systematic-approach-9th-edition-john-salmon/

Kanski’s clinical ophthalmology : a systematic approach


8th Edition Bradley Bowling

https://ebookmass.com/product/kanskis-clinical-ophthalmology-a-
systematic-approach-8th-edition-bradley-bowling/

Columnar Structures of Spheres: Fundamentals and


Applications Jens Winkelmann

https://ebookmass.com/product/columnar-structures-of-spheres-
fundamentals-and-applications-jens-winkelmann/
Chapter 1: Introduction to Data Structures
What are we studying in this chapter?
 Introduction to data structures
 Classification of data structures: Primitive and non-primitive data structures
 Data structure operations
 Inserting, deleting
 Traversing, searching, sorting and merging

1.1 Introduction
In this chapter, let us discuss about the definition of data structures and see how the
data structures are classified. Basic terminology and concepts are defined along with
examples. The way the data is represented, organized, managed and structured is
crucial part of the data structures. The data to be manipulated can be used
individually or in a group under one common name and data can be of different types.

1.2 Basic terminology

First, let us see “What is data? What is information?”


Definition: The word data is the plural of datum. Data is a representation of facts or
concepts in an organized manner. The data may be stored, communicated, interpreted,
or processed. In short, we can say that data is a piece of information or simply set of
values and data as such may not convey any meaning.
For example, numbers, names, marks etc are the data. Consider the two data
items “Rama” and 10. The data “Rama” and 10 does not convey any meaning to the
reader.
Definition: Information is defined as a collection of data from which conclusions may
be drawn. So, information is subset of data which when interpreted conveys meaning
so that the people can understand. Hence, Information can be considered as a message
that is received and understood.
Ex 1: The output of the computer may be “Rama scored 10 marks”. This sentence is
an information. Because, it conveys meaning to the reader.
Ex 2: The instructions given to a person or commands issued to the computer are
considered as information.
1.2  Introduction to data structures and arrays
Now, let us see “What are the differences between data and information?”
Data Information
1. Data is collection of facts and figures 1. Information is the result of
(may be numbers). Facts are the processing the data. So, information
things done or things existing. is collection of data from which we
can draw conclusions.
2. Data do not convey any meaning 2. Information conveys meaning
3. Computers work with data 3. Computers do not work with
information
4. Data is unstructured, lacks context 4. When data is correctly organized,
and may not be relevant to the processed, filtered and presented
recipient. with context, it can become
information because it then has
meaning to the recipient
5. Data is the representation of 5. Information is the things that we
information. So, data representation know. So, even though data
may change representation changes, information
do not change

Note: Let us take an example relating to the last difference. Consider the statement
“My daughter is seven years old”. I can represent may daughter’s age as “seven in
words” or “7 in figures” or “VII in roman” or “111 in binary” or “1111111 in unary”
and so on. All these representations we call as data. Even though representation
changes, my daughter’s age has not changed. So, we say that information does not
change and data representation may change.

Note: Even though normally we use data and information interchangeably, they are
totally different and they are not synonyms.

Now, let us see “How computers represent data?”

The data are represented by the state of electronic switches. A switch with ON state
represents 1 and a switch with OFF state represents 0 (zero). Thus, all digital
computers use binary number system to represent the data. So, the data that we input
to the computer is converted into 0’s and 1’s. The letters, digits, punctuation marks,
sound and even pictures are represented using 1’s and 0’s. Thus, computers represent
data using binary digits 0 and 1 i.e., in binary number system.
 Systematic Approach to Data Structures using C - 1.3
For example, consider the string “ABC01” that we type from the keyboard. This data
can be represented in the computer as shown below.

Characters typed: A B C 0 1

ASCII values 41 42 43 30 31
(Binary values) 0100 0001 0100 0010 0100 0011 0011 0000 0011 0001

Note: In general, any data whether numerical or non-numerical is represented


using 1’s and 0’s.

All the quantities are measured in some units. For example, length may be measured
in meters or feet. On similar lines, to measure computer memory, we require units.
Now, let us see “How does the data represented using 1’s and 0’s can be grouped or
measured?” The data represented can be grouped or measured using following units:

Bit = 0 or 1
Nibble = 4 bits
Byte = 8 bits
Units of data
Kilobyte = 1024 bytes
Megabyte = 1024 Kilobytes
Gigabyte = 1024 Megabytes
Terabyte = 1024 Gigabytes

Now, let us see “What is an entity and what is an attribute?”


Definition: An entity can be defined as a person, place, thing or concept about which
data can be collected and stored. An entity is made up of a number of attributes which
represent that entity. An attribute is the one which describes the facts, details or
characteristics of an entity.

For example, if we collect name, usn, phone number, branch of engineering of a


particular student, then student is treated as an entity whereas name, usn, phone
number, branch are the attributes. The entity student and its attributes are pictorially
represented as shown below:
1.4  Introduction to data structures and arrays

attributes
entity
student Name Usn Phone_no branch
MONALIKA 101 9900170827 CSE

Attribute values

Now, let us see “What is an entity set?”


Definition: A collection of entities with similar attributes is an entity set. For
example, all the students in a college represent entity set. The entity set of students
can be pictorially represented as shown below:

Name Usn Phone_no branch


Entity set
MONALIKA 101 9900170827 CSE
KRISHNA 102 999999999 MECH
NARENDRA 103 9845070827 CIVIL
MITHIL 104 9844010200 ISE
PADMA 105 9844012222 EC

Now, let us see “In what way the attributes, entities and entity sets are related to
fields, records and files?” The way the data are organized into the hierarchy of fields,
records and files reflect the relationship between attributes, entities and entity sets.
Now, let us see “What is a field? What is a record? What is a file”
Definition: A field is a single elementary unit of information representing an attribute
of an entity. A record is a collection of field values of a given entity. A file is a
collection of records of the entities in a given entity set.

1.3 Data Structures


In this section, we shall “Define data structures?”
Definition: The study of how the data is collected and stored in the memory, how
efficiently the data is organized in the memory, how efficiently the data can be
retrieved and manipulated, and the possible ways in which different data items are
logically related is called data structures. The data structures are mainly classified as
shown below:
 Systematic Approach to Data Structures using C - 1.5

Primitive data structures


Types of data structures
Non-primitive data structures
1.3.1 Primitive Data Structures
Now, let us see “What are primitive data structures?”

Definition: The data structures that can be manipulated directly by machine


instructions are called primitive data structures. Thus, the primitive data structures
are fundamental data types that are supported by a programming language. The
primitive data structures are also called simple data structures.
For example, in C language, the different primitive data structures are defined
using the data types such as int, float, char, double and pointers.

Integers: An integer is a whole number without any decimal point or a fraction part.
No extra characters are allowed other than ‘+’ and ‘–‘ sign. If ‘+’ and ‘–‘ are present,
they should precede the number. The integers are normally represented in binary or
hexadecimal. All negative numbers are represented using 2’s complement. Based on
the sign, the integers are classified into:
 Unsigned integer
 Signed integer

Floating point number: The floating point constants are base 10 numbers with
fraction part such as 10.5. All negative numbers should have a prefix ‘–‘. A positive
number can have an optional ‘+’ sign. No other extra characters are allowed. The
floating point constants can be represented using two forms as shown below:
Fractional form
Floating point
notations Scientific notation
(Exponent notation)
Fractional form: A floating point number represented using fractional form has an
integer part followed by a dot and a fractional part. We can omit the digits before the
decimal point or after the decimal point. For example, 0.5, -0.99, -.6, -9., +.9 etc
are all valid floating point numbers.

Exponent form (Scientific notation): The floating point number represented using
scientific notation (also called exponential notation) has three parts namely:
mantissa e/E exponent.
1.6  Introduction to data structures and arrays
Ex1: 9.86 E 3 imply 9.86x103
Ex2: 9.86 e -3 imply 9.86x10-3
where
 The mantissa can be an integer or a floating point number represented using
fractional notation.
 The letter e or E should follow mantissa.
 The exponent should follow e or E. The exponent has to be an integer with
optional ‘+’ or ‘–‘ sign.

For example,
6.698274e2 means 6.698274 x 102
-0.36e-54 means -0.36 x 10-54

Character: A character data is a primitive data structure. A wide variety of character


sets (also called alphabets) are handled by computers. The two widely used character
sets are:
 ASCII (American Standard Code for Information Interchange)
 EBCDIC(Extended Binary Coded Decimal Interchange Code)
Note: ASCII (pronounced as as-key) code is a 7-bit code to represent various
characters such as letters, digits, punctuation marks and other symbols. ASCII stands
for American Standard Code for Information Interchange. The ASCII Table is shown
below.
0 1 2 3 4 5 6 7 8 9 A B C D E F
0 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI
1 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
2 SP ! " # $ % & ' ( ) * + , - . /
3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4 @ A B C D E F G H I J K L M N O
5 P Q R S T U V W X Y Z [ \ ] ^ _
6 ` a b c d e f g h i j k l m n o
7 p q r s t u v w x y z { | } ~ DEL

Observe from the table that character ‘A’ has an ASCII value 41, the character ‘B’
has an ASCII value 42 and character ‘C’ has an ASCII value 43. So, if we type the
text “ABC” from the keyboard, to the computer, it appears as shown below:
A B C (Characters)

41 42 43 (ASCII values)
0100 0001 0100 0010 0100 0011 (Binary values )
 Systematic Approach to Data Structures using C - 1.7
Pointer: A pointer is a special variable which contains address of a memory location.
Using this pointer, the data can be accessed.
For example, assume that a program contains four occurrences of a constant 3.1459.
During the compilation process, four copies of 3.1459 can be created as shown below:

3.1459 3.1459 3.1459 3.1459


a b c d
However, it is more efficient to use one copy of 3.1459 and three pointers referencing
a single copy, since less space is required for a pointer when compared to floating
point number. This can be represented pictorially as shown below:

c 3.1459 a

The variables b, c and d are called pointers since they contain address of variable a.

1.3.2 Non-primitive Data Structures


Now, let us see “What are non-primitive data structures? What are the different types
of non-primitive data structures?”
Definition: The data structures that cannot be manipulated directly by machine
instructions are called non-primitive data structures. Thus, the non-primitive data
structures are created or constructed using primitive data structures. The non-
primitive data structures are also called compound data structures.

For example, arrays, structures, stacks, queues, linked lists, trees, graphs, files
etc., are some of the non- primitive data structures.
Now, let us see “What are the different types of non-primitive data structures?” The
non-primitive data structures are classified as shown below:

Linear data structures Ex: Arrays, stacks, queues, linked lists

Non-linear data structures Ex: Trees, graphs, files etc.


1.8  Introduction to data structures and arrays
Now, let us see “What are linear data structures?”
Definition: The data structure where its values or elements are stored in a sequential
or linear order is called linear data structure. The elements can be accessed
sequentially one after the other in a linear order and hence the name. The linear
relationship between the elements is maintained:
 by means of sequential memory locations as in arrays: Here, one or more elements
are stored one after the other sequentially.
 by means of links as in linked list: Here, each element is stored in a node. One or
more nodes are logically adjacent and the logical adjacency is maintained using
links. In linked lists, even though the nodes are not physically adjacent, they seem
to be adjacent logically because of links. The logical adjacency is maintained
using pointers.
For example, arrays, stacks, queues, linked lists etc., are all linear data structures.

Now, let us see “What are non-linear data structures?”

Definition: The data structure where its values or elements are not stored in a
sequential or linear order is called non-linear data structures. Unlike linear data
structures, here, the logical adjacency between the elements is not maintained and
hence elements cannot be accessed if we go in sequential order. In non-linear data
structures, a data item (or an element) could be attached to several other data items.

For example, graphs, trees, files are all non-linear data structures.
Now, let us “Explain non-linear data structures?” All the non-linear data structures
such as arrays, stacks, queues, linked lists, graphs, trees and files are discussed below:
 Arrays: Definition: An array is a special and very powerful data structure in C
language. An array is a collection of similar data items. All elements of the array
share a common name. Each element in the array can be accessed by the subscript
(or index). Array is used to store, process and print large amount of data using a
single variable.

Ex 1: Set of integers, set of characters, set of students, set of pens etc. are
examples of various arrays.

Ex 2: An array of 5 integers is pictorially represented as shown below:

10 15 20 25 30
A[0] A[1] A[2] A[3] A[4]
 Systematic Approach to Data Structures using C - 1.9
Ex 3: An array of 5 characters is pictorially represented as shown below:

‘A’ ‘B’ ‘C’ ‘D’ ‘E’


A[0] A[1] A[2] A[3] A[4]

 Stack: A stack is a special type of data structure (linear data structure) where
elements are inserted from one end and elements are deleted from the same end.
Using this approach, the Last element Inserted is the First element to be deleted
Out, and hence, stack is also called Last In First Out (LIFO) data structure.
The stack s={a0, a1, a2,……an-1) is pictorially represented as shown below:
Insert Delete The elements are inserted into the
stack in the order a0, a1, a2,……an-1.
That is, we insert a0 first, a1 next and
so on. The item an-1 is inserted at the
an-1 Top of stack end. Since, it is on top of the stack, it
is the first item to be delted. The
various operations performed on
a2 stack are:
 Insert: An element is inserted
a1
from top end. Insertion operation
a0 Bottom of stack is called push operation
 Delete: An element is deleted from top end only. Deletion operation is called pop
operation.
 Overflow: Check whether the stack is full or not.
 Underflow: Check whether the stack is empty or not.

 Queue: A queue is a special type of data structure (linear data structure) where
elements are inserted from one end and elements are deleted from the other end.
The end at which new elements are added is called the rear and the end from
which elements are deleted is called the front. Using this approach, the First
element Inserted is the First element to be deleted Out, and hence, queue is also
called First In First Out (FIFO) data structure.
For example, consider the queue shown below having the elements 10, 50 and 20:
q
10 50 20
0 1 2 3 4
front rear
 The items are inserted into queue in the order 10, 50 and 20. The variable q is
used as an array to hold these elements
1.10  Introduction to data structures and arrays
 Item 10 is the first element inserted. So, the variable front is used as index to
the first element
 Item 20 is the last element inserted. So, the variable rear is used as index to
the last element
 Linked lists: A linked list is a data structure which is collection of zero or more
nodes where each node is connected to the next node. If each node in the list has
only one link, it is called singly linked list. If it has two links one containing the
address of the next node and other link containing the address of the previous
node it is called doubly linked list. Each node in the singly list has two fields
namely:
 info – This field is used to store the data or information to be manipulated
 link – This field contains address of the next node.

The pictorial representation of a singly linked list where each node is connected to
the next node is shown below:

first

20 30 10 60 \0

The above list consists of four nodes with info fields containing the data items 20,
30, 10 and 60.
 Graphs: A graph is a non-linear data structure which is a collection of vertices
called nodes and the edges that connect these vertices. Formally, a graph G is
defined as a pair of two sets V and E denoted by
G = (V, E)
where V is set of vertices and E is set of edges. For example, consider the graph
shown below:

1 6 Here, graph G = (V, E) where


0  V = {1, 2, 3, 4, 5, 6} is set of vertices

5
4  E = { (1, 6), (1, 2), (2, 3), (4, 3), (5, 3), (5, 6), (6, 4) }
2 0 is set of edges
Note:|V| = |{1, 2, 3, 4, 5, 6}| = 6 represent the number of
3 vertices in the graph.

 |E| = |{(1, 6), (1, 2), (2, 3), (4, 3), (5, 3), (5, 6), (6, 4) }| = 7 represent the
number of edges in the graph.
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
 Systematic Approach to Data Structures using C - 1.11
 Trees: A tree is a set of finite set of one or more nodes that shows parent-child
relation such that:
 There is a special node called the root node
 The remaining nodes are partitioned into disjoint subsets T1, T2, ……Tn, n ≥ 0
where T1, T2, T3 ……Tn which are all children of root node are themselves
trees called subtrees.
Ex1 : Consider the following tree. Let us identify the root node and various
subtrees:
 The tree has 8 nodes : A, B, C, D, E,
root A
F, G and H.
subtrees  The node A is the root of the tree
 We normally draw the trees with root
B C D at the top
 The node B, C and D are the children
E F G H of node A and hence there are 3
subtrees identified by B, C and D
 The node A is the parent of B, C and D whereas D is the parent of G and H

 Binary tree: A binary tree is a tree which is collection of zero or more nodes and
finite set of directed lines called branches that connect the nodes. A tree can be
empty or partitioned into three subgroups namely root, left subtree and right
subtree.
 Root – If tree is not empty, the A
first node is called root node.
 left subtree – It is a tree which is
connected to the left of root. B D
Since this tree comes under root,
it is called left subtree.
 right subtree – It is a tree which C E F I
is connected to the right of root.
Since this tree comes under the H J
root, it is called right subtree.

1.4 Data structure operations


In this section, let us see “What are the operations performed on various data
structures?” The operations performed on various data structures are:
 Creating: The process of repatedly adding various data items into the list is called
creating a list. For example, we can create a student records consisting of names,
1.12  Introduction to data structures and arrays
marks, address, phone number etc., by repeatedly adding or inserting data items
into the list.
 Inserting: The process of adding a data item into the list is called inserting. For
example, a student record consisting of name, marks and address can be added
whenever a student joins a course. It is called inserting student record into the list.
 Deleting: The process of removing a data item from a list is called deleting. For
example, removing a student record from the list whenever the student leaves the
course in the middle.
 Searching: The process of informing whether a particular item is present in a list
or it is not present in a list is called searching. We can also find a set of elements
based on some criteria. For example, display student names who have passed in
all subjects or who have scored more than 90%.
 Sorting: The process of arranging various data items either in ascending order or
descending order is called sorting. For example, in a student record consisting of
names, marks, phone number etc., we can arrange student records based on
alphabetical order of names or based on ascending order of marks etc.
 Merging: Given two sorted lists we can combine those two lists into a single
sorted list. This process is called merging. For example, two sorted arrays can be
combined into a single sorted array. This process is called simple merge.
 Traversing: The process of accessing each data item exactly once so that it can be
processed and manipulated is called traversal. For example, to print all array
elements, to display all student names in a class, to display each item in a list etc.

Each of the operations can be performed one after the other. For example, given an
item, we may have to traverse the list and during this process we can search for the
item in the list. If the item is present in the list, we may delete that item and insert
another item in that place. Then we may have to sort the resulting list and display the
sorted list.

Exercises
1) What is data? What is information?
2) What are the differences between data and information?
3) Define the terms: entity, attribute, entity set, field, record, file
4) Define data structures and types of data structures
5) What are primitive data structures? Explain
6) What are non-primitive data structures? Explain
7) Explain the different types of non-primitive data structures
8) What are the different types of number systems that are commonly used?
9) What are linear data structures? What are non-linear data structures? Explain
10) What are the operations performed on various data structures?
Chapter 2: Arrays
What are we studying in this chapter?
 Arrays: Definition and representation of linear arrays in memory
 Dynamically allocated arrays (Discussed in chapter 3)
 Array operations
 Traversing, Inserting and deleting
 Searching and sorting
 Multi-dimensional arrays
 Application of arrays:
 Polynomials (discussed in structures and unions – chapter 5)
 sparse matrices (discussed in structures and unions – chapter 5)

2.1 Introduction
In this section, let us see array concepts in detail. First, let us see “What is an array?”

Definition: An array is a special and very powerful data structure in C language. An


array is a collection of similar data items. All elements of the array share a common
name. Each element in the array can be accessed by the subscript (or index). Array is
used to store, process and print large amount of data using a single variable.

Ex 1: Set of integers, set of characters, set of students, set of pens etc. are examples of
various arrays.

Ex 2: Marks of all students in a class is an array of marks

The pictorial representation of an array of 5 integers, an array of 5 floating point


numbers and an array of 5 characters is shown below:

A[0] 10 B[0] 5.5 C[0] ‘A’


A[1] 20 B[1] 6.5 C[1] ‘B’
A[2] 30 B[2] 7.5 C[2] ‘C’
A[3] 40 B[3] 8.5 C[3] ‘D’
A[4] 50 B[4] 9.5 C[4] ‘E’
Array of 5 Array of 5 Array of 5
integers floats characters
2.2  Arrays
Now, let us see “What is a single-dimensional array?” A single-dimensional array
(also called one-dimensional array) is a linear list consisting of related data items of
same type. In memory, all the data items are stored in contiguous memory locations
one after the other. For example, a single dimensional array consisting of 5 integer
elements is shown below:

10 15 20 25 30
A[0] A[1] A[2] A[3] A[4]

Now, the question is “How to access these elements?” Since an array is identified by
a common name, any element in the array can be accessed by specifying the subscript
(or an index). For example,
 0th item 10 can be accessed by specifying A[0]
 1st item 20 can be accessed by specifying A[1]
 2nd item 30 can be accessed by specifying A[2]
 3rd item 40 can be accessed by specifying A[3]
 4th item 50 can be accessed by specifying A[4]
Now, let us see “How to declare and define a single dimensional array?” As we
declare and define variables before they are used in a program, an array also must be
declared and defined before it is used. The declaration and definition informs the
compiler about the:
 Type of each element of the array
 Name of the array
 Number of elements (i.e., size of the array)
The compiler uses this size to reserve the appropriate number of memory locations so
that data can be stored, accessed and manipulated when the program is executed. A
single dimensional array can be declared and defined using the following syntax:
data type such as int, float, char etc.
name of the array
expression must be evaluated to integer
type array_name [ int_expression ]; // semicolon is must at the end

Ex 1: int marks [5]; /* marks is an array of 5 integers */


5 memory locations
marks [0] [1] [2] [3] [4] with 2 bytes each.
 Systematic Approach to Data Structures using C - 2.3
2.2 Representation of Linear arrays in memory

Consider the following declaration:

C Syntax Pascal Syntax Pictorial representation


int a[5]; a : array[0..4] of integer
lower bound = 0 a[0] a[1] a[2] a[3] a[4]
upper bound = 4
Number of items = 5
= 4– 0 +1
= ub – lb + 1
Where ub is upper bound = 4
lb is lower bound = 0

not possible a : array[5..9] of integer


a[5] a[6] a[7] a[8] a[9]

Number of items = ub – lb + 1
=9 -5 +1
=5

Observe that in C language, array index always starts from 0 whereas in Pascal
language, array index can start from any integer (even negative indexing is possible in
Pascal). Now, let us see “How to obtain the location of a[j] in a single dimensional
array?” Let us take the following array declaration in Pascal language:
a : array[5..9] of integer; // Here, lower bound : LB = 5
// upper bound : UB = 9

The storage representation for the above single a[5] 3000


dimensional matrix assuming base address as 3000 can be a[6] 3002
written as shown in figure on the right hand side. a[7] 3004
a[8] 3006
The location of a[j] is given by:
a[9] 3008
Loc A[j] = base address + x ………………………….(1)

where
 x is the distance from base address upto jth row
2.4  Arrays
Calculation of x: Given the base address, the distance from base address can be
obtained as shown below:
Expressing in
terms of index
Address of each row

a[5] 3000 = 3000 + 0 = 3000 + 2 * 0 = 3000 + 2 * (5 – 5)


a[6] 3002 = 3000 + 2 = 3000 + 2 * 1 = 3000 + 2 * (6 – 5)
a[7] 3004 = 3000 + 4 = 3000 + 2 * 2 = 3000 + 2 * (7 – 5)
a[8] 3006 = 3000 + 6 = 3000 + 2 * 3 = 3000 + 2 * (8 – 5)
a[9] 3008 = 3000 + 8 = 3000 + 2 * 4 = 3000 + 2 * (9 – 5)
distance from base address 3000 = 2 * (j - 5)

So, distance from base address 3000 = 2 * ( j – 5 )


x = w * (j – lb )
where
 2 represent size of integer i.e., w in general
 5 represent the lower bound lb of the array
Substituting x in relation (1) we get:

Loc A[j] = base address(a) + w * (j – lb)


where
 w is the word length. w = 2 for integer values
w = 4 for floating point values
w = 8 for double values
 j is the index of the array
 lb is the lower bound of the array
Note: Observe the following points:

 Given any element a[j], its address can be calculated using the above relation and
the time taken to calculate location is same. So, the time taken to access a[5], a[6],
a[7], a[8] and a[9] remains same.
 The time taken to locate any element a[j] is independent of j. That is, irrespective
of j, the time taken to locate an array element a[j] remains same.
 This is very important property of linear arrays. (Linked lists discussed in chapters
8 and 9 do not have this property.
 Systematic Approach to Data Structures using C - 2.5
Example 2.1: A car manufacturing company uses an array car to record number of
cars sold each year starting from 1965 to 2015. Rather than beginning the array index
from 0 or 1, it is more useful to begin the array index from 1965 as shown below:
500 504 508 512 516 …….. 700

car[1965] car[1966] car[1967] car[1968] car[1969] ………. car[2015]

(a) Find the total number of years


(b) Suppose base address = 500, word length w = 4, find address of
car[1967], car[1969] and car[2015]
Solution:
(a) It is given that lower bound = lb = 1965
Upper bound = ub = 2015
So, total number of years = ub – lb + 1
= 2015 – 1965 + 1
= 51 years
(b) We know that Loc(a[j]) = Base(a) + w *(j – lb)
Loc(car[1967]) = 500 + 4 * (1967 – 1965] = 508
Loc(car[1969]) = 500 + 4 * (1969 – 1965] = 516
Loc(car[2015]) = 500 + 4 * (2015 – 1965] = 700

Example 2.2: Consider the linear arrays AAA(5:50), BBB(-5:10) and CCC(1:18)
(a) Find the number of elements in each array
(b) Suppose Base(AAA) = 300 and w = 4 words per memory cell for AAA. Find
the address of AAA[15], AAA[35] and AAA[55]
Solution:
(a) The number of elements in each array can be calculated using the following
relation:
Number of elements = ub – lb + 1
So, number of elements of array AAA = 50 – 5 + 1 = 46
Number of elements of array BBB = 10 – (-5) + 1 = 16
Number of elements of array CCC = 18 – 1 + 1 = 18
(b) It is given that Base(AAA) = 300, w = 4, lb = 5
We know that Loc(a[i]) = Base(a) + w *(i – lb)
Loc(AAA[15]) = 300 + 4 * (15 – 5) = 340
Loc(AAA[35]) = 300 + 4 * (35 – 5) = 420
Loc(AAA[55]) cannot be computed since 55 exceeds ub = 50
2.6  Arrays

2.3 Operations on arrays


Now, let us see “What are the various operations that can be performed on arrays?”

The various operations that can be performed on arrays are shown below:

Traversing
Inserting
Deleting
searching
sorting
2.3.1 Traversing

Now, let us see “What is traversing an array?” Visiting or accessing each item in the
array is called traversing the array. Here, each element is accessed in linear order
either from left to right or from right to left.

In this section, let us see “How to read the data from the keyboard and how to display
data items stored in the array?”

We can easily read, write or process the array items using appropriate programming
constructs such as for-loop, while-loop, do-while, if-statement, switch-statement etc.
Consider the declaration shown below:

int a[5];

Here, memory for 5 integers is reserved and each item in the array can be accessed by
specifying the index as shown below:
Using a[0] through a[4] we can access 5 integers.

Note: In general, Using a[0] through a[n-1] we can access n data items.

Once we know how to access each location in the memory, next question is “How to
store the data items in these locations which are read from the keyboard?”

This is achieved by reading n data items from the keyboard using scanf() function
which is available in C library as shown below:
 Systematic Approach to Data Structures using C - 2.7
scanf(“%d”, &a[0]);
scanf(“%d”, &a[1]);
scanf(“%d”, &a[2]);
………………
………………
scanf(“%d”,&a[n-1]);

In general, scanf(“%d”,&a[i]) where i = 0, 1, 2, 3,……n-1.

So, in C language, if we want to read n data items from the keyboard, the following
statement can be used:

for (i = 0; i <= n-1; i++) for (i = 0; i < n; i++)


{ {
scanf(“%d”, &a[i]); or scanf(“%d”, &a[i]);
} }

Similarly to display n data items stored in the array, replace scanf() by printf()
statement as shown below:
for (i = 0; i < n; i++)
{
printf(“%d”, a[i]);
}
Now, the function to create an array by reading n elements can be written as shown
below:
Example 2.3: Functions to read n items into an array

void create_array(int a[], int n)


{
int i;
for (i = 0; i < n; i++) i=0 1 2 3 4
{ a[0] a[1] a[2] a[3] a[4]
scanf(“%d”, &a[i]); 10 20 30 40 50
}
}
Now, the function to display n elements of the array can be written as shown below:
2.8  Arrays
Example 2.4: Functions to display n elements of array

void display_array(int a[], int n)


{
int i;

for (i = 0; i < n; i++) i=0 1 2 3 4


{ a[0] a[1] a[2] a[3] a[4]
printf(“%d ”, a[i]); 10 20 30 40 50
}
}

2.3.2 Inserting an item into an array (based on the position)

Now, let us see “How to insert an item into an unsorted array based on the position?”

Problem statement: Given an array a consisting of n elements, it is required to insert


an item at the specified position say pos.

Design: An item can be inserted into the array by considering various situations as
shown below:

Step 1: Elements are present (Invalid position): This case can be pictorially
represented as shown below:
Item = 60
a 50 40 20 90 70 80 30
0 1 2 3 4 5 6 7 8 9
n=7 1
pos
Can you insert an item at 8th position onwards in the above array? No, we cannot
insert since, it is invalid position. That is, if pos is greater than 7 or if pos is less than
0, the position is invalid. The code for this case can be written as shown below:
if (pos > n || pos < 0) // When pos is greater than number of items
{
1 printf (“Invalid position\n”);
return n; // No insertion and return number of items
}
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Other documents randomly have
different content
Visconti; but that monarch preferred the large sum which they
offered him for his sanction of their rule as Imperial Vicars, rather
than the hostility of princes who could assemble six thousand men-
at-arms and numberless foot soldiers beneath his window as a
spectacle for his entertainment when he visited them in Milan. The
Gonzaga of Mantua, once their allies and now their bitterest foes,
leagued, however, with the Church and the hereditary foes of the
Visconti and dealt them some heavy blows. The German company
which the Mantuan princes employed invaded the Milanese
territories under the formidable Count Lando, and penetrated nearly
to the capital. But the citizens, in spite of their softness and lack of
military practice, went forth with the courage of despair and
defeated and drove away the Count, who was greatly surprised,
since he nothing esteemed the Milanese. In other directions the
Visconti suffered great losses. Genoa revolted in 1356, and to secure
peace they were compelled to surrender Parma and Asti two years
later.
The eldest brother, Matteo, had died in 1355. Weak, injudicious and
a glutton, he was only a hindrance to the progress of his House.
General report laid his death to his brothers’ charge. Bernabò and
Galeazzo made a fresh division of the State, and Milan itself was split
up between them. They worked together, however, with a single
aim, in spite of mutual hatred and jealousy, to repair the losses of
their State. Pavia had set up a free government, headed by the friar,
Giacomo de’ Bussolari, who, an earlier Savonarola, sought to purge
his city from tyranny and sin at once. Steadfastly beset by Galeazzo’s
army, it had to yield at last to famine and sickness. Further afield
Bernabò spent years in a desperate struggle to recover Bologna,
under a tempest of papal anathemas, and though baffled himself, he
prepared the way for his successor. He was constantly in fierce
conflict with the Marquises of Este, whose rebel kinsmen he
sheltered while they employed Luchino’s disinherited sons against
him. Galeazzo on his side had to sustain the assaults of Savoy and
Montferrat, which came near to ruining him.
But multitudinous and determined as their enemies were, the
inimitable statecraft which was the Viscontean heritage, backed by
their vast resources, enabled them to restore their power and to
make Milan feared and respected everywhere abroad. These princes
rarely took the field themselves, but entrusted their enterprises to
the foreign companies by whom the Italian wars were now chiefly
waged. These bands of hardy and unscrupulous adventurers, who
were proof against the enervation which wealth and civilisation had
induced in the Italians, were become powerful factors in the politics
of the country. Most formidable of all was the company of Sir John
Hawkwood. These English mercenaries, says Azario, were more
excellent robbers than any of the other plunderers of the Lombards.
By day they mostly slept and waked by night. And so diligent and
skilful were they in capturing towns that their like had never been
seen. After suffering much from Hawkwood’s zeal against him in the
service of the Pope, Bernabò bribed him to his own side; but after a
few years the great captain, faithful only to caprice, suddenly
deserted the Visconte, with disastrous results to the latter. Later on,
Bernabò tempted him again by the gift of one of his own daughters
in marriage, with a large dowry. Nevertheless, the later part of
Hawkwood’s career was spent in the pay of Milan’s inveterate foe,
Florence.
Milan, unaffected by the quarrels of her sovereigns, was now the
richest, most populous and luxurious city of Italy. The capitals of the
great European kingdoms had no such splendid palaces, such
comely-paved streets, such fair-fountained gardens and pleasaunces
trodden by beautiful exotic beasts and birds, as this seat of citizen
princes. The Visconti assumed the dignity and state of royalty.
Galeazzo was himself married to a princess of the ancient House of
Savoy, and both brothers pursued the sagacious policy of making
alliances for their children with the sovereign Houses of Europe.
Bernabò made statesmanlike use of his ten daughters and five sons
by his wife Regina della Scala, and his score or so of illegitimate
children, wedding them, according to the conditions of their birth, to
royal princes and great Italian potentates, or to lesser nobles and
successful soldiers, such as Hawkwood and Count Lando. Galeazzo
married his one son and daughter with even greater splendour, and
endowed them so lavishly that it was almost the ruin of his State.
For his heir, Gian Galeazzo, he obtained the hand of Isabella de
Valois, for a sum of five hundred thousand florins. The maiden
Violante he gave to Lionel, Duke of Clarence, son of Edward III.,
with two hundred thousand florins and many fair lands and castles in
Piedmont.
This last marriage was celebrated in 1368, with unexampled
magnificence. The bridegroom arrived in Milan accompanied by the
Sire le Despencer and a train of two thousand Englishmen. A
splendid cavalcade went forth to meet him. First came Galeazzo
himself, who was said to be more beautiful in person than any other
man in Italy, wearing, as his custom was, a wreath of roses on his
flowing golden hair, and attended by his greatest vassals. With him
was his wife, Bianca of Savoy, and his daughter-in-law, the young
French Isabella, and other noble ladies, followed by eighty damsels
apparelled in scarlet, with sleeves of white cloth embroidered with
trefoils, and girdles so richly worked that their worth was eighty
florins each. Gian Galeazzo, a boy of fifteen, came next, leading a
company of knights on steeds caparisoned as if for a joust, and after
these followed the officers of State and of the household with their
pages, all gorgeously arrayed. At the marriage feast the very meats
were gilded, and with each of the sixteen courses splendid gifts were
offered to the guests—highly-bred hounds with velvet and silken
collars and leashes of silk; falcons with chains of gold and hoods of
velvet, and silver buttons enamelled with the Snake; richly
ornamented saddles and other horse furniture; suits of armour
fashioned by the famous Milanese smiths; brocades of gold and
richest silk, silver flagons worked with enamel, silver-gilt basins,
mantles and doublets thickly sewn with pearls for the prince, and
seventy-six splendid coursers and war-horses, each more generous,
beautiful, and gorgeously caparisoned than the one before; and last
of all twelve fat oxen. Galeazzo and the bridegroom sat at one table
with the noblest of the guests, among whom was Messer Francesco
Petrarca the poet, in the most honourable place. At another were
placed Regina della Scala and a number of ladies. Such scenes as
these are dimly pictured for us in primitive frescoes here and there,
in which we see assemblages of ladies in jewelled robes and lofty
peaked head-dresses, and gentlemen correspondingly fine stiffly
seated at narrow boards, or pacing with slow and stately step
through the dance within some spacious pillared hall.
Though extravagantly lavish for State purposes, the Visconti did not
keep open Court like their predecessors. No tables were set out in
the streets for the common people on holidays, no oxen roasted
whole or wine-vats broached for all who liked to drink. The
chroniclers complain of the avarice of their Lords. The taxes were
continually increased. Pressed by the huge cost of their wars and
their alliances, the Visconti were in fact always in need of money,
and so assured was their supremacy in Milan, that they no longer
feared the discontent of the citizens. With the development of their
despotism the social gulf between the Visconti and the rest of the
community had grown wide. Both brothers were proud, suspicious
and cruel. But the severity of the silent Bernabò, and his terrible fits
of rage and strange capricious temper, made him the most feared.
He was laudably resolved to maintain justice and order, so that a
man might go unarmed through any part of his dominions, and to
suppress the old faction hatreds, but his methods were intolerably
harsh. No one was allowed to call himself Guelf or Ghibelline on pain
of having his tongue cut out. To be found abroad in the city at night,
for any reason whatever, was to lose a foot, and so forth. Moreover,
on mere suspicion people were put to cruel death or torment. This
arbitrary severity was, however, of little avail, and crime was far
more rife in the city than before Bernabò’s time. The tyrant’s passion
for dogs was as extravagant as his disregard for human suffering. He
had five thousand hounds, which his subjects were compelled to
keep and tend for him, and if one were found to be either too fat or
too lean for the chase, or to have come to any harm, woe to its
guardian. Every sort of game was sacred to the prince’s sport, and
the peasants who slew wild boars or other forest creatures for food
during a severe famine, were hanged or blinded. Two Franciscan
brothers, who dared to expostulate with the prince for his
harshness, were burnt as heretics, an act something ironical on the
part of one who himself spent nearly all his life under the ban of the
Church. There was a certain grim humour in some of Bernabò’s
fierce deeds, as in his treatment of two dignified Benedictine abbots,
who were sent to treat with him by the Pope. The prince met them
on a bridge over the Lambro, where, with due reverence, they
presented to him the pontifical Bulls. Bernabò read them, and
looking up, eyed the legates grimly, and asked them whether they
would prefer food or drink. Perceiving a sinister meaning in the
question, the trembling clerics glanced at the deep river flowing
beneath, and said that they would rather eat. Whereupon the papal
missives, parchment, seals, silk cord and all, were crammed down
their throats.
Galeazzo was not so capriciously cruel as his brother, but his rule
was equally oppressive. To add to the afflictions of the people, the
country was devastated by the foreign Companies, who robbed
friends and foes alike; and years of famine and pestilence came,
which their Lords took no more thoughtful measure to relieve than
hanging some of the chief ministers. To both brothers clings the
horrible reproach of a decree, condemning prisoners of State to the
so-called Quaresima, a series of tortures lasting forty days. Yet
Galeazzo was conspicuous for domestic virtues, and both princes
were very devout, and founded many churches and convents, and
gave largely in alms. One has to remember in judging these
sovereigns that the Florentine chroniclers, who have always held the
ear of the world, hated them as the enemies of their city. They
depict them as barbarous and ignorant tyrants, sunk in gross vice.
Yet Petrarca, the recognised sovereign of thought and letters in
fourteenth century Italy, spent several years at Milan, in the service
first of Archbishop Giovanni, and afterwards of Galeazzo, and speaks
of the city and its Lords with great affection and respect. The high
honour which the Visconti paid to the poet shows their regard for
the things of the spirit. Their capture of Petrarca was felt to be as
great a triumph as the conquest of a province. Boccaccio and other
Tuscan writers inveigh fiercely against their countryman for his
adherence to the Visconti, pretending that he who loved freedom
had been deluded by the vulgar worship of riches and luxury, and
had become a slave. But Petrarca, whose close acquaintance could
judge better of his hosts, probably appreciated the large and far-
reaching political ideas which were the heritage of the Visconti, and
perhaps saw in Milan a hope for Italy, outside the conception of the
Florentines, the possibility of a larger freedom in national union,
which should restore the successors of the Romans to their lost
glory.
The Visconti, moreover, took great pains to advance learning and
culture in their dominions. They founded the University of Pavia, the
once celebrated school of jurisprudence there having long decayed,
and richly endowed its chairs, and it was Galeazzo who started the
famous library at Pavia, to which all students were allowed access.
Bernabò was something of a scholar himself, and had studied the
Decretals in his youth; but the anxiety of constant wars and the
cares of State hindered him from doing all that he would willingly
have done for the intellectual welfare of the capital.
The bitter jealousy which prevailed between the two brothers
divided them much in later years, though it could not disunite them
in the face of their foes, and Galeazzo had left Milan and removed
his Court to Pavia, though still keeping his share of the government
of the capital. He died in 1378. His son, Gian Galeazzo, was delicate
of constitution, of retiring habits, and much given to study. The
gentleness with which he began to rule, remitting taxes and seeking
to propitiate his subjects, excited the scorn of the grim Bernabò,
who readily accepted the proposal of the young widower—Isabella
de Valois having died—for the hand of his daughter Caterina,
thinking thus to get an extra hold upon him. Little did the veteran
prince suspect that this mild recluse, who was hardly ever seen out
of his palace at Pavia, was the very quintessence of that subtlety,
tenacity and ambition which had made the House of the Visconti the
most dreaded in Italy. Gian Galeazzo’s genius for statecraft had been
carefully trained by his father. While Bernabò regarded him as of
little account, he was strengthening his position both at home and
abroad by quiet diplomacy, and evolving mighty schemes in his
mind, while he patiently waited the ripe moment for their
accomplishment.
There is nothing more dramatic in all the sensational story of
mediæval Italy than Gian Galeazzo Visconte’s sudden spring to
power. Seven years had passed since his father’s death, and
Bernabò’s tyranny had grown ever more oppressive, in sharp
contrast to his fellow-ruler’s. One day in 1385 Gian Galeazzo set
forth from Pavia for Milan, escorted by four hundred men-at-arms,
having announced his intention of visiting a holy shrine near Varese
and his desire of embracing his honoured uncle on his way. He had
arranged not to enter the capital, but to skirt the walls till he
reached the castle beside Porta Giovia, recently built by his father.
Laughing at the young man’s caution and his pusillanimity in
bringing so large an escort, the elder Visconte sent two of his sons
on ahead, and swinging himself into the saddle, galloped off, with
two or three servants only, to meet his nephew. The two Sovereigns
had but exchanged greetings when, Gian Galeazzo signed to the
captain of his escort, Jacopo dal Verme, who laid his hand upon
Bernabò’s shoulder, and in a moment the tyrant found himself a
prisoner. With his sons he was hurried into the Castle of Porta
Giovia. Gian Galeazzo entered the city and was received with
immense joy. Not vainly had he counted upon the terror and hatred
which his uncle had excited. The people, rushing to the houses of
the fallen tyrant and his sons, sacked them from end to end, fired
and tore them down, and razed them to the ground. In a General
Council of the citizens the sole and absolute dominion of Milan was
unanimously conferred upon Gian Galeazzo and upon his male heirs.
Bernabò was removed soon after to the Castle of Trezzo, and died
seven months later, of poison, it was said. His sons, except the two
captured, had fled in all directions, and were doing their utmost to
raise help against the usurper. But so perfectly had Gian Galeazzo
conceived and accomplished his great stroke, and with the exercise
of such consummate diplomacy and such victorious arms did he
secure himself afterwards, that not one of Bernabò’s children, in
spite of their princely alliances, were able, with all their constant
efforts, to overthrow him or recover any part of their heritage.
The usurper’s one excuse for his treachery was that his uncle and
cousins had been openly intriguing against him. Immediately after
the capture of Bernabò he drew up a solemn indictment against him,
charging him with a catalogue of appalling crimes, and with insidious
designs against his, Gian Galeazzo’s, life, and sent it to all the Courts
of Europe. This characteristic attempt to give legal justification to his
action deceived nobody. Italy at large regarded the young ruler with
an admiration and dread which events soon proved well-founded.
The brain which had shown such sovereign dissimulation cherished
ambitions before which whole cities and states were to fall. It was
not long before his schemes began to be fulfilled. The story of Gian
Galeazzo’s military enterprises is one of almost unbroken conquest.
He was no soldier himself, but he knew how to choose his generals,
and he got the best out of them by interfering with them little and
rewarding them very generously. The chaotic state of Italy at the
time gave him his chance. So extraordinary was his success, that he
was regarded as something almost diabolical. It seemed to his
terrified enemies that he fascinated those whom he marked for
destruction, so that they fell with eyes open into his snares.
Francesco da Carrara, Lord of Padua, was persuaded to aid him to
overthrow the Scaligeri of Verona. That city having been conquered
in 1387, Gian Galeazzo picked a quarrel with his ally, besieged and
captured Padua (1389), and sent Francesco to die in the dungeons
of Monza. Master now of Verona and Padua, the Visconte had
touched the Adriatic shore. Meanwhile Mantua and Venice looked on
stupidly and awaited their own destruction as if paralysed. General
fear possessed Italy at the rapid progress of the conqueror, who,
unseen himself, directed his instruments with such unfailing insight
to his desired ends. The Visconte’s policy was to strike at the weak
first and gradually prepare the way for greater enterprises. The
Church was at this time in the throes of the Great Schism, and Gian
Galeazzo, protesting conscientious difficulties in deciding to which
Pope he owed spiritual obedience, played them against one another,
while he seized the papal fiefs in the Romagna. His armies climbed
the mountains and poured into Umbria and Tuscany. Aroused at last
by the example and exhortations of Florence, Italy shook off her
stupor, and a general effort was made to stem the advance of the
Visconte. Yet still he crept on, remedying the checks to his arms by
his stealthy diplomacy. The King of France, in answer to the appeal
of Florence, sent an army to invade his States, but it was routed by
Jacopo dal Verme, and Charles VI. was himself converted into an ally
by the Visconte’s flatteries and promises. In 1399 he triumphed over
Florence again by acquiring Pisa, without a blow, from Gerardo
d’Appiano, while Perugia, Siena and Assisi submitted to his generals.
Already in 1395 Gian Galeazzo’s great increase of power and
prestige had been marked by his elevation to a new dignity. His
untiring negotiations, backed by the offer of an enormous sum,
persuaded the Emperor Wenceslaus to constitute the Milanese State,
including a number of conquered cities, into a Duchy, and to invest
the Visconte and his male heirs with it in perpetuity. The ceremony
of investiture took place in the Piazza of St. Ambrogio, where upon a
great throne the imperial legate robed and crowned the new duke in
the sight of all the people, in the midst of every pompous
circumstance, while in the basilica afterwards the Bishop of Novara,
destined to become Pope Alexander V., preached the sermon and
lauded the subject of his oration for his illustrious blood, his
conspicuous beauty of person and the virtuous tranquillity of his
mind.
Gian Galeazzo was as great an administrator as statesman and
conqueror. By wisdom, economy, careful distribution of taxation and
supervision of finances, he relieved the people from the cruel and ill-
considered burdens imposed by the bad management of his
predecessors, while increasing his own resources enormously. He
was the very genius of order. He saw that the law was properly and
effectively carried out, justice done to all, and perfect rule
maintained throughout the State. It was by his generous, just, and
wise government of the cities which he conquered that he
consolidated his vast dominions.
In these favourable conditions Milan flourished exceedingly, and
could contribute without overwhelming distress her share of the
duke’s annual revenue of twelve hundred thousand florins, and of
the extra levies for special purposes, amounting sometimes to eight
hundred thousand florins in one year—sums far exceeding those
commanded by any other Italian prince.
Gian Galeazzo’s rule, though sometimes oppressive, was not carried
on by the harsh methods of his predecessors. Violence and wanton
cruelty were probably repugnant to his sensitive physical
temperament and despicable to his unimpassioned mind. He was
never bloody, except for a purpose, as in the awful sack of Verona
after her revolt and recapture in 1390. But for a refined and
ingenious cruelty which exercised itself in long worming plots ending
far off in some unexpected catastrophe, Gian Galeazzo seems to
have had an artistic predilection. It was he, men said, who by Iago-
like suggestions drove Francesco Gonzaga of Mantua to slay his wife
Agnese, one of Bernabò Visconte’s daughters, in a frenzy of jealousy,
that he himself might be first and loudest afterwards in proclaiming
the innocence of the lady and exciting general execration of the
murderer. The beheading of young Obizzo d’Este at Ferrara has been
also attributed to evil suspicions which the Milanese prince instilled
into the Marquis Alberto for political ends. The Visconte’s influence is
plainer still in the hideous treachery and ingratitude of Jacopo
d’Appiano, who, with a kiss of peace, slew his protector and friend,
the noble Pietro Gambacorti, and made himself Lord of Pisa for Gian
Galeazzo’s benefit, as very shortly appeared.
The Duke’s piety was as marked as his less estimable characteristics.
He did not doubt his own righteousness or hesitate to invoke the aid
of Heaven for all his enterprises. He was assiduous in his devotion to
the Saints and observance of the Church’s rites and ceremonies. The
Cathedral of Milan, the vast Certosa of Pavia, and many other great
buildings, were planned and founded by this prince. These works
were not done solely for a spiritual reward, but also to proclaim his
own glory to the world and to encourage art and industry. All Gian
Galeazzo’s greatness of spirit showed in his buildings. His
engineering schemes were as mighty and daring in conception as
undaunted and patient in accomplishment. To subdue Padua and
Mantua he undertook the gigantic task of diverting the Brenta and
Mincio. But here he measured himself too audaciously against
natural forces. One night the Mincio, ‘in piena,’ hurled its waters at
the huge dam and swept away the work which had cost untold
labour and gold.
With all his occupations of war and statesmanship, Gian Galeazzo
found time to continue his father’s patronage of Letters. He had as a
youth studied deeply himself in the University of Pavia. An early
fresco at Pavia, now long lost, represented him as a child standing in
a crowd of nobles and distinguished men in his father’s palace, and
in answer to the question, who was the greatest man present,
pointing to the poet Petrarca. This allegory recorded the honour
which he paid all his life to intellect and learning. He called the
greatest scholars to the Chairs of the University, including Emanuel
Chrysoloras, who thus brought to Milan the newly reviving
knowledge of Greek. He made these men his councillors and familiar
associates. They read poetry to him and discussed the new
discoveries of antiquity, so that his castle has been called a temple
of wisdom. Architecture, sculpture, painting were equally fostered by
him. There was no sort of human activity which he did not seek to
stimulate for the advantage and glory of his State.
Though its operations meant destruction to lesser powers, Gian
Galeazzo’s brain was essentially kingly and creative. This was the
moment in Italy of the formation of great States. The old faction
struggles of the era of freedom had come to an end with the
establishment of tyrannies, and of these the lesser were now being
swallowed up by the greater. In this process Milan under the Visconti
was the leader. Its natural outcome seemed to be the foundation of
a great settled kingdom in the peninsula, like France and England in
the North. The patriotic spirits of the time dreamed of such a
kingdom as the redemption of Italy from her woes of constant
dissension and warfare. The idea took practical shape in the mind of
the great Matteo’s descendant and heir, in whom character and
circumstance united to carry the large political thought and ambition
of the Visconti nearest to its supreme fulfilment. And it was to Gian
Galeazzo that the dreamers looked for the realisation of their desire,
as perhaps Petrarca had looked to the earlier generation. Fazio degli
Uberti, the fourteenth century Florentine poet and exile, who lived
long at the Viscontean Court, in one of his canzoni makes Rome cry

‘O figliuol mio, da quanta crudel guerra
Tutti insieme verremo a dolcie pace
Se Italia soggiace
A un solo re....’[2]

2.
‘Oh my son, from what cruel warfare
Should we come all together to sweet peace
Could Italy be subject
To one sole king....’

To such a single crown Gian Galeazzo undoubtedly aspired. And


though he was defeated in the end, it was by no mortal means. All
the efforts of the hostile league of Florence, Venice, the Pope, and
the lesser Italian Princes, could not hinder his advance. His
dominions at the beginning of the fifteenth century embraced nearly
the whole of Lombardy and the Romagna. The Umbrian cities
Perugia and Assisi were his. Lucca, Pisa and Siena obeyed him. The
tide of his success crept on. He foresaw and discomfited every move
of his opponents. In 1401 Bologna, long an obstacle in his path, was
surrendered to him by the Bentivogli. His bravest and most obstinate
foe, Florence, lay virtually at his mercy. On every side of her he was
supreme. Cut off from all help she waited his deadly attack. The
moment of his triumph was at hand.
In July 1402 the Duke instructed his armies to close round the city of
the Arno. Retiring from Milan, where the plague had appeared, to his
villa at Melegnano, he had the mantle, sceptre and diadem prepared
for his coronation as King of Italy. He had nothing to fear now from
mortal enemies. There was one power only which his arms and
calculations could not defy. On the 10th of August he was seized
with the deadly contagion, and a few days later he died, at the age
of 49.
Who can tell the thoughts of the man as he lay on his death-bed, in
his hands at last all that he had laboured for day and night without
ceasing, and they powerless to close upon it. Who can measure the
passion of that defeated brain? His death caused infinite joy in
Florence, and in Italy generally. Yet there were many who, with an
anonymous poet of the time, wept for the loss which had deprived
‘questo emisfero
de quel che col pensiero
Sanar volia l’italico payese.’

Their lament was justified. The direct result of the tyrant’s death was
the release of all the elements of disorder and reaction in Italy, the
revival of angry faction, the break-up of a great organised State
among a host of greedy and warring pretenders, and the terrorism
of military adventurers over the whole country, ending in the
establishment of a dynasty in Milan destined to sell Italy to her final
shame and ruin. What if Gian Galeazzo had lived a few years longer?
Florence would probably have fallen before him, Florence whose
incurable spirit of individualism had been the one barrier between
him and his ambition. But was that single little torch of liberty, which
itself was soon to waver and be spent, worth the sacrifice of a
united and peaceful Italy, strong enough to resist all outside foes,
forward enough to lead all Europe in the path of progress?
Yet if that noble fruition of art and civilisation which glorifies the
fifteenth century in Florence was conditional on her independence,
then Italy through all the tears of her after centuries of sorrow and
humiliation might well answer Yes.
THE SNAKE OF THE
VISCONTI
CHAPTER VI
From Visconti to Sforza

“Una città corrotta che vive sotto un principe ... mai non si può ridurre libera.”—
Macchiavelli.

G ian Galeazzo’s three sons by Isabella of Valois had died in


infancy, leaving him with one daughter only, Valentina, whom in
1387 he had married to the Duke of Orleans, brother of Charles VI.
of France, an alliance of immense immediate advantage to the
Visconti, but of fatal issue for Milan and Italy generally, in days
beyond even his far vision. After some years of marriage, his second
wife, Caterina Visconte, had borne him a son, whom he had named
Giovanni Maria, decreeing that every one of his descendants should
thenceforth bear the name of Maria, as a token of his gratitude to
the Virgin, to whose intercession he attributed the birth of his heir. A
second son, Filippo Maria, was born later. At the time of the Duke’s
death the elder was only fourteen, and the younger ten. In addition
to their youth, they had the enduring disadvantage of issuing from
parents both of the same stock, which already, in the ferocity and
capriciousness of Bernabò and the physical timidity and weakness of
Gian Galeazzo himself, had shown signs of vitiation. This taint in the
blood became in Giovanni Maria a moral disease, amounting to
mania, and in his brother an exaggerated misanthropy and timidity.
Giovanni Maria succeeded to the dukedom, and Filippo became by
his father’s will Count of Pavia, which had been erected into an
appanage of the sovereign House. The charge of the young Duke’s
person and state immediately became the object of a wild scramble
among the different parties in the city. The dead man’s will,
appointing his widow regent, was utterly disregarded, and she and
her adviser, Francesco Barbavara, were driven out by Estorre and
Carlo Visconte, two of Bernabò’s sons, who now reappeared after
long exile, hoping to recover their heritage. The Duchess died in
1404, poisoned, it was believed, by her son. But this unhappy lady,
who had seen her father entrapped and murdered and her whole
family ruined by her husband, and whose sons were now helpless in
the hands of robbers and foes—who had been driven hither and
thither in the whirl of faction and was already paralytic—might well
sink beneath her sorrows, without the help of this unnatural crime,
which there seems to have been no better reason than his general
wickedness for laying to the young Duke’s charge.
Meanwhile Bernabò’s sons were swept away by other faction
leaders, to return and be again overthrown, as the fortunes of the
struggle surged backwards and forwards. One after another of Gian
Galeazzo’s great captains snatched and held the city for a time. Now
Ottobuono Terzo—now Carlo Malatesta—now Facino Cane, the most
famous of them all, ruled in the name of the utterly incapable Prince,
while out of the ruins of Gian Galeazzo’s vast State, which Venice,
Florence and the Church had hastened to dismember, each faithless
governor seized some remaining fragment wherewith to create a
small independent dominion for himself. Thus while the great Duke’s
conquests, further off, were quickly lost, cities close to the capital
and long subject to the Visconti fell to these lesser depredators.
Pavia and other towns were captured by Facino Cane, who kept the
young Filippo a virtual prisoner, and Monza became the stronghold
of Estorre Visconte and his spirited sister Valentina.
The confusion and struggle in Milan continued throughout the ten
years of Giovanmaria’s reign. The condition of the city was
lamentable. Peace and order were destroyed, and the names of
Guelf and Ghibelline were heard again in the streets, inflaming
household against household and awakening the horrors of civil war.
The Duke made no attempt to rule for himself. His only share in the
government was the execution of State prisoners, whom he caused
to be torn to pieces, under his own eyes, by dogs trained for the
purpose. The extraordinary passion for dogs, together with the
hatred of humankind, visible in Bernabò and others of the Visconti,
had become an extravagant ferocity in this degenerate member of
the race. The story of Milan during his reign is like some dreadful
dream, in which, when sleep has fallen on the incessant riots and
fighting, through the darkness of the night stalk the awful figures of
the maniac Prince, gloating in his sport, and his huntsman, Squarcia
Giramo, beside him, with their terrible hounds in leash, on the scent
of human blood.
The Duke’s appetite for blood was rewarded with Dantesque fitness.
He died in 1412, suffocated in his own blood in the precincts of the
palace, under the daggers of three Milanese nobles, who had sworn
to rid the world of a monster, and his body, lying in its blood in the
Cathedral, whither it had been carried and left alone by the general
horror, had for its only pall blood-red roses strewn upon it by a
harlot.
At the moment of Giovanmaria’s murder, Facino Cane, who for some
years had dominated Milan, lay on his death-bed. Filippo Maria
Visconte, whose youth had passed in confinement at Pavia, now
found himself at one stroke free, and in nominal possession at least
of the Dukedom. He was twenty years old. The astute young man’s
first step was to marry Beatrice Tenda, Facino’s widow, through
whom he became at once master of Pavia and the State which the
Condottiere had conquered for himself, and of Facino’s fine army and
immense treasure. He then led his troops to Milan, where his entry
was opposed by Estorre Visconte and a strong faction. The great
stronghold of Porta Giovia was, however, held for the legitimate
prince by the Castellan, Vincenzo Marliano, who roused the citizens
against Estorre. That brave soldier, the Hector of his race, was
overthrown, and he and his nephew Giovanni Carlo, with all their
supporters, were compelled to fly after a few days. The young Duke
marched in without opposition and was received with enthusiasm by
the people.
The city felt at once the presence of a master. Order was restored,
factions calmed, peaceful industry protected, and punishment
inflicted on Giovanmaria’s murderers. Filippo proceeded to engage
the most successful Condottieri of the day to defend and restore his
State, seconding their valour and generalship in the field by the most
careful and industrious diplomacy in every Court of Italy and the
principal European kingdoms. The rebel Visconti were subdued by
the death of Estorre and the surrender of Monza (1412), which the
brave Valentina relinquished, making honourable terms for herself
and the remaining descendants of Bernabò. Lodi, Como, Piacenza
and Brescia were recovered in the course of a few years, and in
1422 Genoa was won. Filippo’s rapid progress awakened the old
terror of the Snake once again in Italy. The third Duke of Milan had
indeed many of the successful qualities of his race, the craft, the
patience, the untiring industry. But they were vitiated by his timidity
of mind and body, which made him both suspicious and
superstitious. Supremely perfidious himself, he dared trust no man,
and constantly laid snares for his own agents, and ended by falling
into them himself. Thus in 1424, fearful of the glory of his great
general, Carmagnola, who had been the chief means of restoring his
fortunes, he offended and alienated the Condottiere, with disastrous
consequences. In his fear and dislike of all men he shut himself up
in the innermost recesses of the Castle of Porta Giovia, and
maintained as many precautions as if he dwelt in a city of traitors.
He tolerated few persons around him, except his astrologers, who
ruled him through his fears. He dared take no step without
consulting them. He was never seen by his subjects except upon
some rare State occasion, surrounded by guards, or when some
peasant, working in the solitary fields, spied him slipping hastily in
his barge along the canals between Milan and his favourite country
palace of Abbiategrasso.
This dark habit of life made him odious to the sunny-tempered
Milanese. They shuddered at this pale fat man, who increased their
horror by condemning his own wife to death in 1418. To Beatrice
Tenda and her vast dowry Filippo owed almost entirely his
possession of the Dukedom. Her years much exceeded her second
husband’s, though the Duke, like his father, had never been young.
Because he was tired of her, or because she was cross and
avaricious, as the chroniclers variously aver, or more probably
because she had served her purpose and was no longer of any use
to him, Filippo accused her of infidelity. She was arrested and carried
to the Castle of Binasco, together with her supposed lover, a
handsome young knight, Michele Orombello, who had solaced her
dreary existence with his skill upon the lute, and after having
resisted torture inflicted to make her confess herself guilty, she was
beheaded. Orombello and two of her ladies shared her fate. Ten
years later the Duke married, for political reasons, the Princess Maria
of Savoy. This poor lady was hardly less to be pitied than Beatrice.
The Duke neglected her himself, yet jealously kept her secluded
from all but her own women, allowing no man to appear in her
presence. Meanwhile Agnese del Maino, the lady who had secured
the tyrant’s affections, reigned in the Castle as his wife in all but
name. Filippo’s love for Agnese, a woman of spirit and culture, and
his devotion to the daughter she bore him, his only child, Bianca
Maria, were human traits in his otherwise unamiable character.
Though no lover of learning, Filippo continued, as much as
circumstances allowed, the Viscontean patronage of culture and
letters, the tradition that had descended from his ancestors, the
hosts of Petrarca. He kept up the University of Pavia and called great
scholars to its chairs. The celebrated humanist, Pier Candido
Decembrio, was for many years his secretary. He employed artists of
renown, including Brunelleschi and Pisanello, in various works. To his
daughter the Duke was careful to give the scholarly training which
with the revival of learning had become a necessary ornament for
the women as well as the men of the great Italian Houses, and
Bianca Maria added the accomplishments of Latin and Greek to the
beauty and spirit with which nature had endowed her.
But the Duke had neither means nor leisure amid the struggles of his
ambition and the pressure of his fears for much attention to the
peaceful arts. He was entirely occupied in redeeming his heritage
and preserving it from the greed of Venice, the inveterate hate of
Florence, the envy of the smaller States, and, from what he feared
most of all, the ambition and intrigues of the Condottieri in his own
employ. The fortunes of Italy were now, in fact, in the hands of the
great military adventurers. After a century and a half of physical
lassitude, during which her wars had been carried on by foreign
mercenaries, she had bred a race of warriors who had learnt their
craft so well in the camps of the German and English Condottieri
that they had now superseded the foreigners. With hosts of trained
and disciplined soldiers at their command, who knew no faith except
to their leader, they took service now with one sovereign, now with
another, and with their fickle arms and policy made and unmade
States at their will. Facino Cane and Jacopo dal Verme had already
played their parts, to the disruption of the Milanese State.
Carmagnolo, after serving Duke Filippo for many years, went over to
Venice, and for long balanced the two States one against the other,
by his crafty conduct of the war, till he fell a victim to the superior
cunning of the Doge and his councillors in 1432. And now, in the
midst of the noise of battle and the ferment of intrigue, in which all
the years of Duke Filippo were wrapped, the great name of Sforza is
first heard in Milanese story.
With the first Sforza and his son Francesco on the one side, and
Braccio Montone and Niccolò Piccinino on the other, the age of the
Condottieri culminated. The whole of Italy was plunged into strife by
these great leaders, in whom the old faction divisions of the country
were revived, and cities and States split up once again into hostile
parties, Guelfs and Ghibellines reappearing under the new names of
Sforzeschi and Bracceschi. These rival forces were at once the
salvation and the torment of Duke Filippo. The hope of succeeding
to the heirless man’s dominions—an elevation not beyond the
attainment of an obscurely born individual, in an age and country in
which men made themselves, and everything was possible to
strength and ability—was a bait which drew them to his service; and
with all his cunning and perfidious diplomacy he manipulated them
for his own advantage, pitting them against each other, now
encouraging one, now compassing his downfall by means of another.
But they, too, were cunning. It was a game of wits, and Filippo often
found himself outdone. Yet to the very end, though plagued, cajoled
and defeated on all sides, he succeeded in circumventing all the
efforts of either party to seat itself securely in Milan, preferring, with
his strange spite towards mankind, to leave his kingdom to anarchy
rather than adopt an heir.
In spite of him, however, destiny had raised up in a rustic race
hailing from Cotignola, in the Romagna, a regenerator for the worn-
out tyranny of the Visconti. Muzio Attendolo, the founder of the
Sforza family, is pictured by legend as a peasant boy, who, when
twelve years old, flung his woodman’s axe into a tree, and ran away
to the wars. He appears to have been really the son of a small
landowner, rich only in the possession of a progeny mighty in
number and in strength. The name of Sforza is said to have attached
itself to him, in consequence of some signal effort of his
extraordinary strength and will. These qualities, joined to his great
energy, raised him to the highest military fame. His life was chiefly
spent in the wars of Naples and the Church, but he had just
accepted service with the Duke of Milan, when one day he plunged
into a swollen river, under the arrows of the enemy, to save a
drowning boy, and sank beneath the weight of his armour (1424).
His son, Francesco, though only twenty-two, took command of his
army, and soon showed equal valour and much greater ability.
Engaged, in 1425, by Duke Filippo, he rapidly became a power in
Milan, where he struggled with the rival Condottiere, Niccolò
Piccinino, for supremacy in the councils of the Prince, and in the
favour of the people. In 1432, Filippo gave him the highest mark of
favour by promising him the hand of Bianca Maria, and with all
solemnity the little girl of eight years old was betrothed to the great
general. But no sooner had the Duke thus exalted Sforza, than he
hastened to depress and humiliate him in every way. Niccolò
Piccinino was given the chief command of the Visconte’s forces, and
Francesco was fain at the time to abandon Milan, and his hopes of
eventually possessing the Dukedom in his promised wife’s right, and
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookmass.com

You might also like