DBMS Interview Questions-DBMS Interview Questions: Dr. Anil Kumar Dubey (9783934206)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 41

DBMS Interview Questions-DBMS Interview Questions

1. 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.

3. What is a Database system?


The database and DBMS software together is called as Database system.

4. What are the advantages of DBMS?


I. Redundancy is controlled.
II. Providing multiple user interfaces.
III. Providing backup and recovery
IV. Unauthorized access is restricted.
V. Enforcing integrity constraints.

5. What is normalization?
It is a process of analyzing the given relation schemas based on their Functional Dependencies
(FDs) and primary key to achieve the properties
(1).Minimizing redundancy, (2). Minimizing insertion, deletion and update anomalies.

6. What is Data Model?


A collection of conceptual tools for describing data, data relationships data semantics and
constraints.

7. What is E-R model?


This data model is based on real world that consists of basic objects called entities and of
relationship among these objects. Entities are described in a database by a set of attributes.

8. What is Object Oriented model?


This model is based on collection of objects. An object contains values stored in instance
variables with in the object. An object also contains bodies of code that operate on the object.
These bodies of code are called methods. Objects that contain same types of values and the same
methods are grouped together into classes.

9. What is an Entity?
An entity is a thing or object of importance about which data must be captured.

10. What is DDL (Data Definition Language)?


A data base schema is specifies by a set of definitions expressed by a special language called
DDL.

11. What is DML (Data Manipulation Language)?


This language that enable user to access or manipulate data as organized by appropriate data
model. Procedural DML or Low level: DML requires a user to specify what data are needed and
how to get those data. Non-Procedural DML or High level: DML requires a user to specify what
data are needed without specifying how to get those data
Dr. Anil Kumar Dubey [9783934206] Page 1
12. What is DML Compiler?
It translates DML statements in a query language into low-level instruction that the query
evaluation engine can understand.

13. What is Query evaluation engine?


It executes low-level instruction generated by compiler.

14. What is Functional Dependency?


Functional Dependency is the starting point of normalization. Functional Dependency exists
when a relation between two attributes allows you to uniquely determine the corresponding
attributes value.

15. What is 1 NF (Normal Form)?


The first normal form or 1NF is the first and the simplest type of normalization that can be
implemented in a database. The main aims of 1NF are to:
1. Eliminate duplicative columns from the same table.
2. Create separate tables for each group of related data and identify each row with a unique
column (the primary key).

16. What is Fully Functional dependency?


A functional dependency X Y is full functional dependency if removal of any attribute A from X
means that the dependency does not hold any more.

17. What is 2NF?


A relation schema R is in 2NF if it is in 1NF and every non-prime attribute A in R is fully
functionally dependent on primary key.

18. What is 3NF?


A relation is in third normal form if it is in Second Normal Form and there are no functional
(transitive) dependencies between two (or more) non-primary key attributes.

19. What is BCNF (Boyce-Codd Normal Form)?


A table is in Boyce-Codd normal form (BCNF) if and only if it is in 3NF and every determinant
is a candidate key.

20. What is 4NF?


Fourth normal form requires that a table be BCNF and contain no multi-valued dependencies.

21. What is 5NF?


A table is in fifth normal form (5NF) or Project-Join Normal Form (PJNF) if it is in 4NF and it
cannot have a lossless decomposition into any number of smaller tables.

22. What is a query?


A query with respect to DBMS relates to user commands that are used to interact with a data
base.

23. What is meant by query optimization?


The phase that identifies an efficient execution plan for evaluating a query that has the least
estimated cost is referred to as query optimization.

Dr. Anil Kumar Dubey [9783934206] Page 2


24. What is an attribute?
It is a particular property, which describes the entity.

25. What is RDBMS?


Relational Data Base Management Systems (RDBMS) are database management systems that
maintain data records and indices in tables.

26. Whats difference between DBMS and RDBMS?


DBMS provides a systematic and organized way of storing, managing and retrieving from
collection of logically related information. RDBMS also provides what DBMS provides but
above that it provides relationship integrity.

27. What is SQL?


SQL stands for Structured Query Language. SQL is an ANSI (American National Standards
Institute) standard computer language for accessing and manipulating database systems. SQL
statements are used to retrieve and update data in a database.

28. What is Stored Procedure?


A stored procedure is a named group of SQL statements that have been previously created and
stored in the server database.

29. What is a view?


A view may be a subset of the database or it may contain virtual data that is derived from the
database files but is not explicitly stored.

30. What is Trigger?


A trigger is a SQL procedure that initiates an action when an event (INSERT, DELETE or
UPDATE) occurs.

31. What is Index?


An index is a physical structure containing pointers to the data.

32. What is extension and intension?


Extension -It is the number of tuples present in a table at any instance. This is time dependent.
Intension -It is a constant value that gives the name, structure of table and the constraints laid on
it.

33. What do you mean by atomicity and aggregation?


Atomicity-Atomicity states that database modifications must follow an all or nothing rule. Each
transaction is said to be atomic. If one part of the transaction fails, the entire transaction fails.
Aggregation - A feature of the entity relationship model that allows a relationship set to
participate in another relationship set. This is indicated on an ER diagram by drawing a dashed
box around the aggregation.

34. What is RDBMS KERNEL?


Two important pieces of RDBMS architecture are the kernel, which is the software, and the data
dictionary, which consists of the system- level data structures used by the kernel to manage the
database.

35. Name the sub-systems of a RDBMS?

Dr. Anil Kumar Dubey [9783934206] Page 3


I/O, Security, Language Processing, Process Control, Storage Management, Logging and
Recovery, Distribution Control, Transaction Control, Memory Management, Lock Management.

36. How do you communicate with an RDBMS?


You communicate with an RDBMS using Structured Query Language (SQL)

37. Disadvantage in File Processing System?


Data redundancy & inconsistency.
Difficult in accessing data.
Data isolation.
Data integrity.
Concurrent access is not possible.
Security Problems.

38. What is VDL (View Definition Language)?


It specifies user views and their mappings to the conceptual schema.

39. What is SDL (Storage Definition Language)?


This language is to specify the internal schema. This language may Specify the mapping between
two schemas.

40. Describe concurrency control?


Concurrency control is the process managing simultaneous operations against a database so that
database integrity is no compromised. There are two approaches to concurrency control.
The pessimistic approach involves locking and the optimistic approach involves versioning.

41. Describe the difference between homogeneous and heterogeneous distributed database?
A homogenous database is one that uses the same DBMS at each node. A heterogeneous
database is one that may have a different DBMS at each node.

42. What is a distributed database?


A distributed database is a single logical database that is spread across more than one node or
locations that are all connected via some communication link.

43. Explain the difference between two and three-tier architectures?


Three-tier architecture includes a client and two server layers.
The application code is stored on the application server and the database is stored on the
database server. A two-tier architecture includes a client and one server layer. The database is
stored on the database server.

44. Briefly describe the three types of SQL commands?


Data definition language commands are used to create, alter, and drop tables. Data manipulation
commands are used to insert, modify, update, and query data in the database. Data control
language commands help the DBA to control the database.

45. List some of the properties of a relation?


Relations in a database have a unique name and no multi valued attributes exist. Each row is
unique and each attribute within a relation has a unique name. The sequence of both columns and
rows is irrelevant.

46. Explain the differences between an intranet and an extranet?


Dr. Anil Kumar Dubey [9783934206] Page 4
An Internet database is accessible by everyone who has access to a Web site. An intranet
database limits access to only people within a given organization.

47. What is SQL Deadlock?


Deadlock is a unique situation in a multi user system that causes two or more users to wait
indefinitely for a locked resource.

48. What is a Catalog?


A catalog is a table that contains the information such as structure of each file, the type and
storage format of each data item and various constraints on the data .The information stored in
the catalog is called Metadata.

49. What is data ware housing & OLAP?


Data warehousing and OLAP (online analytical processing) systems are the techniques used in
many companies to extract and analyze useful information from very large databases for decision
making.

50. Describe the three levels of data abstraction?


