Data Structures and Applications: A Simple and Systematic Approach 1st edition - eBook PDF download
Data Structures and Applications: A Simple and Systematic Approach 1st edition - eBook PDF download
https://ebooksecure.com/download/data-structures-and-
applications-a-simple-and-systematic-approach-ebook-pdf/
http://ebooksecure.com/product/evaluation-a-systematic-
approach-7th-edition-ebook-pdf/
http://ebooksecure.com/product/ebook-pdf-evaluation-a-systematic-
approach-8th-edition/
https://ebooksecure.com/download/structural-mechanics-and-design-
of-metal-pipes-a-systematic-approach-for-onshore-and-offshore-
pipelines-ebook-pdf/
https://ebooksecure.com/download/data-structures-ebook-pdf/
Data Fusion Methodology and Applications 1st Edition -
eBook PDF
https://ebooksecure.com/download/data-fusion-methodology-and-
applications-ebook-pdf/
http://ebooksecure.com/product/ebook-pdf-auditing-assurance-
services-a-systematic-approach-10th/
http://ebooksecure.com/product/ebook-pdf-data-structures-and-
abstractions-with-java-4th-edition/
http://ebooksecure.com/product/data-structures-and-abstractions-
with-java-5th-edition-ebook-pdf/
http://ebooksecure.com/product/ebook-pdf-auditing-assurance-
services-a-systematic-approach-11th-edition/
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.
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.
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
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
attributes
entity
student Name Usn Phone_no branch
MONALIKA 101 9900170827 CSE
Attribute values
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.
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
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:
c 3.1459 a
The variables b, c and d are called pointers since they contain address of variable a.
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:
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.
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:
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:
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.
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.
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?”
Ex 1: Set of integers, set of characters, set of students, set of pens etc. are examples of
various arrays.
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
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
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
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
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
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]);
So, in C language, if we want to read n data items from the keyboard, the following
statement can be used:
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
Now, let us see “How to insert an item into an unsorted array based on the position?”
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
}
Systematic Approach to Data Structures using C - 2.9
Step 2: Make room for the item to be inserted at the specified position: Consider
the following list with 7 elements and item 60 to be inserted at position 3.
Item = 60
a 50 40 20 90 70 80 30
0 1 2 3 4 5 6 7 8 9
n=7 pos
We have to make room for the item to be inserted at position 3. This can be done by
moving all the elements 30, 80, 70 and 90 from positions 6, 5, 4, 3 into new positons
7, 6, 5, 4 respectively towards right by one position as shown below:
2
Item = 60
a 50 40 20 90 70 80 30
0 1 2 3 4 5 6 7 8 9
n=7 pos
This is possible using the following assignment statements in the order specified:
a[7] = a[6];
a[6] = a[5];
a[5] = a[4];
a[4] = a[3]
In general, a[i+1] = a[i] for i = 6 down to 3
for i = n-1 down to pos
Now, the code for above activity can be written as shown below:
for (i = n-1; i >= pos; i--)
{
2 a[i+1] = a[i];
}
After executing, the above statement, the array contents 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 pos
2.10 Arrays
Step 3: Insert item at the specified position: The code for this case can be written as
shown below:
3 a[pos] = item;
Now, the contents of array can be written as shown below:
Item = 60 3
a 50 40 20 60 90 70 80 30
0 1 2 3 4 5 6 7 8 9
n=7 pos
Step 4: Update number of elements in above array: The code for this case can be
written as shown below:
4 return n + 1;
Now, the complete function to insert an item at the specified position can be written
as shown below:
Example 2.5: Function to insert an item at the specified position in the array
Design: An item can be deleted from 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:
a 50 40 20 90 70 80 30
0 1 2 3 4 5 6 7 8 9
n=7 1
pos
Can you delete an item from 7th position onwards in the above array? No, we cannot
delete since, it is invalid position. That is, if pos is greater than or equal to 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 >= number of items
{
1 printf (“Invalid position\n”);
return n; // No deletion and return number of items
}
Step 2: Display the item to be deleted: Consider the following list with 7 elements
and let the position pos is 3.
a 50 40 20 90 70 80 30
0 1 2 3 4 5 6 7 8 9
n=7 pos
The item at position pos can be accessed by writing a[pos] and it can be displayed
using the printf() function as as shown below:
a 50 40 20 70 80 30
0 1 2 3 4 5 6 7 8 9
n=6
Step 4: Update number of elements in above array: After deleting an item, the
number of items in the array should be decremented by 1. It can be done using the
following statement:
4 return n - 1;
Now, the complete function to delete an item from the specified position can be
written as shown below:
Example 2.6: Function to delete an item from the specified position in the array
Systematic Approach to Data Structures using C - 2.13
int delete_at_pos (int a[], int n, int pos)
{
int i;
if (pos >= n || pos < 0) // When pos >= number of items
{
1 printf (“Invalid position\n”);
return n; // No deletion and return number of items
}
2 printf(“Item deleted = %d\n”, a[pos]);
for (i = pos + 1; i < n; i++) // Move elements towards left
{
3 a[i - 1] = a[i];
}
4 return n - 1; // Decrement the number of items in array
}
Example 2.7: Design, Develop and Implement a menu driven Program in C for the
following Array operations
1. Creating an Array of N Integer Elements
2. Display of Array Elements with Suitable Headings
3. Inserting an Element (ELEM) at a given valid Position (POS)
4. Deleting an Element at a given valid Position(POS)
5. Exit.
Support the program with functions for each of the above operations.
#include <stdio.h>
#include <process.h>
void main()
{
int choice, a[10], n, item, pos;
2.14 Arrays
for (;;)
{
printf("1:Creat an array 2: Display \n");
printf("3:Insert at position 4: Delete at position \n”);
printf(“5:Exit\n”);
printf("Enter the choice\n");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("Enter the number of elements\n");
scanf("%d", &n);
printf(“Enter %d elements\n”, n);
create_array(a, n);
break;
case 2:
printf(“The contents of the array are\n”);
display_array(a, n);
break;
Definition: More often programmers will be working with large amount of data and it
may be necessary to arrange them in ascending or descending order. This process of
arranging the given elements so that they are in ascending order or descending order
is called sorting. For example, consider the unsorted elements:
Before writing the algorithm or the program let us know the answer for “What is the
concept used in bubble sort (Why it is also called sinking sort)?”
Design: Once we know what is sorting, the next question is “How to sort the elements
using bubble sort?”
Step 2: Return type: Our intention is only to sort the numbers. Hence, we are not
returning any value. So,
Step 3: Designing body of the function: This is the simplest and easiest sorting
technique. In this technique, the two successive items A[i] and A[i+1] are exchanged
whenever A[i] = A[i+1]. For example, consider the elements shown below:
A[0] = 50 40 40 40 40 30 30 30 20 20 10
A[1] = 40 50 30 30 30 40 20 20 30 10 20
A[2] = 30 30 50 20 20 20 40 10 10 30 30
A[3] = 20 20 20 50 10 10 10 40 40 40 40
A[4] = 10 10 10 10 50 50 50 50 50 50 50
Given 50 sinks to 40 sinks to 30 sinks to 20 sinks
array bottom bottom bottom to bottom
after pass 1 after pass 2 after pass 3
In the first pass 50 is compared with 40 and they are exchanged since 50 is greater
than 40.
Next 50 is compared with 30 and they are exchanged since 50 is greater than 30.
If we proceed in the same manner, at the end of the first pass the largest item
occupies the last position.
On each successive pass, the items with the next largest value will be moved to
the bottom and thus elements are arranged in ascending order.
Note: Observe that after each pass, the larger values sinks to the bottom of the array
and hence it is called sinking sort. The following figure below shows the output of
each pass.
A[0] = 50 40 30 20 10
Note: Observe that at the end of each
A[1] = 40 30 20 10 20
pass smaller values gradually “bubble”
A[2] = 30 20 10 30 30 their way upward to the top (like air
bubbles moving to surface of water)
A[3] = 20 10 40 40 40
and hence called bubble sort.
A[4] = 10 50 50 50 50
Algorithm BubbleSort(a[], n)
for j 1 to n – 1 do // Perform n-1 passes
for i 0 to n-j-1do // To compare items in each pass
if ( a[i] > a[i+1] ) // If out of order exchange
temp a[i]
a[i] a[i+1]
a[i+1] temp
end if
end for
end for
2.18 Arrays
Note: All variables other than parameters should be declared as local variables i.e.,
the variables i, j and temp should be declared as int data type in function.
The C equivalent for the above algorithm can be written as shown below:
Example 2.10: C program to read n numbers, sort them using bubble sort
#include <stdio.h>
void main()
{
int a[20]; /* Array of integers to be sorted */
int n; /* Number of elements in array a and b */
int i; /* Index used to access elements in a and b */
Discovering Diverse Content Through
Random Scribd Documents
The Project Gutenberg eBook of Lehrbuch der
Physik zum Schulgebrauche.
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: German
S c h u l g e b r a u c h e.
Bearbeitet von
Wilhelm Winter,
K. Gymnasialprofessor in München.
Sechste Auflage.
München
Theodor Ackermann
Königlicher Hof-Buchhändler.
1905.
W. Winter,
Kgl. Reallehrer.
Vorrede zur sechsten Auflage.
Nachdem das Buch besonders in der vierten und fünften
Auflage einige Änderungen erlitten hatte, besonders um es den
neuen Lehrplänen anzupassen, die Figuren durch bessere zu
ersetzen und die Aufgaben zu vermehren, war ich bei der
vorliegenden Auflage bestrebt, es dem Umfang nach zu verringern.
Ich folgte dabei auch dem Rate befreundeter Fachgenossen und war
bemüht, in allem die Ausdrucksweise zu vereinfachen, die
Erscheinungen in möglichster Kürze zu beschreiben und die Gesetze
möglichst klar und leicht verständlich zu fassen. Doch bin ich dabei
nicht unter eine gewisse Grenze gegangen, da meiner Ansicht nach
der Schüler im Buche selbst noch eine Darstellung finden soll,
welche ihm über manches, was ihm im Unterricht nicht ganz klar
geworden ist, eine leicht faßliche Aufklärung gibt. Die Aufgaben
wurden vermehrt und den einzelnen Kapiteln angefügt, jedoch ohne
die bisherige Numerierung zu ändern.
Ich hege die Hoffnung, daß das Buch auch fernerhin
wohlwollende Beurteilung finden und zum Gedeihen des
physikalischen Unterrichtes beitragen wird.
Der Verfasser.
Inhalts-Übersicht.
Erster Abschnitt.
A l l g e m e i n e E i g e n s c h a f t e n . L e h r e v o n d e n K r ä f t e n.
Zweiter Abschnitt.
L e h r e v o n d e n f l ü s s i g e n K ö r p e r n.
Dritter Abschnitt.
L e h r e v o n d e n l u f t f ö r m i g e n K ö r p e r n.
Vierter Abschnitt.
W ä r m e.
Sechster Abschnitt.
R e i b u n g s e l e k t r i z i t ä t.
Siebenter Abschnitt.
G a l v a n i s c h e E l e k t r i z i t ä t.
Achter Abschnitt.
I n d u k t i o n s - E l e k t r i z i t ä t.
Neunter Abschnitt.
W e l l e n l e h r e u n d A k u s t i k.
Zehnter Abschnitt.
O p t i k.
Elfter Abschnitt.
M e c h a n i k.
Zwölfter Abschnitt.
A n h a n g.
Interferenz der Wellen, des Lichtes. Beugung der Wellen, des Lichtes.
Polarisation. Doppelbrechung des Lichtes.
Die absoluten Maßeinheiten: die mechanischen, elektrostatischen,
elektromagnetischen, praktischen Einheiten.
Elektrische Wellen, drahtlose Telegraphie, Röntgenstrahlen.
Aufgaben.
Erster Abschnitt.
Allgemeine Eigenschaften der
Körper. Lehre von den Kräften.
3. Zusammendrückbarkeit und
Ausdehnbarkeit.
Jeder Körper läßt sich durch Druck auf einen kleineren
Raum zusammenpressen und durch Zug auf einen größeren
Raum ausdehnen.
Wird eine Silberplatte durch sehr großen Druck zur Münze
geprägt, oder Eisen zur Platte gewalzt, so nimmt es einen kleineren
Raum ein als zuerst. Doch beträgt die Verkleinerung bei allen festen
Körpern nur sehr wenig. Ein stabförmiger Körper wird durch Zug
länger und auch sein Volumen wird dabei größer.
4. Die Porosität.
Kein Körper nimmt seinen Raum v o l l s t ä n d i g ein, sondern
jeder hat in seinem Innern kleine Löcher, Gänge und Höhlungen, die
mit einem anderen Stoffe ausgefüllt sind, meist mit Luft oder
Wasser. Diese Hohlräume sind die Poren, und die Eigenschaft heißt
Porosität. Sehr stark porös und g r o ß p o r i g sind: Schwamm,
Brot, Bimsstein, das Mark von Binsen.
Sehr porös aber k l e i n p o r i g sind Kreide, Gips, Mörtel, Ton,
Ziegelsteine, Sandsteine, manche Kalksteine, Holz, Zucker u. s. w.
Ihre Poren sind so fein, daß man sie mit freiem Auge nicht sehen
kann. Taucht man einen solchen Körper ins Wasser, so dringt es in
die Poren des Körpers ein und macht ihn auch im Innern feucht. Die
meisten dieser Körper sind dadurch porös geworden, daß bei ihrer
Bildung oder zu ihrer Herstellung Wasser verwendet wurde, und daß
beim Austrocknen an dessen Stelle Luft eintrat.
Tönerne Gefäße lassen die Flüssigkeit auch in ihr Inneres
eindringen und durchsickern; um das zu verhindern, glasiert man
sie, d. h. man überzieht sie mit einer Glasschichte, welche die Poren
verstopft. Ähnlichen Zweck hat das Auspichen der Fässer, das
Versiegeln der Weinflaschen, Zementieren der Ställe, Wasserbehälter
und Abtrittgruben, das Ölen und Firnissen hölzerner Gegenstände u.
s. w.
In porösen Wänden steigt das Wasser des Erdbodens empor
und hält das Haus feucht (Einlegen von Asphalt- oder Bleiplatten).
Feinporige Körper kleben an der Zunge, weil sie die Feuchtigkeit
aufsaugen. Poröse Gesteine verwittern leicht.
Holz, obwohl sehr porös, läßt das Wasser doch nur langsam
eindringen; denn die meisten Poren des Holzes bestehen nicht aus
Gängen, die das Holz durchsetzen, sondern aus abgeschlossenen
Hohlräumen (Zellen). Ebenso Kork, welcher sogar einen luft- und
wasserdichten Verschluß gibt.
Manche Stoffe zeigen sich unporös; man nennt sie dicht oder
kompakt. Solche sind Marmor, Basalt, Elfenbein, dann die Kristalle
und solche Körper, welche aus einem dichten Gefüge kleiner Kristalle
bestehen (kristallinische Gesteine), dann solche, welche aus ruhigem
Schmelzfluß in den festen Zustand übergegangen sind, wie die
Metalle, Glas, Pech, Schwefel, Kautschuk, Porzellan, Klinkersteine u.
s. w. Glas ist selbst bei hohem Drucke undurchlässig für Wasser und
Luft.
Wasser, jede Flüssigkeit und jede Luftart sind nicht porös in dem
Sinne wie die festen Körper.
Aufgaben:
a) Wodurch wird Brot porös? b) Durch welchen Versuch kann
man erkennen, daß das Holz Poren hat, die es der Länge nach
durchsetzen? c) Welche Papiersorten sind porös? d) Inwiefern kann
man Tuch porös nennen? e) Welche Gesteine aus der nächsten
Umgebung sind porös?
5. Teilbarkeit.
Jeder Körper ist teilbar, d. h. er läßt sich durch Anwendung einer
Kraft in k l e i n e r e S t ü c k e z e r t e i l e n. Bedarf es hiezu nur
geringer Kraft, so nennt man den Körper w e i c h, bedarf es großer
Kraft, so heißt der Körper h a r t. Auch der härteste Körper, der
Diamant, ist teilbar; denn er läßt sich nach gewissen Richtungen
spalten, und mittels seines eigenen Pulvers schleifen. Ein Körper ist
härter als ein zweiter, wenn man mit dem ersten Körper den zweiten
ritzen kann; so ist Diamant härter als Rubin, dann folgen der Härte
nach Stahl, Glas, Eisen, Kupfer u. s. w.
Manche Körper lassen sich ungemein fein zerteilen, besonders
die Farbstoffe. So genügt die geringe Menge Farbstoff, die in einer
Cochenillelaus enthalten ist, um ein ganzes Glas Wasser rot zu
färben, was nur durch äußerst feine Zerteilung des Karmins möglich
ist. Je feiner sich ein Farbstoff zerreiben läßt, desto besser d e c k t
er. Gut deckt Tusch, Berlinerblau, Zinnober, Schweinfurtergrün;
schlecht deckt Bleiweiß (Kremserweiß), Ocker und Veronesergrün.
Riechstoffe müssen sich wohl in ungemein kleine Teile zerlegen;
denn ein erbsengroßes Stück Moschus kann ein ganzes Jahr
hindurch die oft wechselnde Luft eines Zimmers mit seinem Geruche
erfüllen, ohne daß es an Größe merklich abnimmt. Der K i e s e l g u r,
ein feiner Sand der Lüneburger Heide, besteht aus den
Kieselpanzern einer einzelligen Pflanze, welche mikroskopisch klein
ist.
Aufgaben:
a) Nenne Körper, welche sich mit dem Fingernagel ritzen lassen!
b) Wie ordnen sich die Stoffe: Stahl, Glas, Marmor, Quarz und Gips
der Härte nach? c) Warum deckt Tusch besser als zerriebene Kohle?
d) Welche Organismen sind dir aus der Naturkunde als sehr klein
bekannt?
6. Zusammensetzung der Körper aus
Molekülen.
Trotz der weitgehenden Teilbarkeit der Stoffe nimmt man an,
daß die Stoffe aus sehr kleinen Teilchen zusammengesetzt sind, die
an sich u n t e i l b a r sind. Man hat sich also vorzustellen, daß jeder
Körper aus ungemein vielen, ungemein kleinen Teilchen besteht, die
durch kein Mittel in noch kleinere Teile zerlegt werden können; man
nennt ein solches Teilchen Molekül oder Massenteilchen. Ein
einzelnes Molekül ist auch bei der stärksten Vergrößerung nicht zu
sehen, und wir sind wohl nicht imstande, einen festen Körper durch
Zerreiben oder ein ähnliches mechanisches Mittel in seine Moleküle
zu zerlegen. Ein Stäubchen, das in der Luft schwebt, das kleinste
Lebewesen, das nur bei stärkster Vergrößerung eben noch
wahrgenommen wird, besteht doch noch aus sehr vielen Molekülen.
In der Luft sind eine Million Moleküle nebeneinander auf der Länge
eines Millimeters, also ca. 1 Trillion in einem Kubikmillimeter
enthalten. Die Chemie lehrt, daß jedes Molekül aus mehreren
gleichartigen oder verschiedenen Stoffteilchen besteht, daß es in
diese zerlegt und in vielen Fällen aus ihnen wieder zusammengesetzt
werden kann, daß die Stoffteilchen sich aber (bis jetzt) nicht weiter
zerlegen lassen. Die Stoffteilchen nennt man Atome (Atom = das
Unteilbare).
Aufgaben:
a) Wie viele Moleküle enthält 1 cbm Wasser, wenn dessen
Moleküle nach jeder Richtung je ein Zehntausendstel Millimeter groß
sind? b) Wenn man die Luft eine millionmal dünner macht, wie viele
Moleküle sind dann immer noch in 1 cbm? c) Wenn man Zucker in
Wasser auflöst, oder Wasser mit Weingeist vermischt, so tritt eine
Volumverminderung ein. Wie ist das möglich?
Man nimmt ferner an, daß auch bei festen und flüssigen Körpern die Moleküle
sich nicht berühren, sondern in Abständen nebeneinander liegen, welche ca. 10
mal größer sind als ihre Durchmesser. Die Entfernung zwischen den Mittelpunkten
benachbarter Moleküle beträgt bei gewöhnlichen festen oder flüssigen Körpern
nicht mehr als ein Zehnmilliontel und nicht weniger als zwei Hundertmilliontel
eines Millimeters, so daß ein Kubikmillimeter wenigstens 1000 Trillionen und
höchstens 125 000 Trillionen Moleküle enthält. „Dehnt sich eine erbsengroße
Glaskugel oder ein Wassertropfen bis zur Größe der Erdkugel aus, so ist jedes
Molekül größer als ein Schrotkorn und kleiner als ein Krocketball” (Thomson). Von
den kleinsten bekannten Lebewesen (Mikroben), den Spaltpilzen, gehen ca. 3000
Millionen auf 1 Kubikmillimeter, so daß jedes aus vielen Hunderttausend Millionen
Molekülen bestehen kann; deshalb können auch sehr kleine Lebewesen noch
einen komplizierten Bau haben.
Fig. 5.