This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What are the three types of schedulers in the context of operating systems? Explain. |
|
Answer» Schedulers are specialised computer programs that manage process scheduling in a variety of WAYS. Their primary responsibility is to choose which jobs to submit into the system and which processes to run. Following are the three types of schedules:
|
|
| 2. |
What do you know about virtual memory in the context of operating systems? |
|
Answer» VIRTUAL Memory is a storage allocation system that allows secondary memory to be addressed as if it were the main memory. The ADDRESSES used by an application to refer to memory are distinct from the addresses used by the memory system to designate physical storage sites, and program-generated addresses are automatically translated to machine addresses. The capacity of virtual storage is limited by the COMPUTER system's addressing method, and the amount of secondary memory available is DETERMINED by the number of main storage sites available RATHER than the actual number of main storage locations. |
|
| 3. |
What is the purpose of the sudo command in the context of the UNIX operating system? |
|
Answer» sudo is a short form of Super Users DO. In Linux, the sudo command is commonly used as a prefix to a command that only superusers are PERMITTED to RUN. If you use the prefix "sudo" before any command, it will run it with elevated privileges, allowing a user with the necessary permissions to run a command as another user, such as the superuser. This is the Windows version of the "run as administrator" option. The sudoers file, stored at "/etc/sudoers," must contain an entry for each user who MAY use the sudo command. Remember to use the sudo command to EDIT or inspect the sudoers file. The "visudo" command is suggested for editing the sudoers file. |
|
| 4. |
Write a program to calculate how many ways can we make change for N cents if we have an endless supply of each of the C = C1, C2,..Cm valued coins? It makes no difference what order the coins are placed in. |
|
Answer» Example: Input : We can divide all set solutions into TWO sets to count the total number of solutions. 1) Solutions that are devoid of the mth COIN (or Cm). 2) At least one Cm is present in the solution. If solve(C[], m, n) is the function for counting the number of solutions, it may be represented as the sum of solve(C[], m-1, n) and solve(C[], m, n-Cm). We will use dynamic PROGRAMMING to store the result for a particular VALUE of n and m. This will optimise our time complexity to O(nm). Code: #include<bits/stdc++.h>using namespace std;// function to count the number of ways n can be represented from a coin set of SIZE mint solve( int C[], int m, int n ){ int dp[n + 1][m];//Creating a 2D matrix of size (n + 1) 8 m to store the result of each state of our problem // Filling the matrix for the base case when n = 0 for (int i = 0; i < m; i++) dp[0][i] = 1; // Filling the entries in the dp table in bottom up fashion for (int i = 1; i < n + 1; i++) { for (int j = 0; j < m; j++) { // Including C[j] in our current state's answer int x = (i-C[j] >= 0) ? dp[i - C[j]][j] : 0; // Excluding C[j] in our current state's answer int y = (j >= 1) ? dp[i][j - 1] : 0; // storing the sum of x and y in our current state's answer dp[i][j] = x + y; } } return dp[n][m - 1];} int main(){ int C[] = {2, 3, 5, 6}; int m = sizeof(C)/sizeof(C[0]); int n = 10; cout << solve(C, m, n); return 0;}Output: 5Explanation: In the above code, we define a function named ‘solve’ which returns the number of ways in which n can be represented from a set of m coins having distinct values. We create a dp table of size (n+1) * m. dp[i][j] represents the number of ways in which i can be represented by a set of j coins. Here, we have used the recurrence formula dp[i][j] = x + y. Here, x = dp[i - C[j]][j], y = dp[i][j-1]. |
|
| 5. |
Write a program to convert the characters of a string into the opposite case, that is, if a character is lowercase, convert it to upper case and vice versa. |
|
Answer» Input : Input : We scan each character of the string one by one. If the current character is in lowercase, we subtract 32 from the character and convert it to UPPERCASE. Similarly, if the current character is in uppercase, we add 32 to the character and convert it to lowercase. Code: #include <iostream>using namespace std; // Function to convert the characters of the string to its opposite casevoid changeCase(string& s){ int len = s.length(); for (int i = 0; i < len; i++) { if (s[i] >= 'a' && s[i] <= 'z') { s[i] = s[i] - 32;// Subtracting 32 from the character } else if (s[i] >= 'A' && s[i] <= 'Z') { s[i] = s[i] + 32;// Adding 32 to the character } }} int main(){ string s = "inTerVieWbiT"; cout << "Original String : " << s << "\n"; changeCase(s); cout << "Changed String : " << s << "\n"; RETURN 0;}Output: Original String : inTerVieWbiTChanged String : INtERvIEwBItExplanation : In the above code, we define a function named ‘changeCase’ which takes a reference of a string as a parameter. We iterate through each character of the string and change the character to its opposite case by either adding or subtracting 32. |
|
| 6. |
Given a sorted array of 0s and 1s. The goal is to discover the index of the sorted array’s first '1'. It's possible that the array is made up entirely of 0s or 1s. If there are no 1's in the array, display "-1." |
|
Answer» Example: Input : It is given that the array is SORTED. We use this property of the array and apply binary search to find the first occurrence of 1 in the given array. We start with the whole array as our search space and find the middle element. If we encounter 0 as the middle element, it implies that our answer lies to the right side of the middle element. If we encounter 1 as the middle element, our answer can EITHER be this index or the indices left to the CURRENT middle if there are more 1s preceding the current middle. Code: #include <bits/stdc++.h>using namespace std; // function to find the first occurrence of 1 in the give sorted arrayint findIndex(int arr[], int low, int high){ while (low <= high) { int mid = low + (high - low) / 2; // we CHECK if the mid element is a 1 and the mid - 1 element is 0 if (arr[mid] == 1 && (mid == 0 || arr[mid - 1] == 0)) return mid; // our answer lies to the left of mid, we reduce our search space else if (arr[mid] == 1) high = mid - 1; // our answer lies to the right of mid, we reduce our search space else low = mid + 1; } // we return -1 since 1 is not present in the array return -1;} int main(){ int arr[] = { 0, 0, 0, 0, 1, 1, 1, 1 }; int n = sizeof(arr) / sizeof(arr[0]); cout << findIndex(arr, 0, n - 1); return 0;}Output: 4Explanation : In the above code, we defined a function named ‘findIndex’ which finds the first occurrence of the first one in the sorted array. We reduce the search space by changing the values of low and high as per the current value of the middle element. If low exceeds high, we return -1 which INDICATES that no 1 is present in the array. |
|
| 7. |
What do you understand about procedural programming? How is it different from object oriented programming? |
||||||||||||||||
|
Answer» Procedural programming is a programming model that evolved from structured programming and is BASED on the concept of invoking procedures. Procedures, often known as routines, subroutines, or functions, are essentially a set of instructions to be executed. Any procedure in a PROGRAM can be invoked at any time during execution, either by other procedures or by the program itself. The following table illustrates the differences between procedural programming and object-oriented programming:
|
|||||||||||||||||
| 8. |
What do you understand about an entry controlled loop in the context of OOPs programming? |
|
Answer» An entry control LOOP examines the condition at the point of entry and passes control to the body of the loop if the condition or expression becomes true. The name "entry control loop" comes from the FACT that this sort of loop REGULATES loop entry. for loops and while loops are EXAMPLES of entry controlled loops. |
|
| 9. |
Differentiate between quick sort and merge sort in the context of sorting algorithms. |
||||||||||||||||
|
Answer» Following are the DIFFERENCES between quick sort and merge:
|
|||||||||||||||||
| 10. |
What do you understand about a deadlock in the context of operating systems? What are the necessary conditions for a deadlock? |
|
Answer» A deadlock occurs when a group of processes is halted because each process is holding a resource and waiting for another process to obtain it. Consider the situation when two trains are approaching each other on the same TRACK and there is only one track: once they are in front of each other, neither train can move. In operating systems, a similar situation happens when two or more processes hold some resources while waiting on resources owned by other processes (s). For example, let us assume that there are two trucks trying to cross a one-way bridge from opposite ends. NONE of the trucks is ready to move back and neither can any of them cross the bridge. In this situation, a deadlock has been obtained. Following are the necessary conditions for a deadlock :
|
|
| 11. |
What do you understand about arrays? What are some of the real life applications of an array? |
|
Answer» A collection of items stored in contiguous memory spaces is referred to as an array. The objective is to GROUP together goods of the same type. This makes calculating the position of each element EASY by simply adding an offset to a base value, such as the memory ADDRESS of the array's first element. Following are the real-life applications of an array:
|
|
| 12. |
Differentiate between variable/ function declaration and definition in the context of any OOPs programming language. |
||||||||
|
Answer» The purpose of a variable declaration is to tell the compiler of the following INFORMATION: the variable's name, the KIND of value it stores, and the initial value if any. Declaration, in other words, provides information about a variable's attributes. The definition of a variable allocates memory space for the variable and SPECIFIES where the variable will be stored. The following table illustrates the differences between definition and declaration:
|
|||||||||
| 13. |
Differentiate between struct and union in the context of C programming language. |
||||||||||||||||||
Answer»
Syntax: struct structureName { member DEFINITION; member definition; ... member definition; };
Syntax: union unionName { member definition; member definition; ... member definition; };The following table illustrates the differences between struct and union:
|
|||||||||||||||||||
| 14. |
What do you know about the ACID properties of a transaction in the context of a database management system? |
|
Answer» In a SQL Database, every transaction must follow some specific set of properties. These properties are referred to as ACID properties. They are as follows:
|
|
| 15. |
What is a DataBase Management System? What are its advantages over traditional file systems? |
|
Answer» A database management system is a piece of software that manages databases. Examples of database management systems INCLUDE MySQL, ORACLE, and other commercial databases. A database management system (DBMS) provides an interface for doing tasks such as building a database, saving data in it, updating data, and CREATING a table in the database, among others. It ensures the database's safety and security. It also ensures data consistency when there are multiple users. Following are the advantages of a database management system over traditional file systems :
|
|
| 16. |
What do you understand about processes and threads in the context of an operating system? |
||||||||||||||||
Answer»
The following table illustrates the differences between them:
|
|||||||||||||||||
| 17. |
Differentiate between primary memory and secondary memory in the context of a computer. |
||||||||||||
Answer»
The following table illustrates the differences between primary memory and secondary memory:
|
|||||||||||||
| 18. |
What are the functions of an operating system? |
|
Answer» Following are the functions of an operating system :
|
|
| 19. |
Explain function overloading and function overriding in the context of C++ programming language. Differentiate between them. |
Answer»
It allows for multiple definitions of the function by modifying the signature, i.e. the number of parameters, the datatype of the parameters, and the return type. For example: using namespace std; // Method 1void overloadedMethod(int x){ cout << "In Overloaded Method 1" << endl;} // Method 2void overloadedMethod(float x){ cout << "In Overloaded Method 2" << endl;} // Method 3void overloadedMethod(int x1, float x2){ cout << "In Overloaded Method 2" << endl;} int main(){ int x = 5; float y = 5.5; overloadedMethod(x); overloadedMethod(y); overloadedMethod(x, y); return 0;}Output: In Overloaded Method 1In Overloaded Method 2In Overloaded Method 3Explanation: In the above code, we have three functions with the same name and return type. However, they have different function SIGNATURES which differentiates them from each other. When we pass a parameter of int type, method 1 gets EXECUTED. When we pass a parameter of float type, method 2 gets executed. When we pass both an int and a float type parameter, method 3 gets executed.
It is the redefining of a base class function in a derived class with the same signature, that is, the return type and parameters. It's only possible in derived CLASSES. class Test{public: virtual void print(){ cout << "Test Function"; }};class Sample : public Test{public: void print(){ cout << "In Sample Function";}};int main(){ Test obj = new Sample(); obj.print(); return 0;}Output: In Sample FunctionIn the above code, the class Sample extends the class Test and therefore inherits all its properties. We can clearly see that both the classes have a function ‘print’ with the same function signature and return type. Therefore, the above code IMPLEMENTS function overriding. Since we have added a virtual keyword in the function of the base class, the function is CALLED according to the type of object being referred to and so the print function of the Sample class gets called. The following points illustrate the differences between function overloading and function overriding:
|
|
| 20. |
Explain the major concepts of Object Oriented Programming in the context of C++ programming language. |
|
Answer» There are four major concepts in Object-Oriented Programming. They are as follows:
|
|