Physical level: The lowest level of abstraction describes how data are stored.
Logical level: The next higher level of abstraction, describes what data are stored in database and
what relationship among those data.
View level: The highest level of abstraction describes only part of entire database.

51. What is Data Independence?


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.

57. What is Hashing technique?


This is a primary file organization technique that provides very fast access to records on certain
search conditions.
Dr. Anil Kumar Dubey [9783934206] Page 5
58. What is a transaction?
A transaction is a logical unit of database processing that includes one or more database access
operations.

59. What are the different phases of Transaction?


Analysis phase
Redo phase
Undo phase

60. What is transparent dbms?


It is one, which keeps its physical structure hidden from user.

61. What are the primitive operations common to all record management System?
Addition, deletion and modification.

62. Explain the differences between structured data and unstructured data.
Structured data are facts concerning objects and events. The most important structured data are
numeric, character, and dates.
Structured data are stored in tabular form. Unstructured data are multimedia data such as
documents, photographs, maps, images, sound, and video clips. Unstructured data are most
commonly found on Web servers and Web-enabled databases.

63. What are the major functions of the database administrator?


Managing database structure, controlling concurrent processing, managing processing rights and
responsibilities, developing database security, providing for database recovery, managing the
DBMS and maintaining the data repository.

64. What is a dependency graph?


A dependency graph is a diagram that is used to portray the connections between database
elements.

65. Explain the difference between an exclusive lock and a shared lock?
An exclusive lock prohibits other users from reading the locked resource; a shared lock allows
other users to read the locked resource, but they cannot update it.

66. Explain the "paradigm mismatch" between SQL and application programming
languages.
SQL statements return a set of rows, while an application program works on one row at a time.
To resolve this mismatch the results of SQL statements are processed as pseudo files, using a
cursor or pointer to specify which row is being processed.

67. Name four applications for triggers.


(1)Providing default values, (2) enforcing data constraints,
(3) Updating views and (4) enforcing referential integrity

68. What are the advantages of using stored procedures?


The advantages of stored procedures are (1) greater security, (2) decreased network traffic, (3)
the fact that SQL can be optimized and (4) code sharing which leads to less work, standardized
processing, and specialization among developers.

Dr. Anil Kumar Dubey [9783934206] Page 6


69. Explain the difference between attributes and identifiers.
Entities have attributes. Attributes are properties that describe the entity's characteristics. Entity
instances have identifiers. Identifiers are attributes that name, or identify, entity instances.

70. What is Enterprise Resource Planning (ERP), and what kind of a database is used in an
ERP application?
Enterprise Resource Planning (ERP) is an information system used in manufacturing companies
and includes sales, inventory, production planning, purchasing and other business functions. An
ERP system typically uses a multiuser database.

71. Describe the difference between embedded and dynamic SQL?


Embedded SQL is the process of including hard coded SQL statements. These statements do not
change unless the source code is modified. Dynamic SQL is the process of generating SQL on
the fly. The statements generated do not have to be the same each time.

72. Explain a join between tables


A join allows tables to be linked to other tables when a relationship between the tables exists.
The relationships are established by using a common column in the tables and often uses the
primary/foreign key relationship.

73. Describe a subquery.


A subquery is a query that is composed of two queries. The first query (inner query) is within the
WHERE clause of the other query (outer query).

74. Compare a hierarchical and network database model?


The hierarchical model is a top-down structure where each parent may have many children but
each child can have only one parent. This model supports one-to-one and one-to-many
relationships.
The network model can be much more flexible than the hierarchical model since each parent can
have multiple children but each child can also have multiple parents. This model supports one-
to-one, one-to-many, and many-to-many relationships.

75. Explain the difference between a dynamic and materialized view.


A dynamic view may be created every time that a specific view is requested by a user. A
materialized view is created and or updated infrequently and it must be synchronized with its
associated base table(s).

76. Explain what needs to happen to convert a relation to third normal form.
First you must verify that a relation is in both first normal form and second normal form. If the
relation is not, you must convert into second normal form. After a relation is in second normal
form, you must remove all transitive dependencies.

77. Describe the four types of indexes?


A unique primary index is unique and is used to find and store a row. A non-unique 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
non-unique secondary index is not unique and used to find table rows.

78. Explain minimum and maximum cardinality?

Dr. Anil Kumar Dubey [9783934206] Page 7


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.

80. Explain what we mean by an ACID transaction.


An ACID transaction is one that is atomic, consistent, isolated, and durable. Durable means that
database changes are permanent. Consistency can mean either statement level or transaction
level consistency. With transaction level consistency, a transaction may not see its own changes.
Atomic means it is performed as a unit.

81. Under what conditions should indexes be used?


Indexes can be created to enforce uniqueness, to facilitate sorting, and to enable fast retrieval by
column values. A good candidate for an index is a column that is frequently used with equal
conditions in WHERE clauses.

82. What is difference between SQL and SQL SERVER?


SQL is a language that provides an interface to RDBMS, developed by IBM. SQL SERVER is a
RDBMS just like Oracle, DB2.

83. What is Specialization?


It is the process of defining a set of subclasses of an entity type where each subclass contain all
the attributes and relationships of the parent entity and may have additional attributes and
relationships which are specific to it self.

84. What is generalization?


It is the process of finding common attributes and relations of a number of entities and defining a
common super class for them.

85. What is meant by Proactive, Retroactive and Simultaneous Update?


Proactive Update: The updates that are applied to database before it becomes effective in real
world.
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.

86. What is RAID Technology?

Redundant array of inexpensive (or independent) disks. The main goal of raid technology is to
even out the widely different rates of performance improvement of disks against those in
memory and microprocessor. Raid technology employs the technique of data striping to achieve
higher transfer rates.

87. What are serial, non serial schedule?

Dr. Anil Kumar Dubey [9783934206] Page 8


A schedule S is serial if, for every transaction T participating in the schedule, all the operations
of T is executed consecutively in the schedule, otherwise, the schedule is called non-serial
schedule.

88. What are conflict serializable schedules?


A schedule S of n transactions is serializable if it is equivalent to some serial schedule of the
same n transactions.

89. What is view serializable?


A schedule is said to be view serializable if it is view equivalent with some serial schedule.

90. What is a foreign key?


A key of a relation schema is called as a foreign key if it is the primary key of
some other relation to which it is related to.

91. What are the disadvantages of using a dbms?


1) High initial investments in h/w, s/w, and training.
2) Generality that a DBMS provides for defining and processing data.
3) Overhead for providing security, concurrency control, recovery, and integrity functions.

92. What is Lossless join property?


It guarantees that the spurious tuple generation does not occur with respect to relation schemas
after decomposition.

93. What is a Phantom Deadlock?


In distributed deadlock detection, the delay in propagating local information might cause the
deadlock detection algorithms to identify deadlocks that do not really exist. Such situations are
called phantom deadlocks and they lead to unnecessary aborts.

94. What is a checkpoint and When does it occur?


A Checkpoint is like a snapshot of the DBMS state. By taking checkpoints, the DBMS can
reduce the amount of work to be done during restart in the event of subsequent crashes.

95. What is schema?


The description of a data base is called the database schema , which is specified during database
design and is not expected to change frequently . A displayed schema is called schema diagram
.We call each object in the schema as schema construct.

OS Interview Questions
1. What is an operating system?
An operating system is a program that acts as an intermediary between the user and the computer
hardware. The purpose of an OS is to provide a convenient environment in which user can
execute programs in a convenient and efficient manner.

2. What are the different operating systems?


1. Batched operating systems
2. Multi-programmed operating systems
3. timesharing operating systems
4. Distributed operating systems
5. Real-time operating systems
Dr. Anil Kumar Dubey [9783934206] Page 9
3. What are the basic functions of an operating system?
Operating system controls and coordinates the use of the hardware among the various
applications programs for various uses. Operating system acts as resource allocator and manager.
Also operating system is control program which controls the user programs to prevent errors and
improper use of the computer. It is especially concerned with the operation and control of I/O
devices.

4. What is kernel?
Kernel is the core and essential part of computer operating system that provides basic services
for all parts of OS.

