logo

Crowdly

Browser

Add to Chrome

Questions Bank (1527141 total)

The following function brings the non-zero elements of the array to the front, sequentially. Explain how it does that. Also state what is being returned.

  1 int pruneArray1(float arr[], int n) {

  2         float newArr[n];

  3         int i, j;   

  4         for (i = 0, j = 0; i < n; ++i)

  5           if (arr[i] != 0.0)

  6                 newArr[j++] = arr[i];

  7         for (i = 0; i < j; ++i)

  8                 arr[i] = newArr[i];

  9         for (   ; j < n; ++j)

 10                 arr[j] = 0.0;

 11         return i;

 12   }

View this question

The following piece of code encrypts the line of text taken as input by shifting each character of the line by a key value. It uses the index notation. (Assume MAX is a #define constant.)

  char line[MAX]; 

  int i = 0, key = 4;

  printf("Enter a line of text:");

  scanf("%[^\n]", line);

  while (line[i])

  {

    putchar(line[i]+key);

    i++;

  }

In an attempt to rewrite the entire code using pointer notation, a beginner program made the following attempt:

  char line[MAX];

  int key = 4;

  printf("Enter a line of text: ");

  scanf("%[^\n]", line);

  while (*line)

  {

  putchar(*line + key);

  line++;

  }

Unfortunately, the code would not compile. Can you find the mistake and fix it? You do not have to rewrite the entire code segment, but only the parts you are modifying.

View this question
The objective is to compute the statistics of Test-2 of Coding Cafe - in terms of the highest score, lowest score and the average score. Please study the following main() function, which calls another function called getStats() in line 11:

  1 #include <stdio.h>

  2 #define MAX 186

  3 

  4 int main()

  5 {

  6   float test1[MAX];

  7   float highest,lowest,average;

  8   for (i=0; i<MAX; ++i)

  9     scanf("%d", &test1[i]);

 10 

 11   getStats(test1, &highest, &lowest, &average);

 12   printf("%f %f %f\n", highest, lowest, average);

 13 

 14   return 0;

 15 }                                                                     

(a) Write the function declaration (prototype) of getStats() function. No need to write the body of the function.

(b) Instead of the current version of line 11, suppose the function was invoked by writing

getStats(test1, highest, lowest, average); 
would it make any difference to the way the program works? Explain your answer.

View this question

In less than 10 words, state what the following function does:

void strmanip(char a[]) /* receives a string as its argument */

{ 

  char *b, temp;

  b = a + strlen(a) - 1;        

  for (  ; a < b ; a++, b--)            

  {                     

          temp = *a;

          *a = *b;

          *b = temp;

  }     

  return;

}

View this question

Write a single statement using the ternary operator (? : ) to find out the maximum of three numbers (stored in variables a, b and c) and store the result should in a variable called max.

View this question

Військовозобов’язаним,

які підлягають бронюванню згідно з переліками посад і професій, ТЦК та СП

(органами СБУ, СЗР) за місцем розташування органів державної влади, інших

державних органів, органів місцевого самоврядування, підприємств, установ,

організацій оформлюються:

❌
❌
✅
❌
View this question

Quel est le message essentiel contenu dans l’article du journal ?

100%
0%
0%
0%
View this question

Comment insère-t-on un nouvel élément dans un arbre binaire de recherche (BST) ?

How do you insert a new element into a binary search tree (BST)?

0%
0%
0%
0%
View this question

Nous avons demandé à ChatGPT la définition d'un arbre binaire balancé.

Voici sa réponse (nous avons ajouté la structuration pour les questions) : 

A) Un arbre binaire équilibré est un type d'arbre binaire dans lequel la différence de hauteur entre les sous-arbres gauche et droit de chaque nœud est limitée à une constante, généralement 1. Cela signifie que pour chaque nœud de l'arbre, la hauteur du sous-arbre gauche et la hauteur du sous-arbre droit diffèrent au plus d'une unité.

B) Plus formellement, un arbre binaire équilibré est un arbre binaire dans lequel la différence de hauteur entre le sous-arbre gauche et le sous-arbre droit de chaque nœud est au plus 1 et les sous-arbres gauche et droit sont eux-mêmes des arbres binaires balancés.

C) L'équilibrage d'un arbre binaire est important, car il garantit que les opérations telles que l'insertion, la suppression et la recherche peuvent être effectuées en temps logarithmique par rapport au nombre de nœuds dans l'arbre, assurant ainsi des performances efficaces dans les structures de données basées sur des arbres binaires comme les arbres de recherche binaires (BST) ...

Quelles propositions sont vraies ? 

----

Version en anglais -

We asked ChatGPT for the definition of a balanced binary tree.

Here is his answer (we've added the structure in the answers):

A) A balanced binary tree is a type of binary tree in which the height difference between the left and right subtrees of each node is bounded by a constant, usually 1. This means that for each node in the tree, the height of the left subtree and the height of the right subtree differ by at most one unit.

B) More formally, a balanced binary tree is a binary tree in which the height difference between the left and right subtrees of each node is at most 1, and the left and right subtrees are themselves balanced binary trees.

C) Balancing a binary tree is important because it ensures that operations such as insertion, deletion, and search can be performed in logarithmic time relative to the number of nodes in the tree, thus ensuring efficient performance in binary tree-based data structures such as binary search trees (BSTs).

Which statements are true?

0%
0%
0%
0%
0%
0%
0%
View this question

Soit un BST T et 2 éléments distincts x et y qui ne sont pas dans T.

On note :

  • Tx,y le BST obtenu par insertion des 2 éléments dans l'ordre x puis y
  • Ty,x le BST obtenu par insertion des 2 éléments dans l'ordre y puis x.

Version en anglais :

Consider a BST T and two distinct elements x and y that are not in T

Let:

Tx,y be the BST obtained by inserting the two elements in order x then y

Ty,x  be the BST obtained by inserting the two elements in order y then x.

✅
❌
❌
View this question