¡GoConqr estrena diseño! Cuéntanos qué te parece.

Test

Sin título

Adrian Mendoza 4 preguntas

Hacer el test

Preguntas del test (4)

  1. 1True or false: If an array is already sorted, Linear Search / Sequential Search is more efficient than Binary Search.
    1. Atrue
    2. Bfalse
  2. 2What must be true before performing a binary search?
    1. AThe elements must be sorted.
    2. BIt can only contain binary values.
    3. CThe elements must be some sort of number (i.e. int, double, Integer)
    4. DThere are no necessary conditions.
  3. 3Which of the following functions is a proper implementation of binary search?
    1. Apublic static int binarySearch(int[] array, int key)
      {
      int n = array.length;
      int first = 0;
      int last = n - 1;
      int middle = (first + last)/2;

      while( first <= last )
      {
      if ( array[middle] < key )
      {
      first = middle + 1;
      }
      else if ( array[middle] == key )
      {
      return (middle + 1);
      }
      else
      {
      last = middle - 1;
      }

      middle = (first + last)/2;
      }
      return -1;
      }
    2. Bpublic static int binarySearch(int[] array, int key)
      {
      int n = array.length;
      int first = 0;
      int last = n - 1;
      int middle = (first + last)/2;

      while( first <= last )
      {
      if ( array[middle] < key )
      {
      first = middle + 1;
      }
      else if ( array[middle] == key )
      {
      return middle;
      }
      else
      {
      last = middle - 1;
      }

      middle = (first + last)/2;
      }
      return -1;
      }
    3. Cpublic static int binarySearch(int[] array, int key)
      {
      n = array.length;
      first = 0;
      last = n - 1;
      middle = (first + last)/2;

      while( first <= last )
      {
      if ( array[middle] < key )
      {
      first = middle + 1;
      }
      else if ( array[middle] == key )
      {
      System.out.println(key + " found at index " + middle);
      }
      else
      {
      last = middle - 1;
      }
      middle = (first + last)/2;
      }
      System.out.println("Key not found!")
      }
    4. Dpublic static int binarySearch(int[] array, int key)
      {
      int n = array.length;
      int first = 0;
      int last = n - 1;
      int middle = (first + last)/2;

      while( first <= last )
      {
      if ( array[middle] < key )
      {
      first = middle + 1;
      }
      else if ( array[middle] == key )
      {
      int result = middle;
      }
      else
      {
      last = middle - 1;
      }

      middle = (first + last)/2;
      }
      }
  4. 4Given this array:

    1 2 4 5 6 7 8 12 14 21 22 42 53
    How many comparisons are required to find 42 using the Linear Search / Sequential Search?
    1. A3
    2. B2
    3. C12
    4. D5

Información

Descripción
Test sobre Sin título, creado por Adrian Mendoza el 01/02/2023.
Idioma
English
Visitas
0
Etiquetas
grade 9
Valoración
Aún sin valoraciones
Valora este test
Valora este test

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?