5. What is difference between micro kernel and macro kernel?


Micro kernel is a kernel which run services those are minimal for operating system performance.
In this kernel all other operations are performed by processor.
Macro Kernel is a combination of micro and monolithic kernel. In monolithic kernel all
operating system code is in single executable image.

6. What is dead lock?


Deadlock is a situation or condition where the two processes are waiting for each other to
complete so that they can start. This result both the processes to hang.

7. What is a process?
A program in execution is called a process.
Processes are of two types:
1. Operating system processes
2. User processes

8. What are the states of a process?


1. New
2. Running
3. Waiting
4. Ready
5. Terminated

9. What is starvation and aging?


Starvation is Resource management problem where a process does not get the resources it needs
for a long time because the resources are being allocated to other processes.
Aging is a technique to avoid starvation in a scheduling system.

10. What is semaphore?


Semaphore is a variable, whose status reports common resource, Semaphore is of two types one
is Binary semaphore and other is Counting semaphore.

11. What is context switching?


Transferring the control from one process to other process requires saving the state of the old
process and loading the saved state for new process. This task is known as context switching.

12. What is a thread?


A thread is a program line under execution. Thread sometimes called a light-weight process, is a
basic unit of CPU utilization; it comprises a thread id, a program counter, a register set, and a
Dr. Anil Kumar Dubey [9783934206] Page 10
stack

13. What is process synchronization?


A situation, where several processes access and manipulate the same data concurrently and the
outcome of the execution depends on the particular order in which the access takes place, is
called race condition. To guard against the race condition we need to ensure that only one
process at a time can be manipulating the same data. The technique we use for this is called
process synchronization.

14. What is virtual memory?


Virtual memory is hardware technique where the system appears to have more memory that it
actually does. This is done by time-sharing, the physical memory and storage parts of the
memory one disk when they are not actively being used.

15. What is thrashing?


It is a phenomenon in virtual memory schemes when the processor spends most of its time
swapping pages, rather than executing instructions. This is due to an inordinate number of page
faults.

16. What is fragmentation? Tell about different types of fragmentation?


When many of free blocks are too small to satisfy any request then fragmentation occurs.
External fragmentation and internal fragmentation are two types of fragmentation. External
Fragmentation happens when a dynamic memory allocation algorithm allocates some memory
and a small piece is left over that cannot be effectively used. Internal fragmentation is the space
wasted inside of allocated memory blocks because of restriction on the allowed sizes of allocated
blocks.

17. What are necessary conditions for dead lock?


1. Mutual exclusion (where at least one resource is non-sharable)
2. Hold and wait (where a process holds one resource and waits for other resource)
3. No preemption (where the resources cant be preempted)
4. Circular wait (where p[i] is waiting for p[j] to release a resource. i= 1,2,n
j=if (i!=n) then i+1
else 1 )

18. What is cache memory?


Cache memory is random access memory (RAM) that a computer microprocessor can access
more quickly than it can access regular RAM. As the microprocessor processes data, it looks first
in the cache memory and if it finds the data there (from a previous reading of data), it does not
have to do the more time-consuming reading of data from larger memory.

19. What is logical and physical addresses space?


Logical address space is generated from CPU; it bound to a separate physical address space is
central to proper memory management. Physical address space is seen by the memory unit.
Logical address space is virtual address space. Both these address space will be same at compile
time but differ at execution time.

20. Differentiate between Complier and Interpreter?


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

Dr. Anil Kumar Dubey [9783934206] Page 11


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.

29. Explain the meaning of mutex.


Mutex is the short form for Mutual Exclusion object. A mutex allows multiple threads for
sharing the same resource. The resource can be file. A mutex with a unique name is created at
the time of starting a program. A mutex must be locked from other threads, when any thread that
needs the resource. When the data is no longer used / needed, the mutex is set to unlock.

30. What is cycle stealing?


We encounter cycle stealing in the context of Direct Memory Access (DMA). Either the DMA
controller can use the data bus when the CPU does not need it, or it may force the CPU to
temporarily suspend operation. The latter technique is called cycle stealing. Note that cycle
stealing can be done only at specific break points in an instruction cycle.
Dr. Anil Kumar Dubey [9783934206] Page 12
31. What is Marshalling?
The process of packaging and sending interface method parameters across thread or process
boundaries.

32. What is a daemon?


Daemon is a program that runs in the background without users interaction. A daemon runs in a
multitasking operating system like UNIX. A daemon is initiated and controlled by special
programs known as processes.

33. What is pre-emptive and non-preemptive scheduling?


Preemptive scheduling: The preemptive scheduling is prioritized. The highest priority process
should always be the process that is currently utilized.
Non-Preemptive scheduling: When a process enters the state of running, the state of that process
is not deleted from the scheduler until it finishes its service time.

34. What is busy waiting?


The repeated execution of a loop of code while waiting for an event to occur is called busy-
waiting. The CPU is not engaged in any real productive activity during this period, and the
process does not progress toward completion.

35. What is page cannibalizing?


Page swapping or page replacements are called page cannibalizing.

36. What is SMP?


To achieve maximum efficiency and reliability a mode of operation known as symmetric
multiprocessing is used. In essence, with SMP any process or threads can be assigned to any
processor.

37. What is process migration?


It is the transfer of sufficient amount of the state of process from one machine to the target
machine.

38. Difference between Primary storage and secondary storage?


Primary memory is the main memory (Hard disk, RAM) where the operating system resides.
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.

Dr. Anil Kumar Dubey [9783934206] Page 13


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).

51. 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.

52. What is cycle stealing?


We encounter cycle stealing in the context of Direct Memory Access (DMA). Either the DMA
controller can use the data bus when the CPU does not need it, or it may force the CPU to
temporarily suspend operation. The latter technique is called cycle stealing. Note that cycle
stealing can be done only at specific break points in an instruction cycle.

Dr. Anil Kumar Dubey [9783934206] Page 14


53. What is an idle thread?
The special thread a dispatcher will execute when no ready thread is found.

54. What is FtDisk?


It is a fault tolerance disk driver for Windows NT.

55. What is Dispatcher?


Dispatcher module gives control of the CPU to the process selected by the short-term scheduler;
this involves: Switching context, Switching to user mode, Jumping to the proper location in the
user program to restart that program, dispatch latency time it takes for the dispatcher to stop
one process and start another running.

56. When does the condition 'rendezvous' arise?


In message passing, it is the condition in which, both, the sender and receiver are blocked until
the message is delivered.

57. What is process spawning?


When the OS at the explicit request of another process creates a process, this action is called
process spawning

58. What are the reasons for process suspension?


swapping
interactive user request
timing
parent process request

59. What are the sub-components of I/O manager in Windows NT?


Network redirector/ Server
Cache manager.
File systems
Network driver
Device driver

60. What is a drawback of MVT?


ability to support multiple processors
virtual storage
source level debugging

Java Interview Questions

1. What is JVM?
The Java interpreter along with the runtime environment required to run the Java application in
called as Java virtual machine (JVM)

2. What is the most important feature of Java?


Java is a platform independent language.

3. What do you mean by platform independence?


Platform independence means that we can write and compile the java code in one platform (eg
Windows) and can execute the class in any other supported platform eg (Linux, Solaris, etc).

Dr. Anil Kumar Dubey [9783934206] Page 15


4. What is the difference between a JDK and a JVM?
JDK is Java Development Kit which is for development purpose and it includes execution
environment also. But JVM is purely a run time environment and hence you will not be able to
compile your source files using a JVM.

5. What is the base class of all classes?


java.lang.Object

6. What are the access modifiers in Java?


There are 3 access modifiers. Public, protected and private, and the default one if no identifier is
specified is called friendly, but programmer cannot specify the friendly identifier explicitly.

7. What is are packages?


A package is a collection of related classes and interfaces providing access protection and
namespace management.

8. What is meant by Inheritance and what are its advantages?


Inheritance is the process of inheriting all the features from a class. The advantages of
inheritance are reusability of code and accessibility of variables and methods of the super class
by subclasses.

