Question: Evaluate a given prefix expression Resources: https://www.youtube.com/watch?v=o6vj5l_W2h8&list=PLdo5W4Nhv31bbKJzrsKfMpo_grxuLl8LU&index=37
Java Programs
Stack: Evaluate a postfix expression
Question: Evaluate a postfix expression
Stack: Postfix to infix expression
Question: Convert Postfix to infix expression Resources: https://www.youtube.com/watch?v=1zqgyoZzda4&list=PLdo5W4Nhv31bbKJzrsKfMpo_grxuLl8LU&index=38
Stack: Infix to prefix expression
Question: Convert an infix expression to a prefix expression Resource: https://www.youtube.com/watch?v=8QxlrRws9OI&list=PLdo5W4Nhv31bbKJzrsKfMpo_grxuLl8LU&index=35
Stack: Infix to Postfix Expression
Question: Convert an infix expression to a postfix expression Resources: https://www.youtube.com/watch?v=TB7qzDgX-pI
Stack: Basic stack implementation using an array
Question: Write a class ‘Stack’ that has:1. private data fields to store the stack, the top element, and the total capacity of the stack. 2. Continue Reading
Stack Programming Problems
Basic Stack Implementation (push, pop, length, peek) using array Infix expression to postfix expression Infix expression to prefix expression Evaluate Prefix Expression Evaluate Postfix Expression Continue Reading
Linked List: Reverse a linked list
Question: Reverse a linked list
Linked List: Modular Node
Question: Given a singly linked list and a number K, you are required to complete the function modularNode() which returns the modular node of the linked list. A modular node Continue Reading
Linked List: Implement a stack using a linked list
Question: You have to try to implement push and pop functionality of a stack using a linked list
Linked List: Sum of last N nodes
Question: Write a function that returns the sun of the last N nodes of a linked list. For example. for the linked list 4->6->10->8->9->10->18->20, and Continue Reading
Linked List: Circular Linked List?
Question: Write a function isCircular() which checks whether a linked list is circular or not.
Linked List: Delete Alternating Nodes
Question: Given a linked list, delete alternating nodes. For example is the linked list is 4->6->10->8->9->10->18->20, then the output should be 4->10->9->18.
Linked List: Flatten a linked list
Question: You are given a linked list where every node represents a linked list. All linked lists are sorted. You have to flatten the lists Continue Reading
Linked List: Insert node at the ith position
Question: Write a function that inserts a node at the ith position of a linked list. Consider the position of the head as the 0th Continue Reading
Linked List: Find the middle of the linked list
Question: Find the middle of a linked list. For example, if the given linked list is 1->2->3->4->5 then the output should be 3. If there are Continue Reading
Linked List: Find the length of the linked list
Question: Write a function that returns the length of the linked list. Throw an exception if the list is empty.
Linked List: Delete a specific node
Question: Write a function that deletes the node passed as a parameter
Linked List: Print the linked list
Question: Write a function print() function to print the entire linked list. Throw an exception if the linked list of empty
Linked List: Add a new node at the end of the linked list
Question: Write a function add(Listnode node) function to add a new node at the end of the linked list
Linked List: ListNode Class to create a node of a linked list
Question: Create a class Listnode which has two private data fields: data (int type) and next (Listnode type). The class should have a constructor which Continue Reading
Linked List Programming Problems
ListNode Class to create a node of a linked list In the Linked List Class: add(Listnode node) function to add a new node at the Continue Reading
Classes and Objects: Algebra: 2×2 linear equations
Question: Design a class named LinearEquation for a 2×2 system of linear equations: ax+by=e cx+dy=f x=(ed−bf)/(ad−bc) y=(af−ec)/(ad−bc)The class contains:o Private data fields a, b, c, Continue Reading
Classes and Objects: Algebra- quadratic equations
Question: Design a class named QuadraticEquation for a quadratic equation ax2+bx+c=0 . The classcontains:o Private data fields a, b, and c represents three coefficients.o A Continue Reading
Classes and Objects: Geometry: n-sided regular polygon
Question: In an n-sided regular polygon, all sides have the same length and all angles have the same degree (i.e., thepolygon is both equilateral and Continue Reading
Classes and Objects: Fan Class
Question: Design a class named Fan to represent a fan. The class contains:o Three constants named SLOW , MEDIUM , and FAST with the values Continue Reading
Classes and Objects: Create a bank account
Question: Design a class named Account that contains:o A private int data field named id for the account (default 0 ).o A private double data Continue Reading
Classes and Objects: Build a watch Stopwatch
Question: Design a class named StopWatch . The class contains:o Private data fields startTime and endTime with getter methods.o A no-arg constructor that initializes startTime Continue Reading
Classes and objects: Use the GregorianCalendar class
Question: Java API has the GregorianCalendar class in the java.util package, which you can use toobtain the year, month, and day of a date. The Continue Reading
Classes and objects: Use the Random class
Question: Write a program that creates a Random objectwith seed 1000 and displays the first 50 random integers between 0 and 100using the nextInt(100) method.
Classes and objects: Use the Date class
Question: Write a program that creates a Date object, sets itselapsed time to 10000 , 100000 , 1000000 , 10000000 , 100000000 ,1000000000 , 10000000000 Continue Reading
Classes and Objects: Stock Class
Question: Design a class named Stock that contains:o A string data field named symbol for the stock’s symbol.o A string data field named name for Continue Reading
Classes and Objects: Rectangle Class
Question: Design a class named Rectangle to represent a rectangle. The class contains:1. Two double data fields named width and height specify thewidth and height Continue Reading
Classes and Objects: Track the number of objects
Question: Create a class which keeps track of the number of its objects
Arrays: Identical arrays
Question: The arrays list1 and list2 are identical if they have the same contents.Write a method that returns true if list1 and list2 are identical, Continue Reading
Arrays: Strictly identical arrays
Question: The arrays list1 and list2 are strictly identical if their corresponding elements are equal.Write a method that returns true if list1 and list2 are Continue Reading
Classes and Objects: Random Class
Question: Write a program that generates two sequences of random int values which are identical. Use the java.util.Random class. OutputSeries 1:87 92 74 24 6 Continue Reading
Classes and Objects: Point2D Class
Question: Create two Point2D object for a point with the specified x- and y- coordinates, use the distance method to compute the distance between the Continue Reading
Classes and Objects: TV Class
Question: Create a class TV which defines for its objecs: states (channelNumber, volume, and power on or off)and behaviors (change channels (channelUp(), channelDown(), setChannel()), adjust Continue Reading
Classes and Objects: Circle Class
Question: Create a class Circle that has a data field radius. If no radius is passed during instantiation then set the radius to 1. Write Continue Reading
Classes and Objects Programming Problems
Circle Class TV Class Point2D Class (Built-in Java Class) Date Class (Built-in Java Class) Random Class (Built-in Java Class) Track the number of objects Rectangle Continue Reading
Array: Math: Combinations
Question: Write a program that prompts the user to enter 10 integers and displays all combinations of picking two numbers from the 10 numbers. Sample Continue Reading
Array: Algebra: solve quadratic equation
Question: Write a method for solving a quadratic equation using the following header:public static int solveQuadratic(double[] eqn, double[] roots)The coefficients of a quadratic equation ax2+bx+c=0 Continue Reading
Array: Unique suit picker
Question: Coupon collector is a classic statistics problem with many practical applications. The problem is to repeatedly pick objects from a set of objects and Continue Reading
Array: Locker Puzzle
Question: A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the studentsenter, the first student, Continue Reading
Array: Find the number of upper case letters in a String which is entered from the command line
Question: Write a program that passes a string to the command line and displays the number of uppercase letters in the string. Input from Command Continue Reading
Array: Sum Integer from command line array input
Question: Write a program that passes an unspecified number of integers from the command line and displays their total. Sample input/output: args: [“1”, “2”, “3”, Continue Reading
Array: Revise Selection Sort
Question: The selection-sort method repeatedly finds the smallest number in the current array and swaps it with the first.Rewrite this program by finding the largest Continue Reading
Array: Sorted?
Question: Write the following method that returns true if the list is already sorted in non-decreasing order:public static boolean isSorted(int[] list)Write a test program that Continue Reading
Array: Bubble Sort
Question: Write a sort method that uses the bubble-sort algorithm.The bubble-sort algorithm makes several passes through the array. On each pass, successive neighboring pairs are Continue Reading
Array: Sort Students
Question: Write a program that prompts the user to enter the number of students, the student’s names, and theirscores and prints student names in decreasing Continue Reading
Array: Execution Time
Question: Write a program that randomly generates an array of 100,000 integers and a key.Estimate the execution time of invoking the linearSearch method.Sort the array Continue Reading
Array: Eliminate duplicates
Question: Write a method that returns a new array by eliminating the duplicate valuesin the array using the following method header:public static int[] eliminateDuplicates(int[] list)Write Continue Reading
Array: Computing GCD
Question: Write a method that returns the gcd of an unspecified number of integers. The method header is specified as follows:public static int gcd(int… numbers)Write Continue Reading
Array: Random number chooser
Question: Write a method that returns a random number between 1 and 54, excluding the numbers passed in the argument.The method header is specified as Continue Reading
Array: Reverse array without creating a new array
Question: Write a program to reverse the elements in an integer array without copying it into a new array.Write a test program that prompts the Continue Reading
Array: Statistics- Compute deviation
Question: Write a program that takes 10 elements as input for a double array and calculates the mean andstandard deviation of the elements.Mean= (n1+n2+n3+…+nl)/lStandard deviation= Continue Reading
Array: Find the index of the smallest element
Question: Write a method that returns the index of the smallest element in an array of integers. If the number of such elements is greater Continue Reading
Array: Find the smallest element
Question: Write a method that finds the smallest element in an array of double values using the following header:public static double min(double[] array)Write a test Continue Reading
Array: Average an array
Question: Write two overloaded methods that return the average of an array with the following headers:public static int average(int[] array)public static double average(double[] array)Write a Continue Reading
Array: Count Single Digits
Question: Write a program that generates 10 random integers between 0 and 9 and displays the count for each number. Example:3 4 4 5 0 Continue Reading
Array: Prime Numbers less than 50
Question: Write a program that gives the first 50 prime numbers using the following approach: Check whether any of the prime numbers less than or Continue Reading
Array: Print Distinct Numbers
Question: Write a program that reads in 10 numbers and displays the number of distinct numbers and the distinct numbers in their input order and Continue Reading
Array: Analyze scores
Question: Write a program that reads an unspecified number of scores and determines how many scores are above or equal to the average, and how Continue Reading
Array: Count occurrence of numbers
Question: Write a program that generates random integers between 1 and 100 and counts the occurrences of each.
Array: Reverse the numbers entered
Question: Write a program that reads 10 integers then displays them in the reverse of the order in which they were read. Example: Enter array Continue Reading
Array: Assign Grades
Question: Write a program that reads student scores, gets the best score, and then assigns grades based on the following scheme: The grade is A Continue Reading
Arrays: Calculator
Question: Write a program that takes three arguments (num1 operation num2) from the command line and displays the result of the expression
Array: Selection Sort
Array: Binary Search
Array: Linear Search
Array: Random Characters generator + counter
Question: Generate 10 random characters and store them in an array. Count and display the occurrence of each letter in the character array Example: Output Continue Reading
Array: Reverse an array
Question: Write a program to reverse an array Example: original array: {1,2,3,4,5} Output:5,4,3,2,1
Array: Use arraycopy method
Question: Use arraycopy method to contents of one array to another
Array: Deck of cards
Question: Write a program that will pick four random cards from a deck of cards Examples: Output 1: 9 of Hearts6 of Spade4 of Diamond2 Continue Reading
Array: Number of elements greater than average
Question: Write a program that finds the average of contents in an array and counts the number of elements greater than the average
Array: Randomly shuffle the elements of an array
Q) Randomly shuffle the elements of an array Example Original Array: 2,5,1,7,8,2 Output 1:5 2 8 1 2 7 Output 2:5 1 8 2 2 Continue Reading
Array: Obtain the English name of a given month by its number
Q) Obtain the English name of a given month by its number Example: Input:Enter month number: 4 Output:April
Array: Shift elements of an array to the right
Q) Shift elements of an array to the right Example: Array:1,2,3,4,5 Output:5 1 2 3 4
Array: Shifting elements of an array to the left
Q) Shifting elements of an array to the left Example: Array: 1,2,3,4,5 Output:2 3 4 5 1
Array: Find the lowest index of the largest element in an array
Q) Find the lowest index of the largest element in an array Example: Array: 1,5,2,3,5,5 Output: Lowest Index of max element= 2
Array: Find the largest element in an array
Q) Find the largest element in an array Example: Array: 33 93 29 40 36 81 46 14 60 24 Output:Max Element= 93
Array: Find the sum of all elements in an array
Q) Find the sum of all elements in an array Example: Array: 27 26 11 41 53 18 90 82 79 46 Output: Sum= 473
Array: Display the contents of an array
Q) Display the contents of an array
Array: Initialize an array with random values between 1 and 100
Q) Initialize an array with random values between 1 and 100 Example: First time running the program: 94 74 73 76 50 70 88 55 Continue Reading
Array Programming Problems Links
Initialize an array with input values from the user Initialize an array with random values between 1 and 100(Hint: use Math.random()) Display the contents of Continue Reading
Array: Initialize an array with input values from the user
Q) Initialize an array with input values from the user Example: Enter 10 elements of the array:1 2 3 4 5 6 7 8 9 Continue Reading