0% found this document useful (0 votes)
40 views18 pages

Boading Week

Node.js is an open-source JavaScript runtime environment that allows running JavaScript code outside of a browser for server-side development. It uses an event-driven, non-blocking I/O model implemented through an event loop to handle asynchronous operations efficiently. MongoDB is a popular NoSQL database that stores data in flexible, JSON-like documents and provides high performance, scalability, and flexibility through features like dynamic schema, horizontal scaling with sharding, and replication.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views18 pages

Boading Week

Node.js is an open-source JavaScript runtime environment that allows running JavaScript code outside of a browser for server-side development. It uses an event-driven, non-blocking I/O model implemented through an event loop to handle asynchronous operations efficiently. MongoDB is a popular NoSQL database that stores data in flexible, JSON-like documents and provides high performance, scalability, and flexibility through features like dynamic schema, horizontal scaling with sharding, and replication.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

node js

1. What is Node.js?

Node.js is an open-source JavaScript runtime environment built on Chrome's


V8 JavaScript engine. It allows running JavaScript code outside of a browser,
enabling server-side development.

2. How does Node.js work?

Node.js operates on a single-threaded, event-driven, non-blocking I/O model. It


uses an event loop to handle concurrent operations efficiently, allowing high
scalability and responsiveness.

3. What is an event loop in Node.js?

The event loop is the core mechanism in Node.js that handles and dispatches
events, including I/O operations, callbacks, and timers. It ensures non-blocking
and asynchronous behavior by constantly checking for events and executing
associated callbacks.

4. What are the advantages of using Node.js?

Node.js offers several advantages, including:

High performance and scalability due to its non-blocking I/O model.

Efficient handling of concurrent requests.

Simplified development with JavaScript for both the client and server.

Large ecosystem of modules and packages available via npm.

Fast execution with V8 engine and optimized code performance.

5. Explain the concept of non-blocking I/O in Node.js.

Non-blocking I/O means that Node.js can continue executing other tasks while
waiting for I/O operations to complete. It does not block the execution of
subsequent code and utilizes callbacks or promises to handle the results once
the I/O operation is finished.

6. What is the role of the package.json file in Node.js?

node js 1
The package.json file serves as a manifest for a Node.js project. It contains
metadata about the project, including dependencies, scripts, author information,
and project-specific configurations. It is also used by the npm package manager
to manage dependencies and perform various project-related tasks.

7. How do you handle asynchronous operations in Node.js?

Asynchronous operations in Node.js can be handled using callbacks, promises,


or async/await syntax. Callbacks are a traditional approach, while promises and
async/await provide more readable and structured code for handling
asynchronous tasks.

8. Explain the difference between process.nextTick() and setImmediate() in Node.js.

process.nextTick() is used to schedule a callback function to be executed in the


next iteration of the event loop, before any I/O operations. It has higher priority
than setTimeout() or setImmediate() .

setImmediate() is used to schedule a callback function to be executed in the


next iteration of the event loop, after any I/O operations. It has lower priority
than process.nextTick() .

9. How can you avoid callback hell in Node.js?

To avoid callback hell, you can use techniques like modularization, named
functions, and control flow libraries such as async.js or Promises. Alternatively,
you can utilize the async/await syntax, which provides a more readable and
structured way to handle asynchronous code.

10. What is the purpose of the exports object in Node.js modules?

The exports object in Node.js modules is used to define the public interface of
the module. It allows you to expose functions, objects, or values from a module
to be used by other parts of the application.

11. How can you handle errors in Node.js?

In Node.js, errors can be handled using try-catch blocks for synchronous code
or using error-first callbacks or promises for asynchronous code. Additionally,
you can utilize middleware error handlers in frameworks like Express.js to
handle errors in web applications.

12. What is the purpose of the stream module in Node.js?

node js 2
The stream module in Node.js provides an interface for streaming data, allowing
efficient processing of large amounts of data in a chunked manner. It enables
reading or writing data in small chunks, which is especially useful for handling
files, network sockets, or data transformations.

13. How can you deploy a Node.js application?

Node.js applications can be deployed using various methods, including:

Deploying on a cloud platform like AWS, Azure, or Google Cloud.

Using a containerization technology like Docker and deploying on container


orchestration platforms like Kubernetes.

Deploying on a PaaS (Platform as a Service) provider like Heroku or


Now.sh.

Setting up your own server or virtual machine and configuring it to run


Node.js applications.

14. Explain the concept of middleware in Express.js.

In Express.js, middleware functions are functions that have access to the


request ( req ), response ( res ), and next middleware function in the
application's request-response cycle. They can perform tasks like modifying
request/response objects, executing code before reaching the route handler,
handling errors, etc.

15. How does clustering work in Node.js?

Clustering in Node.js allows the utilization of multiple processes to handle


incoming requests. It helps to take advantage of multi-core systems and
improve the application's performance and scalability. The cluster module in
Node.js provides APIs to create and manage worker processes, each running
its own instance of the application.

Mongo db

1. What is MongoDB?

MongoDB is a popular open-source NoSQL database that provides high


performance, scalability, and flexibility. It is a document-oriented database that

node js 3
stores data in flexible, JSON-like documents.

2. What are the key features of MongoDB?

Key features of MongoDB include:

Document-based data model

Dynamic schema

Scalability and horizontal scaling with sharding

Replication for high availability

Flexible querying with support for complex queries

Secondary indexes

Aggregation framework for data processing

Geospatial indexing and queries

Full-text search capabilities

3. What is a document database?

A document database, such as MongoDB, is a type of NoSQL database that


stores and retrieves data in flexible, self-describing JSON-like documents. Each
document can have a different structure and can store nested data, making it
highly flexible for storing complex data models.

4. How does MongoDB differ from a relational database?

MongoDB differs from relational databases in several ways:

MongoDB is schema-less, while relational databases have predefined


schemas.

MongoDB stores data in flexible, JSON-like documents, while relational


databases use tables with rows and columns.

MongoDB supports horizontal scalability through sharding, whereas scaling


relational databases can be more complex.

MongoDB supports dynamic queries, while relational databases use SQL


for querying.

5. What is BSON in MongoDB?

node js 4
BSON stands for Binary JSON. It is a binary representation of JSON-like
documents used by MongoDB for data storage and network transfer. BSON
extends JSON by providing additional data types and optimizations for
efficiency and performance.

6. Explain the concept of sharding in MongoDB.

Sharding in MongoDB is the process of distributing data across multiple


machines or servers in a cluster. It allows horizontal scaling and improves
performance by dividing the dataset into smaller, more manageable chunks
called shards. Each shard contains a subset of the data, and MongoDB routes
queries to the appropriate shard to retrieve the results.

7. What is a replica set in MongoDB?

A replica set in MongoDB is a group of MongoDB servers that maintain the


same data set. It provides high availability and automatic failover by electing a
primary node responsible for processing write operations and maintaining the
latest data. The other nodes, called secondary nodes, replicate the primary's
data and can take over as the primary in case of failures.

8. How does indexing work in MongoDB?

Indexing in MongoDB improves query performance by creating indexes on


specific fields. It allows the database to quickly locate and retrieve documents
based on the indexed fields. MongoDB supports various types of indexes,
including single field indexes, compound indexes, multi-key indexes, text
indexes, geospatial indexes, and more.

9. What is the difference between MongoDB's find() and findOne() methods?

The find() method in MongoDB returns a cursor that can be iterated over to
retrieve multiple documents matching the specified query criteria. It returns all
matching documents by default.

The findOne() method in MongoDB returns a single document that matches the
specified query criteria. It stops searching after finding the first matching
document.

10. What is the aggregation framework in MongoDB?

node js 5
The aggregation framework in MongoDB provides powerful data processing
and aggregation capabilities. It allows you to perform complex data
transformations, grouping, filtering, and computations on the data stored in
MongoDB. It is used to analyze data, generate reports, and extract meaningful
insights from large datasets.

11. How can you perform a backup and restore in MongoDB?

MongoDB provides tools like mongodump and mongorestore to perform backup and
restore operations. mongodump creates a binary export of the data, while
mongorestore restores the data from the backup files. Additionally, MongoDB
also supports backup solutions provided by third-party vendors.

12. Explain the concept of transactions in MongoDB.

Transactions in MongoDB allow multiple operations to be grouped together in a


single atomic unit. It ensures data consistency by either applying all the
operations in the transaction or rolling back if any operation fails. Transactions
are supported in replica sets starting from MongoDB 4.0 and in sharded
clusters from MongoDB 4.2.

13. What is the purpose of the MongoDB Compass tool?

MongoDB Compass is a graphical user interface (GUI) tool provided by


