294 views
0 votes
0 votes
Qn. 68 Which of the data structure is suitable for implementing a buffer to file?

(A) File

(B) Linked List

(C) Array

(D) All of the above

(E) None of the above

2 Answers

0 votes
0 votes

Ans (C) Arrays

Buffers are implemented both as Contiguous memory cells -Arrays and Non Contiguous memory cells - Linked lists.
Both implementations have their own benefits in different scenarios. 

Different Buffers:

1. Circular Buffer

Default: FIFO implementation over Arrays. 
Each item is contiguous and has the correct data alignment, so software reading and writing these values can be faster than software that handles non-contiguous and non-aligned values.

Usage scenario 1: Queue with fixed maximum size. 

Advantages: All Queue Operations take constant time. 

Note: In some implementations of fixed size Circular Buffer, when Buffer is full,
(i) only the most recent data are stored 
(ii) data are overwritten - The routines that manage the buffer could prevent overwriting the data and return an error or raise an exception. Whether or not data is overwritten is up to the semantics of the buffer routines or the application using the circular buffer.

Usage scenario 2: Queue with expanding size.

Disadvantage:
Expanding a circular buffer requires shifting memory, which is comparatively costly. 

Solution: For arbitrarily expanding queues, a Linked list approach may be preferred instead.

2. Non-circular Buffer

Default: LIFO implementation over Arrays.

Reference link

Related questions

0 votes
0 votes
1 answer
1
Ritwik asked May 18, 2017
266 views
Qn 70. Which of the data structure is not suitable for building a cache?(A) File(B) Linked List(C) Arrays(D) All of the above(E) None of the above
1 votes
1 votes
1 answer
2
Ritwik asked May 18, 2017
449 views
Q 69. Which data structure is used to implement a request handler in a web server?(A) Stack(B) Queue(C) Arrays(D) All of the above(E) None of the above
1 votes
1 votes
0 answers
3
Gunjack asked Oct 5, 2018
331 views
As a Mechanical Engineering graduate I decided to pursue M.Tech in Computer Science.Can I apply for PSU after completing M.Tech in Computer Science branch?I have heard so...