Data Structure Using C and C++ Basic
Data Structure Using C and C++ Basic
A data structure should be seen as a logical concept that must address two
fundamental concerns.
1. First, how the data will be stored, and
2. Second, what operations will be performed on it?
BCA-S202T: DS
Computer programmers decide which data structures to use based on the
nature of the data and the processes that need to be performed on that data.
Some of the more commonly used data structures include lists, arrays, stacks,
queues, heaps, trees, and graphs.
BCA-S202T: DS
Simple Data Structure: Simple data structure can be constructed with the help of
primitive data structure. A primitive data structure used to represent the standard
data types of any one of the computer languages. Variables, arrays, pointers,
structures, unions, etc. are examples of primitive data structures.
Compound Data structure: Compound data structure can be constructed with the
help of any one of the primitive data structure and it is having a specific
functionality. It can be designed by user. It can be classified as
Linear data structure
Non-linear data structure
BCA-S202T: DS
Non-linear Data Structure:
Non-linear data structure can be constructed as a collection of randomly distributed
set of data item joined together by using a special pointer (tag). In non-linear Data
structure the relationship of adjacency is not maintained between the data items.
Array:
In computer science, the obvious way to store an ordered collection of items is as
an array. Array items are typically stored in a sequence of computer memory
locations, but to discuss them, we need a convenient way to write them down on
paper. We can just write the items in order, separated by commas and enclosed by
square brackets. Thus,
[1; 4; 17; 3; 90; 79; 4; 6; 81]
is an example of an array of integers. If we call this array a, we can write it as:
a = [1; 4; 17; 3; 90; 79; 4; 6; 81]
This array has 9 items, and hence we say that its size is 9. In everyday life, we
usually start counting from 1. When we work with arrays in computer science,
however, we more often (though not always) start from 0. Thus, for our array a, its
positions are 0; 1; 2; : : : ; 7; 8.
The element in the 8th position is 81, and we use the notation a[8] to denote this
element. More generally, for any integer i denoting a position, we write a[i] to
denote the element in the ith position. This position i is called an index (and the
plural is indices). Then, in the above example, a[0] = 1, a[1] = 4, a[2] = 17, and so
on.
We say that the individual items a[i] in the array a are accessed using their index i,
and one can move sequentially through the array by incrementing or decrementing
that index, or jump straight to a particular item given its index value. Algorithms
that process data stored as arrays will typically need to visit systematically all the
items in the array, and apply appropriate operations on them.
Algorithms:
BCA-S202T: DS
4) Effectiveness: The operations of the algorithm must be basic enough to be
put down on pencil and paper. They should not be too complex to warrant
writing another algorithm for the operation.
5) Input-Output: The algorithm must have certain initial and precise inputs, and
outputs that may be generated both at its intermediate and final steps.
BCA-S202T: DS
Space Complexity: The space complexity of an algorithm or program is a
function of the space needed by the algorithm or program to run to
completion. The time complexity of an algorithm can be computed either by
an empirical or theoretical approach. The empirical or posteriori testing
approach calls for implementing the complete algorithms and executing
them on a computer for various instances of the problem. The time taken by
the execution of the programs for various instances of the problem are
noted and compared. The algorithm whose implementation yields the
least time is considered as the best among the candidate algorithmic
solutions.
BCA-S202T: DS