Coding Questions: Array Manipulations
9 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What will be the main result of the program that removes prime numbers from an array?

  • It will output the original array unchanged.
  • It will print the non-prime numbers in the array. (correct)
  • It will output the smallest prime number remaining.
  • It will print an array containing only even numbers.

Which output is generated by reversing the array elements [10, 20, 30, 40, 50]?

  • 50, 40, 30, 20, 10 (correct)
  • 20, 30, 40, 50, 10
  • 10, 20, 30, 40, 50
  • 30, 20, 10, 50, 40

What should be included in the output when finding the smallest and largest elements in an input array?

  • Both the smallest and largest elements printed on the same line.
  • Only the smallest element.
  • Only the largest element.
  • The smallest element on the first line and the largest element on the second line. (correct)

In the context of sorting an array, what would be the output of sorting the array [50, 10, 20, 40, 30]?

<p>10, 20, 30, 40, 50 (B)</p> Signup and view all the answers

What does the input format specify for taking to create an array for processing?

<p>An integer n must be provided as the first input followed by n elements. (B)</p> Signup and view all the answers

Given the input array [100, 200, 31, 13, 97, 10, 20, 11], which numbers will remain after removing all prime numbers?

<p>100, 200, 10, 20 (C)</p> Signup and view all the answers

What is the expected output if the input is the array [7, 11, 15, 16, 19] when removing prime numbers?

<p>15, 16 (A)</p> Signup and view all the answers

What is the main purpose of the 'New Paradise' program described?

<p>To identify locations with the maximum number of travel routes. (A)</p> Signup and view all the answers

Which of the following operations is performed to swap elements in an array?

<p>Swapping the first with the last, second with second last, etc. (A)</p> Signup and view all the answers

Flashcards

Swap Array 1: Reverse Array Elements

A function that takes an array and swaps the first element with the last, the second with the second last, and so on, effectively reversing the array.

Remove Prime Numbers

A function that takes an array and removes all prime numbers, leaving only the non-prime numbers.

Array Sorting: Ascending Order

A function that takes an array and sorts all of its elements in ascending order.

Find Smallest/Largest Elements

A function that takes an array and finds the smallest and largest elements within it.

Signup and view all the flashcards

Swap Array Elements (Reversing)

A function that takes an array and outputs the elements after swapping its first and last elements, second and second last, and so on.

Signup and view all the flashcards

New Paradise: Finding Best House Locations

Given the number of locations and the routes from each, find the number of locations with the most routes. This represents the best locations with the maximum travel options.

Signup and view all the flashcards

Prime Number Removal

A function that identifies and outputs only the non-prime numbers from an array. It filters out all the prime numbers.

Signup and view all the flashcards

Swapping Array Elements

A function that modifies an array by swapping pairs of elements, effectively reversing the order of elements in the array.

Signup and view all the flashcards

Array Sorting

The process of arranging elements in an array from smallest to largest, or vice-versa.

Signup and view all the flashcards

Finding Minimum and Maximum Elements

Identifying the elements with the minimum and maximum values within a sequence of numbers—finding the smallest and largest.

Signup and view all the flashcards

Study Notes

Coding Questions

  • Several coding problems are described, each with input, output, and formatting requirements.
  • Input formats involve taking integer values (array size, array elements) from the user.
  • Output formats vary, including:
    • Array elements after swapping/reversing
    • Smallest and largest elements in an array
    • Array elements after removing prime numbers
    • Sorted array elements in ascending order
  • Constraints usually limit the size of the input array (e.g., n >= 1 && n <= 10000) and the values within the array.

Problem 26: Remove Prime Numbers

  • Input: An array of integers.
  • Output: The array with all prime numbers removed.
  • Example Input: 100, 200, 31, 13, 97, 10, 20, 11
  • Example Output: 100, 200, 10, 20

Problem 27: Array Sorting

  • Input: An unsorted array of integers.
  • Output: The sorted array in ascending order.
  • Example Input: 50, 10, 20, 40, 30
  • Example Output: 10, 20, 30, 40, 50

Problem 25: Swap Array 1

  • Input: An array of integers.
  • Output: The array with elements swapped in reverse order.
  • Example Input / Output:
    • Input 1234 -> Output 4321
  • This describes elements of an array and reversing them.

Problem 30: New Paradise

  • Input: A single integer representing the number of locations. Integer values for the number of routes through each location are given as input.
  • Output: A single integer representing the number of locations with the maximum number of routes.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Description

This quiz presents a series of coding problems focused on array manipulations such as removing prime numbers and sorting arrays. Each problem provides input requirements along with expected outputs, ensuring a comprehensive understanding of array handling. Challenge your coding skills with these varied tasks!

More Like This

One-Dimensional Array Average and Above
5 questions
Java Array Manipulation and Iteration Quiz
5 questions
Java Array Manipulation and For Loops Quiz
5 questions
Array Manipulation Technique
34 questions
Use Quizgecko on...
Browser
Browser