MongoDB. It allows developers and administrators to visualize and interact with
MongoDB databases, collections, and documents. It provides a convenient way
to explore and manipulate data, write queries, create indexes, and analyze the
performance of database operations.

14. How does MongoDB handle scalability and high availability?

MongoDB handles scalability and high availability through sharding and replica
sets. Sharding allows data to be distributed across multiple servers or shards
for horizontal scaling. Replica sets ensure high availability by maintaining
multiple copies of data across different servers, automatically promoting a new
primary node if the current primary fails.

15. What are the different types of relationships in MongoDB?

MongoDB supports three types of relationships between data models:

node js 6
One-to-One: Embedding or referencing a document within another
document.

One-to-Many: Embedding or referencing an array of documents within


another document.

Many-to-Many: Using an array of references in both related documents to


establish relationships between them.

express

1. What is Express.js?

Express.js is a popular web application framework for Node.js. It provides a


minimal and flexible set of features for building web applications and APIs.
Express.js simplifies the process of handling HTTP requests, defining routes,
and managing middleware.

2. What are the key features of Express.js?

Key features of Express.js include:

Simplicity and minimalism

Middleware-based architecture

Robust routing capabilities

Support for template engines

Built-in error handling

Easy integration with other Node.js modules and middleware

3. Explain the concept of middleware in Express.js.

Middleware in Express.js is a function that receives the req (request) and res
(response) objects and has access to the next middleware function in the
request-response cycle. It can perform tasks such as modifying the request or
response objects, executing code, or terminating the request-response cycle.

4. How do you handle routes in Express.js?

node js 7
Routes in Express.js are defined using the app.get() , app.post() , app.put() ,
app.delete() , or other HTTP method functions provided by the Express app

object. Each route can have a handler function that defines the behavior when
that route is accessed.

5. What is the purpose of the app.listen() method in Express.js?

The app.listen() method in Express.js is used to start a server and listen for
incoming requests on a specified port. It binds and listens to the specified port
number and optionally a hostname.

6. How can you handle static files in Express.js?

Express.js provides the express.static() middleware to serve static files, such


as images, CSS files, and client-side JavaScript files. By specifying a directory
path, Express.js automatically handles serving the static files for you.

7. What is the role of the req and res objects in Express.js?

The req (request) object represents the incoming HTTP request from the client.
It contains information about the request, such as headers, parameters, query
strings, and the request body.

The res (response) object represents the server's response to the client's
request. It is used to send the response back to the client, set response
headers, and manage the response body.

8. How do you handle error handling in Express.js?

Error handling in Express.js is done by defining a middleware function with four


parameters: (err, req, res, next) . This function is called whenever an error
occurs during request processing. You can define custom error handlers or use
built-in error handling middleware, such as app.use((err, req, res, next) => {}) ,
to handle errors in Express.js.

9. What is routing in Express.js?

Routing in Express.js refers to the process of defining how an application


responds to client requests to specific URLs (or routes). It involves mapping
URLs to route handlers and defining the behavior and logic that should be
executed when a specific route is accessed.

10. Explain the concept of middleware chaining in Express.js.

node js 8
Middleware chaining in Express.js refers to the process of applying multiple
middleware functions to a specific route or to the entire application. Middleware
functions are executed in the order they are defined, with each function having
the option to pass control to the next middleware using the next() function.

11. How do you handle form data in Express.js?

Express.js provides middleware such as express.urlencoded() and


express.json() to handle form data. express.urlencoded() parses form data and

populates the req.body object, while express.json() parses JSON data in the
request body. You can then access the form data using req.body .

12. What is the purpose of template engines in Express.js?

Template engines in Express.js are used to dynamically generate HTML


markup by combining static HTML templates with dynamic data. Popular
template engines for Express.js include Pug (formerly Jade), EJS, and
Handlebars. They allow you to easily generate dynamic content and reuse
templates across multiple views.

13. How can you handle authentication and sessions in Express.js?

Authentication and session management in Express.js can be achieved using


middleware such as express-session or by integrating with authentication
libraries like Passport.js. These middleware enable you to handle user
authentication, session creation, session storage, and manage user sessions
across multiple requests.

14. How does Express.js handle scalability and high availability?

Express.js itself is agnostic to scalability and high availability concerns.


However, Express.js applications can be deployed and managed using
techniques like load balancing, clustering, and containerization. Additional tools
and platforms such as PM2, Docker, and Kubernetes can be used to achieve
scalability and high availability for Express.js applications.

react js

1. What is React.js?

