Write a program in C which randomly generates two integers X and Y between 10 and 50, and then creates a dynamic array which can hold as many numbers as there are between those two random numbers. Fill the array with numbers between X and Y and print it on screen. Do not forget to free the allocated memory locations whenever they are no longer needed.
Example:
Randomly generated numbers are: 43 23
Expected Output :
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
In: Computer Science
I want to know the details interpretation of this code for my interview preperation on this code. This is A* algorithm in c++
#include<bits/stdc++.h>
using namespace std;
#define DISCONNECTED -1
int num_of_node,num_of_edge,graph[30][30],pathCost[30];
void init_Heuristic();
struct Node{
int from,to;
int cost;
};
struct CompareNode{
bool operator()(Node& n1, Node&
n2){
if(n1.cost >
n2.cost)return true;
return false;
}
};
map<int,int>Heuristic;
priority_queue<Node, vector<Node>, CompareNode>
PQ;
vector<Node>path;
void AStarSearch(int source,int destination){
init_Heuristic();
for(int i = 1; i <= num_of_node; i++){
if(graph[source][i] !=
DISCONNECTED){
Node n;
n.from = source;
n.to = i;
n.cost = graph[source][i] + Heuristic[i];
pathCost[i] = graph[source][i];
PQ.push(n);
}
}
while(!PQ.empty()){
Node tmp =
PQ.top();
path.push_back(tmp);
if(tmp.to ==
destination)break;
PQ.pop();
for(int i = 1; i <=
num_of_node; i++){
if(graph[tmp.to][i] != DISCONNECTED){
Node n;
n.from = tmp.to;
n.to = i;
n.cost = pathCost[tmp.to] + graph[tmp.to][i] + Heuristic[i];
pathCost[i] = pathCost[tmp.to] + graph[tmp.to][i];
PQ.push(n);
}
}
}
}
int main(){
int a,b,c,source,destination;
cout << "Enter Node: " <<
endl;
cin >> num_of_node;
cout << "Enter Edge: " <<
endl;
cin >> num_of_edge;
for(int i=1; i<=num_of_node; i++)
for(int j=1; j<=num_of_node; j++)
graph[i][j] = DISCONNECTED;
for(int i = 0; i < num_of_edge;
i++){
cin >> a >>
b >> c;
graph[a][b] = c;
}
cout << "Enter source: " <<
endl;
cin >> source;
cout << "Enter destination: " <<
endl;
cin >> destination;
AStarSearch(source,destination);
for(int i = 0; i < path.size(); i++)
cout <<
path.at(i).from << " -> " << path.at(i).to <<
" = " << path.at(i).cost << endl;
return 0;
}
void init_Heuristic(){
///straight line distance ///
Heuristic[1] = 10;
Heuristic[2] = 5;
Heuristic[3] = 0;
Heuristic[4] = 13;
}
In: Computer Science
In what ways are user-level threads better/more efficient than kernel-level threads?
In: Computer Science
In: Computer Science
In Java, a set of integers is given. write a function to find 2 integers in this set that sums upto a target value.
i.e [1,5,2,0,11,3] target = 7
result [5,2]
i.e [1,5,4,0,14,-7] target = 9
result [5,4]
NOTE: THE SAME INTEGER CANNOT BE USED TWICE !!!
In: Computer Science
IN C++:
Create sets of 1 Million integers with the following
characteristics;
Sets where no numbers repeat
Sets where the range of numbers is 1% of the array size
Sets where no numbers repeat and each integer has 20 digits
In: Computer Science
consider the victoria university information technology department, department has setup a small library for NIT5130 students. The department library maintains a checkout list ( CALL NO, USER ID, DATE REQUESTED) of all the books borrowed by students, Every student record consists of User ID, User name, Borrow limit, Number checked out, and fines. Suppose that the library will have multiple copies (CALL NO, AUTHOR NAME, PUBLISHER, ISBN, DATE PUBLISHED) can have multiple authors (AUTHOR NAME, DATE OF BIRTH, COUNTRY OF BIRTH, DECEASE BIRTH). You have volunteered to set up a database system for the library,
Draw an Entity relationship diagram for the IT department library
In: Computer Science
How can I return in a list all possible paths from a grid if I can only go right and down?
For example consider the following table:
A B C
D E F
If I go right I need to insert in my list 'H' if I go down I need to insert in my list 'V'.
For example the path A - > B -> C -> F would be H - H - V
The path A -> D -> E -> F would be V - H - H
How would be the code for that? Please preference write in JAVA.
Thank you,
In: Computer Science
Please solve this problem, in c++ (algoritms) write code and explaination how to solve it!
1) N numbers are given. The first K of them are sorted in ascending order, the remaining NK are also sorted in ascending order. Sort numbers in ascending order in O (N).
Input data format N - number of numbers, K - number of numbers in the first half (sorted).
Example input
10 6
1 2 5 6 8 9 3 4 7 12
Sample Output
1 2 3 4 5 6 7 8 9 12
In: Computer Science
6.5 The time taken by machines A, B, and C to execute a given task is
A 16m, 9s
B 14m, 12s
C 12m, 47s
What is the performance of each of these machines relative to machine A?
6.6 Why is clock rate a poor metric of computer performance? What are the relative strengths and weaknesses of clock speed as a performance metric?
6.7 What are the relative strengths and weaknesses of the MIPS as a metric of computer performance?
In: Computer Science
Using python:
In the directory rootdir some of the files contain randomly generated content while others are written by human authors. Determine how many of the files contained in the directory are written by human authors. Store your answer in the variable number_human_authored
In: Computer Science
AverageGrade.
Assume the professor gives five exams during the semester with
grades 0 through 100 and drops one of the exams with the lowest
grade. Write a program to find the average of the remaining four
grades. The program should use a class named Exams that has
An instance variable to hold a list of five grades,
A method that calculate and return average.
A string that return the “exams Average” for printing.
Your program output should prompt for an input for each grade. Use
any number between 0 and 100.
Your submission should include compiled output.
In Java Please
In: Computer Science
In C# Problem 1: Order matters! For this question, you’re going to write two recursive functions, both of which take in only a single string as a parameter; you will not receive credit if you pass in an integer as well. Note: you will need to understand substrings to get the correct solution. The first function should simply print out the string, but do so letter by letter – and recursively. The second function should print out the string in reverse; the code is almost identical, but the concept is different. Hint, note the title of the problem. Example Output: Hello world! !dlrow olleH
Problem 2: Summing up sums. For this question, you’ll understand the importance of using the results of smaller sets of work. You’re going to create a recursive function that takes in an array of random integers and returns a “sum of sums”. This is best explained through an example. If you have 5 elements in an array, the function should return the sum of elements 0-4, 1-4, 2-4, 3-4, and 4. So, if we had an array of: 5, 18, 4, 7, 11 The sum of sums would be (45+40+22+18+11) = 136. Hint: is the sum of sums not just the sum of the current array + the sum of sums of an array?
In: Computer Science
Using Ubuntu, what are the commands for the following:
Assume that your company just hired 3 new software developers. You are responsible for setting up a LDAP server and adding those three new employees into the LDAP database. Please complete the follow tasks:
dn:ou=People,dc=nodomain
objectClass:organizationalUnit
ou:People
dn:cn=SoftwareDeveloper,ou=People,dc=nodomain
objectClass:posixGroup
cn:SoftwareDeveloper
gidNumber:7000
In: Computer Science
Processes D, E, and F all send a message to a mailbox owned by process A. Who can receive the messages that arrive in the mailbox owned by A?
In: Computer Science