Questões de Concurso
Filtrar
1.176 Questões de concurso encontradas
Página 63 de 236
Questões por página:
Questões por página:
Concurso:
Prefeitura de Bandeirantes - PR
Disciplina:
Algoritmos e Estrutura de Dados
Considere os códigos a seguir:
Código 01 import java.util.Stack; public class PilhaExemplo { public static void main(String[] args) { Stack<Integer> pilha = new Stack<>(); pilha.push(10); pilha.push(20); pilha.push(30); System.out.println("Elementos removidos da pilha:"); while (!pilha.isEmpty()) { System.out.println(pilha.pop()); } } } Código 02 import java.util.LinkedList; import java.util.Queue; public class FilaExemplo { public static void main(String[] args) { Queue<Integer> fila = new LinkedList<>(); fila.add(10); fila.add(20); fila.add(30); System.out.println("Elementos removidos da fila:"); while (!fila.isEmpty()) { System.out.println(fila.poll()); } } }
Com base nos dois trechos de código apresentados, assinale a alternativa correta ao comparar o código da pilha com o código da fila.
Código 01 import java.util.Stack; public class PilhaExemplo { public static void main(String[] args) { Stack<Integer> pilha = new Stack<>(); pilha.push(10); pilha.push(20); pilha.push(30); System.out.println("Elementos removidos da pilha:"); while (!pilha.isEmpty()) { System.out.println(pilha.pop()); } } } Código 02 import java.util.LinkedList; import java.util.Queue; public class FilaExemplo { public static void main(String[] args) { Queue<Integer> fila = new LinkedList<>(); fila.add(10); fila.add(20); fila.add(30); System.out.println("Elementos removidos da fila:"); while (!fila.isEmpty()) { System.out.println(fila.poll()); } } }
Com base nos dois trechos de código apresentados, assinale a alternativa correta ao comparar o código da pilha com o código da fila.
Concurso:
Prefeitura de Bandeirantes - PR
Disciplina:
Algoritmos e Estrutura de Dados
Considere o código a seguir:
public class HeapSort { public void heapSort(int arr[]) { int n = arr.length; for (int i = n / 2 - 1; i >= 0; i--) { heapify(arr, n, i); } for (int i = n - 1; i > 0; i--) { int temp = arr[0]; arr[0] = arr[i]; arr[i] = temp; heapify(arr, i, 0); } } void heapify(int arr[], int n, int i) { int maior = i; int esquerda = 2 * i + 1; int direita = 2 * i + 2; if (esquerda < n && arr[esquerda] > arr[maior]) { maior = esquerda; } if (direita < n && arr[direita] > arr[maior]) { maior = direita; } if (maior != i) { int temp = arr[i]; arr[i] = arr[maior]; arr[maior] = temp; heapify(arr, n, maior); } } public static void main(String args[]) { int arr[] = {12, 11, 13, 5, 6, 7}; int n = arr.length; HeapSort heapSort = new HeapSort(); heapSort.heapSort(arr); System.out.println("Array ordenado: "); for (int i : arr) { System.out.print(i + " "); } } }
Considerando o algoritmo apresentado, qual é a principal característica deste algoritmo de ordenação?
public class HeapSort { public void heapSort(int arr[]) { int n = arr.length; for (int i = n / 2 - 1; i >= 0; i--) { heapify(arr, n, i); } for (int i = n - 1; i > 0; i--) { int temp = arr[0]; arr[0] = arr[i]; arr[i] = temp; heapify(arr, i, 0); } } void heapify(int arr[], int n, int i) { int maior = i; int esquerda = 2 * i + 1; int direita = 2 * i + 2; if (esquerda < n && arr[esquerda] > arr[maior]) { maior = esquerda; } if (direita < n && arr[direita] > arr[maior]) { maior = direita; } if (maior != i) { int temp = arr[i]; arr[i] = arr[maior]; arr[maior] = temp; heapify(arr, n, maior); } } public static void main(String args[]) { int arr[] = {12, 11, 13, 5, 6, 7}; int n = arr.length; HeapSort heapSort = new HeapSort(); heapSort.heapSort(arr); System.out.println("Array ordenado: "); for (int i : arr) { System.out.print(i + " "); } } }
Considerando o algoritmo apresentado, qual é a principal característica deste algoritmo de ordenação?
Concurso:
Prefeitura de Bandeirantes - PR
Disciplina:
Algoritmos e Estrutura de Dados
Analise os códigos a seguir:
Código 01 import java.util.Stack; public class Pilha { public static void main(String[] args) { Stack<Integer> pilha = new Stack<>(); pilha.push(5); pilha.push(3); pilha.push(8); pilha.push(1); Stack<Integer> pilhaOrdenada = new Stack<>(); while (!pilha.isEmpty()) { int temp = pilha.pop(); while (!pilhaOrdenada.isEmpty() && temp > pilhaOrdenada.peek()) { pilha.push(pilhaOrdenada.pop()); } pilhaOrdenada.push(temp); } System.out.println("Pilha Ordenada: " + pilhaOrdenada); } }
Código 02
import java.util.Stack; public class Pilha { public static void main(String[] args) { Stack<Integer> pilha = new Stack<>(); pilha.push(5); pilha.push(3); pilha.push(8); pilha.push(1); Stack<Integer> pilhaOrdenada = new Stack<>(); while (!pilha.isEmpty()) { int temp = pilha.pop(); while (!pilhaOrdenada.isEmpty() && temp < pilhaOrdenada.peek()) { pilha.push(pilhaOrdenada.pop()); } pilhaOrdenada.push(temp); } System.out.println("Pilha Ordenada: " + pilhaOrdenada); } }
Ao comparar os dois códigos apresentados, assinale a alternativa correta.
Código 01 import java.util.Stack; public class Pilha { public static void main(String[] args) { Stack<Integer> pilha = new Stack<>(); pilha.push(5); pilha.push(3); pilha.push(8); pilha.push(1); Stack<Integer> pilhaOrdenada = new Stack<>(); while (!pilha.isEmpty()) { int temp = pilha.pop(); while (!pilhaOrdenada.isEmpty() && temp > pilhaOrdenada.peek()) { pilha.push(pilhaOrdenada.pop()); } pilhaOrdenada.push(temp); } System.out.println("Pilha Ordenada: " + pilhaOrdenada); } }
Código 02
import java.util.Stack; public class Pilha { public static void main(String[] args) { Stack<Integer> pilha = new Stack<>(); pilha.push(5); pilha.push(3); pilha.push(8); pilha.push(1); Stack<Integer> pilhaOrdenada = new Stack<>(); while (!pilha.isEmpty()) { int temp = pilha.pop(); while (!pilhaOrdenada.isEmpty() && temp < pilhaOrdenada.peek()) { pilha.push(pilhaOrdenada.pop()); } pilhaOrdenada.push(temp); } System.out.println("Pilha Ordenada: " + pilhaOrdenada); } }
Ao comparar os dois códigos apresentados, assinale a alternativa correta.
Concurso:
Prefeitura de Bandeirantes - PR
Disciplina:
Algoritmos e Estrutura de Dados
O Bubble Sort é um algoritmo simples de ordenação
que percorre repetidamente a lista, compara
elementos adjacentes e os troca se estiverem na
ordem errada. Esse processo é repetido até que a lista
esteja ordenada. Considerando essas informações e o
uso do algoritmo Bubble Sort, qual das seguintes
afirmações é verdadeira?
Concurso:
Prefeitura de Bandeirantes - PR
Disciplina:
Algoritmos e Estrutura de Dados
Considere os dois pseudocódigos recursivos apresentados a seguir:
Código 01
função fibonacci(n: inteiro) -> inteiro:
se n <= 1 então
retornar n
senão
retornar fibonacci(n-1) + fibonacci(n-2)
fim se
Código 02
função fatorial(n: inteiro) -> inteiro:
se n <= 1 então
retornar 1
senão
retornar n * fatorial(n-1)
fim se
A partir da análise dos códigos apresentados, assinale a alternativa que apresenta a principal diferença entre os pseudocódigos recursivos 1 e 2 em termos de seu propósito e operação.