9. What is the difference between superclass and subclass?


A super class is a class that is inherited whereas sub class is a class that does the inheriting.

10. What is an abstract class?


An abstract class is a class designed with implementation gaps for subclasses to fill in and is
deliberately incomplete.

11. What are the states associated in the thread?


Thread contains ready, running, waiting and dead states.

12. What is synchronization?


Synchronization is the mechanism that ensures that only one thread is accessed the resources at a
time.

13. What is deadlock?


When two threads are waiting each other and cant precede the program is said to be deadlock.

14. What is an applet?


Applet is a dynamic and interactive program that runs inside a web page displayed by a java
capable browser

15. What is the lifecycle of an applet?


init() method - Can be called when an applet is first loaded
start() method - Can be called each time an applet is started.
paint() method - Can be called when the applet is minimized or maximized.
stop() method - Can be used when the browser moves off the applets page.
destroy() method - Can be called when the browser is finished with the applet.

16. How do you set security in applets?


Dr. Anil Kumar Dubey [9783934206] Page 16
using setSecurityManager() method

17. What is a layout manager and what are different types of layout managers available in
java AWT?
A layout manager is an object that is used to organize components in a container. The different
layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and
GridBagLayout

18. What is JDBC?


JDBC is a set of Java API for executing SQL statements. This API consists of a set of classes
and interfaces to enable programs to write pure Java Database applications.

19. What are drivers available?


-a) JDBC-ODBC Bridge driver b) Native API Partly-Java driver
c) JDBC-Net Pure Java driver d) Native-Protocol Pure Java driver

20. What is stored procedure?


Stored procedure is a group of SQL statements that forms a logical unit and performs a particular
task. Stored Procedures are used to encapsulate a set of operations or queries to execute on
database. Stored procedures can be compiled and executed with different parameters and results
and may have any combination of input/output parameters.

21. What is the Java API?


The Java API is a large collection of ready-made software components that provide many useful
capabilities, such as graphical user interface (GUI) widgets.

22. Why there are no global variables in Java?


Global variables are globally accessible. Java does not support globally accessible variables due
to following reasons:
1) The global variables breaks the referential transparency
2) Global variables creates collisions in namespace.

23. What are Encapsulation, Inheritance and Polymorphism?


Encapsulation is the mechanism that binds together code and data it manipulates and keeps both
safe from outside interference and misuse. Inheritance is the process by which one object
acquires the properties of another object. Polymorphism is the feature that allows one interface to
be used for general class actions.

24. What is the use of bin and lib in JDK?


Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all
packages.

25. What is method overloading and method overriding?


Method overloading: When a method in a class having the same method name with different
arguments is said to be method overloading. Method overriding: When a method in a class
having the same method name with same arguments is said to be method overriding.

26. What is the difference between this() and super()?


this() can be used to invoke a constructor of the same class whereas super() can be used to
invoke a super class constructor.

Dr. Anil Kumar Dubey [9783934206] Page 17


27. What is Domain Naming Service (DNS)?
It is very difficult to remember a set of numbers (IP address) to connect to the Internet. The
Domain Naming Service (DNS) is used to overcome this problem. It maps one particular IP
address to a string of characters. For example, www.mascom.com implies com is the domain
name reserved for US commercial sites, moscom is the name of the company and www is the
name of the specific computer, which is mascoms server.

28. What is URL?


URL stands for Uniform Resource Locator and it points to resource files on the Internet. URL
has four components: http://www. address.com:80/index.html,where http-protocol name, address
- IP address or host name, 80 - port number and index.html - file path.

29. What is RMI and steps involved in developing an RMI object?


Remote Method Invocation (RMI) allows java object that executes on one machine and to invoke
the method of a Java object to execute on another machine. The steps involved in developing an
RMI object are: a) Define the interfaces b) Implementing these interfaces c) Compile the
interfaces and their implementations with the java compiler d) Compile the server
implementation with RMI compiler e) Run the RMI registry f) Run the application.

30. What is RMI architecture?


RMI architecture consists of four layers and each layer performs specific functions: a)
Application layer - contains the actual object definition. b) Proxy layer - consists of stub and
skeleton. c) Remote Reference layer - gets the stream of bytes from the transport layer and sends
it to the proxy layer. d) Transportation layer - responsible for handling the actual machine-to-
machine communication.

31. What is a Java Bean?


A Java Bean is a software component that has been designed to be reusable in a variety of
different environments.

32. What are checked exceptions?


Checked exception are those which the Java compiler forces you to catch. e.g. IOException are
checked Exceptions.

33. What are runtime exceptions?


Runtime exceptions are those exceptions that are thrown at runtime because of either wrong
input data or because of wrong business logic etc. These are not checked by the compiler at
compile time.

34. What is the difference between error and an exception?


An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These
JVM errors and you can not repair them at runtime. While exceptions are conditions that occur
because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not
exist. Or a NullPointerException will take place if you try using a null reference. In most of the
cases it is possible to recover from an exception (probably by giving user a feedback for entering
proper values etc.).

35. What is the purpose of finalization?


The purpose of finalization is to give an unreachable object the opportunity to perform any
cleanup processing before the object is garbage collected. For example, closing a opened file,
closing a opened database Connection.
Dr. Anil Kumar Dubey [9783934206] Page 18
36. What is the difference between yielding and sleeping?
When a task invokes its yield() method, it returns to the ready state. When a task invokes its
sleep() method, it returns to the waiting state.

37. What is the difference between preemptive scheduling and time slicing?
Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead
states or a higher priority task comes into existence. Under time slicing, a task executes for a
predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines
which task should execute next, based on priority and other factors.

38. What is mutable object and immutable object?


If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, ) If
you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer,
Float)

39. What is the purpose of Void class?


The Void class is an uninstantiable placeholder class to hold a reference to the Class object
representing the primitive Java type void.

40. What is JIT and its use?


Really, just a very fast compiler In this incarnation, pretty much a one-pass compiler no
offline computations. So you cant look at the whole method, rank the expressions according to
which ones are re-used the most, and then generate code. In theory terms, its an on-line
problem.

41. What is nested class?


If all the methods of a inner class is static then it is a nested class.

42. What is HashMap and Map?


Map is Interface and Hashmap is class that implements that.

43. What are different types of access modifiers?


public: Any thing declared as public can be accessed from anywhere. private: Any thing declared
as private cant be seen outside of its class. protected: Any thing declared as protected can be
accessed by classes in the same package and subclasses in the other packages. default modifier :
Can be accessed only to classes in the same package.

44. What is the difference between Reader/Writer and InputStream/Output Stream?


The Reader/Writer class is character-oriented and the InputStream/OutputStream class is byte-
oriented.

45. What is servlet?


Servlets are modules that extend request/response-oriented servers, such as java-enabled web
servers. For example, a servlet might be responsible for taking data in an HTML order-entry
form and applying the business logic used to update a companys order database.

46. What is Constructor?


A constructor is a special method whose task is to initialize the object of its class.
It is special because its name is the same as the class name.
They do not have return types, not even void and therefore they cannot return values.
Dr. Anil Kumar Dubey [9783934206] Page 19
They cannot be inherited, though a derived class can call the base class constructor.
Constructor is invoked whenever an object of its associated class is created.

47. What is an Iterator?


The Iterator interface is used to step through the elements of a Collection.
Iterators let you process each element of a Collection.
Iterators are a generic way to go through all the elements of a Collection no matter how it is
organized.
Iterator is an Interface implemented a different way for every Collection.

48. What is the List interface?


The List interface provides support for ordered collections of objects.
Lists may contain duplicate elements.

49. What is memory leak?


A memory leak is where an unreferenced object that will never be used again still hangs around
in memory and doesnt get garbage collected.

50. What is the difference between the prefix and postfix forms of the ++ operator?
The prefix form performs the increment operation and returns the value of the increment
operation. The postfix form returns the current value all of the expression and then performs the
increment operation on that value.

51. What is the difference between a constructor and a method?