node js 9
React.js is a popular JavaScript library used for building user interfaces. It
allows developers to create reusable UI components and efficiently update and
render them when the underlying data changes. React.js follows a component-
based approach and uses a virtual DOM for efficient rendering.

2. What are the key features of React.js?

Key features of React.js include:

Component-based architecture

Virtual DOM for efficient rendering

Declarative syntax for defining UI

Reusability and modularity of components

One-way data flow with props

Efficient update and rendering through reconciliation

React Native for building mobile applications

Large and active community support

3. What is the Virtual DOM in React.js?

The Virtual DOM is a lightweight, in-memory representation of the actual DOM.


React.js uses the Virtual DOM to efficiently update and render components.
When the state or props of a component change, React.js compares the Virtual
DOM with the actual DOM, calculates the minimum required changes, and
updates only those parts of the actual DOM, minimizing the need for full page
reloads.

4. Explain the concept of JSX in React.js.

JSX is a syntax extension in React.js that allows you to write HTML-like code
within JavaScript. It is a combination of JavaScript and XML-like syntax and is
used to define the structure and content of React components. JSX makes it
easier to create and manipulate React elements and allows you to embed
JavaScript expressions within the HTML-like syntax.

5. What are components in React.js?

node js 10
Components are the building blocks of React.js applications. A component in
React.js is a reusable, self-contained piece of UI that can be composed
together to create complex UIs. Components can be either functional or class-
based and encapsulate their own state, props, and rendering logic.

6. What is the difference between functional and class components in React.js?

Functional components are simple JavaScript functions that accept props as


parameters and return JSX elements. They are easier to write, test, and
understand. Class components, on the other hand, are JavaScript classes that
extend the React.Component class. They have more features, such as local
state and lifecycle methods, and are used when more advanced functionality is
required.

7. How do you handle state in React.js?

State in React.js represents the data that can change over time and affects the
rendering of components. State is typically managed within a component using
the or this.state mechanism. Functional components can use the
useState

useState hook, while class components use this.state and this.setState to

manage and update the state.

8. What are React hooks?

React hooks are functions that allow you to use state and other React features
in functional components. They were introduced in React 16.8 and provide a
way to use stateful logic without the need for class components. Hooks, such as
useState and useEffect , allow you to manage state, perform side effects, and

access lifecycle methods within functional components.

9. What is the purpose of the setState() method in React.js?

The setState() method is used in React.js to update the state of a component.


When setState() is called, React re-renders the component, updating the UI
based on the new state values. It is important to note that setState() is
asynchronous and batched for performance reasons.

10. What is the significance of keys in React lists?

Keys in React lists are used to provide a unique identifier for each item in a list
of components. They help React efficiently update and re-render the list when
the underlying data changes. Keys ensure that React can correctly identify

node js 11
added, removed, or re-ordered list items, improving performance and reducing
unnecessary DOM manipulations.

11. How does React.js handle props?

Props (short for properties) are used to pass data from a parent component to
its child components in React.js. Props are read-only and cannot be modified by
the child component. They are passed as attributes to child components and
can be accessed within the child component using this.props (for class
components) or directly within the function body (for functional components).

12. Explain the concept of lifecycle methods in React.js.

Lifecycle methods in React.js are special methods that are called at different
stages of a component's life cycle. They allow you to execute code at specific
points during a component's creation, update, and removal. Common lifecycle
methods include componentDidMount() , componentDidUpdate() , and
componentWillUnmount() . However, with the introduction of React hooks, the use
of lifecycle methods is less common in functional components.

13. What is React Router?

React Router is a popular routing library for React.js applications. It provides a


declarative way to define routes and manage navigation within a single-page
application. React Router allows you to create different routes, handle URL
parameters, and dynamically render components based on the current URL.

14. How can you optimize performance in React.js?

Some strategies for optimizing performance in React.js include:

Implementing memoization using the React.memo() or React.PureComponent to


prevent unnecessary re-renders.

Using the shouldComponentUpdate() or React.memo() to control when a


component should update.

Splitting components into smaller, more manageable pieces.

Using the useCallback and useMemo hooks to optimize function references


and expensive computations.

Implementing lazy loading or code splitting to load components on demand.

node js 12
Implementing virtualized lists for efficient rendering of long lists of data.

15. What are controlled and uncontrolled components in React.js?

