What are the advantage and disadvantage of the bucket sort?
Adv: BucketSort is an example of a sorting algorithm that runs in O(n). This is possible only because BucketSort does not rely primarily on comparisons in order to perform sorting.
Dis: BucketSort is not useful when scanning the buckets for large arrays which is too costly.
Minimum number of queues needed to implement the priority queue?
Separated queue for every possible priority value.
Is it possible for a function to return more than one value at a time?
No, you can only return one value with a return statement. However, you can return a structure or pointer, so the real answer is yes, though requiring some added complexity.
A set of Rules that define a programming language is called?
The rules of a language is called its syntax.
What is a platform dependent language?
There is no such thing as a platform-free programming language. The correct term is platform-independent language. It simply means that the same source code can be compiled or interpreted upon any platform; the code is not machine-dependent.
What is machine language the the uses and importance?
Machine language is the only language the machine understands. All other languages must be converted to machine code using an assembler, a compiler or an interpreter, depending on whether the source code is written in low-level assembly language or a high-level compiled or interpreted language.
Assemblers and compilers convert the entire source code to machine code whereas interpreters only convert one statement at a time. As a result, interpreted languages do not perform well compared with their compiled and assembled counterparts, but are better suited to testing and debugging high-level algorithms because the code can be executed immediately, there is no need to wait on the assembler or compiler to convert the whole program (which can easily take several minutes).
Java is slightly different to other high-level languages in that it is both compiled and interpreted. However, the Java compiler does not emit machine code like other compilers, it emits Java byte code which is suitable for interpretation by the Java virtual machine. Java is easy to program and highly-portable because the Java virtual machine is consistent across all platforms and the Java byte code is easier to interpret so it performs better than a purely interpreted language. However, it still cannot compete with native machine code programs in terms of performance and resource consumption.
Compilers are easier to work with than assemblers because assembly language requires programs to be written in minute detail at the machine level. Compiled languages incorporate a higher level of abstraction (hence they are high-level) thus you can perform more low-level computations in fewer lines of code. Although some high-level languages such as C and C++ also allow low-level programming through inline assembly, the compiler incorporates optimisers that can take advantage of the machine's hardware to produce machine code that is as efficient if not more efficient than would be possible with assembly language alone.
What are function of flow chart?
Flow charts show a process in steps by connecting them. They are used in designing a process in various fields.
When a piece of software running for an extended time uses more and more memory. The software is not releasing its resources correctly! And so the machine cannot recoup memory.
It is possible that eventually the machine will crash, or the offending software will need restarted.
The two types of looping include the closed loop and the open loop.There is the count loop, the conditional loop and the unconditional loop.
Program that uses struct in c plus plus?
C++ of course uses classes (class) as opposed to structures (struct) for the purpose of keeping data members with an implicit 'private' access specifer as opposed to data members being 'public' by default (as with a struct.) Unless use of external C libs or routines are mandatory and wrapped in the appropriate C header(s), I don't know of any reason to use a struct anywhere in C++.
C-Program on reversing a digit?
int RevNum( int num )
{
const int base = 10;
int result = 0;
do
{
result *= base;
result += num % base;
} while( num /= base);
return( result );
}
Largest palindrome substring of a string?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector; /**
*
*/ /**
* @author omnipath
*
*/
public class Palindrome { /**
* @param args
*/
public static void main(String[] args) { // open up standard input
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String string = null; // readLine() method try { string = br.readLine(); } catch (IOException ioe) { System.out.println("IO error trying to read input!"); System.exit(1); }
Palindrome palindromeCase = new Palindrome(string);
System.out.println("The longest palindrome is: " + palindromeCase.palindrome);
System.out.println("The length of the longest palindrome is: " + palindromeCase.palindrome.length());
System.out.println("Counter is: " + palindromeCase.PalindromeCounter);
} String originalString;
String palindrome;
Vector vectPalindromes;
int palindromeLength;
int PalindromeCounter; public Palindrome(String s) {
PalindromeCounter = 0;
this.palindrome = "";
this.palindromeLength = this.palindrome.length();
this.originalString = s;
this.calculateLongestPalindrome(s);
} public void calculateLongestPalindrome(String s) {
if (s.length() == 1) {
this.palindrome = this.originalString;
this.palindromeLength = this.palindrome.length();
} this.parseForPalindrome(this.originalString); } public void parseForPalindrome(String s) {
PalindromeCounter++;
if (s.length() -1; i--) {
sb.append(s.charAt(i));
}
return sb.toString();
}
}
I couldn't tell what answer your teacher expects to get for this question. Ask him/her personally.
What is the coding of a pogram in c to implement the builtin function of clrscr?
You could manipulate screen's video memory directly in order to achieve that. Video memory address in DOS text mode is allocated on segment 0xB800.
Look at the related links section, I've coded an example program for you that uses ClrScr() and ClrScrAsm() functions. Both featuring color support! ;)
Swap two number using pointer?
The only way to swap two values using call by value semantics is to pass pointer variables by value. A pointer is a variable that stores an address. Passing a pointer by value copies the address, the value of the pointer, not the pointer itself. By passing the addresses of the two values to be swapped, you are effectively passing those values by reference. Both C and C++ use pass by value semantics by default, however C++ also has a reference data type to support native pass by reference semantics. By contrast, Java uses pass by reference semantics by default.
In C, to swap two variables using pass by value:
void swap (int* p, int* q) {
int t = *p;
*p = *q;
*q = t;
}
In C++, to swap two variables using pass by reference:
void swap (int& p, int& q) {
std::swap (p, q);
}
Note that C++ is more efficient because std::swap uses move semantics; there is no temporary variable required to move variables. With copy semantics, a temporary is required. However, with primitive data types, there is a way to swap values without using a temporary, using a chain of exclusive-or assignments:
void swap (int* p, int* q) {
*p^=*q^=*p^=*q;
}
C program - to perform matrix addition?
M
#include<stdio.h>
#include<conio.h>
int main()
{
int a[3][3], b[3][3], sum[3][3], i,j;
clrscr();
printf("Enter the first matrix");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d", &a[i][j]);
printf("Enter the second matrix");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d", &b[i][j]);
printf("\nThe first matrix is \n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf("%d\t", a[i][j]);
}
printf("\nEnter the second matrix");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf("%d\t", b[i][j]);
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
sum[i][j]=a[i][j]+ b[i][j];
printf("\n The addition of two matrix is \n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf("%d\t", sum[i][j]);
}
getch();
return 0;
}
What are legal variable names and declarations in c and c plus plus?
Any name that is not a reserved word can be a legal variable, function or type name. All names must be alphanumeric, but they cannot begin with a digit. The C++ standard recommends that all user-defined names be written entirely in lower case with underscores for spaces. Some programmers prefer 'camel case' (such as PrintObject and MaxNumber), which was a popular convention amongst the Pascal programming community, however print_object and max_number are the C++ conventions. Names in all caps are typically reserved for macro definitions (which is effectively a separate language from C++ itself), while names with leading underscores should generally be avoided as this convention is utilised extensively within the standard library.
Why int take 2 byte of memory in c?
Platform dependent, use sizeof (int). You may want to use types int8_t, int16_t, int32_t or int64_t from inttypes.h,theirs sizes are predefined (1, 2, 4 and 8 bytes).
As for pointers, I think you have to readjust them. Pointers are just variables that store a memory address in them. You can have as many pointers that point to a single location in memory as you want.
It is a term for sequences in which a finite number of terms are defined explicitly and then all subsequent terms are defined by the preceding terms.
The best known example is probably the Fibonacci sequence in which the first two terms are defined explicitly and after that the definition is recursive:
x1 = 1
x2 = 1
xn = xn-1 + xn-2 for n = 3, 4, ...