Monday, December 28, 2020

Operating systems multiple choice questions for exams - Set 22

Operating systems exams - multiple choice questions (MCQ) and answers, Objective type questions, OS exam questions, MCQ in system programming, semaphores, marshaling, monitors, race condition


Operating Systems MCQ questions and answers – Set 22

 

1. A race condition is when:

a) Multiple processes are all trying to finish first

b) A process runs too slow

c) The correctness of the code depends upon the timing of the execution

d) None of the above

Answer: (c) The correctness of the code depends upon the timing of the execution       

A race condition is a semantic error. It is a flaw that occurs in the timing or the ordering of events that leads to erroneous program behavior.

A race condition occurs when two threads access a shared variable at the same time. The first thread reads the variable, and the second thread reads the same value from the variable. Then the first thread and second thread perform their operations on the value, and they race to see which thread can write the value last to the shared variable. The value of the thread that writes its value last is preserved, because the thread is writing over the value that the previous thread wrote. [Refer here for more]

 

2. Semaphores, Condition Variables, and Monitors support which of the following set of distinct operations?

a) Parallelization and event notification

b) Synchronization and event notification

c) Synchronization and parallelization

d) None of the above

Answer: (b) Synchronization and event notification  

The operations of semaphores, condition variables and monitors include synchronization and event notification.

The main aim of using a semaphore is process synchronization and access control for a common resource in a concurrent environment. The operations of semaphores are wait and signal.

Condition variables provide a mechanism to wait for events. Condition variables support three operations: Wait, Signal and Broadcast.

Monitors provide a structured concurrent programming primitive, which is used by processes to ensure exclusive access to resources, and for synchronizing and communicating among users.

 

3. The main advantage of multilevel page tables is that they

a) Use page table memory efficiently

b) Reduce the complexity of the paging system

c) Speed up page table references

d) None of the above

Answer: (a) Use page table memory efficiently

With many processes in a system, the page tables can potentially take up a large chunk of physical memory. One solution to the large memory requirements of page tables is to use multilevel paging. In this scheme, a virtual address is divided into three or more sections, with all but the last section being page numbers in different page tables, and the last one being the offset. We look up the first page table to find the second table, then look up the second table to find the frame in which the page is stored.

This scheme uses the page table memory efficiently. [Refer here for more]

4. Remote procedure calls rely on marshaling parameters. Marshaling means ______.

a) transforming the parameters into a form suitable for network transmission.

b) sending the parameters over the network to a remote server.

c) having the remote server extract the parameters from the network message.

d) having the remote server place the parameters on the stack to make a procedure call.

Answer: (a) transforming the parameters into a form suitable for network transmission           

Marshaling is placing all the parameters into a stream of bytes in an agreed upon format so that they can be transmitted. Unmarshaling is the opposite process.

Marshaling is the process of gathering data and transforming it into a standard format before it is transmitted over a network so that the data can transcend network boundaries.

 

5. Which of the following protocols is most suitable to the statement “a message may be lost between the sending process and the receiving process and as a result the receiving process may never receive that message.”

a) UDP protocol

b) TCP protocol

c) IP protocol

d) Both UDP  and TCP

Answer: (a) UDP protocol 

The UDP protocol does not do anything to resend lost messages, but TCP will resend until an ACK is received.

The service provided by UDP is an unreliable service that provides no guarantees for delivery and no protection from duplication (e.g. if this arises due to software errors within a router). The simplicity of UDP reduces the overhead from using the protocol and the services may be adequate in many cases.

 

*********

Related links:


OS Interview questions with answers

solved Interview questions in operating systems

GATE questions in system programming and operating systems

MCQ Interview questions in OS

Operating systems interview questions for competitive exams

objective type OS questions for IIT JEE entrance exam

Define marshaling

Saturday, December 26, 2020

Multiple choice questions in Data structures and algorithms with answers set 09

Data structures and algorithms multiple choice questions with answers, important interview questions in data structures, data structures questions for entrance exams, frequently asked questions in data structures and algorithms, GATE questions in data structures with explained answers


Data Structures and Algorithms Multiple Choice Questions

SET 09

1. Which among the following comparison sorts are in-place sorts?

a) Bucket sort

b) Insertion sort

c) Selection sort

d) Parallel merge sort

Answer: (b) Insertion sort and (c) Selection sort

What is in-place sort?

An in-place sort is one that sorts the input without requiring additional space.

A sort algorithm in which the sorted items occupy the same storage as the original ones. A sorting algorithm that uses a small constant amount of extra space in addition to the original input, usually overwrite the input space, is referred as in-place sorting. [Refer here for more, what is in-place sort].

Insertion Sort is typically done in-place, by iterating up the array, growing the sorted list behind it. At each array-position, it checks the value there against the largest value in the sorted list (which happens to be next to it, in the previous array-position checked). If larger, it leaves the element in place and moves to the next. If smaller, it finds the correct position within the sorted list, shifts all the larger values up to make a space, and inserts into that correct position. [Refer here for more, Wikipedia. ]

The selection sort algorithm finds the smallest (or largest, depending on sorting order) element in the unsorted sub-list, exchanges it with the leftmost unsorted element (putting it in sorted order), and moves the sub-list boundaries one element to the right without any additional space. [Refer here more more - Wikipedia, Selection sort]

 

2. A max heap can be converted into a min heap in ________.

a) Exponential time

b) Quadratic time

c) Linear time

d) Logarithmic time

Answer: (c) Linear time

Building a min heap on any array will take linear time. Hence, converting a max heap array into min heal will take the same time.

Min heap is a special binary tree where the value stored in the parent node is less than or equal to the children and max heap is a tree where the parent is larger than or equal to the children.

 

3. To delete a dynamically allocated tree, the most suitable traversal technique is ________.

a) Pre-order

b) Post-order

c) In-order

d) Level-order

Answer: (b) Pos-order

To delete a dynamically allocated tree, we can delete children first and then the parent.

We will traverse the tree by using post Order traversal because we have to delete all child nodes first before deleting root node. If we delete root node first then we cannot traverse child nodes of root without maintaining a separate data store.

 

*************************

Interview questions and answers in data structure and algorithms

DSA quiz questions with answers explained

Solved true or false questions in DSA

Practice questions in data structures

Data structures and algorithms GATE exam questions 

Why insertion sort is a in-place sorting algorithm?

Why do we refer selection sort as in-place sorting algorithm?

What is the time complexity of converting min heap into a max heap?

Why do we say that the post-order traversal as suitable traversal technique to delete a dynamically allocated binary tree?


Featured Content

Multiple choice questions in Natural Language Processing Home

MCQ in Natural Language Processing, Quiz questions with answers in NLP, Top interview questions in NLP with answers Multiple Choice Que...

All time most popular contents