Use boolean array to perform set operations

I am currently taking a computer science class that uses Java as the language of choice. I have no prior experience with Java. We have a homework assignment in which we are supposed to use a boolean array to implement set operations. We have to create a method that inserts an integer into the array, another that deletes an integer element, and several others. I am confused as how to do this with integers, as it is a boolean array. The datr for this class is:
private boolean base[];The constructor is:
public largeset(int size){ }We then have to create a method that inserts an integer into the array:
public void insert(int i){ }And one that deletes the element:
public void delete(int i) { }I am unsure how to do this using a boolean array. If it were an integer array I would not have any trouble, but I get an error when trying to insert/delete an integer from the boolean array. Can anyone help point me in the right direction? I would prefer advice only, not the actual code, as this is a homework assignment, and I would like to create the code myself so I actually know what I am doing. Thanks.

This is the assignment exactly as posted on the course website:
In this homework, we will use a boolean array to implement various set operations. Please create a class called largeset that supports set operations of any number of elements. The data of this class is
private boolean[] base;The constructor of the class is
public largeset(int size);  // create a boolean array of size "size" and store it in "base"The methods of the class are:
public void insert(int i);  // insert number i into the current set, where 0 <= i < base.length
public void delete(int i);  // delete number i from the current set, where 0 <= i < base.length
public boolean member(int i); // test if i is in the set
public largeset union(largeset B); // return the union of two sets
public largeset interset(largeset B); // return the intersection of two sets
public largeset subtract(largeset B); // return the subtraction of two sets
public largeset complement(); // return the complement of the current set
public boolean subset(largeset B); // test if the current set is a subset of set B
public int cardinality();  // return the number of elements in the current set
public String toString();  // return a string which is a printing of the current setThen create another class called testset that uses the largeset class. At first, please create the following two sets:
X = { 1, 3, 5, 7, ..., 999 };
Y = { 9, 18, 27, 36, ..., 999 };
Please perform the following tests:
1. display the cardinalities of X and Y, respectively.
2. display the content of substraction of Y by X.
3. display the square root of the sum of all the elements of X (Math.sqrt(x) will return the square root of x in double type).
4. For every pair of distinct elements x and y in Y, compute the sum of (Math.max(x, y) - Math.min(x, y)) (or equivalently, Math.abs(x - y)), and report this sum.

