### Project Idea (Trip Planner)

Also different algorithms can be developed to design the travel itinerary. About the author: “Harshit is a technology enthusiast and has keen interest in programming. He holds a B.Tech. degree in Computer Science from JIIT, Noida and currently works as Front-end Developer at SAP. He is also a state level table tennis player.

### Menu-Driven program to implement Travel Agency

Menu-Driven program to implement Travel Agency. Prerequisites: Classes and Objects in Java, Switch Case statement in Java. Book ticket for users/passengers on given routes via the various payment method. Print the ticket via ticket details and the user credentials. Update the passenger details on the booked ticket via ticket ID or E-mail ID and

### Minimum possible travel cost among N cities

Minimum possible travel cost among N cities. There are N cities situated on a straight road and each is separated by a distance of 1 unit. You have to reach the (N + 1)th city by boarding a bus. The ith city would cost of C [i] dollars to travel 1 unit of distance. In other words, cost to travel from the ith city to the jth city is abs (i – j

### Find Itinerary from a given list of tickets

Once we find the starting point, we can simply traverse the given map to print itinerary in order. Following are steps. 1) Create a HashMap of given pair of tickets. Let the created HashMap be 'dataset'. Every entry of 'dataset' is of the form "from->to" like "Chennai" -> "Banglore" 2) Find the starting point of itinerary.

### Travelling Salesman Problem Greedy Approach

We introduced Travelling Salesman Problem and discussed Naive and Dynamic Programming Solutions for the problem in the previous post. Both of the solutions are infeasible. In fact, there is no polynomial-time solution available for this problem as the problem is a known NP-Hard problem. There are approximate algorithms to solve the problem though.

### Find the minimum cost to reach destination using a train

There are N stations on route of a train. The train goes from station 0 to N-1. The ticket cost for all pair of stations (i, j) is given where j is greater than i. Find the minimum cost to reach the destination. Consider the following example: Input: cost[N][N] = { {0, 15, 80, 90}, {INF, 0, 40, 50

### Traveling Salesman Problem using Branch And Bound

In branch and bound, the challenging part is figuring out a way to compute a bound on best possible solution. Below is an idea used to compute bounds for Traveling salesman problem. Cost of any tour can be written as below. Cost of a tour T = (1/2) * ∑ (Sum of cost of two edges adjacent to u and in the tour T) where u ∈ V For every vertex u

### Given n appointments, find all conflicting appointments

2) Do following for all other appointments starting from the second one. a) Check if the current appointment conflicts with any of the existing appointments in Interval Tree. If conflicts, then print the current appointment. This step can be done O (Logn) time. b) Insert the current appointment in …

### Count ways to reach the n'th stair

Method 1: The first method uses the technique of recursion to solve this problem. Approach: We can easily find the recursive nature in the above problem. The person can reach n th stair from either (n-1) th stair or from (n-2) th stair. Hence, for each stair n, we try to find out the number of ways to reach n-1 th stair and n-2 th stair and add them to give the answer for the n th stair.

### Travelling Salesman Problem implementation using

Travelling Salesman Problem (TSP): Given a set of cities and distance between every pair of cities, the problem is to find the shortest possible route that visits every city exactly once and returns back to the starting point. Note the difference between Hamiltonian Cycle and TSP. The Hamiltoninan cycle problem is to find if there exist a tour that visits every city exactly once.

### Travelling Salesman Problem Set 1 (Naive and Dynamic

Travelling Salesman Problem (TSP): Given a set of cities and distance between every pair of cities, the problem is to find the shortest possible route that visits every city exactly once and returns to the starting point. Note the difference between Hamiltonian Cycle and TSP. The Hamiltoninan cycle problem is to find if there exist a tour that visits every city exactly once.

### Performance of a Network

Propagation Time: It is the time required for a bit to travel from the source to the destination. Propagation time can be calculated as the ratio between the link length (distance) and the propagation speed over the communicating medium. For example, for an electric signal, propagation time is the time taken for the signal to travel through a wire.

### Depth First Search or DFS for a Graph

Depth First Traversal (or Search) for a graph is similar to Depth First Traversal of a tree. The only catch here is, unlike trees, graphs may contain cycles, a node may be visited twice. To avoid processing a node more than once, use a boolean visited array. Approach: Depth-first search is an

### Number of ways to go from one point to another in a grid

Given the NxN grid of horizontal and vertical roads. The task is to find out the number of ways that the person can go from point A to point B using the shortest possible path. Note: A and B point are fixed i.e A is at top left corner and B at bottom right corner as shown in the below image. In the above image, the path shown in the red and light green colour are the two possible paths to

### Traveling Salesman Problem (TSP) Implementation

Traveling Salesman Problem (TSP) Implementation. Travelling Salesman Problem (TSP) : Given a set of cities and distances between every pair of cities, the problem is to find the shortest possible route that visits every city exactly once and returns to the starting point. Note the difference between Hamiltonian Cycle and TSP.

