Question

1.What does a file index do? Why do we need a file index? 2.Modified All-Pairs Shortest...

1.What does a file index do? Why do we need a file index?

2.Modified All-Pairs Shortest Paths Problem

This is the All-Pairs Shortest Paths problem with the following modification. Let n be the number of nodes in input graph. There are additional inputs  k1, d in [1..n]. For every path that starts at, or ends at, or passes through node k1,distance d is added to the total distance of the path. Calculate shortest distances for all pairs of nodes (as in the original problem).

Write a program that solves the above problem. in c-language

The format of the input will be the following:

n k1, d (the number of nodes, node k1, and added distance d, e.g. 10 5 3)

i j w (direct edge from i to j with weight w; e.g. 2 3 8)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1:

   A file index is basically found in a file which contains an index. The index in the file basically allows easy random access to any file with the help of a particular key. The key should be unique. The key is used to identify a unique record in a table.

                                 We need a file index for sequential searching of a data in comparatively lesser time. The key in the file index helps us to uniquely identify a record.

Modified version:

#include <stdio.h>

#define infinity 9999

#define MAX 20

int minimum(int a,int b)

{

            if(a<=b)

            return a;

            else

            return b;

}/*End of minimum()*/

int display(int matrix[MAX][MAX],int n )

{

            int i,j;

            for(i=0;i<n;i++)

            {

                        for(j=0;j<n;j++)

                                    printf("%7d",matrix[i][j]);

                        printf("\n");

            }

}/*End of display()*/

main()

{

            int i,j,k,n;

            int adj[MAX][MAX],path[MAX][MAX];

            printf("Enter number of vertices : ");

            scanf("%d",&n);

            printf("Enter weighted matrix :\n");

            for(i=0;i<n;i++)

               for(j=0;j<n;j++)

                        scanf("%d",&adj[i][j]);

            printf("Weighted matrix is :\n");

            display(adj,n);

            /*Replace all zero entries of adjacency matrix with infinity*/

            for(i=0;i<n;i++)

               for(j=0;j<n;j++)

               if(adj[i][j]==0)

                        path[i][j]=infinity;

               else

                        path[i][j]=adj[i][j];

            for(k=0;k<n;k++)

            {

                        printf("Q%d is :\n",k);

                        display(path,n);

                        for(i=0;i<n;i++)

                        for(j=0;j<n;j++)

                            path[i][j]=minimum( path[i][j] , path[i][k]+path[k][j] );

            }

            printf("Shortest path matrix Q%d is :\n",k);

            display(path,n);

}

Add a comment
Know the answer?
Add Answer to:
1.What does a file index do? Why do we need a file index? 2.Modified All-Pairs Shortest...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q1: Here we consider finding the length of the shortest path between all pairs of nodes...

    Q1: Here we consider finding the length of the shortest path between all pairs of nodes in an undirected, weighted graph G. For simplicity, assume that the n nodes are labeled 1; 2; : : : ; n, that the weight wij of any edge e = (i; j) is positive and that there is an edge between every pair of nodes. In this question, the goal is to solve this via dynamic programming. Note that the algorithm you will...

  • Problem 6. (Weighted Graph Reduction) Your friend has written an algorithm which solves the all pairs shortest path pr...

    Problem 6. (Weighted Graph Reduction) Your friend has written an algorithm which solves the all pairs shortest path problem for unweighted undirected graphs. The cost of a path in this setting is the number of edges in the path. The algorithm UNWEIGHTEDAPSP takes the following input and output: UNWEİGHTEDA PSP Input: An unweighted undirected graph G Output: The costs of the shortest paths between each pair of vertices fu, v) For example, consider the following graph G. The output of...

  • Problem 2: As we discussed in class, one can use an algorithm for computing all-pairs shortest...

    Problem 2: As we discussed in class, one can use an algorithm for computing all-pairs shortest paths to also compute the transitive closure of a graph. If using Floyd-Warshall for example, it is possible to do this in On") time (where as usual n is the number of nodes and m is the number of edges). Show how to compute the transitive closure of a directed graph in O(nm) time. For which type of graphs is this better than using...

  • 6. [20 pts.] Below is the final P matrix after applying Floyd's all pairs shortest path algorith on a graph with nodes (A, B, C, D, E, F, G, H). In the matrix below 1 corresponds o 0 5 0 2 0...

    6. [20 pts.] Below is the final P matrix after applying Floyd's all pairs shortest path algorith on a graph with nodes (A, B, C, D, E, F, G, H). In the matrix below 1 corresponds o 0 5 0 2 0 5 5 Determine the shortest path between nodes D and F. a) 6. [20 pts.] Below is the final P matrix after applying Floyd's all pairs shortest path algorith on a graph with nodes (A, B, C, D,...

  • Design and implement Dijkstra’s algorithm to compute all-pair shortest paths in any given graph using An...

    Design and implement Dijkstra’s algorithm to compute all-pair shortest paths in any given graph using An adjacency matrix using a one-dimensional array for storing only the elements of the lower triangle in the adjacency matrix.[Program in C language] The input to program must be connected, undirected, and weighted graphs. The programs must be able to find shortest paths on two types of connected, undirected, and weighted graphs: complete graph (a graph with a link between every pair of nodes) and...

  • Hi there. I tried to submit this before, but the copy/paste didn't copy my vectors correctly....

    Hi there. I tried to submit this before, but the copy/paste didn't copy my vectors correctly. Hello there. I am trying to implement the djikstras shortest path algorithm into my code in C++ with a vector of vectors. However, when I test I get an error "Exception thrown at 0x75FFC762 in graphMain.exe: Microsoft C++ exception: std::out_of_range at memory location 0x009CF26C" for line 115 in graph.cpp. Could you help me debug? I am so close! ----------------------------FILE NAME: pch.h--------------------------------------- // pch.cpp: source...

  • C. 7. True/False Questions. (2 points each) a. Applying Horner's Rule, an n-degree polynomial can be...

    C. 7. True/False Questions. (2 points each) a. Applying Horner's Rule, an n-degree polynomial can be evaluated at a given point using only n multiplications and n additions. b. Quick Sort and Merge Sort are comparison-based sorting algorithms. Heap Sort and Distribution Counting Sort are not comparison-based sorting algorithms. An AVL tree applies four types of rotations: RIGHT, LEFT, RIGHT-LEFT, and LEFT-RIGHT. d. When an AVL tree's left sub-tree is left-heavy, a LEFT rotation is needed. e. When an AVL...

  • I need this in C++. This is all one question Program 2: Linked List Class For...

    I need this in C++. This is all one question Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...

  • Please follow all the instructions and do all the parts (a-d)! Create a Java program which implem...

    Please follow all the instructions and do all the parts (a-d)! Create a Java program which implements Dijkstra’s shortest path algorithm according to the psueudocode below. Base the design on the weighted graph implementation used in Problem3.java (provided at the bottom). Your program should include the following features: a. A new method receives a starting vertex index and a target vertex index (e.g. 0 and 4). It computes the shortest distances to all vertexes using Dijkstra’s algorithm. The pseudocode is...

  • I need help in C++ implementing binary search tree. I have the .h file for the...

    I need help in C++ implementing binary search tree. I have the .h file for the binary search tree class. I have 4 classic texts, and 2 different dictionaries. Classic Texts: Alice In Wonderland.txt A Tale of Two Cities.txt Pride And Prejudice.txt War and Peace.txt 2 different dictionaries: Dictionary.txt Dictionary-brit.txt The data structures from the standard template library can not be used.The main program should open the text file, read in the words, remove the punctuation and change all the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT