Accreditation Bodies
Accreditation Bodies
Accreditation Bodies
Supercharge your career with our Multi-Cloud Engineer Bootcamp
KNOW MOREHere is a collection of the best interview Computer Science interview questions and answers, curated by experts in the field, to assist you in succeeding when you appear for computer science job interviews. With the help of the drafted answers, you can confidently face questions related to job positions like Software Developer L2, Software Developer L3, Software Developer L4, Full Stack Developer, and many more like Application Engineer, Support Engineer, etc. and make a good impression at your next interview with companies like Cognizant, Accenture, Wipro, HCL, Infosys, JP Morgan Chase, and others, by being well-prepared with these Computer Science interview questions and answers. Nearly all service-based, and product-based companies ask such questions during the interview for job roles with packages up to 45-60 lakh. So here are the top 60 Computer Science Interview Questions and Answers, 2024 edition. In this article, you will learn about various Computer Science engineering interview questions for freshers, intermediate professionals, and experienced professionals.
Filter By
Clear all
An operating system is a piece of software that controls all the hardware and software resources. It acts as an interface between software and hardware. It serves as a resource manager and hides the hardware's underlying complexity to give users a convenient and effective environment in which they can run their applications smoothly.
Let’s see various types of operating system: -
Types of the operating system:
The definition of an object according to the dictionary is a thing or a thing that is real. Oriented is a verb that means to be interested in a specific sort of item or entity. It is a programming paradigm.
Object-oriented programming is essentially a philosophy or approach for computer programming that organizes software architecture around data or objects rather than functions and logic.
A data field is referred to as an object if it has distinct characteristics and behavior. In OOP, everything is categorized as self-sustaining objects.
Among developers, it is the most often used programming paradigm. Large, complicated, and actively updated or maintained programs work well with it.
A vehicle is an example of OOP in the real world. It fully exemplifies the effectiveness of object-oriented design.
The foundation of OOP consists of four pillars are:
Benefits of OOPS:
Difference between procedural language and object-oriented language:
This is a frequently asked question in Computer Science interviews. Classes and objects are the building blocks of OOP.
A class is an object's blueprint or template. Member variables, constants and functions, and other functionality are defined in the classes. It connects data and functions as a single entity. At runtime, it doesn't require any memory. Classes are not thought of as data structures.
An object is a physical thing with characteristics, actions, and qualities. It is also called as a class instance. It includes variables and member functions that we have declared in the class. It takes up room in the memory.
Keep in mind that while an object can exist without a class, the reverse is not feasible.
What is a Computer Network, Internet, World Wide Web? Differentiate between WWW and the Internet.
A computer network is a collection of linked computing systems that may communicate and share resources. These networked devices communicate data through wireless or physical technologies using a set of guidelines known as communications protocols.
The internet is a massive, electronically connected network of computers and other devices.
The World Wide Web is a compilation of all web sites and publications that may be found on the Internet by searching for their URLs (Uniform Resource Locator).
The following are the differences between the internet and the world wide web: The world wide web is where all web pages and documents are kept, and you need a unique URL for each website in order to access it. In contrast, the internet is a vast computer network that can be accessed through the World Wide Web.
WWW | Internet |
---|---|
The world wide web is software-oriented | The internet is hardware-oriented |
The world wide web uses HTTP | The internet uses IP addresses |
It is also one of the important general computer science interview questions of Networking that is asked in interview.
Let’s see what is data and information before actually jumping to their difference.
Data:
A collection of unprocessed, unstructured facts and information is known as data. Examples include text, observations, figures, symbols, and object descriptions.
In other words, data is meaningless on its own and does not serve any purpose.
Additionally, data is expressed in terms of bits and bytes, which are the fundamental units of information used in computer processing and storage. Although data can be captured, it cannot be meaningful without processing it.
There are two types of data:
Information:
Information is structured and organised data. It gives the data context and makes decision-making possible and make sense to us. Data are analysed and parts of data are interpreted to get information.
Now, let’s see what is the difference between data and information.
Data vs Information:
Data | Information |
---|---|
Data is a collection of facts | Information places such facts into perspective |
Data is raw and disorganised | Information is structured |
Each data point is unique and unrelated | Information depicts that data in order to give a broad overview of how everything fits together |
Data by itself has no value | Meaningful information is created after it has been studied and understood |
Data is dependent on information | Information is not dependent on data |
Graphs, numbers, figures, or statistics are the most common visual representations of data | Normally, information is communicated via words, language, thoughts, and concepts |
Attributes: An attribute in a database management system (DBMS) is a piece of information that specifies an entity.
Let's see various types of attributes: -
Types of Attributes:
Examples: In a database of an employee, ‘gender’ can be considered simple
Attribute because it is not subdivided anymore.
For instance, a person's name may be broken down into first, middle, and last names.
Examples: In a database of an employee, ‘address’ can be considered a composite
Attribute because it can be further subdivided into two or more sub-attributes i.e., ‘house
number', ‘street name’, ‘city’, ‘state’, ‘PIN code’.
Another example can be ‘name’ because it can be further subdivided into ‘First Name’,
‘Middle Name’ and ‘Last Name’.
Examples: In a database of an employee, ‘Employee ID’ can be considered as single-valued
attribute because every employee has a unique and only one ID that is given to them.
Examples: In a database of an employee, ‘phone number’ can be considered as
multi-valued attribute because an employee can have more than one phone number.
Upper or lower limits may be used as a limit restriction.
Example: In a database of an employee, ‘age’ can be considered as derived attribute
because it can be determined using the employee's birthdate and the current time.
Let’s see various types of entity: -
Types of Entity:
Example: In a database of university, “student” can be considered as strong entity because each student has a unique ID, so the entity can exist without depending on any
Other entities.
Example: In a database of university, the "Course Enrolment" can be considered as weak entity because it doesn't have a unique identifier without the corresponding " Student " and "Course" entities.
In C++, structure works the exact way as class but there are some differences between them.
Structure | Class |
---|---|
By default, Members of this is private. | By default, Members of this is public. |
It is declared using the keyword struct. | It is declared using the keyword class. |
It is mainly used for data abstraction and inheritance. | It is mainly used for data grouping. |
Based on their scale, computer networks are classified into three kinds:
Let’s see first, what is a topology: -
The advantages of bus topology are as mentioned below:
The followings are the drawbacks of bus topology:
Ring topology: Every computer is connected to another computer on each side known as a "ring topology." A ring-shaped network is created when the final computer is hooked up to the first. Each computer can have precisely two neighbouring computers for this architecture. Tokens are used to facilitate the exchange of data between devices. The computer station must possess the token in order to send data. Only once the transmission is finished is the token released, at which point other computer systems can use it to transfer data.
Ring Topology is faster than Bus Topology.
Swapping is a method that enables a process to be temporarily moved to secondary storage (disc) and out of main memory, freeing up that memory for use by other processes. The system switches the process back from secondary storage to main memory at a later time. It eliminates memory-resident processes to minimize the degree of multi-programming. These eliminated processes can be put back into memory and resume their execution from where it left off, it is known as swapping.
Swapping is required to increase the process mix. It is handled through Middle Term Scheduler which reduces degree of multi-programming.
It is a process of Switching from one process to another in the CPU.
Database:
A database is a location where data is kept in a form that makes it simple to access, manage, and modify.
DBMS:
A group of connected data and a set of software tools for accessing that data make up a database-management system (DBMS). The database, a collection of data, often contains information important to an organisation. A DBMS's main objective is to offer a simple and effective method for storing and retrieving database data.
The database itself, along with all the software and functions, is a DBMS. It is used to carry out many actions, including data insertion, access, updating, and deletion.
Now, let’s see what are the disadvantages of file systems that leads to creation of DBMS.
Disadvantages of File Systems:
These are the few reasons, why we should use DBMS and not file systems for storing and managing data.
Let’s see first what is a process: -
Process: A process is a computer program that is currently in execution.
It is the still-running process whose parent process has been destroyed. The init process i.e., the first process of OS, adopts orphan processes.
A process that has finished its execution but still has an entry in the process table is considered a zombie process. Because the parent process still needs to read its child's departure status, zombie processes often happen for child processes. The zombie process is then removed from the process table when this is completed using the wait system call. This is referred to as the zombie reaping procedure. The child process remains a zombie till it is removed from the process table. The child process was terminated significantly early since the parent process may call wait () on it for a longer period of time.
Expect to come across this popular question in Computer Science job interview questions. SQL (Structured Query Language) is a standard language used to manage relational databases.
The rest of the keys are alternate keys, composite keys, unique key etc.
There are several types of views in SQL:
A common question in Computer Science interview questions and answers for freshers, don't miss this one. The static keyword is mostly utilized for memory management. With variables, methods, blocks, and nested classes, the static keyword can be used. The static keyword is a property of the class rather than a class instance.
The static can be:
Static Variable:
A variable is considered static if you declare it to be static.
The static variable can be used to refer to an attribute that is shared by all objects but is not specific to each object, such as the name of the organization for employees or the university for students. When the class is loaded, the static variable receives only one memory allocation in the class area.
Benefit:
Uses of Static Variable:
Maintain count: Static variables are commonly used to count that how many times a function has been called. For example, if you want to know how many times a function is called then you can declare a static variable in that function and increment its value each time the function is called.
Data sharing between function calls: Data may be shared across function calls by using static variables. The value of a static variable set in one function call can also be utilised in subsequent function calls since static variables retain their values.
Global variables: Static variables defined outside of a function have file scope, which implies that any function in the file may access them. This may be used to implement global variables with file-specific restrictions.
Static method:
Any method that uses the static keyword is referred to as a static method.
Benefit:
Uses of Static Method:
Encapsulation:
Encapsulation is the technique of combining code and data into a single entity, such as a capsule containing a variety of medications. By making every data member of the class private, we may construct a class that is completely enclosed. We can now set and retrieve data from it using getter and setter functions.
Data encapsulation differs from data hiding in that it concentrates on wrapping (or encapsulating) the complex data to give the user a more user-friendly view. Data hiding concentrates on restricting data use in a programme to ensure data security.
Benefits of encapsulation include:
The capability of a class to acquire characteristics and properties from another class is referred to as inheritance. It is an important component of OOPs (Object Oriented programming system).
Let’s see various types of inheritance: -
Types of Inheritance:
Note: Multiple and hybrid inheritance is not supported in Java.
Java programming only supports multiple and hybrid inheritance through interfaces.
Use of inheritance:
Let’s see various terms that are primarily used in inheritance.
Terms used in Inheritance:
Polymorphism:
The idea of polymorphism allows us to carry out a single operation in several ways.
Greek terms poly and morphs are the roots of the word polymorphism. Poly means numerous, and morphs implies forms.
Polymorphism entails diversity of forms.
Example:
A person can play many roles and carry out multiple duties at once like he/she can be a writer and a software developer at the same time. So, the same person behaves differently depending on the situation. This is polymorphism.
Types:
Compile-time polymorphism and runtime polymorphism are the two forms of polymorphism.
By using method overloading (Compile-time polymorphism) and method overriding (runtime polymorphism), we may implement polymorphism.
Compile-time polymorphism is also known as static polymorphism and runtime polymorphism is also known as dynamic polymorphism.
Static polymorphism is another name for it. In order to create this form of polymorphism, either operators or functions must be overloaded. It is also known as early binding.
Method Overloading: When these functions have several instances of the same name but different parameters, they are said to be overloaded. A change in the number of arguments or/and a change in the type of arguments might cause a function to be overloaded.
Note: Operator Overloading is not supported by Java but supported by C++.
It is also known as late binding or dynamic polymorphism. It is achieved by method overriding. It is also called as dynamic method dispatch.
Dynamic Method Dispatch: The process by which a call to an overridden method is resolved at run time is known as dynamic method dispatch.
Method Overriding: A function call to the overridden method is resolved during this procedure at runtime. Method Overriding is used to accomplish this kind of polymorphism. Contrarily, method overriding happens when a derived class defines one of the base class's member functions. It is referred to as overriding that base function.
Modifiers can be either access modifiers or non-access modifiers.
By using the access modifier, we may modify the access level of fields, constructors, methods, and classes.
Java access modifiers come in four different varieties:
C++ does not support default modifier, it has only public, private and protected.
Non-access modifiers come in a variety of forms, including static, abstract, synchronised, native, volatile, transient, etc.
Getter and Setter methods are used to secure your code and safeguard your data.
Horizontal partitioning, or "sharding," is a sort of database partitioning.
Actually, Sharding is a database design that break a big database into smaller, more manageable pieces called shards to scale the database horizontally.
Instead of having all the data kept on a single, centralised server, the goal behind sharding is to distribute the workload of a database among several servers.
When to Shard a table?
Your database's performance can be greatly enhanced by slicing up your data. Here are some examples of how sharding might enhance performance:
When not to shard a table?
Sharding should only be utilised when all other optimization methods are insufficient. The following possible issues are brought on by the complexity that database sharding introduces:
Indexing helps to improve database speed by reducing the number of disc accesses required during query processing. One kind of data structure is the index. It is employed to rapidly find and retrieve the data in a database table. The search key, which is the first column in the database, contains a copy of the primary key or candidate key for the table. To make it simple to obtain the appropriate data, the values of the primary key are kept in sorted order. The database's second column contains the data references. It includes a group of pointers that store the location of the disc block's address where the value of a certain key may be located.
Various types of Indexing Methods are:
Primary Index:
Primary indexing is the process of building an index based on the table's primary key. These primary keys have a 1:1 relationship between the records and are particular to each record. The performance of the searching operation is highly effective since primary keys are kept in sorted order.
There are two categories for the primary index: Dense and Sparse index.
Dense Index:
Sparse Index:
Secondary Index:
When using sparse indexing, the size of the mapping also increases as the size of the table does. These mappings are often retained in the main memory to speed up address fetches. Using the address obtained via mapping, the secondary memory then searches the real data. The process of retrieving the address itself becomes slower as the mapping size increases. The sparse index will not function effectively in this situation. Secondary indexing is used to address this issue.
Clustering Index:
An ordered data file can be used to construct a clustered index. On non-primary key columns, which might not be distinct for each record, the index is occasionally built. In this instance, we will aggregate two or more columns to obtain the unique value and make an index out of them in order to identify the record more quickly. This technique is known as a clustering index.
When a large problem is broken down into multiple smaller sub-problems, it can be addressed more quickly just like partitioning. It creates smaller, more manageable data slices known as partitions from a large database that contains data metrics and indexes. Once the database has been partitioned, the data definition language can easily handle the smaller slices of the partitioned database rather than the entire enormous database. Partitioning solves the issue directly by making it comparatively easier to manage huge database tables
When to partition a table is shown by the following examples:
Let’s see various types of partition techniques that are primarily used: -
Partitioning Techniques:
The hash technique used by Oracle to identify partition tables. This method evenly splits the rows into several divisions, ensuring that each partition has the same dimensions. Hash partitioning is the technique of breaking up database tables into smaller chunks using this hash method. Hash partitioning is the ideal method for regularly distributing data among several devices.
Based on the range of values of the specific partitioning keys for each partition of the data, range partitioning separates the data into a number of divisions. It is a well-liked partitioning strategy that frequently involves dates. For instance, it will include a table with the column name "JULY" and rows with dates ranging from JULY 1 to JULY 31 to represent the days of the month of JULY. All partitions that are smaller than a certain partition appear before its VALUES LESS THAN clause, and all partitions that are higher than that specific partition come after its VALUES LESS THAN clause. Using the MAXVALUE clause, the highest range partition is represented.
A form of database partitioning called list partitioning divides data based on a list of values. List partitioning involves splitting a table into several partitions, each of which holds data depending on a particular set of values.
Normalization is a technique for structuring the data in a database that enables you to prevent anomalous insertion, update, and deletion of data as well as data redundancy. It is a procedure that involves examining relational schemas in light of their many functional relationships and primary keys.
Relational database theory requires normalisation from the outset. It might result in the database having duplicate copies of the same data, which could lead to the formation of new tables. It is most likely asked technical interview questions computer science for freshers
Three forms of data modification abnormalities can be distinguished:
Types of Normal Forms:
Advantages of Normalization:
Disadvantages of Normalization:
Transaction: The smallest processing unit that cannot be further split is a single task. A set of tasks might be referred to as a transaction.
Let’s see various types of transaction states: -
Transaction States:
Process States: The different stages that a process may be in while being run on a computer system are referred to as "process states". Each of the following states is possible for a process.
Process Queues: It determines that the process is in which state.
Job Queue:
Ready Queue:
Waiting Queue:
Constructor is called when an instance of any class is created as object. It is used to initialize the object. It is called every time an object is created using a keyword new. If we did not make any constructor in class then default constructor is called.
There are three types of constructors.
Some important terminology related to constructors are:
It is just opposite to constructor. When we construct a class object, it takes up some memory space (heap). If we do not get rid of these things, they linger in the memory and take up space that is not essential from a programming point of view. We use the destructor to fix this issue. The destructor is used to delete or destroy an object, which releases the resource it was using till now.
Advantage of Destructor:
In a nutshell, a new object that has a pointer to the memory address of the old object is called a shallow copy. As a result, any modifications made to the original object will also be mirrored in the shallow duplicate. When you wish to replicate an item but do not need to create an exact duplicate of the original object, shallow copying might be handy. It's also called as "shallow cloning."
On the other hand, a deep copy is a totally independent copy of an item. Changes to the original object have no impact on the deep copy since it produces a new object with a completely different memory location. When you need to change the original item without changing the duplicate, this is helpful.
In Python, for making shallow and deep copies, use the copy module's methods. A shallow copy is produced by the ‘copy.copy()’ method, and a deep copy is produced by the ’copy.deepcopy()’ function.
A transaction is a very tiny programming unit that can include a number of low-level operations. Atomicity, Consistency, Isolation, and Durability, or ACID qualities, are requirements for a transaction in a database system to maintain correctness, completeness, and data integrity.
A process is a computer program that is currently in execution. A process might produce what are referred to as "Child Processes," or new processes. The process is isolated, which means it does not share memory with any other processes, and therefore takes longer to complete.
The following statuses are possible for the process: new, ready, running, waiting, terminated, and suspended.
A process can have several threads, and these multiple threads are confined within a process since a thread is a segment of a process.
Three states exist for a thread: running, ready, and blocked.
The thread terminates faster than the process, but it does not isolate as the process does.
Thread | Process |
---|---|
Threads share same memory | Each process has different memory |
Creation takes less time. | Creation takes more time. |
Data is shared between threads. | No data is shared between processes. |
Multi-Tasking | Multi-Threading |
---|---|
Multitasking is the technique of carrying out many tasks at once. | A process is broken down into several distinct threaded subtasks, each of which has its own execution path. Multithreading is the term used to describe this idea. |
In this, more than one processes is context switched. | In this, more than one threads is context switched. |
There is memory protection and isolation. Each program that the CPU is running needs its own memory and resources, which the OS must allot. | Resources are shared throughout that process' threads since there is no isolation or memory protection. A process receives memory allocation from the operating system. several threads inside that process share the memory and resources allotted to the process. |
Number of Central Processing Unit is 1. | Number of Central Processing Unit is more than 1. |
Thread Context Switching | Process Context Switching |
---|---|
It is comparatively faster and cheaper. | It is comparatively slower and costlier. |
OS shifts to another thread of the same process while saving the current state of the thread. | OS moves to another process by restoring its state after saving the current state of the current process. |
In this Context Switching, CPU’s cache state is preserved. | In this Context Switching, CPU’s cache state is not preserved but its flushed. |
It excludes switching the memory address space. | It includes switching the memory address space. |
Let us see first what is a kernel: -
Kernel: The core of an operating system is its kernel (OS). It serves as a link between a computer's hardware and its software programmes. The system's resources, including the CPU, memory, and input/output devices, are managed by the kernel.
Now, let’s see various types of kernels in operating system.
Example: Linux, Unix, and MS-DOS.
Example: L4 Linux, Symbian OS, MINIX, etc.
Example: MacOS, Windows NT/7/10
Apart from that there are more types of kernels that is comparatively less used in OS.
Thrashing occurs when a computer system has insufficient memory and spends a lot of time switching data between the disk and memory rather than performing tasks.
The process will immediately page-fault if it does not have the necessary number of frames to support the active pages. It must now swap out a page at this point. It must, however, replace a page that will be immediately required again because all of its pages are currently being used. As a result, it faults frequently, replacing pages that it needs to bring back in right away. Thrashing is the name for this high-paging action.
Thrash is the term used in computer science to describe the poor performance of a virtual memory (or paging) system caused by the repetitive loading of the same pages when there is not enough main memory to retain them in mind.
The Causes of Thrashing are as follows:
Recovery from thrashing:
Banker’s algorithm is used to avoid deadlock.
The term was chosen because the algorithm might be implemented in a banking system to make sure that the bank never distributes its funds in a way that prevents it from meeting the needs of every customer. There should be a maximum number of each resource type's instances.
The maximum amount that may be allocated safely to determine the allocation for all resources is tested using this algorithm. Before deciding whether or not to continue allocating, it also checks for all potential activities.
For instance, there are G dollars total in the accounts of X number of account holders at a particular bank.
A car loan is processed by the bank using software subtracts the loan amount for a car purchase from the total amount of money the bank possesses (G+ Fixed Deposit + Monthly Income Scheme + Gold, etc.).
Additionally, it verifies whether the difference exceeds G or not. Even if every account holder withdraws funds at once, the auto loan won't be processed until the bank has enough cash.
Friend class is a class that has been designated as a friend can access the private and protected members of other classes. Sometimes it is advantageous to provide a certain class access to another class's private members.
A friend class can access both private and protected members of the class in which it has been declared as a friend.
Friend Functions:
Friend Functions, like friend class, can also access private and protected members.
In C++, a friend function is a special function that, although not belonging to a class, has the ability to access its private and protected data.
The following are some crucial details about friend functions and classes:
Merits of using Friend Class/Function:
Demerits of using Friend Class/Function:
Abstraction: Abstraction is showing only the essential information and hiding all the other unnecessary things and details.
Example:
Let’s say a man is driving a vehicle. The man only knows that pressing the accelerators will make a car go faster or that applying the brakes will cause the car to stop, but he has no idea how pressing the accelerator actually increases speed. He also has no idea how the accelerator, brakes, and other car controls are used inside the vehicle.
Abstracts Class:
An abstract class is declared by the keyword “abstract”. It can contain abstract as well as non-abstract methods. An abstract class is one that can't be created on its own. It offers a base class definition from which subsequent classes can inherit and serves as a blueprint for developing concrete subclasses.
Creation: abstract type name(parameter-list);
Properties of Abstract Class:
A must-know for anyone heading into a CS interview, this question is frequently asked in CS interview questions. Http and Https are protocols rather they are application-layer protocols used for transmitting data over the Internet.
Let us see what is a protocol and application-layer protocol.
If a particular HTTP request has indeed been correctly answered, it will be indicated by a response status code.
Five categories have been used to categorize responses:
IP address: An IP address (Internet Protocol address) is a unique numerical identifier given to each connected device to a computer network that makes use of the Internet Protocol. A host's or network interface's identification and position inside the network are the two primary purposes of an IP address. Although IP addresses are often expressed as a string of alphanumeric letters, computers interpret them as binary codes (1s and 0s).
There are two main versions of IP addresses: IPv4 and IPv6.
IPv4:
IPv6:
They all are various types of networking device.
A theoretical framework known as the OSI (Open Systems Interconnection) model specifies and standardises a communication system's operations in seven different levels.
The functions of the transport layer are:
It makes it possible for the hosts who are communicating to have a discussion.
It can also provide flow control, verification, and error checking.
Note: In TCP/IP model, its application layer combines the features of the OSI model's session layer, presentation layer, and application layer.
The idea of concurrency control falls within the database management system's Transaction category (DBMS). A DBMS procedure lets us manage two concurrent processes so that they may run without conflicting with one another, which happens in multi-user systems.
Executing many transactions simultaneously is the simplest definition of concurrency. To improve time efficiency, it is necessary. Inconsistency develops when many transactions attempt to access the same piece of data. Data consistency requires the use of concurrency control.
If we use ATMs as an example, numerous people cannot withdraw money simultaneously at various locations if concurrency is not used. We require concurrency here.
The following are concurrency control's advantages:
Main problems in using Concurrency: Updates will be lost: Updates won't be saved if one transaction makes modifications and another one undoes them. The changes of one transaction override those of another. Uncommitted Dependency or Dirty Read Problem: When a variable is updated in one transaction and its value is deleted in a subsequent transaction, the variable that was updated in the first transaction is not updated or committed, giving us false values or the variable's previous value. Inconsistent retrievals: When one transaction updates several distinct variables and another transaction is in the process of updating those variables, the problem is that the same variable appears inconsistently in several contexts.
Concurrency control strategies: The strategy for concurrency control are as follows:
Locking: Lock ensures that a current transaction has sole access to certain data objects. It initially obtains a lock to get access to the data items, and once the transaction is over, it releases the lock.
The various lock types are as follows:
Relationship constraints are rules that specify how different database entities relate to one another. In order to ensure that data is saved and retrieved consistently and properly, they are used to enforce business rules and preserve data integrity.
There are two main types of binary relationship constraints.
Mapping Cardinality / Cardinality Ratio:
Number of entities that may be connected to another entity through a connection is known as the mapping cardinality or cardinality ratio.
Types of Mapping Cardinality:
One to One: An entity in entity set A associates with no more than one entity in entity set B. And a B entity can only be related to a single A entity.
E.g., Let’s take an example of student database, where each student has only one roll number.
In this example, the relationship between the "Student" entity and the "Roll Number" entity would be a one-to-one relationship, as each student has only one roll number and each roll number is assigned to only one student. This can be represented using the following mapping cardinality:
One to Many: N entities in B are connected to an entity in A. While only one of the entities in A is connected to the entity in B.
E.g., Let's take the example of a bookstore database. Each book (entity B) can be written by only one author (entity A), but an author can have written multiple books. Therefore, the relationship between authors and books would be a one-to-many relationship.
This can be represented using the following mapping cardinality: One author can write many books (1:N)
Many to one: Entity in A is connected to at most one entity in B. However, N entity in A can be connected to entity in B.
E.g., Let’s take the same example of student database, where many students can have the same academic advisor.
In the case of the student database, many students could potentially have the same academic advisor (entity B), but one academic advisor can advise many students (entities A). Therefore, the relationship between students and academic advisors would be a many-to-one (N:1) relationship.
Many to Many: N entities in B are connected to an entity in A. While N entity in A is also connected to entity in B.
E.g., Again, let’s take an example of student database, where many students can be taught by many teachers.
In the case of the student database where many students can be taught by many teachers, each student can be associated with multiple teachers (entities B), and each teacher can teach multiple students (entities A). Therefore, the mapping cardinality for this relationship would be many-to-many (N:N).
Participation Constraints: Participation constraints can be defined as the minimum and maximum participation of an entity in a relationship. They determine whether an entity must participate in a relationship or not.
There are 2 types of participation constraints: -
In Java, a class's blueprint is called an interface. It has abstract methods and static constants. Java uses the interface as a tool to achieve abstraction. The Java interface can only include abstract methods, method bodies are not allowed. In Java, it is used to achieve multiple inheritance and abstraction. In other words, interfaces are capable of containing abstract methods and variables. Using the keyword interface, you can fully abstract a class’ interface from its implementation.
In C++, there is not any concept of interfaces.
The properties of interfaces are:
32-Bit OS | 64-Bit OS |
---|---|
A 32-bit operating system can access 2^32 (i.e., 4GB of physical memory) different memory locations and contains 32-bit registers | A 64-bit operating system can access 2^64 (i.e., 17,179,869,184 GB of physical memory) different memory locations and contains 64-bit registers. |
A 32-bit CPU design is capable of processing 32 bits of information and data | A 64-bit CPU design is capable of processing 64 bits of information and data |
It is less secure compared to 64-bit OS | It is more secure and less prone to hacking compared to 32-bit OS |
It is less efficient compared to 64-bit OS | It is more efficient compared to 32-bit OS |
It is cheaper compared to 64-bit OS | It is costlier compared to 32-bit OS |
Benefits of 64-bit operating systems over 32-bit ones:
The components of operating system are:
Virtual Memory: Virtual memory enables a computer to compensate for physical memory shortages by temporarily moving pages of data from random access memory (RAM) to disc storage.
It gives the user the impression that their primary memory is quite large. By considering a portion of secondary memory as the main memory, this is accomplished. (Swap-space)
In order to be executed, instructions must reside in physical memory. However, it restricts program size to that of actual memory. In many instances, the full program is not even required at once.
Therefore, having the capacity to run programmes that are only partially in memory would provide a number of advantages:
Virtual Function: A member function that is declared in a base class and redefined (overridden) by a derived class is known as a virtual function.
Page Replacement: Operating systems that use virtual memory and Demand Paging require page replacement. As is well known, only a certain set of pages for a process are loaded into memory when using demand paging. This is done so that multiple processes can run concurrently in memory. The operating system must determine which page will be substituted when a process requests the execution of a page that is present in virtual memory. This procedure, called page replacement, is a crucial part of managing virtual memory.
The different types of Page Replacement Algorithms are:
First In First Out (FIFO): This page replacement technique is the simplest. The operating system maintains a queue for all of the memory pages in this method, with the oldest page at the front of the queue. The first page in the queue is chosen for removal when a page needs to be replaced.
Optimal Page Replacement: The optimal page replacement algorithm always chooses to replace the page that won't be utilised for the longest period of time in the future. By doing this, performance is enhanced and page faults are reduced.
Optimal page replacement algorithm is the best page replacement algorithm as it gives the least number of page faults.
Optimal page replacement algorithm cannot be implemented practically. Because it requires knowledge of the future memory access patterns, which is not possible to predict with certainty in most practical scenarios. As a result, the optimal page replacement algorithm is not practical for use in real-world systems.
Least Recently Used (LFU): Using this algorithm, the least recently used page will be replaced.
Most Recently Used (MRU): Using this approach, recently used pages will be replaced.
Belady’s anomaly: The phenomenon where increasing the number of page frames causes an increase in the frequency of page faults for a specific memory access pattern is known as Belady's anomaly.
The following page replacement algorithms frequently encounter this phenomenon:
Race Condition: When two or more threads have simultaneous access to common data and attempt to modify it, this is known as a race situation. You cannot predict the sequence in which the threads will attempt to access the shared data since the thread scheduling method might switch between threads at any time. Since both threads are competing to access/alter the data, the outcome of the change in data depends on the thread scheduling method.
Solution to Race Condition:
Note: We cannot use a simple flag variable to solve the problem of race condition.
Paging: Paging is a memory management scheme that eliminates the need for contiguous allocation of physical memory. The process of retrieving processes in the form of pages from the secondary storage into the main memory is known as paging. The basic purpose of paging is to separate each procedure into pages. Additionally, frames will be used to split the main memory. This scheme permits the physical address space of a process to be non – contiguous. Paging avoids external fragmentation.
TCP: Transmission Control Protocol is a transport layer protocol. Data is reliably and error-free transmitted from the source to the destination computer by use of this connection-oriented protocol. Prior to transmission, a link is formed between the peer entities. TCP segments an incoming byte stream at the transmitting host and gives each segment a unique sequence number. TCP rearranges the segments on the receiving host and notifies the sender that the segments were correctly received.
UDP: User Datagram Protocol is a transport layer protocol. It is a message-oriented protocol that offers a straightforward unreliable, connectionless service that is not recognised. It is appropriate for applications that do not need the flow control, error control, or sequencing features of TCP. It is used to send little amounts of data where delivery speed is more crucial than delivery precision.
SCTP: Stream Control Transmission Protocol is a transport layer protocol. It incorporates elements of both TCP and UDP. It provides a dependable, connection-oriented service like TCP while being message-oriented like UDP. It is utilised for Internet telephony.
Logical Address Space: During the program execution, the CPU creates the logical address. Since the logical address does not physically exist, it is also referred to as a virtual address. The CPU choses to refer to this particular address when attempting to access a physical memory location. The collection of all logical addresses produced by a program's perspective is referred to as the "logical address space.” Memory-Management Unit is a piece of hardware that maps logical addresses to their corresponding physical addresses.
Resource Allocation Graph:
A system resource allocation graph is a directed graph that can be used to more precisely define deadlock. The graph consists of a set of edges (set of "E"s) and a set of "V"s or vertices. The vertices V are divided into two groups of nodes, P (P1, P2, P3, etc.), which represent all of the system's processes, and R (R1, R2, R3, etc.), which represent all of the system's resource types.
P -> R represents the direct edge between P and R, meaning that P has asked for an instance of resource type R and is now waiting for that resource.
A resource type R instance has been assigned to the process P, which is indicated by the direct edge from R to P being denoted as R->P.
Here, the resource categories and processes are depicted visually by rectangles and circles, respectively.
A resource allocation graph is not considered to be in a stalemate if it lacks a cycle. Additionally, the system might or might not be in Deadlock if there is a cycle.
Resource request/release life cycle:
The following sequence describes the resource request/release life cycle of OS:
Super:
Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword ‘super’.
Thus, super( ) always refers to the superclass immediately above the calling class.
This is true even in a multileveled hierarchy.
It is used in variables, methods and constructors.
Code:
class Animal { public void makeSound() { System.out.println("Animal make a sound"); } } class Human extends Animal { public void makeSound() { super.makeSound(); // calls the makeSound() method of the parent class System.out.println("Human speaks"); } } public class Main { public static void main(String[] args) { Human A = new Human (); A.makeSound(); } }
Output:
Animal make a sound Human speaks
In this example, we have an Animal class and a Human class that extends the Animal class. The Animal class has a makeSound() method that simply prints out a message. The Human class overrides the makeSound() method and first calls the makeSound() method of the parent class using super.makeSound(), and then prints out a message specific to the Human class.
In C++, the super keyword is not used to refer to the parent class.
Final:
When we are declaring a method, adding the modifier final at the beginning can prevent it from being overridden. Methods marked as final are incompatible with overriding. Methods marked as final can occasionally improve performance: Since the compiler "knows" they won't be replaced by a subclass, it is free to inline calls to them.
Sometimes we will want to prevent a class from being inherited. To do this, precede the class declaration with final. Declaring a class as final implicitly declares all of its methods as final, too.
As we might expect, it is not possible to declare a class as both abstract and final since an abstract class is incomplete by itself & relies upon its subclasses to provide complete implementations.
Example:
final public class MyClassName { // Class definition }
This class can no longer be inherited by another class.
Const: Any moment the const keyword is associated with a method(), variable, pointer variable, or class object, that particular object/method()/variable is not allowed to change the value of its data items.
Example:
const a = 5;
Now, the value of ‘a’ cannot be changed further.
One of the most frequently posed Computer Science Interview Questions, be ready for it.
Port: Virtual points where network connections begin and stop are called ports. Ports are controlled by the operating system of a computer and are software-based. Each port is connected to a distinct procedure or service. Using ports, computers may distinguish between different types of communication with ease. For example, although using the same Internet connection, emails travel to a separate port than webpages.
Port Number: Every network-connected device uses a standard set of ports, each of which is given a port number. The majority of ports are set aside for certain protocols, for instance, port 80 is the designated location for all HTTP transmissions. The targeting of certain services or applications inside those devices is made possible via port numbers as opposed to IP addresses, which allow messages to move to and from particular devices.
There are 65,535 potential port numbers, however not all of them are often used. The following are some of the most popular ports and the corresponding networking protocols:
Deadlock occurs when two or more processes are unable to move forward because they are all reliant on a single event that actually never happens.
Resources assigned to a process are typically not preemptable. This indicates that once a resource is assigned to a process, there is no simple way for the system to remove it from the process unless the process voluntarily gives it up or the system administration kills the process. This might result in a condition known as stalemate.
If there is a stalemate among a group of processes or threads because they are all waiting for resources that are already in use.
Example:
A deadlock in a database occurs when many transactions are waiting for each other to release locks.
Deadlock Necessary Condition are as follows:
All 4 are the essential for deadlock to occur.
A process can recover from deadlock in the following ways:
Conditional Variable: A synchronisation primitive called a condition variable allows a thread to wait until a certain condition is met.
Conditional variable is used to avoid busy waiting.
Semaphores:
A shared integer variable across threads is all that a semaphore is.
There are 2 types of semaphores:
Binary semaphore:
Counting semaphore:
Peterson’s solution: Although Peterson's method only works for two processes or threads, it can be utilised to eliminate race conditions.
Mutex/Locks: By limiting access to critical section to a single thread or process, locks may be utilised to establish mutual exclusion and prevent race conditions. It has starvation of threads with high priority. It can generate deadlock and debugging is a problem.
Critical Section: The code segment known as the critical section is where processes and threads access and write to shared resources like files and common variables. Any process can be stopped mid-execution since processes and threads run simultaneously.
Concurrency: The simultaneous execution of several instruction sequences is known as concurrency. When many process threads are active at once, it occurs in the operating system.
Thread Scheduling: A thread's execution is planned according to its priority. Although threads are running within the runtime, the operating system nevertheless allots processor time slices to each thread.
Time Stamping: A DBMS-created unique identifier called a "time stamp" shows the approximate commencement time of a transaction. Whatever transaction we are carrying out, it records the transaction's beginning time and designates a precise time.
SDLC: The software development life cycle (SDLC) is a method that creates software quickly and at the lowest possible cost.
Domain Resolution: Domain Resolution is a service that links a domain name to the IP address of a website space so that users of the registered domain name may quickly visit the website. A network location is identified by a site's IP address, which is a numerical address. The domain name is used to identify the web address rather than the IP address to aid memorization. The process of translating domain names into IP addresses is known as domain resolution. The DNS server is responsible for domain name resolution.
Domain resolution is sometimes referred to as domain pointing, server setup, reverse IP registration, and other similar terms.
Now, let’s see how domain resolution works: -
3 Way Handshake:
This may alternatively be thought of as the process through which a TCP connection is made.
TCP uses a technique known as Positive Acknowledgement with Retransmission to guarantee dependable communication (PAR). A segment is the name given to the Protocol Data Unit (PDU) of the transport layer. Now, until it receives an acknowledgement, a device employing PAR must resend the data unit. The receiver discards the segment if the data unit it has received is damaged (it validates the data using the transport layer's checksum feature, which is used for error detection). The data unit for which a positive acknowledgement was not received must thus be resent by the sender. From the foregoing procedure, it is clear that three segments must be sent and received by the sender (client) and receiver (server) in order for a trustworthy TCP connection to be made.
Let’s see how this works:
Different class of Network:
An operating system is a piece of software that controls all the hardware and software resources. It acts as an interface between software and hardware. It serves as a resource manager and hides the hardware's underlying complexity to give users a convenient and effective environment in which they can run their applications smoothly.
Let’s see various types of operating system: -
Types of the operating system:
The definition of an object according to the dictionary is a thing or a thing that is real. Oriented is a verb that means to be interested in a specific sort of item or entity. It is a programming paradigm.
Object-oriented programming is essentially a philosophy or approach for computer programming that organizes software architecture around data or objects rather than functions and logic.
A data field is referred to as an object if it has distinct characteristics and behavior. In OOP, everything is categorized as self-sustaining objects.
Among developers, it is the most often used programming paradigm. Large, complicated, and actively updated or maintained programs work well with it.
A vehicle is an example of OOP in the real world. It fully exemplifies the effectiveness of object-oriented design.
The foundation of OOP consists of four pillars are:
Benefits of OOPS:
Difference between procedural language and object-oriented language:
This is a frequently asked question in Computer Science interviews. Classes and objects are the building blocks of OOP.
A class is an object's blueprint or template. Member variables, constants and functions, and other functionality are defined in the classes. It connects data and functions as a single entity. At runtime, it doesn't require any memory. Classes are not thought of as data structures.
An object is a physical thing with characteristics, actions, and qualities. It is also called as a class instance. It includes variables and member functions that we have declared in the class. It takes up room in the memory.
Keep in mind that while an object can exist without a class, the reverse is not feasible.
What is a Computer Network, Internet, World Wide Web? Differentiate between WWW and the Internet.
A computer network is a collection of linked computing systems that may communicate and share resources. These networked devices communicate data through wireless or physical technologies using a set of guidelines known as communications protocols.
The internet is a massive, electronically connected network of computers and other devices.
The World Wide Web is a compilation of all web sites and publications that may be found on the Internet by searching for their URLs (Uniform Resource Locator).
The following are the differences between the internet and the world wide web: The world wide web is where all web pages and documents are kept, and you need a unique URL for each website in order to access it. In contrast, the internet is a vast computer network that can be accessed through the World Wide Web.
WWW | Internet |
---|---|
The world wide web is software-oriented | The internet is hardware-oriented |
The world wide web uses HTTP | The internet uses IP addresses |
It is also one of the important general computer science interview questions of Networking that is asked in interview.
Let’s see what is data and information before actually jumping to their difference.
Data:
A collection of unprocessed, unstructured facts and information is known as data. Examples include text, observations, figures, symbols, and object descriptions.
In other words, data is meaningless on its own and does not serve any purpose.
Additionally, data is expressed in terms of bits and bytes, which are the fundamental units of information used in computer processing and storage. Although data can be captured, it cannot be meaningful without processing it.
There are two types of data:
Information:
Information is structured and organised data. It gives the data context and makes decision-making possible and make sense to us. Data are analysed and parts of data are interpreted to get information.
Now, let’s see what is the difference between data and information.
Data vs Information:
Data | Information |
---|---|
Data is a collection of facts | Information places such facts into perspective |
Data is raw and disorganised | Information is structured |
Each data point is unique and unrelated | Information depicts that data in order to give a broad overview of how everything fits together |
Data by itself has no value | Meaningful information is created after it has been studied and understood |
Data is dependent on information | Information is not dependent on data |
Graphs, numbers, figures, or statistics are the most common visual representations of data | Normally, information is communicated via words, language, thoughts, and concepts |
Attributes: An attribute in a database management system (DBMS) is a piece of information that specifies an entity.
Let's see various types of attributes: -
Types of Attributes:
Examples: In a database of an employee, ‘gender’ can be considered simple
Attribute because it is not subdivided anymore.
For instance, a person's name may be broken down into first, middle, and last names.
Examples: In a database of an employee, ‘address’ can be considered a composite
Attribute because it can be further subdivided into two or more sub-attributes i.e., ‘house
number', ‘street name’, ‘city’, ‘state’, ‘PIN code’.
Another example can be ‘name’ because it can be further subdivided into ‘First Name’,
‘Middle Name’ and ‘Last Name’.
Examples: In a database of an employee, ‘Employee ID’ can be considered as single-valued
attribute because every employee has a unique and only one ID that is given to them.
Examples: In a database of an employee, ‘phone number’ can be considered as
multi-valued attribute because an employee can have more than one phone number.
Upper or lower limits may be used as a limit restriction.
Example: In a database of an employee, ‘age’ can be considered as derived attribute
because it can be determined using the employee's birthdate and the current time.
Let’s see various types of entity: -
Types of Entity:
Example: In a database of university, “student” can be considered as strong entity because each student has a unique ID, so the entity can exist without depending on any
Other entities.
Example: In a database of university, the "Course Enrolment" can be considered as weak entity because it doesn't have a unique identifier without the corresponding " Student " and "Course" entities.
In C++, structure works the exact way as class but there are some differences between them.
Structure | Class |
---|---|
By default, Members of this is private. | By default, Members of this is public. |
It is declared using the keyword struct. | It is declared using the keyword class. |
It is mainly used for data abstraction and inheritance. | It is mainly used for data grouping. |
Based on their scale, computer networks are classified into three kinds:
Let’s see first, what is a topology: -
The advantages of bus topology are as mentioned below:
The followings are the drawbacks of bus topology:
Ring topology: Every computer is connected to another computer on each side known as a "ring topology." A ring-shaped network is created when the final computer is hooked up to the first. Each computer can have precisely two neighbouring computers for this architecture. Tokens are used to facilitate the exchange of data between devices. The computer station must possess the token in order to send data. Only once the transmission is finished is the token released, at which point other computer systems can use it to transfer data.
Ring Topology is faster than Bus Topology.
Swapping is a method that enables a process to be temporarily moved to secondary storage (disc) and out of main memory, freeing up that memory for use by other processes. The system switches the process back from secondary storage to main memory at a later time. It eliminates memory-resident processes to minimize the degree of multi-programming. These eliminated processes can be put back into memory and resume their execution from where it left off, it is known as swapping.
Swapping is required to increase the process mix. It is handled through Middle Term Scheduler which reduces degree of multi-programming.
It is a process of Switching from one process to another in the CPU.
Database:
A database is a location where data is kept in a form that makes it simple to access, manage, and modify.
DBMS:
A group of connected data and a set of software tools for accessing that data make up a database-management system (DBMS). The database, a collection of data, often contains information important to an organisation. A DBMS's main objective is to offer a simple and effective method for storing and retrieving database data.
The database itself, along with all the software and functions, is a DBMS. It is used to carry out many actions, including data insertion, access, updating, and deletion.
Now, let’s see what are the disadvantages of file systems that leads to creation of DBMS.
Disadvantages of File Systems:
These are the few reasons, why we should use DBMS and not file systems for storing and managing data.
Let’s see first what is a process: -
Process: A process is a computer program that is currently in execution.
It is the still-running process whose parent process has been destroyed. The init process i.e., the first process of OS, adopts orphan processes.
A process that has finished its execution but still has an entry in the process table is considered a zombie process. Because the parent process still needs to read its child's departure status, zombie processes often happen for child processes. The zombie process is then removed from the process table when this is completed using the wait system call. This is referred to as the zombie reaping procedure. The child process remains a zombie till it is removed from the process table. The child process was terminated significantly early since the parent process may call wait () on it for a longer period of time.
Expect to come across this popular question in Computer Science job interview questions. SQL (Structured Query Language) is a standard language used to manage relational databases.
The rest of the keys are alternate keys, composite keys, unique key etc.
There are several types of views in SQL:
A common question in Computer Science interview questions and answers for freshers, don't miss this one. The static keyword is mostly utilized for memory management. With variables, methods, blocks, and nested classes, the static keyword can be used. The static keyword is a property of the class rather than a class instance.
The static can be:
Static Variable:
A variable is considered static if you declare it to be static.
The static variable can be used to refer to an attribute that is shared by all objects but is not specific to each object, such as the name of the organization for employees or the university for students. When the class is loaded, the static variable receives only one memory allocation in the class area.
Benefit:
Uses of Static Variable:
Maintain count: Static variables are commonly used to count that how many times a function has been called. For example, if you want to know how many times a function is called then you can declare a static variable in that function and increment its value each time the function is called.
Data sharing between function calls: Data may be shared across function calls by using static variables. The value of a static variable set in one function call can also be utilised in subsequent function calls since static variables retain their values.
Global variables: Static variables defined outside of a function have file scope, which implies that any function in the file may access them. This may be used to implement global variables with file-specific restrictions.
Static method:
Any method that uses the static keyword is referred to as a static method.
Benefit:
Uses of Static Method:
Encapsulation:
Encapsulation is the technique of combining code and data into a single entity, such as a capsule containing a variety of medications. By making every data member of the class private, we may construct a class that is completely enclosed. We can now set and retrieve data from it using getter and setter functions.
Data encapsulation differs from data hiding in that it concentrates on wrapping (or encapsulating) the complex data to give the user a more user-friendly view. Data hiding concentrates on restricting data use in a programme to ensure data security.
Benefits of encapsulation include:
The capability of a class to acquire characteristics and properties from another class is referred to as inheritance. It is an important component of OOPs (Object Oriented programming system).
Let’s see various types of inheritance: -
Types of Inheritance:
Note: Multiple and hybrid inheritance is not supported in Java.
Java programming only supports multiple and hybrid inheritance through interfaces.
Use of inheritance:
Let’s see various terms that are primarily used in inheritance.
Terms used in Inheritance:
Polymorphism:
The idea of polymorphism allows us to carry out a single operation in several ways.
Greek terms poly and morphs are the roots of the word polymorphism. Poly means numerous, and morphs implies forms.
Polymorphism entails diversity of forms.
Example:
A person can play many roles and carry out multiple duties at once like he/she can be a writer and a software developer at the same time. So, the same person behaves differently depending on the situation. This is polymorphism.
Types:
Compile-time polymorphism and runtime polymorphism are the two forms of polymorphism.
By using method overloading (Compile-time polymorphism) and method overriding (runtime polymorphism), we may implement polymorphism.
Compile-time polymorphism is also known as static polymorphism and runtime polymorphism is also known as dynamic polymorphism.
Static polymorphism is another name for it. In order to create this form of polymorphism, either operators or functions must be overloaded. It is also known as early binding.
Method Overloading: When these functions have several instances of the same name but different parameters, they are said to be overloaded. A change in the number of arguments or/and a change in the type of arguments might cause a function to be overloaded.
Note: Operator Overloading is not supported by Java but supported by C++.
It is also known as late binding or dynamic polymorphism. It is achieved by method overriding. It is also called as dynamic method dispatch.
Dynamic Method Dispatch: The process by which a call to an overridden method is resolved at run time is known as dynamic method dispatch.
Method Overriding: A function call to the overridden method is resolved during this procedure at runtime. Method Overriding is used to accomplish this kind of polymorphism. Contrarily, method overriding happens when a derived class defines one of the base class's member functions. It is referred to as overriding that base function.
Modifiers can be either access modifiers or non-access modifiers.
By using the access modifier, we may modify the access level of fields, constructors, methods, and classes.
Java access modifiers come in four different varieties:
C++ does not support default modifier, it has only public, private and protected.
Non-access modifiers come in a variety of forms, including static, abstract, synchronised, native, volatile, transient, etc.
Getter and Setter methods are used to secure your code and safeguard your data.
Horizontal partitioning, or "sharding," is a sort of database partitioning.
Actually, Sharding is a database design that break a big database into smaller, more manageable pieces called shards to scale the database horizontally.
Instead of having all the data kept on a single, centralised server, the goal behind sharding is to distribute the workload of a database among several servers.
When to Shard a table?
Your database's performance can be greatly enhanced by slicing up your data. Here are some examples of how sharding might enhance performance:
When not to shard a table?
Sharding should only be utilised when all other optimization methods are insufficient. The following possible issues are brought on by the complexity that database sharding introduces:
Indexing helps to improve database speed by reducing the number of disc accesses required during query processing. One kind of data structure is the index. It is employed to rapidly find and retrieve the data in a database table. The search key, which is the first column in the database, contains a copy of the primary key or candidate key for the table. To make it simple to obtain the appropriate data, the values of the primary key are kept in sorted order. The database's second column contains the data references. It includes a group of pointers that store the location of the disc block's address where the value of a certain key may be located.
Various types of Indexing Methods are:
Primary Index:
Primary indexing is the process of building an index based on the table's primary key. These primary keys have a 1:1 relationship between the records and are particular to each record. The performance of the searching operation is highly effective since primary keys are kept in sorted order.
There are two categories for the primary index: Dense and Sparse index.
Dense Index:
Sparse Index:
Secondary Index:
When using sparse indexing, the size of the mapping also increases as the size of the table does. These mappings are often retained in the main memory to speed up address fetches. Using the address obtained via mapping, the secondary memory then searches the real data. The process of retrieving the address itself becomes slower as the mapping size increases. The sparse index will not function effectively in this situation. Secondary indexing is used to address this issue.
Clustering Index:
An ordered data file can be used to construct a clustered index. On non-primary key columns, which might not be distinct for each record, the index is occasionally built. In this instance, we will aggregate two or more columns to obtain the unique value and make an index out of them in order to identify the record more quickly. This technique is known as a clustering index.
When a large problem is broken down into multiple smaller sub-problems, it can be addressed more quickly just like partitioning. It creates smaller, more manageable data slices known as partitions from a large database that contains data metrics and indexes. Once the database has been partitioned, the data definition language can easily handle the smaller slices of the partitioned database rather than the entire enormous database. Partitioning solves the issue directly by making it comparatively easier to manage huge database tables
When to partition a table is shown by the following examples:
Let’s see various types of partition techniques that are primarily used: -
Partitioning Techniques:
The hash technique used by Oracle to identify partition tables. This method evenly splits the rows into several divisions, ensuring that each partition has the same dimensions. Hash partitioning is the technique of breaking up database tables into smaller chunks using this hash method. Hash partitioning is the ideal method for regularly distributing data among several devices.
Based on the range of values of the specific partitioning keys for each partition of the data, range partitioning separates the data into a number of divisions. It is a well-liked partitioning strategy that frequently involves dates. For instance, it will include a table with the column name "JULY" and rows with dates ranging from JULY 1 to JULY 31 to represent the days of the month of JULY. All partitions that are smaller than a certain partition appear before its VALUES LESS THAN clause, and all partitions that are higher than that specific partition come after its VALUES LESS THAN clause. Using the MAXVALUE clause, the highest range partition is represented.
A form of database partitioning called list partitioning divides data based on a list of values. List partitioning involves splitting a table into several partitions, each of which holds data depending on a particular set of values.
Normalization is a technique for structuring the data in a database that enables you to prevent anomalous insertion, update, and deletion of data as well as data redundancy. It is a procedure that involves examining relational schemas in light of their many functional relationships and primary keys.
Relational database theory requires normalisation from the outset. It might result in the database having duplicate copies of the same data, which could lead to the formation of new tables. It is most likely asked technical interview questions computer science for freshers
Three forms of data modification abnormalities can be distinguished:
Types of Normal Forms:
Advantages of Normalization:
Disadvantages of Normalization:
Transaction: The smallest processing unit that cannot be further split is a single task. A set of tasks might be referred to as a transaction.
Let’s see various types of transaction states: -
Transaction States:
Process States: The different stages that a process may be in while being run on a computer system are referred to as "process states". Each of the following states is possible for a process.
Process Queues: It determines that the process is in which state.
Job Queue:
Ready Queue:
Waiting Queue:
Constructor is called when an instance of any class is created as object. It is used to initialize the object. It is called every time an object is created using a keyword new. If we did not make any constructor in class then default constructor is called.
There are three types of constructors.
Some important terminology related to constructors are:
It is just opposite to constructor. When we construct a class object, it takes up some memory space (heap). If we do not get rid of these things, they linger in the memory and take up space that is not essential from a programming point of view. We use the destructor to fix this issue. The destructor is used to delete or destroy an object, which releases the resource it was using till now.
Advantage of Destructor:
In a nutshell, a new object that has a pointer to the memory address of the old object is called a shallow copy. As a result, any modifications made to the original object will also be mirrored in the shallow duplicate. When you wish to replicate an item but do not need to create an exact duplicate of the original object, shallow copying might be handy. It's also called as "shallow cloning."
On the other hand, a deep copy is a totally independent copy of an item. Changes to the original object have no impact on the deep copy since it produces a new object with a completely different memory location. When you need to change the original item without changing the duplicate, this is helpful.
In Python, for making shallow and deep copies, use the copy module's methods. A shallow copy is produced by the ‘copy.copy()’ method, and a deep copy is produced by the ’copy.deepcopy()’ function.
A transaction is a very tiny programming unit that can include a number of low-level operations. Atomicity, Consistency, Isolation, and Durability, or ACID qualities, are requirements for a transaction in a database system to maintain correctness, completeness, and data integrity.
A process is a computer program that is currently in execution. A process might produce what are referred to as "Child Processes," or new processes. The process is isolated, which means it does not share memory with any other processes, and therefore takes longer to complete.
The following statuses are possible for the process: new, ready, running, waiting, terminated, and suspended.
A process can have several threads, and these multiple threads are confined within a process since a thread is a segment of a process.
Three states exist for a thread: running, ready, and blocked.
The thread terminates faster than the process, but it does not isolate as the process does.
Thread | Process |
---|---|
Threads share same memory | Each process has different memory |
Creation takes less time. | Creation takes more time. |
Data is shared between threads. | No data is shared between processes. |
Multi-Tasking | Multi-Threading |
---|---|
Multitasking is the technique of carrying out many tasks at once. | A process is broken down into several distinct threaded subtasks, each of which has its own execution path. Multithreading is the term used to describe this idea. |
In this, more than one processes is context switched. | In this, more than one threads is context switched. |
There is memory protection and isolation. Each program that the CPU is running needs its own memory and resources, which the OS must allot. | Resources are shared throughout that process' threads since there is no isolation or memory protection. A process receives memory allocation from the operating system. several threads inside that process share the memory and resources allotted to the process. |
Number of Central Processing Unit is 1. | Number of Central Processing Unit is more than 1. |
Thread Context Switching | Process Context Switching |
---|---|
It is comparatively faster and cheaper. | It is comparatively slower and costlier. |
OS shifts to another thread of the same process while saving the current state of the thread. | OS moves to another process by restoring its state after saving the current state of the current process. |
In this Context Switching, CPU’s cache state is preserved. | In this Context Switching, CPU’s cache state is not preserved but its flushed. |
It excludes switching the memory address space. | It includes switching the memory address space. |
Let us see first what is a kernel: -
Kernel: The core of an operating system is its kernel (OS). It serves as a link between a computer's hardware and its software programmes. The system's resources, including the CPU, memory, and input/output devices, are managed by the kernel.
Now, let’s see various types of kernels in operating system.
Example: Linux, Unix, and MS-DOS.
Example: L4 Linux, Symbian OS, MINIX, etc.
Example: MacOS, Windows NT/7/10
Apart from that there are more types of kernels that is comparatively less used in OS.
Thrashing occurs when a computer system has insufficient memory and spends a lot of time switching data between the disk and memory rather than performing tasks.
The process will immediately page-fault if it does not have the necessary number of frames to support the active pages. It must now swap out a page at this point. It must, however, replace a page that will be immediately required again because all of its pages are currently being used. As a result, it faults frequently, replacing pages that it needs to bring back in right away. Thrashing is the name for this high-paging action.
Thrash is the term used in computer science to describe the poor performance of a virtual memory (or paging) system caused by the repetitive loading of the same pages when there is not enough main memory to retain them in mind.
The Causes of Thrashing are as follows:
Recovery from thrashing:
Banker’s algorithm is used to avoid deadlock.
The term was chosen because the algorithm might be implemented in a banking system to make sure that the bank never distributes its funds in a way that prevents it from meeting the needs of every customer. There should be a maximum number of each resource type's instances.
The maximum amount that may be allocated safely to determine the allocation for all resources is tested using this algorithm. Before deciding whether or not to continue allocating, it also checks for all potential activities.
For instance, there are G dollars total in the accounts of X number of account holders at a particular bank.
A car loan is processed by the bank using software subtracts the loan amount for a car purchase from the total amount of money the bank possesses (G+ Fixed Deposit + Monthly Income Scheme + Gold, etc.).
Additionally, it verifies whether the difference exceeds G or not. Even if every account holder withdraws funds at once, the auto loan won't be processed until the bank has enough cash.
Friend class is a class that has been designated as a friend can access the private and protected members of other classes. Sometimes it is advantageous to provide a certain class access to another class's private members.
A friend class can access both private and protected members of the class in which it has been declared as a friend.
Friend Functions:
Friend Functions, like friend class, can also access private and protected members.
In C++, a friend function is a special function that, although not belonging to a class, has the ability to access its private and protected data.
The following are some crucial details about friend functions and classes:
Merits of using Friend Class/Function:
Demerits of using Friend Class/Function:
Abstraction: Abstraction is showing only the essential information and hiding all the other unnecessary things and details.
Example:
Let’s say a man is driving a vehicle. The man only knows that pressing the accelerators will make a car go faster or that applying the brakes will cause the car to stop, but he has no idea how pressing the accelerator actually increases speed. He also has no idea how the accelerator, brakes, and other car controls are used inside the vehicle.
Abstracts Class:
An abstract class is declared by the keyword “abstract”. It can contain abstract as well as non-abstract methods. An abstract class is one that can't be created on its own. It offers a base class definition from which subsequent classes can inherit and serves as a blueprint for developing concrete subclasses.
Creation: abstract type name(parameter-list);
Properties of Abstract Class:
A must-know for anyone heading into a CS interview, this question is frequently asked in CS interview questions. Http and Https are protocols rather they are application-layer protocols used for transmitting data over the Internet.
Let us see what is a protocol and application-layer protocol.