Documente Academic
Documente Profesional
Documente Cultură
Declaration:
I declare that this assignment is my individual work. I have not copied from any other student’s
work or from any other source except where due acknowledgment is made explicitly in the text,
nor has any part been written for me by another person.
Student’s Signature :
_____________
Evaluator’s comments:
_____________________________________________________________________
QUES 1: Write advantages and disadvantages of using pointer. How the concept of
pointers is useful in the implementation of data structures?
Ans 1- The main advantages of using pointers are:
1.) Function can return only one value. At the time of the same function the pointer help to
recognize the variable.
2.) In the case of arrays we can decide the size of the array at runtime by allocating the necessary
space.
3) The pointer has the address of the variable so it make the fast.
4) The pointer is necessary at the time of the run time memory.
Disadvantages of pointers:
1) It is complex.
2) If sufficient memory is not available during runtime for the storage of pointers, the program
may crash immediately.
3) If the programmer is not useful and consistent with the use of pointers, the program may
crash.
The concept of pointers in the implementation of data structures is that if the link is
broken at any node then the error is occurred. The pointer is related to the data structure .The
data structure is the organization of the data that can be fetch easily at the line when it is needed.
The pointer help to store the address, so at the time of fetching the data the pointer work. It tell
the address of the data and we can receive data easily. In this way the pointer is useful in the data
structure.
QUES 2: Elaborate the concept of “Fixed block storage allocation” and “Buddy
system” in dynamic memory management.
Ans 2-
Fixed block storage allocation: It means the block that is assign fix size is called the fixed
block storage allocation. It is also called pool allocation, uses a free list of fixed-size blocks of
memory . This works well for simple embedded systems
Buddy System : The system in which the memory is allocated in the big blocks and the size of
that blocks is 2n then it is called the buddy system. The block is broken when the block that is
allocated is large than it should be then the block is broken in two parts. The all blocks are in the
link list, they have the particular size. The block is compared its buddy only when the block is
free. They are combined if they are both free.
Dyanamic memory allocation: The dynamic memory is the memory that is given or assign to
the variable on the run time. It is the opposite of the static memory allocation. Memory
management functions handle the allocation, reallocation, and deallocation of dynamic memory
used by the encode/decode functions.
b.Malloc(): It return the void pointer to NULL. It used to create a dynamic memory allocation in
the C language.
c.Calloc(): It allocate the data on the unused space. It used to create memory allocation. In calloc
we use 2 arguments i.e no. of arguments and size of it.
e. Realloc()-This function works in the same way as the C realloc function. It reallocates an
existing block of memory.
Ptr = realloc(ptr,new)
Pointer: The pointer is the variable that can store the address of the another variable. It is also
helpful for the storing the data. It manage the records.
File: The file system is also helpful to manage record. We store the information in the file. The
all info can be kept by the file.
PART – B
We will use an array of character pointers to point to the strings declared as follows:
char * nameptr[MAX];
Pointers to an array: Now that we know that the name of an array holds the address of the
first member of the array, we realize that we can declare a pointer of the same data type as the
array and initialize it with the array.
int number[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int *pNumbers = Number;
QUES 6: Give example to show the use of far pointer and dangling pointer
problems?
Ans 6-
Far pointer
The pointer in which a segment selector is available is called far pointer. It make possible to
point. It point to addresses of the segment. It is used to access the far segment. Far pointer is used
to address data stored in data spaces . It includes segment number.
Typically, such pointers are used with farmalloc() and such, to manage a heap separate from
where all the rest of the data lives.
Dangling pointer
Dangling pointer means the pointer of invalid address. It means when any object is deleted then
this kind of problem come. There is no element on the location. The element is deleted that is
point by the dangling pointer.
f() {
struct s *p = 0;
// p is local
g(p);
p->next->val =...; // p->next is dangling
}
g(struct s *p) {
p->next = malloc(sizeof(struct s));
create_10_Node_List(p);
initialize(p);
h(p);
free_all_but_head(p);
}
QUES 7: Differentiate between linked list and arrays in terms of representations,
traversal and searching?
Ans 7-
Linked list is the concept which is related with the pointer concept. The pointer is used in the
linked list. But in the array the pointer is not used because there is no need of the link in the
array.
Array is the collection of same type of elements in continuous type. Traverse means-go to the
every node . Search means- to find any element and give the location
QUES 8: Can we perform binary search in linked list, if no then illustrate the
reason?
Ans 8-
No, we can’t binary search in link list. It is not possible to binary searching the link list because
in the linked list there is no confirmation of the beginning and ending point.
Suppose we have 10 nos. in the array, for any no. to be searched we'll check it first
with the middle no. i.e. 5th no. If it matches OK, otherwise if it is less than it, we'll check the
middle no. of 1 & 5 i.e. 3 and so on. If it is greater then we will check it with the middle no. of 5
& 10 i.e. 7 and so on. The search is carried till the no. is found or till middle no. equal to
bounding no, i.e. no. not found.
Coming to linked list, it is a way to store information without using arrays. The problem with
array is we should know the maximum size in advance, in order to avoid it we use linked lists.
i.e. we'll create a node containing information & the address of next node.