Controlled components are React components whose form elements (e.g.,


input, select) are fully controlled by React state. The value of the form element
is stored in state, and any changes are handled by updating the state.
Uncontrolled components, on the other hand, store their own state internally
and directly access the DOM. They are typically used when you need to access
form values imperatively or when integrating with third-party libraries.

bst
1. What is a Binary Search Tree (BST)?

A Binary Search Tree (BST) is a binary tree data structure where each node
has at most two children, referred to as the left child and right child. The left
child is always less than the parent node, and the right child is always
greater. This property allows for efficient searching, insertion, and deletion
of nodes in logarithmic time complexity.

2. How does a Binary Search Tree work?

In a Binary Search Tree, each node's value is greater than all values in its
left subtree and less than all values in its right subtree. This property allows
for efficient searching by recursively comparing the target value with the
current node's value and navigating to the left or right child accordingly until
the target value is found or the tree is exhausted.

3. What are the properties of a Binary Search Tree?

The properties of a Binary Search Tree are as follows:

The left subtree of a node contains only values less than the node's
value.

The right subtree of a node contains only values greater than the
node's value.

Both the left and right subtrees are also Binary Search Trees.

There are no duplicate values allowed in the tree.

node js 13
4. How do you insert a node into a Binary Search Tree?

To insert a node into a Binary Search Tree, compare the value of the new
node with the current node. If the value is less, move to the left child if it
exists, or create a new left child. If the value is greater, move to the right
child if it exists, or create a new right child. Repeat this process until the
appropriate position for the new node is found.

5. How do you delete a node from a Binary Search Tree?

Deleting a node from a Binary Search Tree involves finding the node to be
deleted, considering three cases:

If the node has no children, simply remove the node from the tree.

If the node has one child, replace the node with its child.

If the node has two children, find the successor or predecessor node,
replace the node's value with the successor or predecessor value, and
then recursively delete the successor or predecessor node.

6. What is the time complexity of searching for a node in a Binary Search Tree?

The time complexity of searching for a node in a Binary Search Tree is


O(log n) in the average case and O(n) in the worst case, where n is the
number of nodes in the tree. This efficiency is due to the BST's property
that allows for quickly traversing the tree by choosing the left or right
subtree based on the comparison between the target value and the current
node's value.

7. How do you find the minimum and maximum values in a Binary Search Tree?

The minimum value in a Binary Search Tree is found by following the left
child pointers until a leaf node is reached. The maximum value is found by
following the right child pointers until a leaf node is reached.

8. What is the difference between an in-order, pre-order, and post-order traversal


of a Binary Search Tree?

In-order traversal visits the nodes in ascending order, visiting the left
subtree first, then the current node, and finally the right subtree.

node js 14
Pre-order traversal visits the current node first, then the left subtree, and
finally the right subtree.

Post-order traversal visits the left subtree first, then the right subtree, and
finally the current node.

9. How do you check if a Binary Search Tree is balanced?

To check if a Binary Search Tree is balanced, calculate the height of the left
and right subtrees for each node and ensure that the absolute difference
between the heights is no more than 1 for all nodes in the tree. If this
condition holds true for all nodes, the tree is balanced.

10. What is the height of a Binary Search Tree?

The height of a Binary Search Tree is the maximum number of edges


between the root node and a leaf node. It represents the length of the
longest path from the root to any leaf in the tree.

11. How do you find the successor or predecessor of a node in a Binary Search
Tree?

To find the successor of a node, check if the node has a right child. If it
does, the successor is the minimum value node in the right subtree. If it
doesn't, traverse up the tree until you find a node whose left child is the
ancestor of the target node. That node is the successor.

To find the predecessor, follow a similar approach but check for the
presence of a left child and find the maximum value node in the left subtree
or traverse up the tree to find the predecessor.

12. What is the concept of a self-balancing Binary Search Tree?

A self-balancing Binary Search Tree (BST) automatically maintains a


balance in the tree to ensure efficient searching, insertion, and deletion
operations. Examples of self-balancing BSTs include AVL trees, Red-Black
trees, and B-trees. These data structures perform rotations and reordering
of nodes during insertions and deletions to maintain a balanced tree
structure.

13. Explain the difference between a Binary Search Tree and a Binary Heap.

node js 15
A Binary Search Tree (BST) is a data structure that allows efficient
searching, insertion, and deletion operations. It maintains the property that
values in the left subtree are less than the current node, and values in the
right subtree are greater. BSTs are commonly used for fast searching and
ordered data storage.

A Binary Heap is a complete binary tree data structure that is commonly


