Computer Science Homework Solutions

Data Structure and Algorithms

Question 1 Implement an array-based abstract data type 'stack' specified in class and do the following: Write a procedure called read_and_evaluate_expression that reads in and evaluates a postfix expression (defined below) and writes out its value. (JAVA) Your procedure must follow the algorithm sketched below, and it must ...continues

Java data structures and alg.

1. QUESTION 1a Write a recursive "Merge" method meeting this specification: Inputs: a sorted list L1 and a sorted list L2. Outputs: a sorted list that is the merging of L1 and L2, and, the number of times two list elements were compared during the merging process (call it C). The recursive Merge ...continues

Matrix Identity in C++

Write a function in c++ Isidentity (t) t is two dimensional array. (int t[rwos] [columns] return true, if it is an identity matrix, return false if it is not like example square tolls colum all 1's on principal diagonal, otherwise 0's 1 0 0 0 1 0 0 0 1 Note: This is a c++ question. This is not a math questions.

Divide a group of people into two disjoint subgroups (of arbitrary size) such that the difference in the total ages of the members of the two subgroups is as large as possible.

Reword the question below so it's less ambiguous so I can understand the question and answer it on my own. maybe give example diagram/inputs/outputs (primitives if possible) but don't show any algorithms in the answer. I know big theta notation/sorting algorithms etc.. This question has been answered at brainmass but I don't w ...continues

Arrays in java

Write the definition of a method, isReverse , whose two parameters are arrays of integers of equal size. The method returns true if and only if one array is the reverse of the other. ("Reverse" here means same elements but in reverse order.) So, suppose you had two int arrays, forward and backward, each with 4 elements. N ...continues

Demo of Java array and code that assigns values based on the membership of the array

Given: an int variable k , an int array currentMembers that has been declared and initialized, an int variable memberID that has been initialized, and an boolean variable isAMember , write code that assigns true to isAMember if the value of memberID can be found in currentMembers , and that assigns fa ...continues

Demo of Java array and code that assigns values based on the membership of the array

Given: an int variable k , an int array currentMembers that has been declared and initialized, an int variable memberID that has been initialized, and an boolean variable isAMember , write code that assigns true to isAMember if the value of memberID can be found in currentMembers , and that assigns fa ...continues

Find the Largest and Smallest and Sort all the values in an Array in ascending order

Write two function in C++ with using arrays to find largest and smallest number. For example you have 1,43,42,9,8,5. You need arrange them smallest to highest and highest to smallest.

Efficiency of algorithm finding the second smallest of n elements

Prove that the second smallest of n elements can be found with n + cieling(log n) - 2 comparisons in the worst case.

Algorithm to find majority element

Let A be an array of n elements. An element x is said to be a majority element in A if it occurs in A more than n/2 times. Assume that the only comparisons allowed between elements are tests of equality. Give an algorithm that uses no more than 2n comparisons to determine whether the array A contains a majority element and, i ...continues

Browse