homework

How to read input from the stdout of another command (pipe) in linux shell script?

My objective (read Homework) is to find the process that is consuming the most CPU and RAM by writing a script. I've managed to extract the info from TOP command however I'm having trouble parsing the output. The following command top -b -n 1 | tail -n +8 | head -n 1 will output something similar to this single line 915 root ...

C++ minimax function

I have searched Google and Stackoverflow for this question, but I still don't understand how a minimax function works. I found the wikipedia entry has a pseudocode version of the function: function integer minimax(node, depth) if node is a terminal node or depth <= 0: return the heuristic value of node α = -∞ for ch...

Simply Pseudocode Question

I'm new to psuedocode, and I'm having trouble putting all the pieces together: Here is the definition of a function named foo whose inputs are two integers and an array of integers a[1] ... a[n]. 1 Foo(k,m, a[1],...,a[n]) 2 if (k < 1 or m > n or k > m) return 0 3 else return a[k] + Foo(k+1,m,a[1],...,a[n]) Suppose that the inpu...

Implementing filter using HoF in Haskell

I'm trying to write a function that takes a predicate f and a list and returns a list consisting of all items that satisfy f with preserved order. The trick is to do this using only higher order functions (HoF), no recursion, no comprehensions, and of course no filter. ...

Help with ifstream in programming test

Hello all, I recently did a programming test in which there was a ifstream section which I could not solve. Since then I have been trying to solve the problem in my free time to no avail. The problem is basically to read from a binary file and extract the information there. Here is the file format: ---------------------------------...

Memory Units, calculating sizes, help!

I am preparing for a quiz in my computer science class, but I am not sure how to find the correct answers. The questions come in 4 varieties, such as-- Assume the following system: Auxiliary memory containing 4 gigabytes, Memory block equivalent to 4 kilobytes, Word size equivalent to 4 bytes. How many words are in a block, expressed...

F# a function to check if a list is sorted or not

I have to write a function, that returns true if a given list is sorted in ascending order. The empty and 1-element lists are sorted. Also, [5,12,12] should return true. I've written a function that seems to work: let rec isSorted (l: int list) = match l with | [] -> true | [x] -> true | [x;y] -> x <= y | x::y::xr ...

How to search keyword in 100 billions of posts ?

This is a college project: I have a database ( mysql or postgresql doesn't matter ) with 100 billion of posts and I need to search ( as fast as possible ) a generic keyword. Every post is 500-1000 keywords. This isn't only a database issue but also a software ( for indexing or other ) issue. How can I do that ? I could use some adva...

Using class type in switch statement: is it better than using typeid operator ?

Hi, I saw below thing about switch statement in c++ standard $6.4.2. Switch statement can take a condition. The condition shall be of integral type, enumeration type, or of a class type for which a single conversion function to integral or enumeration type exists (12.3). If the condition is of class type, the condition is converte...

Removing volatile nature using const_cast

Hi, I heard that volatile nature of a variable can be removed using const_cast operator. In which scenarios we need to remove volatile nature of a variable ? are there any good use cases ? Is it dangerours operation, because we declared it as volatile thinking that it would be modified by external factors and removing volatile nature co...

Trying to come up with an algorithm to sort to Spanish words.

Hello, I am writing a program to sort Spanish words.The letters are almost the same as the English alphabet, only with a few exceptions. a,b,c,ch,d,e,f,g,h,i,j,k,l,ll,m,n,ñ,o,p,q,r,rr,s,t,u,v,w,x,y,z Further, for this problem, assume that any pair of characters which can represent a letter does; for example, the combination ch would a...

How to check if my iterator stands on nothing

Hello, i'm using a multimap stl, i iterate my map and i did'nt find the object i wanted inside the map, now i want to check if my iterator holds the thing i wanted or not and i'm having difficulties with it because it's not null or something. thanx! ...

Count the number of operations for a sorting algorithm

This is my assignment question: Explain with an example quick sort , merge sort and heap sort . further count the number of operations, by each of these sorting methods. I don't understand what exactly i have to answer in the context of " count the number of operations " ? I found something in coremen book in chapter 2, they have expla...

A randomized algorithm to statistic in a set of n elements Select

The question is as follows : " Write a randomized algorithm to statistic in a set of n elements Select ?" can anyone please tell me what does the above question means ? ...

i am unable to find the algo of short path plz help in this??

"Bob has become lost in his neighborhood. He needs to get from his current position back to his home. Bob's neighborhood is a 2 dimensional grid, that starts at (0, 0) and (width - 1, height - 1). There are empty spaces upon which bob can walk with no difficulty, and houses, which Bob cannot pass through. Bob may only move horizontally o...

C# - Suggestions of control statement needed

Hello! I'm a student and I got a homework i need some minor help with =) Here is my task: Write an application that prompts the user to enter the size of a square and display a square of asterisks with the sides equal with entered integer. Your application works for side’s size from 2 to 16. If the user enters a number less than 2 or ...

GPA calculator/ adding outside a loop

Greetings, I'm just looking for a bit of help here. Here's the prompt: For research purposes the admissions officers of your local university wants to know how well female and male students perform in certain courses. The user enters the number of courses to be considered. The student's data for each course is provided as a GPA followe...

Regex to match a string that does not contain 'xxx'

One of my homework questions asked to develop a regex for all strings over x,y,z that did not contain xxx After doing some reading I found out about negative lookahead and made this which works great: (x(?!xx)|y|z)* Still, in the spirit of completeness, is there anyway to write this without negative lookahead? Reading I have done mak...

Recursive Programming for Text Predictive text

I want to make a program that takes a set of numbers like 234, and at the moment, print out every combination of letters possible that are on a mobile phone keypad. (1 - nothing, 2 - abc, 3- def and so on) I currently have: import java.util.*; public class testCombo { static String str="217"; static ArrayList<String> list=new...

What will be the candidate key and why? Please refer question

Consider a relation R(ABCDEG) The functional dependencies are given below: AB->C AC->B AD->E B->D C->A E->G Determine the candidate key(s) for the relation R. Options: A. AB, AC and C B. AB and AC C. AB and C D. C only ...