A constructor is a member function of a class that is used to create objects of that class. It has the
same name as the class itself, has no return type, and is invoked using the new operator.
A method is an ordinary member function of a class. It has its own name, a return type (which
may be void), and is invoked using the dot operator.

52. What will happen to the Exception object after exception handling?
Exception object will be garbage collected.

53. Difference between static and dynamic class loading.


Static class loading: The process of loading a class using new operator is called static class
loading. Dynamic class loading: The process of loading a class at runtime is called dynamic class
loading.
Dynamic class loading can be done by using Class.forName(.).newInstance().

54. Explain the Common use of EJB


The EJBs can be used to incorporate business logic in a web-centric application.
The EJBs can be used to integrate business processes in Business-to-business (B2B) e-commerce
applications. In Enterprise Application Integration applications, EJBs can be used to house
processing and mapping between different applications.

55. What is JSP?


JSP is a technology that returns dynamic content to the Web client using HTML, XML and
JAVA elements. JSP page looks like a HTML page but is a servlet. It contains Presentation logic
and business logic of a web application.

56. What is the purpose of apache tomcat?

Dr. Anil Kumar Dubey [9783934206] Page 20


Apache server is a standalone server that is used to test servlets and create JSP pages. It is free
and open source that is integrated in the Apache web server. It is fast, reliable server to configure
the applications but it is hard to install. It is a servlet container that includes tools to configure
and manage the server to run the applications. It can also be configured by editing XML
configuration files.

57. Where pragma is used?


Pragma is used inside the servlets in the header with a certain value. The value is of no-cache
that tells that a servlets is acting as a proxy and it has to forward request. Pragma directives allow
the compiler to use machine and operating system features while keeping the overall
functionality with the Java language. These are different for different compilers.

58. Briefly explain daemon thread.


Daemon thread is a low priority thread which runs in the background performs garbage
collection operation for the java runtime system.

59. What is a native method?


A native method is a method that is implemented in a language other than Java.

60. Explain different way of using thread?


A Java thread could be implemented by using Runnable interface or by extending the Thread
class. The Runnable is more advantageous, when you are going for multiple inheritance.

61. What are the two major components of JDBC?


One implementation interface for database manufacturers, the other implementation interface for
application and applet writers.

62. What kind of thread is the Garbage collector thread?


It is a daemon thread.

63. What are the different ways to handle exceptions?


There are two ways to handle exceptions,
1. By wrapping the desired code in a try block followed by a catch block to catch the
exceptions. And
2. 2. List the desired exceptions in the throws clause of the method and let the caller of the
method handle those exceptions.

64. How many objects are created in the following piece of code?
MyClass c1, c2, c3;
c1 = new MyClass ();
c3 = new MyClass ();
Answer: Only 2 objects are created, c1 and c3. The reference c2 is only declared and not
initialized.

65. What is UNICODE?


Unicode is used for internal representation of characters and strings and it uses 16 bits to
represent each other.

Networking Advanced
1. How many numbers of addresses are usable for addressing in a Class C network?
a. 256
Dr. Anil Kumar Dubey [9783934206] Page 21
b. 255
c. 254
d. 258
Answer: c. 254

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
Class C 192.0.0.0 - 223.255.255.255
Class D 224.0.0.0 - 239.255.255.255
Class E 240.0.0.0 - 247.255.255.255

2. How are the data units at Application layer is called?


a. Message
b. Datagram
c. User Datagram
d. Signals
Answer: a. Message

The data unit created at the application layer is called a message, at the transport layer the data
unit created is called either a segment or an user datagram, at the network layer the data unit
created is called the datagram, at the data link layer the datagram is encapsulated in to a frame
and finally transmitted as signals along the transmission media

3. What protocol is used by DNS name servers? Justify.


a. TCP
b. SNMP
c. UDP d. It can use any routing protocol
Answer: c. UDP
DNS uses UDP for communication between servers. It is a better choice than TCP because of the
improved speed a connectionless protocol offers. Of course, transmission reliability suffers with
UDP

4. Which of the following is used to direct a packet inside an internal networks?


a. Routers
b. Modem
c. Gateway
d None of the above
Answer: a. Routers

Routers are machines that direct a packet through the maze of networks that stand between its
source and destination. Normally a router is used for internal networks while a gateway acts a
door for the packet to reach the outside of the internal network

Software Testing Interview Questions


1. Whats the Software Testing?
Dr. Anil Kumar Dubey [9783934206] Page 22
A set of activities conducted with the intent of finding errors in software.

2. What is Acceptance Testing?


Testing conducted to enable a user/customer to determine whether to accept a software product.
Normally performed to validate the software meets a set of agreed acceptance criteria.

3. What is Accessibility Testing?


Verifying a product is accessible to the people having disabilities (deaf, blind, mentally disabled
etc.).

4. What is Ad Hoc Testing?


A testing phase where the tester tries to 'break' the system by randomly trying the system's
functionality.

5. What is Application Programming Interface (API)?


A formalized set of software calls and routines that can be referenced by an application program
in order to access supporting system or network services.

6. What is Backus-Naur Form?


A metalanguage used to formally describe the syntax of a language.

7. What is Beta Testing?


Testing of a release of a software product conducted by customers.

8. What is Application Binary Interface (ABI)?


A specification defining requirements for portability of applications in binary forms across
different system platforms and environments.

9. What is Binary Portability Testing?


Testing an executable application for portability across system platforms and environments,
usually for conformation to an ABI specification.

10. What is Black Box Testing?


Testing based on an analysis of the specification of a piece of software without reference to its
internal workings. The goal is to test how well the component conforms to the published
requirements for the component.

11. What is Bottom Up Testing?


An approach to integration testing where the lowest level components are tested first, then used
to facilitate the testing of higher level components. The process is repeated until the component
at the top of the hierarchy is tested.

12. What is Boundary Testing?


Test which focus on the boundary or limit conditions of the software being tested. (Some of
these tests are stress tests).

13. What is the difference between verification and validation?


Verification is a review without actually executing the process while validation is checking the
product with actual execution. For instance, code review and syntax check is verification while
actually running the product and checking the results is validation.
Dr. Anil Kumar Dubey [9783934206] Page 23
14. What is Bug?
A fault in a program which causes the program to perform in an unintended or unanticipated
manner.

15. What is Defect?


If software misses some feature or function from what is there in requirement it is called as
defect.

16. What is Branch Testing?


Testing in which all branches in the program source code are tested at least once.

17. What is Breadth Testing?


A test suite that exercises the full functionality of a product but does not test features in detail.

18. What's the Alpha Testing ?


The Alpha Testing is conducted at the developer sites and in a controlled environment by the end
user of the software

19. What's the Beta Testing ?


Testing the application after the installation at the client place.

20. What is Component Testing ?


Testing of individual software components (Unit Testing).

21. What is End-to-End testing ?


Testing a complete application environment in a situation that mimics real-world use, such as
interacting with a database, using network communications, or interacting with other hardware,
applications, or systems if appropriate.

22. What is CAST?


Computer Aided Software Testing.

23. What is CMM?


The Capability Maturity Model for Software (CMM or SW-CMM) is a model for judging the
maturity of the software processes of an organization and for identifying the key practices that
are required to increase the maturity of these processes.

24. What is Cause Effect Graph?


A graphical representation of inputs and the associated outputs effects which can be used to
design test cases.

25. What is Coding?


The generation of source code.

26. What is Compatibility Testing?


Testing whether software is compatible with other elements of a system with which it should
operate, e.g. browsers, Operating Systems, or hardware.

27. What is Cyclomatic Complexity?


A measure of the logical complexity of an algorithm, used in white-box testing.

Dr. Anil Kumar Dubey [9783934206] Page 24


28. What is Debugging?
The process of finding and removing the causes of software failures.

29. What is Dependency Testing?


Examines an application's requirements for pre-existing software, initial states and configuration
in order to maintain proper functionality.

30. What are the different Ways of doing Black Box testing?
There are five methodologies most frequently used:
A)Top down according to budget
B)WBS (Work Breakdown Structure)
C)Guess and gut feeling
D)Early project data
E)TPA (Test Point Analysis)

