I tried the output for 1 3 4 2 0 and found that the While loop executes 4 times only for i=0, it doesn't execute for other i's. The output was sorted. This of course took O(n) time.
Isn't the worst case complexity of comparison based sorting algorithms O(nlogn)?
Can someone explain why the running time of following piece of pseudo code is O(n) and not O(n2)?
for i := 0 to n - 1
while A[A[i]] != A[i]
swap(A[i], A[A[i]])
end while
end for
The for loop executes at most n times and the inner while loop executes at most n-1 times...
Can some one explain me the difference between the following two pieces of code ?
First one doesn't work. I debugged it and made it to work but I am unable to understand how.
The lines with changes have been made red bold.#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE...
I got my code working.
Below if the final version.
If I need to improve on something please let me know.
#include <stdio.h>
#define MAX 20
static struct cellnode *a[MAX];
static int k=0;
struct cellnode {
int val;
int col;
struct cellnode *nextcell;
};
struct rownode...
This is an assignment, and my professors won't help.
I just used one global variable head2. That's how we did in class for a single linked list. Here we have a single linked list of rownodes.
Attached is the .txt file containing input matrix.
Every time the end of a row is reached, i.e. a...
I modified my program as per your suggestion.
It works pretty good before the display() function is called, where it gives a segmentation fault. I spent hours debugging it but came up with no error.
#include <stdio.h>
#define MAX 20
static struct cellnode *a[MAX];
static int k=0;struct...
I hope you understood my problem.
In the following code snippet:
void link2(int r){
struct rownode *temp,*new;
new=create_rownode();
new->row=r;
new->firstcell=head1;
new->nextrow=NULL;...
the firstcell of the newly created node should point to the first non zero valued node of the...
Homework Statement
The idea is to create following type of structure:
first_row_with_a_nonzero_cell->next_row_with_a_nonzerocell->...->NULL
rowN_with_a_nonzerocell->firstnonzerocolinrowN->nextnonzerocolinrowN...->NULL
Input file is a 20x50 sparse matrix.
The only problem I have is...
Why is Fourier sine series of any function satisfying Dirichlet's theorem, not defined on the discontinuous points whereas we define it for Fourier cosine series?
ex - sine series of f(x) = cosx, 0<=x<=∏ is defined on 0<x<∏
whereas cosine series of f(x) = sinx, 0<=x<=∏ is defined on 0<=x<=∏