Sie sind auf Seite 1von 6

HOMEWORK NO:1

CAP205: Data Structure

SUBMITTED TO: - SUBMITTED BY:-


SANJAY SOOD SURENDRA
MCA 3nd SEM
ROLL NO- D3804A15
REGD NO- 10806601
Part-A
1. Write advantages and disadvantages of using pointer. How the concept
of pointers is useful in the implementation of data structures?

Answer:-
Advantages:-
1. the function return only one value. At the time of the same function the pointer
help to recognize the variable.
2.) the pointer is necessary at The time of the run time memory
3). The pointer has the address of the variable so it make the fast.

Disadvantage:
• It is complex
• If the link is broken at any node then the error is occurred.

The pointer is the related to the data structure. The data structure is the organization
of the data that can be fetch easily at the time when it is needed.
The pointer help to store the address. So at the time of the 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..

2. Elaborate the concept of “Fixed block storage allocation” and “Buddy


system” in dynamic memory management.
Answer:- Fixed-blocks storage allocation means the block that is assign fix size is
called the fixed block storage allocation it is also called it is also called pool
allocation, it uses a the list that is free, it is use fixed blocks size memory..This is
very simple.
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 . these has the particular size. The block is
compared its buddy only when the block is free..they are combine when both they
are free If they are both free
3. Differentiate between static memory allocation and dynamic memory
allocation. Illustrate various memory management functions
Answer.
• Static memory: The static memory is the memory that is given or assign to
the variable on the compile time. It is the opposite of the dynamic memory
allocation. In this type of the memory allocation the data is allocated
logically. a single copy of the data is retained.
• 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. Thre
are many function as:-
a. Alloc: it allocate the memory
b. Malloc: it return the void pointer to NULL.
c. Calloc: it allocate the data on the unused space.
d. Free: it help to deallocate the memory

4. Write different ways to manage records in memory

Answer. We have to manage the record so that we can get back when ever we
want. There are many ways to manage the records:

• Array: In the c the array store the same kind of elements. With the help of
the array we can store the data of the same type.

• 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
5. Illustrate the use of array of pointers and pointers to an array.
Answer:

Pointer 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;

array of pointer:-

Definition: a pointer is a variable that stores the memory address of another


variable.

So it's possible to have an array of pointers. In other words, an array of memory


addresses:

#include <stdio.h>

int main() {
int int_array[3] = {1,2,3};

int *ptr1 = &int_array[0];

int *ptr2 = &int_array[1];


5. Give example to show the use of far pointer and dangling pointer
problems

Answer.
• 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.

• uses a far pointer to address data stored in data spaces

• A far pointer includes segment number

• 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.

6. Differentiate between linked list and arrays in terms of representations,


traversal and searching.

Answer. 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.

(array)

The above fig. are the representation of the array and link list.
Traverse means-go to the every node
Search means- to find any element and give the location

7. Can we perform binary search in linked list ,if no then illustrate the
reason.

Answer. No, we can’t binary search in link list, it is not possible to binary search
in the link list, because in the linked list there is no confirmation of the beginning
and ending point .

Das könnte Ihnen auch gefallen