### Minimum cost to connect all cities

Method: Here we have to connect all the cities by path which will cost us least. The way to do that is to find out the Minimum Spanning Tree() of the map of the cities(i.e. each city is a node of the graph and all the damaged roads between cities are edges).And the total cost is the addition of the path edge values in the Minimum Spanning Tree.

### Puzzle Minimum planes to go around the world

After 1/6th of the circumference (50 units), Y passes 1/3rd of its fuel to Z and returns (Y has fuel left to travel exactly 50 units). Now Z has fuel left for 150 units (Completely filled). At 1/4th of the distance around the world, Z has fuel for 125 units and X has fuel for 75 units.

### Proof that traveling salesman problem is NP Hard

Pre-requisite: Travelling Salesman Problem, NP Hard Given a set of cities and the distance between each pair of cities, the travelling salesman problem finds the path between these cities such that it is the shortest path and traverses every city once, returning back to the starting point.. Problem – Given a graph G(V, E), the problem is to determine if the graph has a TSP consisting of …

### Minimum distance to visit all the nodes of an undirected

To travel from l 1 to l 2 some of the edges will be visited twice ( till the LCA of l 1 and l 2 all the edges will be visited twice ), for l 2 to l 3 and some of the edges will be visited ( till the LCA of l 2 and l 3 all the edges will be visited twice ) twice and similarly every edge of …

### Tree Traversals (Inorder, Preorder and Postorder

Unlike linear data structures (Array, Linked List, Queues, Stacks, etc) which have only one logical way to traverse them, trees can be traversed in different ways. Following are the generally used ways for traversing trees. In case of binary search trees (BST), Inorder traversal gives nodes in …

### Total time required to travel a path denoted by a given

Step 1: Travel north. Time Taken = 2 minutes. Step 2: Travel south on that same visited segment. Time Taken = 1 minutes. Step 3: Travel east.Time Taken = 2 minutes. Therefore, total time taken = 2 + 1 + 2 = 5. Approach: The idea is to use a Set to store all …

### Check if possible to move from given coordinate to desired

Given two coordinates (x, y) and (a, b). Find if it is possible to reach (x, y) from (a, b). If we take a closer look at the problem, we can notice that the moves are similar steps of Euclidean algorithm for finding GCD. So, it is only possible to reach coordinate (a, b) from (x, y) if GCD of x, y

### Breadth First Traversal ( BFS ) on a 2D array

Approach: Follow the steps below to solve the problem: Initialize direction vectors dRow [] = {-1, 0, 1, 0} and dCol [] = {0, 1, 0, -1} and a queue of pairs to store the indices of matrix cells. Start the BFS traversal from the first cell, i.e. (0, 0) and enqueue the index of this cell into the queue. Initialize a boolean array to mark the

### Paths to travel each nodes using each edge (Seven Bridges

There are n nodes and m bridges in between these nodes. Print the possible path through each node using each edges (if possible), traveling through each edges only once. It is one of the famous problems in Graph Theory and known as problem of “Seven Bridges of Königsberg”. This problem was

### Traveling Salesman Problem using Genetic Algorithm

In this article, a genetic algorithm is proposed to solve the travelling salesman problem. Genetic algorithms are heuristic search algorithms inspired by the process that supports the evolution of life. The algorithm is designed to replicate the natural selection process to carry generation, i.e. survival of the fittest of beings.

### Optimum location of point to minimize total distance

Given a set of points as and a line as ax+by+c = 0. We need to find a point on given line for which sum of distances from given set of points is minimum. In above figure optimum location of point of x - y - 3 = 0 line is (2, -1), whose total distance with other points is 20.77, which is minimum

### Number of refills to complete the journey of N km

Approach: As total journey is of N km, so keep a track of distance covered till now in a variable, say distCovered, which will be initialized by 0.Increment distCovered by K km till distCovered is less than N because K is the amount of distance vehicle can travel since the last refill. Also, with each increment, check if there is a compulsory petrol pump to stop between distCovered and

### Minimum time required to visit all the special nodes of a

