Giter VIP home page Giter VIP logo

gr-affable's People

Contributors

abhijit424515 avatar adibyju avatar atishay25 avatar harpoonix avatar rohankalbag avatar ryuusama09 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gr-affable's Issues

Extracting frequency of each character into a compressed string

Go to Communication/Huffman Codes/huffman.cpp, there is a problem in calculating the frequency of each character in the given string. Can you fix it?
$data$ is the compressed string which has each character if given string one time and $freq[i]$ has the frequency of character at $data[i]$.

Inefficient and wrong implementation for tunnel traversal

for(int i = 0; i < m; i++){
if(start[i] == first){
int sum = tunnel[i];
int dest = end[i];
while(dest!=last){
for(int j = 0; j < m; j++){
if(start[j] == dest){
sum += tunnel[j];
dest = end[j];
break;
}
}
}
score.push_back(sum);
}
}

  • A simple Brute force search kind of algorithm is being used here which is inefficient and has high time complexity
  • It does not take into account the fact that we can go through the same tunnel several times!
  • May get stuck into a loop. For example, $n = 6$ and tunnels are $1\rightarrow3$, $3\rightarrow5$, $5\rightarrow4$, $4\rightarrow1$.
  • As given in Instructions, the idea is to use Bellman Ford algorithm here. Can you do it?

Merge the PRs :D

You guys do realise that PRs must be merged for them to be considered as successful contributions ๐Ÿ˜„

Incorrect output

for(int i = 0; i < m; i++){
int boughtIndex = getMinIndex(price); // Index with minimum price
for(int j = 0; j < n; j++){
if(price[j] > price[boughtIndex] && !bought[boughtIndex] && price[j] <= customer[i]){
boughtIndex = j;
}
}
// Now boughtIndex variable has the index of the
// price which is maximum among all those prices
// that are below the maximum price as told by customer
if(!bought[boughtIndex]){ // Sold it to customer, if not bought already by someone else
bought[boughtIndex] = true;
customer[i] = price[boughtIndex];
}
else { // else give -1 to customer
customer[i] = -1;
}

There seems a problem somewhere here. The code is not providing the desired output for sample testcase given. Solve this issue, if you can
(Hint - It is just one word)

Redundant Loop

for (int j=i; j<n; j++) {
int sum_of_this_subarray = 0;
for (int k=i; k<=j; k++) {
sum_of_this_subarray += array[k];
}
best_sum = max(best_sum, sum_of_this_subarray);

We don't need to calculate the sum of the subarray again when the end shifts from j to j+1. We can simply add array[j+1] to the previous sum.
Saves computation.

Improper input method

long long int *tunnel = new long long int[m];
int *start = new int[m];
int *end = new int[m];
vector<int> score;
for(int i = 0; i < m; i++){
cin >> start[i] >> end[i] >> tunnel[i];
}

start end end represent starting and ending node of a tunnel and thus constitute an edge together as a pair. Here, inputs of there values are being taken into two separate arrays, which may cause error. Shouldn't it be better to make a pair of them?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.