List Advantages and Disadvantages of Dynamic Memory Allocation vs. Static Memory Allocation.? Advantages
List Advantages and Disadvantages of Dynamic Memory Allocation vs. Static Memory Allocation.? Advantages
List Advantages and Disadvantages of Dynamic Memory Allocation vs. Static Memory Allocation.? Advantages
Advantages:
Memory is allocated on an as-needed basis. This helps remove the inefficiencies inherent to static memory
allocation (when the amount of memory needed is not known at compile time and one has to make a guess).
Disadvantages:
Dynamic memory allocation is slower than static memory allocation. This is because dynamic memory allocation
happens in the heap area.
Dynamic memory needs to be carefully deleted after use. They are created in non-contiguous area of memory
segment.
Dynamic memory allocation causes contention between threads, so it degrades performance when it happens in a
thread.
Memory fragmentation.
What is Java?
Java is an object-oriented programming language developed initially by James Gosling and colleagues at Sun
Microsystems. The language, initially called Oak (named after the oak trees outside Gosling's office), was intended
to replace C++, although the feature set better resembles that of Objective C. Java should not be confused with
JavaScript, which shares only the name and a similar C-like syntax. Sun Microsystems currently maintains and
updates Java regularly.
Yes, all functions in Java are virtual by default. This is actually a pseudo trick question because the word "virtual"
is not part of the naming convention in Java (as it is in C++, C-sharp and VB.NET), so this
would be a foreign concept for someone who has only coded in Java. Virtual functions or virtual methods are
functions or methods that will be redefined in derived classes.
What is a transient variable in Java?
A transient variable is a variable that may not be serialized. If you don't want some field to be serialized, you can
mark that field transient or static.
What is thread?
A thread is an independent path of execution in a system.
What is multi-threading?
Multi-threading means various threads that run in a system.
What are the advantages and disadvantages of B-star trees over Binary trees.?
The major difference between B-tree and binary tres is that B-tree is a external data structure and binary tree is a
main memory data structure. The computational complexity of binary tree is counted by the number of comparison
operations at each node, while the computational complexity of B-tree is determined by the disk I/O, that is, the
number of node that will be loaded from disk to main memory. The comparision of the different values in one node
is not counted.
Answer: 5,20,1
An interpreter reads one instruction at a time and carries out the actions implied by that instruction. It
does not
perform any translation. But a compiler translates the entire instructions
21. What is Throughput, Turnaround time, waiting time and Response time?
Throughput – number of processes that complete their execution per time unit
Turnaround time – amount of time to execute a particular process
Waiting time – amount of time a process has been waiting in the ready queue
Response time – amount of time it takes from when a request was submitted until the first response is
produced, not
output (for time-sharing environment)
22. What is Memory-Management Unit (MMU)?
Hardware device that maps virtual to physical address. In MMU scheme, the value in the relocation
register is added
to every address generated by a user process at the time it is sent to memory.
->The user program deals with logical addresses; it never sees the real physical addresses
23. What is a Real-Time System?
A real time process is a process that must respond to the events within a certain time period. A real time
operating
system is an operating system that can run real time processes successfully
24. What is a trap and trapdoor?
Trapdoor is a secret undocumented entry point into a program used to grant access without normal
methods of
access authentication. A trap is a software interrupt, usually the result of an error condition.
25. When is a system in safe state?
The set of dispatchable processes is in a safe state if there exists at least one temporal order in which all
processes
can be run to completion without resulting in a deadlock.
26. Explain the concept of the Distributed systems?
Distributed systems work in a network. They can share the network resources, communicate with each
other.
27. What is cache-coherency?
In a multiprocessor system there exist several caches each may containing a copy of same variable A.
Then a
change in one cache should immediately be reflected in all other caches this process of maintaining the
same value
of a data in all the caches s called cache-coherency.
28. What is a long term scheduler & short term schedulers?
Long term schedulers are the job schedulers that select processes from the job queue and load them into
memory for
execution. The short term schedulers are the CPU schedulers that select a process from the ready queue
and
allocate the CPU to one of them.
Secondary memory can be external devices like CD, floppy magnetic discs etc. secondary storage
cannot be directly
accessed by the CPU and is also external memory storage.
39. Define compactions.
Compaction is a process in which the free space is collected in a large memory chunk to make some
space available
for processes.
40. What are residence monitors?
Early operating systems were called residence monitors.
41. What is dual-mode operation?
In order to protect the operating systems and the system programs from the malfunctioning programs
the two mode
operations were evolved
System mode
User mode.
42. What is a device queue?
A list of processes waiting for a particular I/O device is called device queue.
43. What are the different types of Real-Time Scheduling?
Hard real-time systems required to complete a critical task within a guaranteed amount of time.
Soft real-time computing requires that critical processes receive priority over less fortunate ones.
44. What is relative path and absolute path?
Absolute path-- Exact path from root directory.
Relative path-- Relative to the current path.
45. What are the disadvantages of context switching?
Time taken for switching from one process to other is pure over head. Because the system does no
useful work while
switching. So one of the solutions is to go for threading when ever possible.
46. What is a data register and address register?
Data registers - can be assigned to a variety of functions by the programmer. They can be used with any
machine
instruction that performs operations on data.
Address registers - contain main memory addresses of data and instructions or they contain a portion of
the address
that is used in the calculation of the complete addresses.
47. What is DRAM?
Dynamic Ram stores the data in the form of Capacitance, and Static RAM stores the data in Voltages.
48. What are local and global page replacements?
Local replacement means that an incoming page is brought in only to the relevant process' address
space. Global
replacement policy allows any page frame from any process to be replaced. The latter is applicable to
variable
partitions model only.
49. Explain the concept of the batched operating systems?
In batched operating system the users gives their jobs to the operator who sorts the programs according
to their
requirements and executes them. This is time consuming but makes the CPU busy all the time.
50. What is SCSI?
SCSI - Small computer systems interface is a type of interface used for computer components such as
hard drives,
optical drives, scanners and tape drives. It is a competing technology to standard IDE (Integrated Drive
Electronics).
. What is database?
A database is a collection of information that is organized. So that it can easily be accessed, managed,
and updated.
2. What is DBMS?
DBMS stands for Database Management System. It is a collection of programs that enables user to
create and maintain a database.
Data independence means that the application is independent of the storage structure and access
strategy of data.
52. How many types of relationship exist in database designing?
There are three major relationship models:-
One-to-one
One-to-many
Many-to-many
53. What is order by clause?
ORDER BY clause helps to sort the data in either ascending order to descending
54. What is the use of DBCC commands?
DBCC stands for database consistency checker. We use these commands to check the consistency of
the databases, i.e., maintenance, validation task and status checks.
55. What is Collation?
Collation refers to a set of rules that determine how data is sorted and compared.
56. What is difference between DELETE & TRUNCATE commands?
Delete command removes the rows from a table based on the condition that we provide with a WHERE
clause. Truncate will actually remove all the rows from a table and there will be no data in the table
after we run the truncate command.
multiple children but each child can also have multiple parents. This model supports one-to-one, one-
to-many, and many-to-many relationships.
A unique primary index is unique and is used to find and store a row. A nonunique primary index is
not unique and is used to find a row but also where to store a row (based on its unique primary
index). A unique secondary index is unique for each row and used to find table rows. A nonunique
secondary index is not unique and used to find table rows.
78. Explain minimum and maximum cardinality?
Minimum cardinality is the minimum number of instances of an entity that can be associated with each
instance of another entity. Maximum cardinality is the maximum number of instances of an entity
that can be associated with each instance of another entity.
79. What is deadlock? How can it be avoided? How can it be resolved once it occurs?
Deadlock occurs when two transactions are each waiting on a resource that the other transaction
holds. Deadlock can be prevented by requiring transactions to acquire all locks at the same time; once
it occurs, the only way to cure it is to abort one of the transactions and back out of partially completed
work.
Retroactive Update: The updates that are applied to database after it becomes effective in real world.
Simultaneous Update: The updates that are applied to database at the same time when it becomes
effective in real world.
5. Which is better ?
A. SQL
B. Procedures
Answer: SQL
• SQL is often much shorter to write - you can do an update or summary procedure in one
line of code that would take you several lines of procedural.
• For set-based problems - SQL is much faster processor-wise and IO wise too because all
the underlining looping iteration is delegated to a database server process that does it in a
very low level way and uses IO/processor more efficiently and knows the current state of
the data - e.g. what other processes are asking for the data
If you were to update say a sales person of all customers in a particular region - your
procedural way would look something like this
do until eof
if rs("state") = "NH" then
rs("salesperson") = "Mike"
end if
rs.next
loop
The SQL way would be: UPDATE customers SET salesperson = "Mike" WHERE state = "NH"
If you had, say 2 or 3 tables you need to check, your procedural quickly becomes difficult to
manage as you pile on nested loop after loop.
C Interview Questions and Answers
1) How can we construct an increment statement or decrement statement in C?
Answer: We can do this in two different ways. 1) By using the increment operator ++ and
decrement operator. For example, the statement “i++” means to increment the value of x
by 1. Likewise, the statement “x –” means to decrement the value of x by 1. 2) The
2nd way of writing increment statements is to use the conventional + plus sign or minus
sign. In the case of “i++, another way to write it is “i = i +1.
2) List the different storage class specifiers in C?
Answer: static, auto, extern, register
3) Some Programmers debug their programs by placing comment symbols on
some of the codes instead of deleting it. How does this aid in debugging?
Answer: Using comment symbols “/* */ ” in a code, also called as commenting out, is a
way of segregate some codes that you think maybe causing errors in the code, without
deleting the program. The aim is that if the code is in fact correct, we can simply remove
the comment symbols and continue on. It also saves you time and effort on having to
retype the codes if you have deleted it in the first place.
4) What is call by value and call by reference in C Programming language?
We can pass value to function by two different ways: call by value and call by reference. In
case of call by value, a copy of value is passed to the function, so original value is not
modified in the call by value. But in case of call by reference, an address of value is passed
to the function, so original value is modified in the call by reference.
5) How can we replace the following statement by using WHILE Loop?
for (x=1; x<=100; x++)
printf ("%d ", x *x );
Answer:
x=1;
while (x<=100)
{
printf ("%d ", x * x);
x++;
}
6) Name the different functions are used for dynamic memory allocation in C
Program?
Answer:
malloc(), calloc(), realloc(), free()
7) Explain about spaghetti programming?
Answer: Spaghetti programming refers to programs that tend to get tangled and overlapped
throughout the codes. This unorganized approach to coding is usually attributed to lack of
experience on the part of the programmer. Spaghetti coding makes a program complex and
analysing the codes difficult, and so must be avoided as much as possible.
8) Write the programming code to swap two numbers without using third
variable?
int x=10, y=20;
}
Solution2 is the best solution since no extra variable is required.
3. Which of the following Bitwise operators can be used efficiently to swap two numbers?
a. &
b. ^
c. |
d. ||
Solution:b ^
a=a^b
b=a^b
a=a^b
Now ‘a’ will have ‘b’s initial value and wise-versa.
4. Do you find any issue with the above snippet of code?
a. No issues
b. P is a bad pointer
c P is a void pointer
d. Both 2& 3
Answer: b. P is a bad pointer
When a pointer is first allocated, it does not have a pointee. The pointer is "uninitialized" or
simply "bad". A de-reference operation on a bad pointer is a serious run-time error. If you are
lucky, the de-reference operation will crash or halt immediately (Java behaves this way). If you
are unlucky, the bad pointer de-reference will corrupt a random area of memory, slightly altering
the operation of the program so that it goes wrong some indefinite time later. Each pointer must
be assigned a pointee before it can support de-reference operations. Before that, the pointer is
bad and must not be used. Bad pointers are very common. In fact, every pointer starts out with
a bad value. Correct code overwrites the bad value with a correct reference to a pointee, and
thereafter the pointer works fine. There is nothing automatic that gives a pointer a valid pointee.
void BadPointer()
{
int* p; // allocate the pointer, but not the pointee
*p = 42; // this de-reference is a serious runtime error
}
5. void add(int a, int b)
{
int c;
c = a + b;
add (1,1);
}
What is the result of above funtion?
a. Sum of a,b,1
b. Results in Buffer Overflow
c Results in Compiler Error
d Results in Stack Overflow
Answer: d. Results in Stack Overflow
When a function is called recursively, sometimes infinite recursions occur which results in
STACK OVERFLOW. What does it mean? Well when a function is called,
1. First it will evaluate actual parameter expressions.
2. Then, memory is allocated to local variables.
3. Store caller’s current address of execution (return address of the current function) and
then continue execute the recursive call.
4. Then it executes rest of the function body and reaches end and returns to the caller’s
address.
Now when a function is infinitely called (recursively) without a proper condition to check its
recursive, then only first 3 steps keep executing and function will never reach step 4 to finish
execution and return to previous function. In this way, function will keep allocating memory and
at some point of time it will go out of memory or reaches stack limit and will never be able to
accommodate another function and hence crashes. This is called stack overflow.
6. Which of the following will initialize the new memory to 0 ?
a. malloc
b. free
c. new
d delete
Answer: c. new
“new” will initlize the new memory to 0 but “malloc()” gives random value in the new alloted
memory location
7. Which of the following standard C library converts a string to a long integer and reports
any .leftover. numbers that could not be converted.
a. atol
b. atoi
c. stol
d. strtol
Answer: d. strtol
strtol() Converts a string to a long integer and reports any .leftover. numbers that could not be
converted.
atoi() Converts a string to an integer.
atol() Converts a string to a long integer.
5. Define and describe an iterative process with general steps of flow chart?
There are four parts in the iterative process they are
Initialization: -The decision parameter is used to determine when to exit from the loop.
Decision: -The decision parameter is used to determine whether to remain in the loop or
not.
Computation: - The required computation is performed in this part.
Update: - The decision parameter is updated and a transfer to the next iteration results.
7. Define and state the importance of sub algorithm in computation and its relation
ship with main algorithm?
A sub algorithm is an independent component of an algorithm and for this reason is defined
separately from the main algorithm. The purpose of a sub algorithm is to perform some
computation when required, under control of the main algorithm. This computation may be
performed on zero or more parameters passed by the calling routine.
8. Name any three skills which are very important in order to work with
generating functions.
The three most important skills which are used extensively while working with generating
functions are
1)Manipulate summation expressions and their indices.
2)Solve algebraic equations and manipulate algebraic expressions, including partial function
decompositions.
3)Identify sequences with their generating functions
18. What is a greedy algorithm? Give examples of problems solved using greedy
algorithms.
A greedy algorithm is any algorithm that makes the local optimal choice at each stage with
the hope of finding the global optimum. A classical problem which can be solved using a
greedy strategy is the traveling salesman problem. Another problems that can be solved
using greedy algorithms are the graph coloring problem and all the NP-complete problems.
proportional to the number of elements in the list; and so is its expected cost, if all list
elements are equally likely to be searched for. Therefore, if the list has more than a few
elements, other methods (such as binary search or hashing) may be much more efficient.
algorithm used for lossless data compression. The term refers to the use of a variable-
length code table for encoding a source symbol (such as a character in a file) where the
variable-length code table has been derived in a particular way based on the estimated
probability of occurrence for each possible value of the source symbol.
Is it possible to find a loop in a Linked list ?
a. Possilbe at O(n)
b. Not possible
c. Possible at O(n^2) only
d. Depends on the position of loop
Solution: a. Possible at O(n)
Have two pointers say P1 and P2 pointing to the first node of the list.
Start a loop and Increment P1 once and P2 twice in each iteration. At any point of time if
P1==P2 then there is a loop in that linked list. If P2 reaches NULL (end of linked list) then
no loop exists.
2. Two linked lists L1 and L2 intersects at a particular node N1 and from there all
other nodes till the end are common. The length of the lists are not same. What
are the possibilities to find N1?.
a. Solution exist for certain cases only
b. No linear solution exist
c. Linear solution is possible
d Only Non-linear solution exist.
Solution: c. Linear solution is possible
Have two pointers say P1 pointing to the first node of L1 and P2 to that of L2. Traverse
through both the lists. If P1 reaches L1’s last node, point it to the first node of L2 and
continue traversing. Do the same thing for P2 when it reaches L2’s last node. (By doing this,
we are balancing the difference in the length between the linked lists. The shorter one will
get over soon and by redirecting to longer list’s head, it will traverse the extra nodes also.)
Finally they will Meet at the Intersection node.
3. void PrintTree (Tree T)
{
if (T != NULL)
{
PrintTree (T-> Left);
PrintElement (T-> Element);
PrintTree (T->Right);
}
}
The above method ‘PrintTree’ results in which of the following traversal
a Inorder
b. Preorder
c. Postorder
d. None of the above
Solution: a. Inorder
Inorder:
void PrintTree (Tree T)
{
if (T != NULL)
{
PrintTree (T-> Left);
PrintElement (T-> Element);
PrintTree (T->Right);
}
}
For preorder use this order
PrintElement (T-> Element);
PrintTree (T-> Left);
PrintTree (T->Right);
For postorder use this order
PrintTree (T-> Left);
PrintTree (T->Right);
PrintElement (T-> Element);
4. Given a Binary Search Tree (BST), print its values in ascending order.
a. Perform Depth first traversal
b. Perform Breadth first traversal
c. Perform Postorder traversal
d. Perform Inorder traversal
Solution: d. Perform Inorder traversal
It is the properfy of BST and Inorder traversal.
6. Given a Tree, is it possible to find the greatest and least among leaves in linear
time?.
a. Solution depends on the tree structure
b.Linear solution exist
c. Only Non-linear solution exist.
d. No linear solution exist
Solution: b. Linear solution exist
Have two variables Min and Max. Perform any tree traversal.Assign the first traversed leaf
element to Min and Max for all other leaf elements check with these variables and update it
accordingly. If a current element is < Min then update Min with that element. If it is > Min
then check with Max.
Note: If you want to find the greatest and least among all nodes perform the checks for
each node traversed.
7. Is it possible to find find the greatest and least value among the nodes in a
given BST without using any extra variables?
a. No solution exist.
b. Solution need 2 extra variables
c. Solution exist without any extra variables
d Solution need 1 extra variable
Solution:c Solution exist without any extra variables
As per BST property, the left most node should be the least one and the rightmost node
should be the greatest. In other words, the first and last node of an Inorder traversal are
the least and greatest among the nodes respectively.
9. Given two keys K1 & K2, write an algorithm to print all the elements between
them with K1<=K2 in a BST.
a. Solution need 2 extra spaces
b. Linear solution is possible without using any extra space
c No linear solution exist
d Solution need 1 extra space
Solution:b. Linear solution is possible without using any extra space
Perform an inorder traversal. Once you find K1 print it and continue traversal now, print all
other traversed elements until you reach K2.
Note: If K1 == K2 stop once you find K1.
The number of addresses usable for addressing specific hosts in each network is always 2 power N - 2
(where N is the number of rest field bits, and the subtraction of 2 adjusts for the use of the all-bits-
zero host portion for network address and the all-bits-one host portion as a broadcast address. Thus,
for a Class C address with 8 bits available in the host field, the number of hosts is 254
Class A 0.0.0.0 - 127.255.255.255
Class B 128.0.0.0 - 191.255.255.255
Define Network?
A network is a set of devices connected by physical media links. A network is recursively is
a connection of two or more nodes by a physical link or two or more networks connected by
one or more nodes.
2. What is Protocol?
A protocol is a set of rules that govern all aspects of information communication.
3. What is a Link?
At the lowest level, a network can consist of two or more computers directly connected by
some physical medium such as coaxial cable or optical fiber. Such a physical medium is
called as Link.
4. What is a node?
A network can consist of two or more computers directly connected by some physical
medium such as coaxial cable or optical fiber. Such a physical medium is called as Links and
the computer it connects is called as Nodes.
e. Session Layer
f. Presentation Layer
g. Application Layer
C RC appends a sequence of redundant bits derived from binary division to the data unit.
The divisor in the CRC generator is often represented as an algebraic polynomial.
It is of two types:
1.Pure aloha
2.Slotted aloha
58. What is the minimum and maximum length of the header in the TCP segment and IP
datagram?
The header should have a minimum length of 20 bytes and can have a maximum length of
60 bytes.
STAR topology: In this all computers are connected using a central hub.
Advantages: Can be inexpensive, easy to install and reconfigure and easy to trouble shoot
physical problems.
RING topology: In this all computers are connected in loop.
Advantages: All computers have equal access to network media, installation can be simple,
and signal does not degrade as much as in other topologies because each computer
regenerates it.
61. What is mesh network?
A network in which there are multiple network links between computers to provide multiple
paths for data to travel.
help manage congestion is forcing the packet to be transmitted at a more predictable rate.
This is called traffic shaping.
69. Name the factors that affect the reliability of the network?
a. Frequency of failure
b. Recovery time of a network after a failure
## The other focus areas of New India 2022 have shown significant improvements such as reduction in
black money
(demonetization), and dirt free nation (Swatch Bharat Scheme).
## The aim of ‘Poverty free India’ seems almost achievable by the year 2022 with Modi government
providing
loans to needy farmers.
Against the GD topic:
## There is not much improvement in caste politics and looks difficult to eradicate in the promised
timeline.
## Social bans, lob lynching and beef ban have resulted in fear in minorities during Modi Government.
2.Social Media- Curse or Boon
Points for the GD topic:
## Social media helps in expanding knowledge to wider audience in a cost-effective manner via posts
or videos.
## It is easily available to everyone and provides an option to voice opinion freely.
## Many people are also contributing to the society by using social media for good cause by using
hashtags or
YouTube videos to either highlight a social issue or help a victim. The recent role of social media in
Arab Spring is
one such example.
Points Against the GD topic:
## Social media encourages violent behavior by easily spreading fake news that might hurt social
sentiments or
people of some repute.
## Social media is misused by many people to harass others. It also promotes cyber bullying that
promotes violent
human behavior.
3.Industrial Revolution 4.0- Pros & Cons
Points for the GD topic:
## It is a collaborative era of Cyber Physical Systems that has a potential to bring a massive
improvement in the way
we live.
## It can bring advantages like building sustainable economies and transparency in governance.
## It will bring huge digital transformation.
## It can be utilized to provide low cost healthcare facilities and bring improvement in other sectors as
well.
Points Against the GD topic:
## It might not be helpful for those who are not digital literates.
## Adopting to Industry 4.0 can increase cyber security issues.
4.Why scams like Nirav Modi Happen with Indian banks?
Points for the discussion:
## There is a loophole in the quality of internal audits conducted by banks.
## Fake LoUs (Letter of Undertaking) are not tracked easily as SWIFT is not integrated with core
banking in several
banks in India.
## There is a dire need of more regulating authorities of RBI that can keep a track of such frauds.
## Several checkpoints should be made by the Government, RBI as well as banks to prevent such huge
frauds.
Note: Such topics help a hiring manager to judge a candidate’s ability to understand a problem and
offer a
solution to it. Your analytical and decision making skills are highlighted here.
5.For or Against Modi Government
Points for the topic: Highlight Achievements
## Demonetization was a welcomed step to discourage black money and reduce fake currency in
circulation.
## 4 years of Modi government brought improvement in international relationships with several
countries like USA
and Japan.
## ‘Digital India’ was an excellent initiative.
## GST was the biggest change implemented that no previous government thought of.
Points Against the topic: Highlight Failures
## Demonetization created several issues and suffering for poor people.
## The government failed to take serious action to resolve issues such as threat for minorities by some
Hindu groups
in the name of culture and cow vigilantism.