Given an undirected tree consisting of N vertices where some of the nodes are special nodes, the task is to visit all the special nodes from the root node in minimum time. Time for travelling from one node to another node can be assumed as unit time. A node is special if the path from the root to the node consists of distinct value nodes.. Example: Input: N = 7, edges[] = {(0, 1), (0, 2), (1

### Count ways to reach the nth stair using step 1, 2 or 3

If the value of n is less than 0 then return 0, and if the value of n is equal to zero then return 1 as it is the starting stair. Call the function recursively with values n-1, n-2 and n-3 and sum up the values that are returned, i.e. sum = count (n-1) + count (n-2) + …

### Number of stopping station problem

Explanation 1 : Fix/remove of the four stops as fixed points and calculate in how many ways the other stations can be inserted between them, if you must have at least one station between stops. A x x x x x x x x B. Between these 8 non-halting stations we have 9 places and we select these 9 places as halt between these 8 stations.

### Traversing a map (or unordered_map) in C++ STL

Output [NOTE: For unordered_map output rows can be in any order] Element Frequency 1 4 2 1 3 2 4 1 This article is contributed by Kartik.If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to [email protected] See your article appearing on the GeeksforGeeks main page and …

### numpy.ravel() in Python

numpy.ravel () in Python. The numpy.ravel () functions returns contiguous flattened array (1D array with all the input-array elements and with the same type as it). A copy is made only if needed.

### Python Implementation of Movie Recommender System

Python | Implementation of Movie Recommender System. Recommender System is a system that seeks to predict or filter preferences according to the user’s choices. Recommender systems are utilized in a variety of areas including movies, music, news, books, research articles, search queries, social tags, and products in general.

### Zigzag (or diagonal) traversal of Matrix

Given a 2D matrix, print all elements of the given matrix in diagonal order. For example, consider the following 5 X 4 input matrix. Following is the code for diagonal printing. The diagonal printing of a given matrix “matrix[ROW][COL]” always has “ROW + COL – 1” lines in output

### Class 10 NCERT Solutions

If the cars travel in the same direction at different speeds, they meet in 5 hours. If they travel towards each other, they meet in 1 hour. What are the speeds of the two cars? Solution: Let’s take. Speed of car from point A = x km/he . Speed of car from point B = y km/h.

### How to iterate through a Vector without using Iterators in

Syntax: for (auto &itr : vector_name) Explanation: Here itr is an address to the value stored in vector which is used to traverse vectors. Below is the program to illustrate the same: #include <bits/stdc++.h>. using namespace std; void updateVector (vector<int> arr) {. …

### 10 Tips For First Year Computer Science Engineering

In this article, you will get to know about things you should be doing or not doing in your first year of college, if you are a computer science, engineering student: 1. Work on Typing Speed. First and foremost thing you should be doing is working on your typing speed. From now onwards you want to work with computers for your whole life and if

### Unique paths in a Grid with Obstacles

Given a grid of size m * n, let us assume you are starting at (1, 1) and your goal is to reach (m, n). At any instance, if you are on (x, y), you can either go to (x, y + 1) or (x + 1, y). Now consider if some obstacles are added to the grids. How many …

### Java Program to Solve Travelling Salesman Problem Using

Java Program to Solve Travelling Salesman Problem Using Incremental Insertion Method. Incremental is actually used in software development where the model is designed, implemented, and tested incrementally (a little more is added each time) until the product is finished. It involves both development and maintenance.

### Travelling Salesman Problem Set 2 (Approximate using MST

Following are some important facts that prove the 2-approximateness. 1) The cost of best possible Travelling Salesman tour is never less than the cost of MST. (The definition of MST says, it is a minimum cost tree that connects all vertices). 3) The output of …

### Schedule elevator to reduce the total time taken

Given an integer k and an array arr[] representing the destination floors for N people waiting currently at the ground floor and k is the capacity of the elevator i.e. maximum number of people it can hold at the same time. It takes 1 unit time for the elevator to reach any consecutive floor from the current floor. The task is to schedule the elevator in a way to minimize the total time taken

### How to find the position of HTML elements in JavaScript

Given an HTML document and the task is to get the position of any element by using JavaScript. Use the following steps to get the position: Step 1: Selecting an element: Before finding the position, it is necessary to select the required HTML element. Every element in HTML is structured in a tree-like format known as DOM or Document Object Model.

### Count all possible paths from top left to bottom right of

Java. // A Java program to count all possible paths. // from top left to bottom right. class GFG {. // Returns count of possible paths to reach. // cell at row number m and column number n from. // the topmost leftmost cell (cell at 1, 1) static int numberOfPaths ( int m, int n) {.

### LOOK Disk Scheduling Algorithm

LOOK is the advanced version of SCAN (elevator) disk scheduling algorithm which gives slightly better seek time than any other algorithm in the hierarchy (FCFS->SRTF->SCAN->C-SCAN->LOOK). The LOOK algorithm services request similarly as SCAN algorithm meanwhile it also “looks” ahead as if there are more tracks that are needed to be serviced

### Find the number of islands Set 1 (Using DFS)

Find the number of islands | Set 1 (Using DFS) Given a boolean 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains 5 islands. This is a variation of the standard problem: “Counting the number of connected components in an undirected graph”.

### How to set the default value for an HTML element

The select tag in HTML is used to create a dropdown list of options which can be selected.The option tag contains the value that would be used when selected. The default value of the select element can be set by using the ‘selected’ attribute on the required option. This is …