Similar Messages

  • How to perform Set operations in ODI?

    Can anybody suggest me how to perform a set operations in ODI?

    Hi ,
    May be the below threads helpful for u....
    UNION operation in ODI
    How to use Union, Union all, MINIUS in ODI
    Thanks.

  • Case Structure using Byte Array

    I have an array that has 9 bytes. I need to determine method for selecting a case in case structure when a bit is high.
    I know how to do it when it is 1 byte but I am not sure the best method to use when its nine byte array.
    Can someone provide me suggestions? Or example code?
    Thanks..... 

    altenbach wrote:
    Assuming you have a Boolean array with 9 elements, use "boolean array to number" and wire to the selector terminal. Create cases for all relevant patterns and leave the default case empty.
    If only one element can be true at any given time, use search array and search for TRUE. Wire the output to the selector. Leave the "-1" case empty.
    I think the poster has an array of nine bytes, each with the appropriate booleans.  Therefore, I like jcarmody's suggestion that he index the array and performs the operations that the poster is already familiar with.
    Assuming an array of booleans, the first method you described is okay if there is a specific action for each pattern.  In most of the scenarios I've worked with, each bit represented a specific test, for instance, and there would be a lot of duplicate code if I used that method.  (For instance, binary cases 10 and 11 would both have test subVIs for test 2.)  For something like that, I would all my tests in sequence (using error in/out for dataflow, of course) and have T/F cases around each one with the indexed boolean array controlling which tests would be run.  Of course I tend to see things in a literal way, so if the requirements say "do the selected tests in this order", that's how I would develop it.  Maybe there's a better way programmatically?
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • How do I count the number of 1's in a Boolean Array??

    I have a boolean array of 1000 0's or 1's and want to know the number of times this array is in the 1 position.
    The array is repeated within a structure and i need a number for each iteration to be passed onto the next (using a shift register).
    Never really used boolean arrays before so none of the standard things i use seem to work?
    Thanks in Advance.
    Ross

    Ross,
    The quick easy way is to convert the boolean array to a 0-1 array from the boolean menu, then sum the array using "sum array elements" from the numerical menu.
    Bruce
    Bruce Ammons
    Ammons Engineering

  • What is the max number of bits a boolean array can have?

    Hello,
       What is the maximum number of bit that a boolean array can have?
    Regards,
      Kaspar
    Regards,
    Kaspar

    There is no real size limit. (except for the natural limits of arrays because the size is a 32bit integer, etc.)
    ... of course if you ever plan to convert it back to an integer using "boolean array to number", you better stay below 64 bits.
    Can you explain what you want to do in a bit more detail?
    Message Edited by altenbach on 05-23-2007 02:51 PM
    LabVIEW Champion . Do more with less code and in less time .

  • Handy way to order columns in SET operator ?

    Not only this operator can be one of the most loaded with numerous columns but every group has to be ordered the same way and I can't find any tool/menu to swap two columns (as an instance)
    Do you know any other simpler way to do that rather than costingly emptying every single set to refill them in the right order one-by-one ?
    Thanks

    Basically the fastest way would be using OMBPLUS, first create the SET operator and next add columns in the desired order.
    Another option is the OWB Client itself, but only if the order of the columns is the same as that of some table (maybe the target table for the SET operator?).
    Get that table into the mapping, and use it as source for the columns of the SET operator. Next delete that table from the mapping an connect the columns in the SET operator with their desired sources.
    I guess you could even define a 'dummy' table for that in OWB if you need to use it more often, if you set Deployable to FALSE you won't even have to bother about seeing it deployed to your target schema.
    Hope this helps.
    Cheers, Patrick

  • Error : 'The Connection can not be used to perform thsi operation

    Dear All,
    I am getting an error like 'The Connection can not be used to perform thsi operation, it is either close or Invalid in this context.
    Below is the code what am using:
    Sub Select_Query()
    Dim SQL_String As String
    Dim rs As ADODB.Recordset 'This holds the data
    Dim cn As ADODB.Connection 'Declaring Connection
    Dim cmdobj As ADODB.Command 'Declare command Object
    'Sheets("Payment").Select
    Set cn = New ADODB.Connection
    cn.Open ("Provider=MSDAORA;Data Source=MyDatabase;User ID=Prasad; Password=Prasad12;")
    Dim count_value As Long
    count_value = WorksheetFunction.CountA(Worksheets("Payments").Range("A:A"))
    For i = 4 To count_value
    SQL_String = Worksheets("Payments").Range("AA" & i).Value
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open SQL_String, cn, adOpenForwardOnly, adLockOptimistic, adCmdText
    Dim val As Integer
    val = rs.recordCount
    If val = 0 Then
    Worksheets("Payments").Range("AZ" & i).Value = "No"
    'Else
    'Worksheets("Uploaded").Range("O" & i).Value = "Yes"
    End If
    cn.Close
    Set con = Nothing
    Next
    'cn.Execute SQL_String
    'con.Close
    Set con = Nothing
    End Sub
    And select statment is picking one of the sheets, and SQL query is:
    ="SELECT sa.acct_id
    FROM ci_sa sa, ci_sp sp, ci_sa_sp ss, ci_sp_geo spg,ci_acct_char cac
    WHERE sa.sa_id = ss.sa_id
    AND ss.sp_id = sp.sp_id
    AND sp.sp_id = spg.sp_id
    AND spg.geo_type_cd LIKE '%RR%'
    AND spg.geo_val ='"&B4&"'
    and sa.ACCT_ID=cac.ACCT_ID
    AND cac.char_type_cd LIKE '%SDO%'
    AND TRIM (char_val) IN ('"&Master!G9&"')"
    Please help me in this..
    Regards,
    Prasad

    Please, this is a Oracle forum, not a VBA forum. Mark this thread as answered and post it in a VBA forum.

  • Cant schedule refresh - We can't perform this operation because this workbook uses unsupported features. Correlation ID: 42e1a475-20ea-41ae-9d8d-e1889d4c2d77

    Hi all,
    I have a workbook with a set of scheduled refreshes (powerquery via the gateway from web api). I've modified it by adding a new source from the azure marketplace. I've successfully added it to the DMG
    I've uploaded the new report and I'm able to browse it successfully in powerbi
    But when I try to schedule a refresh I get the following error against all the data connections
    We can't perform this operation because this workbook uses unsupported features. Correlation ID: 42e1a475-20ea-41ae-9d8d-e1889d4c2d77
    Also get the error if I uncheck the new data source
    Below is my PQ query for the new data source. Which unsupported feature am I using?
    let
    Source = Marketplace.Subscriptions(),
    #"https://api.datamarket.azure.com/Data.ashx/BoyanPenev/DateStream/v1/" = Source{[ServiceUrl="https://api.datamarket.azure.com/Data.ashx/BoyanPenev/DateStream/v1/"]}[Feeds],
    ExtendedCalendar1 = #"https://api.datamarket.azure.com/Data.ashx/BoyanPenev/DateStream/v1/"{[Name="ExtendedCalendar"]}[Data],
    #"Filtered Rows" = Table.SelectRows(ExtendedCalendar1, each [YearKey] >= 2010 and [YearKey] <= 2020),
    #"Inserted End of Month" = Table.AddColumn(#"Filtered Rows", "EndOfMonth", each Date.EndOfMonth([DateKey]), type datetime),
    #"Inserted End of Quarter" = Table.AddColumn(#"Inserted End of Month", "EndOfQuarter", each Date.EndOfQuarter([DateKey]), type datetime),
    #"Inserted End of Week" = Table.AddColumn(#"Inserted End of Quarter", "EndOfWeek", each Date.EndOfWeek([DateKey]), type datetime),
    #"Renamed Columns" = Table.RenameColumns(#"Inserted End of Week",{{"DateKey", "Date"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}, {"EndOfMonth", type date}, {"EndOfQuarter", type date}, {"EndOfWeek", type date}}),
    #"Renamed Columns1" = Table.RenameColumns(#"Changed Type",{{"YearKey", "CalendarYear"}}),
    #"Inserted FiscalYear" = Table.AddColumn(#"Renamed Columns1", "FiscalYear", each Date.Year(Date.AddMonths([Date],6)), type number),
    #"Inserted FiscalMonth" = Table.AddColumn(#"Inserted FiscalYear", "FiscalMonthSortId", each Date.ToText(Date.AddMonths([Date],6),"MM"), type number),
    #"Inserted Month" = Table.AddColumn(#"Inserted FiscalMonth", "FiscalMonth", each Date.ToText([Date],"MMMM"), type text),
    #"Inserted Month1" = Table.AddColumn(#"Inserted Month", "CalendarMonthSortId", each Date.ToText([Date],"MM"), type number),
    #"Added Custom" = Table.AddColumn(#"Inserted Month1", "DateIsWeekDay", each if [DayOfWeekMon] > 5 then "no" else "yes"),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "HoursPerWeekDay", each if [DateIsWeekDay] = "yes" then 7.5 else 0.0),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"DateIsWeekDay", type text}, {"HoursPerWeekDay", type number}}),
    #"Added Custom2" = Table.AddColumn(#"Changed Type1", "Custom", each Function.Invoke(DateTimeZone.UtcNow,{})),
    #"Split Column by Delimiter" = let #"Changed Type" = Table.TransformColumnTypes(#"Added Custom2", {{"Custom", type text}}, "en-AU"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type","Custom",Splitter.SplitTextByDelimiter(" +"),{"Custom.1", "Custom.2"})
    in #"Split Column by Delimiter",
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Custom.1", type datetime}, {"Custom.2", type time}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type2",{"Custom.2"}),
    #"Renamed Columns2" = Table.RenameColumns(#"Removed Columns",{{"Custom.1", "RefreshDateUtc"}}),
    #"Added Custom3" = Table.AddColumn(#"Renamed Columns2", "RefreshDateLocal", each [RefreshDateUtc] + #duration(0,10,30,0)),
    #"Changed Type3" = Table.TransformColumnTypes(#"Added Custom3",{{"RefreshDateLocal", type text}}),
    #"Added Custom4" = Table.AddColumn(#"Changed Type3", "RefreshDate", each [RefreshDateLocal] & " (UTC + 10.5)"),
    #"Changed Type4" = Table.TransformColumnTypes(#"Added Custom4",{{"DateInt", Int64.Type}, {"CalendarYear", Int64.Type}, {"HalfYearKey", Int64.Type}, {"QuarterKey", Int64.Type}, {"MonthKey", Int64.Type}, {"MonthOfYear", Int64.Type}, {"MonthOfHalfYear", Int64.Type}, {"MonthOfQuarter", Int64.Type}, {"QuarterOfYear", Int64.Type}, {"QuarterOfHalfYear", Int64.Type}, {"HalfYearOfYear", Int64.Type}, {"DayOfYear", Int64.Type}, {"DayOfHalfYear", Int64.Type}, {"DayOfQuarter", Int64.Type}, {"DayOfMonth", Int64.Type}, {"DayOfWeekMon", Int64.Type}, {"DayOfWeekSun", Int64.Type}, {"WeekOfYearISO", Int64.Type}, {"FiscalYear", Int64.Type}, {"FiscalMonthSortId", Int64.Type}, {"CalendarMonthSortId", Int64.Type}}),
    #"Added Custom5" = Table.AddColumn(#"Changed Type4", "CalendarMonthId", each [DateInt]/100),
    #"Round Down" = Table.TransformColumns(#"Added Custom5",{{"CalendarMonthId", Number.RoundDown}}),
    #"Changed Type5" = Table.TransformColumnTypes(#"Round Down",{{"CalendarMonthId", Int64.Type}}),
    #"Added Custom6" = Table.AddColumn(#"Changed Type5", "Custom", each Date.ToText([Date],"ddd")),
    #"Renamed Columns3" = Table.RenameColumns(#"Added Custom6",{{"Custom", "DayName"}}),
    #"Added Custom7" = Table.AddColumn(#"Renamed Columns3", "PastMonthFilter", each if [CalendarMonthId] < Number.FromText(DateTimeZone.ToText(Function.Invoke(DateTimeZone.UtcNow,{}),"yyyyMM")) then 1 else 0)
    in
    #"Added Custom7"
    Jakub @ Adelaide, Australia Blog

    I don't think that's it. I deleted all the powerview reports and worksheets containing pivot tables/charts, and the refresh worked with the function.invoke() call.
    The only reason that's in there is because the execution stops there when I dont have it and i have to manually click an 'invoke' button. If there's a way to get around that i'll happily try that instead.
    Hmm.. i think I found it, but i'll need to do some testing next year after the holidays to verify
    I had added two text boxes (name and desc) to one of my worksheets. I was able to test connection/schedule and run a refresh once I had deleted them.
    Weird, because o365 excel services had no problem displaying the worksheet containing the text boxes, but it looks like workbooks that contain text boxes don't work on a scheduled refresh
    Jakub @ Adelaide, Australia Blog

  • Discussion Forum: Unable to perform the operation: Row was not found using

    Hi all,
    I deployed the Discussion Forum and it shows the Portlet with "Creating a product ..". Very fine.
    I can create a Product. Fine also.
    I can fill in a new Thread, but then, when I try to submit it, I get the error:
    Unable to perform the operation: Row was not found using request parameter: 000100000004313437380000012A000000F8FE832E94.
    When I click Cancel. I see the Overview of the Products. I drill down to the Threads for my Product and the new thread appears on the list. As soon as I click on the Thread in order to read it the following error appears:
    Unable to perform the operation: Row was not found using request parameter: 0001000000043134373800000134000000F8FE832E94.
    Any help is appreciated,
    Michael

    You need to set the Login Frequency (while registering the provider) to 'Once Per Session'. This will allow the portlet to track the user transaction state.
    Make sure that you do not bounce the oc4j container in between the portlet operations, since this will leave the transaction into inconsistent state.
    You have to ensure that whenever you bounce the oc4j container/provider mid-tier you logout of portal and login again.
    This will solve the problem.

  • Set-aduser : Insufficient access rights to perform the operation

    I am a domain admin, enterprise admin, exchange admin, domain user, and others.
    While running a PS on a DC as the administrator, The commands I'm running are ...
    $expdate = get-date -date '01/01/2014'
    set-aduser -identity testmail5 -accountexpirationdate $expdate
    I get the following error ...
    set-aduser : Insufficient access rights to perform the operation
    At line:1 char:1
    + set-aduser -identity testmail5 -accountexpirationdate $expdate
        + CategoryInfo          : NotSpecified: (testmail5:ADUser) [Set-ADUser], ADException
        + FullyQualifiedErrorId : Insufficient access rights to perform the operation,Microsoft.ActiveDirectory.Management.Comm
       ands.SetADUser
    I then switch to a different DC, the command 'might' work once, but will never run again in the same window.
    Then I tried this ...
    start-process powershell -verb runas
    That gave me an additional PS window, and I then tried running the commands again.
    Same error message.
    So I tried the following command ...
    $expdate = get-date -date '01/01/2014'
    set-aduser -server XXDC03 -identity testmail5 -accountexpirationdate $expdate
    Same error message.
    Is there any way that I can get around this problem?
    Please help.

    Keep in mind that the account used to open the PowerShell session must be the same account you're using to open ADUC. The error message means that Set-ADUser is trying to set the attribute for the account, but it's failing. Make sure to test with multiple
    different accounts, in case the access control list of the object you're trying to modify is the cause of the problem.
    Your PowerShell syntax is valid, so this isn't really a scripting question but a security/directory services question.
    -- Bill Stewart [Bill_Stewart]

  • 1d cluster array replace value in a 1d boolean array (without using Loop)

    Hi ,
    is there a way to replace the values (string , boolean) ​​of a 1D array Cluster with value of 1D boolean array without using loop ?
    Regards
    Simone
    Attachments:
    111.png ‏75 KB

    Replace Array Subset requires that the array elements are type compatible with the elements that you want to replace. That seems not the case in your example.
    And the For Loop is anything but slow. How many billion elements do you expect your array to have to worry about performance of the for loop? With the type definition of your example even a ready made LabVIEW function would have to do internally a for loop too, since the boolean data inside the original array can not be in a continous memory area.
    Maybe if you show us what you try to do with the for loop we can understand better what your concerns are. As it is from the front panel image alone it is really hard to understand what your imagined problem might be.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Hi, I have a hard disk failure so to recover my data I am using disk utility to restore the data on an external drive while booting from a second external hard drive. When I perform the operation it gives me an input/output error and stops. Any tips?

    Hi, I have a hard disk failure so to recover my data I am using disk utility to restore the data on an external drive while booting from a second external hard drive. When I perform the operation and after having selected both my destination and source drives, the operation begins but soon fails due to input/output error. If I try to create an image of the drive it gives me the same error message. Any help would be much appreciated.

    Disk Utility only creates a image of the drive, so it's no help getting exactly what you want, which is your files. If the file structure is messed up or the drive is failing then it's no help.
    If you have a external boot drive and you can't access the internal non-booting drive though the typical Finder and windows to transfer your files via drag and drop methods, then you need to install Data Rescue on the external boot drive and it will do as best as it can to recover your files. (works on non-encrypted/non-Filevaulted drives only)
    .Create a data recovery/undelete external boot drive
    Are you sure you have hard drive failure, or that OS X isn't merely not booting?
    Because if the drive is working physically, then there is a host of fixes
    ..Step by Step to fix your Mac
    https://discussions.apple.com/community/notebooks/macbook_pro?view=documents#/

  • AdHoc Set Query - set operations - practical use

    Hi
    I am writing a user manual about AdHoc Query - including Set operations. I am looking for good examples when to use the different operations.  A-B is easy.  Example - 'give me all employees that are not on maternity leave'.  But I am struggling with good practical examples on when to use Union and Intersection.  It needs to be examples that cannot be covered by selection criteria in one single query.
    Does anyone have any good practical examples?  Any help appreciated.
    Kirsten

    Hi Kirsten,
    I use Set Operations many times to find individuals who do not have a certain infotype or plan.  Example:  Find all retirees who are not enrolled in a medical plan.  Group A = All retirees;
    Group B = All retirees in a medical plan.  A - B = Retirees with no medical plan coverage. 
    Ad Hoc Query does not allow you to use "Or" logic in selection with different criteria.  A Union could be used for this.  An example would be employees who are in pay Grade 1 - 5 (Group A) or earn less than $50,000 per year (Group B).  Intersection would be those in Grades 1 - 5 and earn less than $50,000 per year. 
    Paul

  • Using an array in another class to set text of a button

    I am trying to use an array from one class in another to set the text of a button.
    This is the code in the class where i have made the array.
    public class EnterHomeTeam
         public int NumberOfPlayers = 11;
         public String[] PlayerName = new String [NumberOfPlayers];
    private void button1_Click (Object sender, System.EventArgs e)
              PlayerName [0] = this.HGoalKeeper.toString();
              PlayerName [1] = this.HDef1.toString();
              PlayerName [2] = this.HDef2.toString();
              PlayerName [3] = this.HDef3.toString();
              PlayerName [4] = this.HDef4.toString();
              PlayerName [5] = this.HMid1.toString();
              PlayerName [6] = this.HMid2.toString();
              PlayerName [7] = this.HMid3.toString();
              PlayerName [8] = this.HMid4.toString();
              PlayerName [9] = this.HAtt1.toString();
              PlayerName [10] = this.HAtt2.toString();     
              Players IM = new Players();
              this.Hide();
              IM.Show();
    }Then in the class where i want to use the variables (ie. PlayerName[0]) I have got
    public class Players
    EnterHomeTeam HT = new EnterHomeTeam();
    //and included in the button code
    this.button1.set_Text(HT.PlayerName[0]);I hope i have explained this well enough and hope someone can help me solve this problem! Im not a very competent programmer so i apologise if I havent explained this well enough!
    Adam

    .NET automatically generates quite a bit of code.... this is button1:
    private void InitializeComponent()
              this.button1 = new System.Windows.Forms.Button();
    // button1
              this.button1.set_BackColor(System.Drawing.Color.get_LightBlue());
              this.button1.set_Location(new System.Drawing.Point(88, 32));
              this.button1.set_Name("button1");
              this.button1.set_Size(new System.Drawing.Size(72, 56));
              this.button1.set_TabIndex(0);
              this.button1.set_Text(HT.PlayerName[0]);
              this.button1.add_Click( new System.EventHandler(this.button1_Click) );
    this.get_Controls().Add(this.button1);
         private void button1_Click (Object sender, System.EventArgs e)
              System.out.print(HT.PlayerName[0]);
              GKAction GK = new GKAction();
              this.Hide();
              GK.Show();
         }Hope that helps - im pretty sure that's all the button1 code

  • Can we perform Join operation using SQLCall with Datatabae Query

    Hi,
    I am working on Toplink SQLCall query. I am performing join operation but, it is giving error.
    so please, any can tell me . we can perform join operation using SQLCall with Database Query
    Thanking You.

    You can use joining with SQLCall queries in TopLink, provided your SQL returns all of the required fields.
    What is the query you are executing and what error are you getting?

Maybe you are looking for