InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Write a code to print numbers from 0 to 100 in C++ without using loop and recursion. |
|
Answer» Template Metaprogramming is the idea used in this code. Let's have a look at how this works. Non-data types can ALSO be used as parameters in C++ templates. The term "non-datatype" refers to a value rather than a datatype. In the preceding code, for example, N is passed as a value rather than a datatype. For each parameter, a new instance of a generic class is constructed, and these classes are created at compile time. #include <IOSTREAM>using namespace std; template<int n>class PrintZeroToN{public: static void display() { PrintZeroToN<n-1>::display(); // this should not be mistaken for recursion cout << n << endl; }}; template<>class PrintZeroToN<0>{public: static void display() { cout << 0 << endl; }};int main(){ const int n = 100; PrintZeroToN<n>::display(); return 0;}Explanation: N is passed as a value rather than a data type in the above program. For each parameter, a new instance of a generic class is constructed, and these classes are created at compile time. When the compiler encounters the line “PrintZeroToN<>::print()” with N = 100, it produces an instance PrintZeroToN<100>. Another FUNCTION PrintZeroToN<99>::print() is called in function PrintZeroToN<100>::print(), resulting in the creation of an instance PrintZeroToN<99>. All instances from PrintZeroToN<100> to PrintZeroToN<1> are created in the same way. The function PrintZeroToN<0>::print() already exists and prints 0. The PrintZeroToN<1> function prints 1 and so on. As a result, all numbers from 0 to N are printed on the screen. |
|
| 2. |
Write the code to add two numbers without using arithmetic operators. |
|
Answer» The sum of two bits can be found by executing an XOR (^) operation on the two bits. A carry bit can be obtained by performing AND (&) on the two bits. The logic SHOWN below is a simple Half Adder that may be USED to add two single bits. This logic can be extended to integers. If there are no set bits at the same position(s) in a and b, bitwise XOR (^) of a and b yields the sum of a and b. Bitwise AND (&) is used to include COMMON set bits as well. All carry bits are obtained by bitwise AND of a and b. To acquire the needed result, we compute (a & b) << 1 and add it to a ^ b. // C Program for adding two numbers// without the use of arithmetic operators#include<stdio.h>int Addition(int a, int b){ // Iterate until no carry while (b != 0) { // carry now stores common //set bits of a and b unsigned carry = a & b; a = a ^ b; // Carry to be shifted by one so that on adding // it to a, we get the required sum b = carry << 1; } return a;} |
|
| 3. |
What is monkey patch in Python? |
|
Answer» Monkey PATCHES are dynamic (or run-time) alterations of a class or module in Python. We can TRULY CHANGE the behavior of code at runtime in Python. Example: # m.pyclass A: def func(SELF): print ("func() is CALLED")In the code below, we use the above module (m) to change the behavior of func() at runtime by assigning a new value. import mdef monkey_func(self): print ("monkey_func() is called") # replacing the address of "func" with "monkey_func"m.A.func = monkey_funcob = m.A() # calling the function "func"ob.func()Output: monkey_func() is calledExplanation: We have assigned the monkey_func to the address of “func” of class A. Thus, when we call the “func” function of “ob”, the monkey function is called. |
|
| 4. |
Is it possible to override and overload a static method in Java? Is it possible to override a private method in Java? |
|
Answer» Because static methods are resolved at compile time, one cannot override them in Java. Because objects are only available at runtime, overriding REQUIRES a virtual METHOD that is resolved at runtime. In Java, a static method can be overloaded. Overloading has nothing to do with runtime, but each method's signature must be distinct. To alter the method signature in Java, EITHER the number of parameters, the type of ARGUMENTS, or the sequence of arguments must be changed. In Java, you can't override a private method because the subclass doesn't inherit the private method, which is required for overriding. In fact, no one outside the CLASS can see a private method, and a call to it is handled at compile time using Type information rather than at runtime using the actual object. |
|
| 5. |
Is it possible to «resurrect» an object that has become eligible for garbage collection in Java? |
|
Answer» The Garbage Collector (GC) must CALL the FINALIZE method on an object when it becomes garbage COLLECTION eligible. Because the finalize method can only be used once, the GC marks the object as finalized and sets it aside until the next cycle. You can technically "resurrect" an object in the finalize method by assigning it to a static field, for example. The object would revive and become ineligible for garbage collection, preventing the GC from collecting it in the next cycle. The object, on the other hand, would be marked as finalized, thus the finalize method would not be invoked when it became eligible again. In essence, you can only use this "resurrection" method only once. Example: // Java Program to illustrate Object Resurrectionimport java.io.*;import java.util.*;public class InterviewBit { private int num; // Constructor public InterviewBit(int num) { // assigning the parameter value to the member variable this.num = num; } // Creating an ArrayList of class object static final ArrayList<InterviewBit> ar = new ArrayList<InterviewBit>(); protected void finalize() throws Throwable { System.out.println("Resurrect " + num); // By using the this operator, adding the current instance to object ar.add(this); } public String toString() { return "Element(" + "number = " + num + ')'; } public static void main(String[] args) throws InterruptedException { for (int i = 0; i < 3; i++) ar.add(new InterviewBit(i)); for (int j = 0; j < 5; j++) { // printing the element in the object System.out.println("The Elements are : " + ar); // Clearing off elements ar.clear(); // Calling the garbage collector function System.gc(); // Making the THREAD to sleep for 500 ms Thread.sleep(500); } }}Output: The Elements are : [Element(number = 0), Element(number = 1), Element(number = 2)]Resurrect 2Resurrect 1Resurrect 0The Elements are : [Element(number = 2), Element(number = 1), Element(number = 0)]The Elements are : []The Elements are : []The Elements are : []Explanation: The finalize method adds the items to the collection once and then resurrects them. They have been marked as finalized and will not be queued again when they are collected a second time. |
|
| 6. |
What is stored in each of the memory structures- stack and heap, and how are they related to each other? |
|
Answer» The stack is a SECTION of memory that stores information about nested method (RECURSIVE) calls all the WAY down to the present program location. It also holds all local variables and heap references defined in the currently running procedures. This structure enables the runtime to return from the method knowing the address from which it was invoked, as well as to remove all local variables when the procedure has been exited. EVERY thread has a stack of its own. The heap is a big chunk of memory used for dynamic allocation. When you use the new keyword to create an object, it is allocated on the heap. The reference to this object, on the other hand, is stored on the stack. |
|
| 7. |
What is BufferedWriter? What are flush() and close() used for? |
|
Answer» BufferedWriter is a TEMPORARY data storage source. It's used to make a buffered character output stream with the default output buffer size. To flush CHARACTERS from the buffered writer stream to a file, the flush() function of the BufferedWriter class in Java is employed. It ensures that all data items, including the last character, are WRITTEN to the file. The close() function of the Java BufferedWriter class flushes the characters from the buffer stream and then closes it. Calling methods like write() and append() after the stream has been CLOSED will generate an ERROR. |
|
| 8. |
What is the purpose of a Pseudo TTY (pseudo terminals)? |
|
Answer» A bidirectional communication channel is provided by a pair of virtual CHARACTER devices known as a pseudo TTY (or "PTY"). The master is at one end of the channel, while the slave is at the other. The pseudo-terminal's slave end provides an INTERFACE that is IDENTICAL to that of a conventional terminal. A process that expects to be connected to a terminal can open the slave end of a pseudo-terminal, which will subsequently be controlled by a program that has opened the master end. Anything written on the master end is supplied to the slave end's process as if it were any input entered on a terminal. Anything written to the slave end of the pseudo-terminal, on the other hand, can be read by the process linked to the master end. Network login services, terminal emulators, and other such applications EMPLOY pseudo-terminals. |
|
| 9. |
What is the Hamming Code? |
|
Answer» The Hamming code is a set of error-correction codes that can be used to detect and fix errors that can arise when DATA is transferred or stored from one source to ANOTHER. Redundant bits are extra BINARY bits that are created and ADDED to the data TRANSFER's information-carrying bits to ensure that no bits are lost during the data transfer. A parity bit is a bit that is appended to binary data to verify that the total number of 1s is even or odd. Error detection is done with parity bits. The Hamming Code is essentially the use of additional parity bits to allow for error detection. |
|
| 10. |
What do you know about Network Virtual Terminal (NVT)? |
|
Answer» RATHER than communicating in native "languages", all Telnet clients and servers agree to deliver data and commands that conform to a fictional "virtual" terminal TYPE known as the NETWORK Virtual Terminal (NVT). The NVT specifies a set of standards for formatting and sending data, including character set, line termination, and how INFORMATION about the Telnet session is provided. Every Telnet client on a terminal can COMMUNICATE in both its native language and NVT. When a user enters information on his or her local terminal, it is translated to NVT and sent over the network in that format. When the Telnet server receives this information, it converts it from NVT to the format required by the remote host. In reverse, the same procedure is followed for transmissions from the server to the client. |
|
| 11. |
What is Exterior Gateway Protocol (EGP)? |
|
Answer» The Exterior Gateway Protocol (EGP) is a protocol that allows INTERNET gateways from the same or separate autonomous systems to SHARE network reach-ability information. EGP serves THREE primary purposes: |
|
| 12. |
What is a bridge router (als known as brouter) ? |
|
Answer» A bridge router, SOMETIMES known as a brouter, is a network DEVICE that can FUNCTION as both a bridge and a router. The brouter forwards all other packets LIKE a bridge and only routes packets for known protocols. For routable protocols, brouters function at the network layer, while for non-routable protocols, they operate at the data link layer. Brouters operate as routers for routable protocols and bridges for non-routable protocols, handling both routable and non-routable characteristics. Brouters are connecting devices in networking SYSTEMS that serve as both a network bridge and a router in the internetwork. |
|
| 13. |
List the differences between RSA (Rivest, Shamir, Adleman) and Digital Signature Algorithm (DSA). |
||||||||||||
Answer»
|
|||||||||||||
| 14. |
What is the resident set and working set? |
|
Answer» At any given time, the resident SET is the part of the processed image that is actually in the real memory. It's broken down into SUBSETS, one of which is the WORKING set. The working set is the SUBSET of the resident set required for EXECUTION. |
|
| 15. |
What is the Translation Lookaside Buffer? |
|
Answer» TRANSLATION TLB (Transaction Look-aside Buffer) is a particular cache that keeps track of RECENTLY used transactions. The TLB includes the most recently used page table entries. The CPU analyses the TLB when given a VIRTUAL ADDRESS. The frame number is retrieved and the real address is created if a page table entry (TLB hit) is present. If a page table entry is missing from the TLB (TLB miss), the page number is used as an INDEX while processing the page table. The TLB first checks if the page is already in main memory; if it isn't, a page fault is generated, and the TLB is then modified to incorporate the new page entry. |
|
| 16. |
What is Trapdoor in OS? |
|
Answer» A trapdoor is a software or hardware mechanism that can be USED to bypass system controls. In general, it's malicious software that allows an attacker on the other side of the Internet to gain unauthorized access to a computer system or network by accepting remote commands. Trap DOOR software monitors a specific Transmission Control PROTOCOL (TCP) or User Datagram Protocol (UDP) PORT for orders. |
|
| 17. |
Name the typical elements of a processed image. |
|
Answer» The typical elements of a processed image are:
|
|
| 18. |
What is plumbing/piping in Linux or Unix? |
|
Answer» Plumbing/ Piping refers to the technique of USING one program's output as an input to another. For instance, Instead of DELIVERING a folder or drive listing to the main screen, it can be piped and delivered to a file, or sent to the printer to print a hard copy. A pipe is a type of redirection (the transfer of standard output to another location) USED in Linux and other Unix-like OPERATING systems to transport the output of one command/program/process to another for additional processing. The Unix/Linux systems allow a command's stdout to be CONNECTED to another command's stdin. The pipe character ‘|' can be used to do this. |
|
| 19. |
What is Preemptive Multitasking? How is it different from Cooperative Multitasking? |
|
Answer» Preemptive multitasking permits computer programs to share operating systems (OS) and UNDERLYING hardware resources. It distributes the OVERALL operating and computing time amongst processes, and it uses ESTABLISHED criteria to switch resources between processes. Time-shared multitasking is ANOTHER name for preemptive multitasking. The operating system never initiates context switching from one process to another in cooperative multitasking. Only when the processes voluntarily cede control on a routine basis, or when they are inactive or logically blocked, does a context switch occur, allowing MANY applications to run at the same time. In addition, in this multitasking, all processes work together to make the scheduling strategy work. |
|
| 20. |
What is caching? How does caching work? |
|
Answer» CACHING is a technique for saving numerous COPIES of the most frequently used data in a temporary storage area (or cache) so that they can be accessed more quickly. It keeps data in a temporary format for software applications, servers, and web browsers, so users don't have to download information every TIME they VISIT a website or use an application. Cached data works by saving data in a device's memory for later access. The data is kept in the memory of a computer, directly below the central processing unit (CPU). The primary cache level is incorporated into a device's microprocessor CHIP, followed by two more secondary cache levels that feed the primary level. This information is kept until the content's time to live (TTL), which specifies how long it should be cached, expires or the device's disc or hard drive cache fills up. Data is usually cached in one of two ways: browser or memory caching (data stored locally on the computer) or Content Delivery Networks (data stored in geographically distributed locations). |
|
| 21. |
What is the purpose of a Virtual File System (VFS)? |
|
Answer» An abstract layer on top of a more concrete file system is a virtual file system (VFS) or virtual filesystem switch.
|
|
| 22. |
What is Root Partition in OS? |
|
Answer» The root partition is the place where the operating system kernel is LOCATED. Other potentially crucial system files that are mounted during boot TIME are contained in it as WELL. |
|
| 23. |
How does Dynamic Loading help in better memory space utilization? |
|
Answer» In dynamic LOADING, a routine is not loaded until it is CALLED. This strategy is very effective when dealing with VAST quantities of code, such as error routines, that occur infrequently. All routines are saved in a relocatable load format on the disk. The main program is executed after it has been loaded into MEMORY. When a routine requires to call another routine, the calling routine checks to verify if the other routine is loaded first. If this is not the CASE, the relocatable linking loader is used to load the requested routine into memory and update the program's address tables. The newly loaded routine is then given control. In this way, dynamic loading helps in better memory space utilization. |
|
| 24. |
What factors influence whether or not a detection algorithm is required in a deadlock avoidance system? |
|
Answer» One of the FACTORS is that it is DEPENDENT on how frequently a deadlock is likely to OCCUR when this algorithm is IMPLEMENTED. The other is the number of processes that will be affected by deadlock if this algorithm is used. |
|
| 25. |
What are the similarities and the differences between Shortest Job FIrst (SJF) and Shortest Remaining TIme FIrst (SRTF) CPU scheduling algorithms? |
||||||||||||
|
Answer» SJF (Shortest Job First) is a scheduling policy that prioritizes the waiting PROCESS with the shortest EXECUTION time. Shortest Job Next (SJN) or Shortest Process Next are other names for it (SPN). It is a scheduling algorithm that is not preemptive (that is, one process cannot SNATCH the resources assigned to a currently running process). The preemptive variant of SJF scheduling is the Shortest Remaining Time First (SRTF). The procedure, next in the queue, with the least amount of time till completion is chosen to be executed in this scheduling technique. Processes that arrive at the same time transform SRTF to SJF. Similarities:
|
|||||||||||||
| 26. |
Write the steps to create, update and drop a view in SQL. |
|
Answer» In SQL, a view is a single table that contains data from other tables. As a result, a view features rows and columns that are IDENTICAL to those of a real table, as well as fields from one or more tables. In ORDER to create a view: CREATE VIEW View_Name ASSELECT Column1, Column2, Column3, ..., ColumnNFROM Table_NameWHERE Condition;For updating a view: CREATE VIEW OR REPLACE View_Name ASSELECT Column1, Column2, Column3, ..., ColumnNFROM Table_NameWHERE Condition;For dropping a view: DROP VIEW View_Name;In the above queries, Column1, Column2, .. ColumnN denotes the name of the columns to be ADDED or updated. View_Name denotes the name of the view created and Table_name denotes the name of the current table. |
|
| 27. |
What exactly is index hunting, and how does it aid query performance? |
|
Answer» Index hunting is the METHOD of boosting a collection of indexes. This is done because indexes improve query performance as well as query processing time. It aids in query performance IMPROVEMENT in the following ways:
|
|
| 28. |
What is the fill factor in SQL? What is its default value? |
|
Answer» The fill FACTOR is the percentage of space on each leaf-level page that will be filled with data. The smallest unit in SQL SERVER is a page, which is made up of 8K pages. Depending on the size of the row, each page can store one or more rows. The Fill Factor's default value is 100, which is the same as the value 0. The SQL Server will fill the leaf-level pages of an index with the highest NUMBER of rows it can fit if the Fill Factor is set to 100 or 0. When the fill factor is 100, the page will have no or very little vacant space. |
|
| 29. |
List out the differences between Generalization and Specialization in DBMS. |
||||||||||||||||
Answer»
|
|||||||||||||||||
| 30. |
What do you understand about Proactive, Retroactive and Simultaneous Update in the context of DBMS? |
Answer»
|
|
| 31. |
How will you print the address of a variable without using a pointer? |
|
Answer» We may acquire the address of any VARIABLE by USING the “address of operator” (&) operator, which yields the variable's address. #include <stdio.h>int main(void){ // declaring the VARIABLES int x; FLOAT y; char z; printf("Address of x: %p\n", &x); printf("Address of y: %p\n", &y); printf("Address of z: %p\n", &z); return 0;} |
|
| 32. |
Write the code to find the length of a string without using the string functions. |
|
Answer» #include <iostream>using namespace STD;int MAIN(){ char str[100]; int len = 0; cout << "Enter a STRING: "; cin >> str; while(str[len] != '\0') { len++; } cout << "Length of the GIVEN string is: " << len; cout << ENDL; return 0;} |
|