31 Whats the Database testing?


In database testing, we can check the integrity of database field values.

32. How many types of testing?


There are two types of testing-
Functional- Black Box Testing
Structural- white Box Testing

33. What does the mclabe cyclomatic complexity of a program determine?


Cyclomatic complexity is likely the most widely used complexity metric in software
engineering. It describes the complexity of a procedure by measuring the linearly independent
paths through its source code.

34. What is the difference between interoperability and compatibility testing with some
examples?
Interoperatability:-To check if the software can co exist with other supporting softwares in the
system
Compatibility:-To check if the software runs on different types of operating systems according to
customer requirements.

35. Which testing method is used to check the software in abnormal condition?
1) Stress testing
2) Security testing
3) Recovery testing
4) Beta testing

36. Whats the Test Case?


A set of test inputs, execution, and expected result developed for a particular objective.

37. Whats the Traceability Matrix?


A document that showing the relationship between Test Requirements and Test Cases.

Dr. Anil Kumar Dubey [9783934206] Page 25


38. How many types of approaches are used in Integration Testing?
There are two types of approaches used-
Bottom-Up
Top-Down

39. What is Emulator?


A device, computer program, or system that accepts the same inputs and produces the same
outputs as a given system.

40. What is Functional Decomposition?


A technique used during planning, analysis and design; creates a functional hierarchy for the
software.

41. What is Glass Box Testing?


A synonym for White Box Testing.

42. What is Gorilla Testing?


Testing one particular module, functionality heavily.

43. What is Gray Box Testing?


A combination of Black Box and White Box testing methodologies testing a piece of software
against its specification but using some knowledge of its internal workings.

44. What is Integration Testing?


Testing of combined parts of an application to determine if they function together correctly.
Usually performed after unit and functional testing. This type of testing is especially relevant to
client/server and distributed systems.

45. What is Metric?


A standard of measurement. Software metrics are the statistics describing the structure or content
of a program. A metric should be a real objective measurement of something such as number of
bugs per lines of code.

46. What is Quality Assurance?


All those planned or systematic actions necessary to provide adequate confidence that a product
or service is of the type and quality needed and expected by the customer.

47. What is Quality Control?


The operational techniques and the activities used to fulfill and verify requirements of quality.

48. What is Race Condition?


A cause of concurrency problems. Multiple accesses to a shared resource, at least one of which is
a write, with no mechanism used by either to moderate simultaneous access.

49. What is Scalability Testing?


Performance testing focused on ensuring the application under test gracefully handles increases
in work load.

50. What is Software Requirements Specification?

Dr. Anil Kumar Dubey [9783934206] Page 26


A deliverable that describes all data, functional and behavioral requirements, all constraints, and
all validation requirements for software.

Data Structure Advanced


1. 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 L1s last node, point it to the first node of L2 and continue traversing.
Do the same thing for P2 when it reaches L2s 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 lists 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)

Dr. Anil Kumar Dubey [9783934206] Page 27


{
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.

5. Is it possible to implement a queue using Linked List ?. Enqueue & Dequeue should be
O(1).
a. Not possible to implement.
b. Only Enqueue is possible at O(1).
c. Only Dequeue is possible at O(1).
d. Both Enqueue and Dequeue is possible at O(1)
Solution: d. Both Enqueue and Dequeue is possible at O(1)

Have two pointers H pointing to the Head and T pointing to the Tail of the linked list. Perform
enqueue at T and perform dequeue at H. Update the pointers after each operations accordingly.

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.

Dr. Anil Kumar Dubey [9783934206] Page 28


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.

8. Is it possible to implement 2 stack in an array?


Condition: None of the stack should indicate an overflow until every slot of an array is used.
a. Only 1 stack can be implemented for the given condition
b. Stacks can not be implemented in array
c. 2 stacks can be implemented for the given condition.
d. 2 stacks can be implemented if the given condition is applied only for 1 stack.
Solution:c. 2 stacks can be implemented for the given condition

Start 1st stack from left (1st position of an array) and 2nd from right (last position say n). Move
1st stack towards right( i.e 1,2,3 ...n) and 2nd towards left (i.e n,n-1,n-2...1).

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.

10. How many stacks are required to implement a Queue.


a. One
b. Two
c. Three
d. Two + one extra space.

Solution:b Two

Have two stacks S1 and S2.


For Enqueue, perform push on S1.
For Dequeue, if S2 is empty pop all the elements from S1 and push it to S2. The last element you
popped from S1 is an element to be dequeued. If S2 is not empty, then pop the top element in it.

1. Is it possible to find a loop in a Linked list ?


a. Possilbe at O(n)
Dr. Anil Kumar Dubey [9783934206] Page 29
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 L1s last node, point it to the first node of L2 and continue traversing.
Do the same thing for P2 when it reaches L2s 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 lists 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);

Dr. Anil Kumar Dubey [9783934206] Page 30


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.

5. Is it possible to implement a queue using Linked List ?. Enqueue & Dequeue should be
O(1).
a. Not possible to implement.
b Only Enqueue is possible at O(1).
c. Only Dequeue is possible at O(1).
d. Both Enqueue and Dequeue is possible at O(1)

Solution: d. Both Enqueue and Dequeue is possible at O(1)


Have two pointers H pointing to the Head and T pointing to the Tail of the linked list. Perform
enqueue at T and perform dequeue at H. Update the pointers after each operations accordingly.

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?
Dr. Anil Kumar Dubey [9783934206] Page 31
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.

8. Is it possible to implement 2 stack in an array?


Condition: None of the stack should indicate an overflow until every slot of an array is
used.
a. Only 1 stack can be implemented for the given condition
b. Stacks can not be implemented in array
c. 2 stacks can be implemented for the given condition.
d. 2 stacks can be implemented if the given condition is applied only for 1 stack.

Solution:c. 2 stacks can be implemented for the given condition


Start 1st stack from left (1st position of an array) and 2nd from right (last position say n). Move
1st stack towards right( i.e 1,2,3 ...n) and 2nd towards left (i.e n,n-1,n-2...1).

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.

10. How many stacks are required to implement a Queue.


a. One
b. Two
c. Three
d. Two + one extra space.

Solution:b Two
Have two stacks S1 and S2.
For Enqueue, perform push on S1.
For Dequeue, if S2 is empty pop all the elements from S1 and push it to S2. The last
element you popped from S1 is an element to be dequeued. If S2 is not empty, then pop
the top element in it.

Algorithms Interview Questions


1. Define the concept of an algorithm.

Dr. Anil Kumar Dubey [9783934206] Page 32


An algorithm is any well-defined computational procedure that takes some value (or set of
values) as input and produces some value (or set of values) as output. In short, it can be seen as a
sequence of computational steps that transform the input into the output.

2.What are the arguments present in pattern matching algorithms?


These are the following arguments which are present in pattern matching Algorithms.
1) Subject,
2) Pattern
3) Cursor
4) MATCH_STR
5) REPLACE_STR
6) REPLACE_FLAG

3. Explain the function SUB in algorithmic notation?


In the algorithmic notation rather than using special marker symbols, generally people use the
cursor position plus a substring length to isolate a substring. The name of the function is SUB.
SUB returns a value the sub string of SUBJECT that is specified by the parameters i and j and an
assumed value of j.

4. In Algorithmic context how would you define book keeping operations?


Usually when a user wants to estimate time he isolates the specific function and brands it as
active operation. The other operations in the algorithm, the assignments, the manipulations of the
index and the accessing of a value in the vector, occur no more often than the addition of vector
values. These operations are collectively called as book keeping operations.

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.

6. State recursion and its different types?


Recursion is the name given to the technique of defining a set or a process in terms of itself.
There are essentially two types of recursion. The first type concerns recursively defined function
and the second type of recursion is the recursive use of a procedure.

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.
Dr. Anil Kumar Dubey [9783934206] Page 33
3) Identify sequences with their generating functions

9. What is the general strategy for Markov Algorithm?


The general strategy in a Markov Algorithm is to take as input a string x and, through a number
of steps in the algorithm, transform x to an output string y. this transformation process is
generally performed in computers for text editing or program compilation.

