Data Structures and Overview
Data Structures and Overview
Data structure
Strings Trees
Arrays Graphs
Stacks
Linked lists
2. Explain the operations performed on data structures (7m)?
a. Creation operation:
This operation is used to create a DS.
b. Destroy operation:
Used to destroy a DS by using function free ( ).
c. Selection operation:
Used to access a data in DS.
d. Applied operation:
Is used data in a structure
a. Traversing:
Processing each element at least once.
b. Sorting:
Arranging the elements in ascending or descending order.
c. Merging:
Combining the element of two different sorted lists into
single sorted list.
d. Searching:
Finding the location of the element in the given T value.
e. Insertion & deletion:
Adding and removing the element to & from a data
structure.
3. Mention the goals of data structure (3m)?
Two fundamental goals, which are used in designing
high-level descriptions of data structures and algorithm, are:
*Correctness
*Efficiency
Correctness means that a data structure or algorithm is
designed at a high level to work correctly for all possible inputs
that one might encounter within a certain domain of interest.
Useful data structure and algorithm solutions also need to be
efficient i.e. they should be fast and not use more of the
computers resources than is necessary.
t f(n)
n ->
K (g (n)
F (n)
N0 n
A B C
2. Concatenation operation:
This is used to join (concatenate) one or more strings to form
a single string.
In c it can be done by using the function strcat ().
Syntax: strcat (str1, str2)
3. Substring operation:
Extracting a portion of a string from a given string is called
sub string operation.
It requires 3 pieces of information:
*The given string
*Position of the first character of the sub string in the given string.
*Length of the sub string or the position of the last character of the
sub string
Syntax: sub string(s, k, l).
4. Indexing operation:
It refers to finding the position where a string pattern P first
appears in a given string text of T .It is also called as pattern
matching. We call this operation INDEX and write
Syntax: INDEX (T, P) where T is the text & P is the pattern.
Disadvantages:
*Memory is not utilized efficiently.
*Length of the string should not exceed the allocated memory
Space.
Advantages:
*The unoccupied space can be utilized by some other string and
hence memory wastage is minimized.
Disadvantages:
*Memory is wasted for information field.
Advantages:
*Modifications, such as insertion, deletions are easier.
*Efficient storage representation.
Disadvantages:
*Extra memory is required for the link field.
*One cannot directly access a character in the middle of the list.
15. WAP to find the length of the string using pointer variable.
#include<stdio.h>
main ()
{
Char ptr1, ptr2;
Ptr2=ptr1;
printf (enter a string);
while ((*ptr1=get char ())!=\n)
*Ptr1++;
*ptr1=\0;
printf(length=%d, ptr1-ptr2);
}