used for efficient priority queue operations, such as finding the minimum or
maximum element. In a Binary Heap, the parent node's value is either
greater (in a Max Heap) or smaller (in a Min Heap) than its child nodes'
values. However, Binary Heaps do not maintain the sorted order of
elements like Binary Search Trees.

14. How can you convert a Binary Search Tree into a sorted doubly linked list?

To convert a Binary Search Tree into a sorted doubly linked list, perform an
in-order traversal of the tree. While traversing, keep track of the previously
visited node, update the pointers to form the doubly linked list, and finally
return the head node of the list.

15. What is the concept of Binary Search Tree rotation?

Binary Search Tree rotation is an operation used to maintain the balance of


a BST or to restructure the tree. Rotations can be left rotations or right
rotations and are performed by moving nodes around while maintaining the
binary search tree property. Rotations help to optimize search, insertion,
and deletion operations in certain situations, such as when an unbalanced
tree is encountered.

graph ds
1. What is a Graph data structure?

A Graph is a non-linear data structure consisting of a set of vertices (nodes)


and a set of edges that connect pairs of vertices.

2. What are the different types of Graphs?

The different types of Graphs include Directed Graphs (Digraphs), Undirected


Graphs, Weighted Graphs, and Unweighted Graphs.

3. What is the difference between Directed and Undirected Graphs?

node js 16
In a Directed Graph, edges have a direction associated with them, while in an
Undirected Graph, edges have no specific direction.

4. How do you represent a Graph in memory?

There are two common ways to represent a Graph: using an Adjacency Matrix
(2D array) or an Adjacency List (array of linked lists or arrays).

5. What is the Adjacency Matrix representation of a Graph?

An Adjacency Matrix is a 2D array where the value at matrix[i][j] represents


whether there is an edge from vertex i to vertex j.

6. What is the Adjacency List representation of a Graph?

An Adjacency List is an array where each element represents a vertex and


contains a list of its adjacent vertices.

7. How do you traverse a Graph?

There are two common graph traversal algorithms: Depth-First Search (DFS)
and Breadth-First Search (BFS).

8. What is the Depth-First Search (DFS) algorithm?

DFS explores a Graph by visiting a vertex and recursively visiting all its
adjacent vertices before backtracking. It uses a stack or recursion to implement
the traversal.

9. What is the Breadth-First Search (BFS) algorithm?

BFS explores a Graph by visiting a vertex and then visiting all its adjacent
vertices before moving on to the next level of vertices. It uses a queue to
implement the traversal.

10. What is a spanning tree in a Graph?

A spanning tree is a subgraph of a Graph that is a tree and connects all vertices
together without any cycles.

11. What is a minimum spanning tree?

A minimum spanning tree is a spanning tree in a weighted graph that has the
minimum total weight among all possible spanning trees.

12. What are the applications of Graph data structure?

node js 17
Graphs are used to model and solve a variety of real-world problems, including
social networks, web page ranking, routing algorithms, recommendation
systems, and more.

13. What is Dijkstra's algorithm?

Dijkstra's algorithm is a popular algorithm for finding the shortest path between
two vertices in a weighted graph.

14. What is the Bellman-Ford algorithm?

The Bellman-Ford algorithm is an algorithm for finding the shortest path in a


weighted graph, even in the presence of negative weight edges.

15. What is the topological sorting of a directed acyclic graph (DAG)?

Topological sorting is an ordering of the vertices in a DAG such that for every
directed edge (u, v), vertex u comes before vertex v in the ordering.

16. What is the cycle detection algorithm in a Graph?

Cycle detection algorithms, such as Floyd's cycle detection algorithm or depth-


first search, are used to determine whether a Graph contains any cycles.

17. What is the difference between a Graph and a Tree?

A Graph is a collection of vertices and edges that can have cycles, while a Tree
is an acyclic Graph.

18. What is the difference between a Tree and a Binary Tree?

A Tree is a connected acyclic Graph, while a Binary Tree is a Tree where each
node can have at most two children.

19. What is the difference between a Graph and a Linked List?

A Graph is a collection of vertices and edges that can have cycles and multiple
connections, while a Linked List is a linear data structure with nodes connected
sequentially.

20. What is the concept of graph coloring?

Graph coloring is the assignment of colors to the vertices of a Graph such that
no two adjacent vertices have the same color. It has applications in scheduling,
map coloring, register allocation, and more.

node js 18

You might also like