10. Define string in an algorithmic notation and an example to support it?


In the algorithmic notation, a string is expressed as any sequence of characters enclosed in single
quote marks.

11. How to find median of a BST?


Find the no. of elements on the left side.
If it is n-1 the root is the median.
If it is more than n-1, then it has already been found in the left subtree.
Else it should be in the right subtree

12. What is Diffie-Hellman?


It is a method by which a key can be securely shared by two users without any actual exchange.

13. What is the goal of the shortest distance algorithm?


The goal is completely fill the distance array so that for each vertex v, the value of distance[v] is
the weight of the shortest path from start to v.

14. Explain the depth of recursion?


This is another recursion procedure which is the number of times the procedure is called
recursively in the process of enlarging a given argument or arguments. Usually this quantity is
not obvious except in the case of extremely simple recursive functions, such as FACTORIAL
(N), for which the depth is N.

15. Explain about the algorithm ORD_WORDS?


This algorithm constructs the vectors TITLE, KEYWORD and T_INDEX.

16. Which are the sorting algorithms categories?


Sorting algorithms can be divided into five categories:
a) insertion sorts
b) exchange sorts
c) selection sorts
d) merge sorts
e) distribution sorts

17.Define a brute-force algorithm. Give a short example.


A brute force algorithm is a type of algorithm that proceeds in a simple and obvious way, but
requires a huge number of steps to complete. As an example, if you want to find out the factors
of a given number N, using this sort of algorithm will require to get one by one all the possible
number combinations.

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
Dr. Anil Kumar Dubey [9783934206] Page 34
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.

19. What is a backtracking algorithm? Provide several examples.


It is an algorithm that considers systematically all possible outcomes for each decision. Examples
of backtracking algorithms are the eight queens problem or generating permutations of a given
sequence.

20. What is the difference between a backtracking algorithm and a brute-force one?
Due to the fact that a backtracking algorithm takes all the possible outcomes for a decision, it is
similar from this point of view with the brute force algorithm. The difference consists in the fact
that sometimes a backtracking algorithm can detect that an exhaustive search is unnecessary and,
therefore, it can perform much better.

21. Describe divide and conquer paradigm.


When a problem is solved using a divide and conquer algorithm, it is subdivided into one or
more subproblems which are all similar to the original problem in such a way that each of the
subproblems can be solved independently. In the end, the solutions to the subproblems are
combined in order to obtain the solution to the original problem.

22. Describe on short an insertion sorting algorithm.


An algorithm that sorts by insertion takes the initial, unsorted sequence and computes a series of
sorted sequences using the following rules:
a) the first sequence in the series is the empty sequence
b) given a sequence S(i) in the series, for 0<=i<="" p="" style="box-sizing: border-box;">

23. Which are the advantages provided by insertion sort?


Insertion sort provides several advantages:
a) simple implementation
b) efficient for small data sets
c) adaptive - efficient for data sets that are already substantially sorted: the time complexity
is O(n + d), where d is the number of inversions
d) more efficient in practice than most other simple quadratic, i.e. O(n2) algorithms such as
selection sort or bubble sort; the best case (nearly sorted input) is O(n)
e) stable - does not change the relative order of elements with equal keys
f) in-place - only requires a constant amount O( 1) of additional memory space
g) online - can sort a list as it receives it

24. Shortly describe the quicksort algorithm.


In quicksort, the steps performed are the following:
a) pick an element, called a pivot, from the list
b) reorder the list so that all elements with values less than the pivot come before the pivot,
while all elements with values greater than the pivot come after it (equal values can go
either way)
c) recursively sort the sub-list of lesser elements and the sub-list of greater elements

25. What is the difference between selection and insertion sorting?


In insertion sorting elements are added to the sorted sequence in an arbitrary order. In selection
sorting, the elements are added to the sorted sequence in order so they are always added at one
end.

Dr. Anil Kumar Dubey [9783934206] Page 35


26. What is merge sorting?
Merging is the sorting algorithm which combines two or more sorted sequences into a single
sorted sequence. It is a divide and conquer algorithm, an O(n log n) comparison-based sorting
algorithm. Most implementations produce a stable sort, meaning that the implementation
preserves the input order of equal elements in the sorted output.

27. Which are the main steps of a merge sorting algorithm?


Sorting by merging is a recursive, divide-and-conquer strategy. The basic steps to perform are
the following:
a) divide the sequence into two sequences of length
b) recursively sort each of the two subsequences
c) merge the sorted subsequences to obtain the final result

28. Provide a short description of binary search algorithm.


Binary search algorithm always chooses the middle of the remaining search space, discarding
one half or the other, again depending on the comparison between the key value found at the
estimated position and the key value sought. The remaining search space is reduced to the part
before or after the estimated position.

29. What is the linear search algorithm?


Linear search is a method for finding a particular value in a list which consists of checking every
one of its elements, one at a time and in sequence, until the desired one is found. It is the
simplest search algorithm, a special case of brute-force search. Its worst case cost is 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.

30. What is best-first search algorithm?


It is a search algorithm that considers the estimated best partial solution next. This is typically
implemented with priority queues.

31. What is Huffman coding?


In computer science and information theory, Huffman coding is an entropy encoding 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.

C Interview Questions and Answers


1) How do you construct an increment statement or decrement statement in C?
Answer: There are actually two ways you can do this. One is to use the increment operator ++
and decrement operator . For example, the statement x++ means to increment the value of x
by 1. Likewise, the statement x means to decrement the value of x by 1. Another way of
writing increment statements is to use the conventional + plus sign or minus sign. In the case of
x++, another way to write it is x = x +1?.

2) Some coders debug their programs by placing comment symbols on some codes instead
of deleting it. How does this aid in debugging?
Answer: Placing comment symbols /* */ around a code, also referred to as commenting out, is
a way of isolating some codes that you think maybe causing errors in the program, without
deleting the code. The idea is that if the code is in fact correct, you simply remove the comment
Dr. Anil Kumar Dubey [9783934206] Page 36
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.

3) What is the equivalent code of the following statement in WHILE LOOP format?
[c]
for (a=1; a<=100; a++)
printf ("%d\n", a * a);
[/c]
Answer:[c]
a=1;
while (a<=100) {
printf ("%d\n", a * a);
a++;
}
[/c]

4) What is spaghetti programming?


Answer: Spaghetti programming refers to codes that tend to get tangled and overlapped
throughout the program. This unstructured approach to coding is usually attributed to lack of
experience on the part of the programmer. Spaghetti programing makes a program complex and
analyzing the codes difficult, and so must be avoided as much as possible.

5) In C programming, how do you insert quote characters ( and ) into the output screen?
Answer: This is a common problem for beginners because quotes are normally part of a printf
statement. To insert the quote character as part of the output, use the format specifiers \ (for
single quote), and \ (for double quote).

6) What is the use of a \0' character?


Answer: It is referred to as a terminating null character, and is used primarily to show the end of
a string value.

7) What is the difference between the = symbol and == symbol?


Answer: The = symbol is often used in mathematical operations. It is used to assign a value to a
given variable. On the other hand, the == symbol, also known as equal to or equivalent to, is
a relational operator that is used to compare two values.

8) Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
Answer: <> is incorrect. While this operator is correctly interpreted as not equal to in writing
conditional statements, it is not the proper operator to be used in C programming. Instead, the
operator != must be used to indicate not equal to condition.

9) Can the curly brackets { } be used to enclose a single line of code?


Answer: While curly brackets are mainly used to group several lines of codes, it will still work
without error if you used it for a single line. Some programmers prefer this method as a way of
organizing codes to make it look clearer, especially in conditional statements.

10) What are header files and what are its uses in C programming?
Answer: Header files are also known as library files. They contain two essential things: the
definitions and prototypes of functions being used in a program. Simply put, commands that you
use in C programming are actually functions that are defined from within each header files. Each

Dr. Anil Kumar Dubey [9783934206] Page 37


header file contains a set of functions. For example: stdio.h is a header file that contains
definition and prototypes of commands like printf and scanf.

11) Can I use int data type to store the value 32768? Why?
Answer: No. int data type is capable of storing values from -32768 to 32767. To store 32768,
you can use long int instead. You can also use unsigned int, assuming you dont intend to
store negative values.

12) Can two or more operators such as \n and \t be combined in a single line of program
code
Answer: Yes, its perfectly valid to combine operators, especially if the need arises. For
example: you can have a code like printf (Hello\n\n\World\) to output the text Hello on
the first line and World enclosed in single quotes to appear on the next two lines.

13) Why is it that not all header files are declared in every C program?
Answer: The choice of declaring a header file at the top of each C program would depend on
what commands/functions you will be using in that program. Since each header file contains
different function definitions and prototype, you would be using only those header files that
would contain the functions you will need. Declaring all header files in every program would
only increase the overall file size and load of the program, and is not considered a good
programming style.

14) When is the void keyword used in a function?


Answer: When declaring functions, you will decide whether that function would be returning a
value or not. If that function will not return a value, such as when the purpose of a function is to
display some outputs on the screen, then void is to be placed at the leftmost part of the
function header. When a return value is expected after the function execution, the data type of
the return value is placed instead of void.

15) What are compound statements?


Answer: Compound statements are made up of two or more program statements that are
executed together. This usually occurs while handling conditions wherein a series of statements
are executed when a TRUE or FALSE is evaluated. Compound statements can also be executed
within a loop. Curly brackets { } are placed before and after compound statements.

16) Write a loop statement that will show the following output:
1
12
123
1234
12345
Answer:[c]
for (a=1; a<=5; i++) {
for (b=1; b<=a; b++)
printf("%d",b);
printf("\n");
}
[/c]

17) What is wrong in this statement? scanf(%d,whatnumber);

Dr. Anil Kumar Dubey [9783934206] Page 38


Answer: An ampersand & symbol must be placed before the variable name whatnumber. Placing
& means whatever integer value is entered by the user is stored at the address of the variable
name. This is a common mistake for programmers, often leading to logical errors.

18) How do you generate random numbers in C?


Answer: Random numbers are generated in C using the rand() command. For example: anyNum
= rand() will generate any integer number beginning from 0, assuming that anyNum is a variable
of type integer.

19) What could possibly be the problem if a valid function name such as tolower() is being
reported by the C compiler as undefined?
The most probable reason behind this error is that the header file for that function was not
indicated at the top of the program. Header files contain the definition and prototype for
functions and commands used in a C program. In the case of tolower(), the code #include
must be present at the beginning of the program.

20) What does the format %10.2 mean when included in a printf statement?
Answer: This format is used for two things: to set the number of spaces allotted for the output
number and to set the number of decimal places. The number before the decimal point is for the
allotted space, in this case it would allot 10 spaces for the output number. If the number of space
occupied by the output number is less than 10, addition space characters will be inserted before
the actual output number. The number after the decimal point sets the number of decimal places,
in this case, its 2 decimal spaces.

21) What is wrong with this statement? myName = Robin;


Answer: You cannot use the = sign to assign values to a string variable. Instead, use the strcpy
function. The correct statement would be: strcpy(myName, Robin);

22) How do you determine the length of a string value that was stored in a variable?
Answer: To get the length of a string value, use the function strlen(). For example, if you have a
variable named FullName, you can get the length of the stored string value by using this
statement: I = strlen(FullName); the variable I will now have the character length of the string
value.

23) Is it possible to initialize a variable at the time it was declared?


Answer: Yes, you dont have to write a separate assignment statement after the variable
declaration, unless you plan to change it later on. For example: char planet[15] = Earth; does
two things: it declares a string variable named planet, then initializes it with the value Earth.

24) What are the different file extensions involved when programming in C?
Answer: Source codes in C are saved with .C file extension. Header files or library files have the
.H file extension. Every time a program source code is successfully compiled, it creates an .OBJ
object file, and an executable .EXE file.

25) What are reserved words?


Answer: Reserved words are words that are part of the standard C language library. This means
that reserved words have special meaning and therefore cannot be used for purposes other than
what it is originally intended for. Examples of reserved words are int, void, and return.

26) What are linked list?

Dr. Anil Kumar Dubey [9783934206] Page 39


Answer: A linked list is composed of nodes that are connected with another. In C programming,
linked lists are created using pointers. Using linked lists is one efficient way of utilizing memory
for storage.

27) What are binary trees?


Answer: Binary trees are actually an extension of the concept of linked lists. A binary tree has
two pointers, a left one and a right one. Each side can further branch to form additional nodes,
which each node having two pointers as well.

28) Not all reserved words are written in lowercase. TRUE or FALSE?
Answer: FALSE. All reserved words must be written in lowercase; otherwise the C compiler
would interpret this as unidentified and invalid.

29) What is wrong with this program statement? void = 10;


Answer: The word void is a reserved word in C language. You cannot use reserved words as a
user-defined variable.

30) Is this program statement valid? INT = 10.50;


Answer: Assuming that INT is a variable of type float, this statement is valid. One may think that
INT is a reserved word and must not be used for other purposes. However, recall that reserved
words are express in lowercase, so the C compiler will not interpret this as a reserved word.

31) What is a newline escape sequence?


Answer: A newline escape sequence is represented by the \n character. This is used to insert a
new line when displaying data in the output screen. More spaces can be added by inserting more
\n characters. For example, \n\n would insert two spaces. A newline escape sequence can be
placed before the actual output expression or after.

32) What is output redirection?


Answer: It is the process of transferring data to an alternative output source other than the
display screen. Output redirection allows a program to have its output saved to a file. For
example, if you have a program named COMPUTE, typing this on the command line as
COMPUTE >DATA can accept input from the user, perform certain computations, then have the
output redirected to a file named DATA, instead of showing it on the screen.

33) What is the difference between functions abs() and fabs()?


Answer: These 2 functions basically perform the same action, which is to get the absolute value
of the given value. Abs() is used for integer values, while fabs() is used for floating type
numbers. Also, the prototype for abs() is under , while fabs() is under .

34) Write a simple code fragment that will check if a number is positive or negative.
Answer:[c]
If (num>=0)
printf("number is positive");
else
printf ("number is negative");
[/c]

35) What does the function toupper() do?


Answer: It is used to convert any letter to its upper case mode. Toupper() function prototype is
declared in . Note that this function will only convert a single character, and not an entire string.
Dr. Anil Kumar Dubey [9783934206] Page 40
36) Which function in C can be used to append a string to another string?
Answer: The strcat function. It takes two parameters, the source string and the string value to be
appended to the source string.

37) Dothese two program statements perform the same output? 1) scanf(%c, &letter); 2)
letter=getchar()
Answer: Yes, they both do the exact same thing, which is to accept the next key pressed by the
user and assign it to variable named letter.

38) What is the difference between text files and binary files?
Answer: Text files contain data that can easily be understood by humans. It includes letters,
numbers and other characters. On the other hand, binary files contain 1s and 0s that only
computers can interpret.

39) is it possible to create your own header files?


Answer: Yes, it is possible to create a customized header file. Just include in it the function
prototypes that you want to use in your program, and use the #include directive followed by the
name of your header file.

40) What is dynamic data structure?


Answer: Dynamic data structure provides a means for storing data more efficiently into memory.
Using dynamic memory allocation, your program will access memory spaces as needed. This is
in contrast to static data structure, wherein the programmer has to indicate a fix number of
memory space to be used in the program.

41) The % symbol has a special use in a printf statement. How would you place this
character as part of the output on the screen?
Answer: You can do this by using %% in the printf statement. For example, you can write
printf(10%%) to have the output appear as 10% on the screen.

42) What are the advantages and disadvantages of a heap?


Answer: Storing data on the heap is slower than it would take when using the stack. However,
the main advantage of using the heap is its flexibility. Thats because memory in this structure
can be allocated and remove in any particular order. Slowness in the heap can be compensated if
an algorithm was well designed and implemented.

Dr. Anil Kumar Dubey [9783934206] Page 41

You might also like