How can I calculate total path length of a Binary Search Tree?

I have been trying to learn binary search trees, but I can't figure out a way to calculate the total path length and the number of leaves in a BST. I will utilize a linked list for the nodes in the tree. I will be using an innerClass for the nodes; each node will have a variable for an element and links for the left and right. Does anyone have any idea on how to calculate this? Thanks in advance.:)

By the way, all of the elements are comparable objects.

Similar Messages

  • Text on path: How can I calculate the text length?

    Hi
    I have a text on path (spline item). Now I need the length of this text and the length of the spline item.
    I try to calculate the text length using IWaxLine::GetWidth(), but this is always 0.
    - How can I calculate the length of this text?
    - How can I calculate the length of the spline item?
    Thanks
    Hans

    It would be interesting if you could describe the purpose of your "length", but I don't have an answer anyway. Would the bounding box be sufficient?
    Considering that TOP may be combined with arbitrary spline paths, this could become an exercise in higher math. I haven't yet encountered a function that returns the mathematical length of such a spline.
    Otherwise it could be solved if you iterate and sum up the relevant points of the bounding box (ascender, descender, baseline?) of individual glyphs.
    Be warned that the whole TOP looks alien, as if it were a transplant from a different program. Experience also shows that documented and actually used interfaces / commands are completely different animals ...
    Dirk

  • How can I calculate the total time in java?

    Hello!
    I need to calculate the total time!
    For example I have start time:
              Format formatter1;
              Date date1 = new Date();
              formatter1 = new SimpleDateFormat("hh:mm:ss");
              String startTime = formatter1.format(date1);
              //startTime = "14:20:40";
    And I have finish time:
              Format formatter2;
              Date date2 = new Date();
              formatter2 = new SimpleDateFormat("hh:mm:ss");
              String finishTime = formatter2.format(date2);
              //finishTime = "08:30:55";
    So, after manually calculating, I get total time: "18:10:15"
    How can I calculate the total time in java? (Using formatter1 and formatter2 I suppose)
    What I need is to print "total 18:10:15"
    Thanks!

    800512 wrote:
    I did the following but, I think something is wrong here:
    I defined before: Date date1 = new Date(); Date date2 = new Date();
    And it should be exactly 5 seconds between them.
    I found delta between date1 and date2:
    Format formatter = new SimpleDateFormat("HH:mm:ss");
              long timeInMilliFromStart = date1.getTime() - date2.getTime() ;
              Date date3 = new Date(timeInMilliFromStart);
              String timeInSecFromStart = formatter.format(date3);
    and I get always
    //timeInSecFromStart = 02:00:05
    But it should be exactly 00:00:05.
    What can be a problem?Because, like I said, a Date measure an instant in time, not a duration. So when you have 5000 ms, and you turn that into a Date, that means 5 sec. after the epoch, which works out to 1/1/1970 00:00:05.000 GMT.
    As I mentioned, if you're not currently in GMT, then you have to set the TZ of the DateFormat to GMT. Right now, it's showing you the time in your TZ. If you included the date in your SimpleDateFormat, you'd see either 1/1/1970 or 12/31/1969, depending on which TZ you're in.
    Bottom line: You're trying to use these classes in a way they're not meant for, and while you can get the results you want for a limited set of inputs if you understand what these classes do and how to work with that, it's a brittle approach and comes with all kinds of caveats.

  • How can i calculate the average in java

    how can i calculate the avergae mark out of two marks for instance in like exam mark out
    of two other ones
    thanks for considering this message

    Average or Mean:
    sum_of_N/N
    Here N is the number of marks.
    sum_of_N is the total sum of n(all marks added together)
    public int average(int[] marks) {
    int sum;
    sum = 0;
    for(int i=0;i < marks.length;i++) {
    sum=marks[i]+sum; // keep adding to the total
    return average = sum/marks.length;
    // warning- using an int here can be a pitfall(we could have a decimal outcome).
    }

  • How can i calculate the percentile rank?

    How can I calculate where in percentile terms a single value falls within a array of many values?
    In excel it is:
    5
    10
    12
    11
    26
    18
    14
    11
    16
    19
    =PERCENTRANK(A1:A10,10) = 0.111
    Thanks!

    Average or Mean:
    sum_of_N/N
    Here N is the number of marks.
    sum_of_N is the total sum of n(all marks added together)
    public int average(int[] marks) {
    int sum;
    sum = 0;
    for(int i=0;i < marks.length;i++) {
    sum=marks[i]+sum; // keep adding to the total
    return average = sum/marks.length;
    // warning- using an int here can be a pitfall(we could have a decimal outcome).
    }

  • How can we calculate no.of leave used by the employee except sunday.

    Dear Friends,
    i have query how can we calculate no.of leave taken by the employee except sunday & government holiday.
    Example: A person take a sick leave From 13/02/2008 to 20/02/2008 with in that period 17th was sunday.
    when we calculate absence day for that person,Total value is 8 days but exact output is 7days only.How can i get exact result,any function module is avilable for this issue .
    Thanks & Regards,
    Rajkumar.A

    Hi,
    you have to consider SL leave as in holiday's So you can check with clinet if client says consider you can otherwise you con't
    its depend client requirement
    and you can go to controlls inSAP and change absence controlls for SL with holidays
    Regards
    Suresh

  • How can I calculate the request time ?

    Hello,
    How can I calculate the total consume time in each request ?
    For example, I want to start calculating the time when I click on a Link or a button and the end time when it completed load the page !
    Eric

    You could use a filter like this one:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.text.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    public class TimeFilter implements Filter {
        // The filter configuration object we are associated with.  If
        // this value is null, this filter instance is not currently
        // configured.
        private FilterConfig filterConfig = null;
        private static final boolean debug = false;
        private long start = 0;
        private long end = 0;
        public TimeFilter() {
        private void doBeforeProcessing(ServletRequest request, ServletResponse response)
        throws IOException, ServletException {
            if (debug) log("CalendarFilter:DoBeforeProcessing");
            System.out.print("In Filter  ");
            this.start = System.currentTimeMillis();
            System.out.println((new java.util.Date()).toString() +
                               " start request ");
        private void doAfterProcessing(ServletRequest request, ServletResponse response)
        throws IOException, ServletException {
            if (debug) log("TimeFilter:DoAfterProcessing");
            System.out.println("Completion Time = " + (System.currentTimeMillis() - start));
         * @param request The servlet request we are processing
         * @param result The servlet response we are creating
         * @param chain The filter chain we are processing
         * @exception IOException if an input/output error occurs
         * @exception ServletException if a servlet error occurs
        public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain)
        throws IOException, ServletException {
            if (debug) log("TimeFilter:doFilter()");
            doBeforeProcessing(request, response);
            Throwable problem = null;
            try {
                chain.doFilter(request, response);
            catch(Throwable t) {
                problem = t;
                t.printStackTrace();
            doAfterProcessing(request, response);
            // If there was a problem, we want to rethrow it if it is
            // a known type, otherwise log it.
            if (problem != null) {
                if (problem instanceof ServletException) throw (ServletException)problem;
                if (problem instanceof IOException) throw (IOException)problem;
                sendProcessingError(problem, response);
         * Return the filter configuration object for this filter.
        public FilterConfig getFilterConfig() {
            return (this.filterConfig);
         * Set the filter configuration object for this filter.
         * @param filterConfig The filter configuration object
        public void setFilterConfig(FilterConfig filterConfig) {
            this.filterConfig = filterConfig;
         * Destroy method for this filter
        public void destroy() {
         * Init method for this filter
        public void init(FilterConfig filterConfig) {
            this.filterConfig = filterConfig;
            if (filterConfig != null) {
                if (debug) {
                    log("TimeFilter:Initializing filter");
         * Return a String representation of this object.
        public String toString() {
            if (filterConfig == null) return ("TimeFilter()");
            StringBuffer sb = new StringBuffer("TimeFilter(");
            sb.append(filterConfig);
            sb.append(")");
            return (sb.toString());
        private void sendProcessingError(Throwable t, ServletResponse response) {
            String stackTrace = getStackTrace(t);
            if(stackTrace != null && !stackTrace.equals("")) {
                try {
                    response.setContentType("text/html");
                    PrintStream ps = new PrintStream(response.getOutputStream());
                    PrintWriter pw = new PrintWriter(ps);
                    pw.print("<html>\n<head>\n</head>\n<body>\n"); //NOI18N
                    // PENDING! Localize this for next official release
                    pw.print("<h1>The resource did not process correctly</h1>\n<pre>\n");
                    pw.print(stackTrace);
                    pw.print("</pre></body>\n</html>"); //NOI18N
                    pw.close();
                    ps.close();
                    response.getOutputStream().close();;
                catch(Exception ex){ }
            else {
                try {
                    PrintStream ps = new PrintStream(response.getOutputStream());
                    t.printStackTrace(ps);
                    ps.close();
                    response.getOutputStream().close();;
                catch(Exception ex){ }
        public static String getStackTrace(Throwable t) {
            String stackTrace = null;
            try {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                t.printStackTrace(pw);
                pw.close();
                sw.close();
                stackTrace = sw.getBuffer().toString();
            catch(Exception ex) {}
            return stackTrace;
        public void log(String msg) {
            filterConfig.getServletContext().log(msg);
    }and in the web.xml :
       <filter>
            <filter-name>TimeFilter</filter-name>
            <filter-class>
                com.filter.TimeFilter
            </filter>
        <filter-mapping>
            <filter-name>TimeFilter</filter-name>
            <url-pattern>/services/*</url-pattern>
        </filter-mapping > 

  • How can I calculate disk space/DB space and storage spaces.

    Hi all,
    How can I calculate space clauses and memory related parameters for tables and table spaces? Updation is not allowed in these tables.
    I have to create a database also.
    I expect a reply with examples.
    [email protected]
    [email protected]
    Thanks for all replies .

    Boby,
    The formula to estimate the storage parameters for tables and indexes are the following:
    Table size = db block size * (# of Estimated rows in 12 months * average row length)/(db block size-90) *(1-PCTFREE/100)
    Let assume that you want to create a table called Jose_tab,
    db block size = 4092
    Estimated row length in 12 months = 1000
    Average row len = 100
    PCTFREE(Updation is not allowed) = 0
    Then, your INITIAL storage parameter will be estimated as follows:
    4092*1000*100
    (4092-90)*(1-0/100)
    = About 10M
    Your create table command will look like this,
    CREATE TABLE jose_tab
    (col1 VARCHAR2(10), col2 NUMBER(2),
    ....coln VARCHAR2(100))
    STORAGE(INITIAL 10M NEXT 10M
    PCTINCREASE 0)
    PCTFREE 0 PCTUSED 80
    TABLESPACE tablespace_name;
    Storage parameters for tablespace depends on the amount of disk space available. You can ignore tablespace storage parameters since the size of the tablespace is determined by the size(s) of the data files. Refer to the DBA manual for details.
    John

  • You Can't Calculate Totals on that!...SO #@!%#! WHAT, YOU GREAT PILE OF !@#

    In Access you have an asterix which represents every field in the table. Useful if you want to see all the data in a table for a single record. I've done it a million times before.
    So why is it telling me that I can't calculate totals on the *, so I should remove it from the query grid and replace it with the fields I want and calculate totals then.
    I DON'T WANT TO CALCULATE ANY #!@%#@!! TOTALS!!
    I AM PUTTING THE FIELDS I #@!%$#! WANT - I WANT ALL OF THEM!! I JUST DON'T WANT TO DOUBLE CLICK 30 TIMES WHEN ONCE WILL DO!
    It's driving me insane because I'm going through hundreds of Oracle tables and it takes so long to browse to the record I'm looking for and it should work to use the asterix, I've done it so many times before.
    How do I override this utterly unhelpful behaviour? Am I stuck in some sort of "Queries will only calculate Totals! mode that I don't know about?
    I know, I know, Access is a micro$loth invention, not Oracle, but we have to use an ODBC link to the SQL database via Acces and it's going to kill me.
    Unless I slam my PC into my neighbour's head first!
    Any help greatly apprciated.
    Sorry for the rant!
    Cheers
    IsNull

    IsNull wrote:
    Cheers,
    I am serious and I know this isn't an Access site, and I know there are differences between SQL in Access and SQL in Oracle, and I'm trying to get funding to do some proper SQL and VBA training, but if anyone can help I'd be very grateful.What? with the funding? Sorry, there's a credit crisis doncha know! ;)
    In the Access/ODBC/Oracle query design view you can create a query by linking fields in tables and then choosing fields you want to output in the query results. At the top of each table is an asterix which uses all the fields from the entire table in a query and outputs the data from all the fields. I'm looking through various tables to find useful fields and using one particular record as my example so I get consistent data output.
    Now, I can look in the actual linked tables and see what they contain, but I want the data for a single record, not the general table contents and there are hundreds of thousands of records. So I'm using the query design to search for the data for a single record and using only one table per query. But if I double click on the asterix to indicate "Use All Fields from this Tabel" I get the "But you can't calculate totals on that!" message. If I add them all individually I get an "Illegal use of LONG data".I once looked at Access, many moons ago. Didn't like it.
    However, from what you describe, it would seem that you need to somehow join the tables as you're doing, but also apply some restrictions on the data so that you're not trying to retieve all the rows back. As for it's error complaining about the totals, I would expect something like you've got an aggregate function in there and things aren't being grouped together. Either that or there's some "setting" somewhere that automatically tries to total things, which hopefully you could turn off. The best thing is to take the error message/number and lookup what that means via some website/documentation that lists Access errors and how to resolve them.
    You'll be lucky to find anyone here who will know (or care about) Access.

  • How can i calculate manually fact and dimensional table ralations?

    hi friends,
    how can i know the information dimension table >15 of fact table, how can i calculate thses percentages manually?
    regards
    suneel.

    hi Suneel,
    it's another topic, to improve query performance, we evaluate if aggregate help or not, to justify we use bw statistic or ST03N, where summarization ratio is > 10;
    the summarization ratio = number of record read from database / number of record transferred,
    we need also the other parameter 'percentage of db time', time spent on database / total query runtime.
    check
    SAP BW Query Performance Tuning with Aggregates
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3f66ba90-0201-0010-ac8d-b61d8fd9abe9
    hope this helps.

  • How can i calculate overtime hours with PCR?

    hi all,
    i was wandering, can i calculate overtime hours in this case?
    example my DWS for this day is 08.00 - 16.00
    i do early overtime from 06.00 - 08.00, and after my working hours is finished, i do late overtime from 16.00 - 19.00
    (in TIP it is separated in 2 rows)
    how can i calculate my total overtime with pcr? i want to use the total for another calculation..
    06.00 - 08.00 : 2 hours
    16.00 - 19.00 : 3 hours
    +
            total      : 5 hours.
    thx all..

    ZPRN    DVARSTPRSNT
    N      COLOP*
    Y     DOUTTPORIGS
    Y E  HRS=0     HRS=PNUM  ADDDB9066 COLOP*
    Y *  COLOP*
    THE ZPRN PCR WILL GET THE TOTAL NUMBER WORKING HRS IN TIME TYPE 9066
    Now we will write a pcr to get overtime details
          DVARSTDPRCL
    *    DVARSTHOLCL
    * 1  D HRS=D9066  HRS-S HRS?0
    * 1 * ADDDB9067
    * 1 < COLOP*
    0 *
    NOW THIS PCR WILL BRING THE OVERTIME
    BASED ON YOUR DAILY WORK SCHEDULES U NEED TO CHANGE VARSTDPRCL NOW MY RULES WILL WORK FOR ALL THE SHIFTS OTHER THAN WEEKLY OFFS
    REGARDS,
    RAJA SEKHAR.

  • How can I calculate 3D distance with OS10g

    Hi,
    How can i calculate 3D distance between two objects using OS 10g?
    Thanks,

    If you have two 3d points you can:
    Make them into a line string
    Linear reference the 3d line string
    The length of the 3d line string is the distance between the points
    3d linear referencing is not supported for geodetic (non-cartesian) data.
    In 11g of course the story changes drastically.
    Here is a simple example:
    create or replace function points3dDistance(geom1 sdo_geometry,geom2 sdo_geometry)
    return number deterministic as
    geom sdo_geometry;
    length number;
    begin
    -- creating a 3d line segment
      geom := sdo_geometry(3002,null,null,sdo_elem_info_array(),sdo_ordinate_array());
    -- not checking, but should be cartesian coordinate system
    -- also geom1 and geom2 coordinate systems must match
      geom.sdo_srid := geom1.sdo_srid;
    -- creating a line segment from two points
      geom.sdo_elem_info.extend(3);
      geom.sdo_elem_info := sdo_elem_info_array(1,2,1);
      geom.sdo_ordinates.extend(6);
    -- if production i would check first for sdo_ordinates/elem info
    -- and make sure point data with the right number or ordinates
    -- since only demo assume input data comes from sdo_point in geom1 and geom2
      geom.sdo_ordinates(1) := geom1.sdo_point.x;
      geom.sdo_ordinates(2) := geom1.sdo_point.y;
      geom.sdo_ordinates(3) := geom1.sdo_point.z;
      geom.sdo_ordinates(4) := geom2.sdo_point.x;
      geom.sdo_ordinates(5) := geom2.sdo_point.y;
      geom.sdo_ordinates(6) := geom2.sdo_point.z;
    -- Now convert to lrs3d and get the length
      return sdo_lrs.measure_range_3d(sdo_lrs.convert_to_lrs_geom_3d(geom));
    end;
    select points3dDistance(
      sdo_geometry(3001,41048,sdo_point_type(5000,5000,0),null,null),
      sdo_geometry(3001,41048,sdo_point_type(5000,6000,1000),null,null))
    from dual;

  • Can any one suggest me how can I use relative path inside SSIS pacakge to access config file ?

    Can any one suggest me how can I use relative path inside SSIS pacakge to access config file ? Please help me as its urgent.THanks for your help in advance.

    Hi Jay,
    SSIS can only recognize the absolute path of a XML Configuration file, the relative path is not supported. Furthermore, if the XML Configuration file is already generated, we can use the Environment variable package configuration type instead so that
    SSIS runtime automatically looks for the configuration file from the path defined in the environment variable. This is convenient when we need to deploy a package to different environment. We only need to define the environment variable for package configurations
    once on each server, and then the variable can be used by all the packages on this server.
    Regards,
    Mike Yin
    TechNet Community Support

  • How can I script moving paths from one file to another?

    Hello. I have 1 image with various color correction layers. The other is the exact same size but only contains paths. How can I script moving paths from one file to another? Thanks, in advance, for any help you can offer. Thanks!

    Thanks! This one actually worked for me. Thanks for your help.
    http://forums.adobe.com/message/3305389#3305389

  • How can i calculate tempsize and logdir size ?

    Hello:
    I have one database on a primary server and its replica on a replica server.
    Since one week to now, Mexican Exchange have had a considerable growth on transactions.
    My database works in line, every night all data is cleaned waiting for new data on next day.
    From last Thursday (29 april 2010) my replicas have had problems on drop all data using delete from.
    I use delete from because those tables are Oracle cache groups defined.
    Looking for error on tterrors logs (yesterday I got this error) I could see that replica was ran out of temporal memory.
    On line database and replica database I have defined same temporal memory size, on this case 512Mb. But primary database did not send any error about this parameter, so if I checked “monitor” columns on database, my temp_in_use size is too less than temp_allocate_size.
    My problem is, how can I calculate temp_allocate_size ?
    So I have had close to 3,000,000 record on a simple table, I mean, I could have 2 or 3 tables with same number of rows.
    If I have this parameter (may be 9,000,000) rows to be deleted, is there any way to calculate temp_allocate_size ?
    But now, I suppose that I need enogh space on “LogDir”, my high_water_mark for permanent memory is 10GB, I have defined 16 gb for LogDir, but if I stopped replication since the operation starts, I had 100% space used at middle of my operation, so 5Gb on real database used, it is using close to 16 gb on LogDir.
    My second doubt … is there any way to calculate LogDir size having the maximum database size ??
    Thanks a lot for your help.
    Regards.

    I think that approaching this from the perspective of increasing temporary space and log space is not the best way.
    Firstly, there are better ways to delete all rows from a table instead of using delete...
    1. For regular tables (ones that are not part of a cache group) you can use TRUNCATE TABLE ... This operation is replicated but the voilume of replicated data is vastly smaller than if you delete all rows individually. Also, it should take a lot less Temp space on both the source and target system.
    2. For cache tables, you could use UNLOAD CACHE GROUP ... This is similar to TRUNCATE but for cache tables. Again, this operation is replicated. Note that if you are using AWT or SWT cache groups and you DELETE in TimesTen then the data is also deleted from Oracle... is that wjhat is desired?
    If you have to use DELETE then it is very important that you delete the rows in small batches rather than as one huge transaction. Trying to replicate a delete of 3M rows will cause huge problems for replication. A much better solution is to delete in smaller batches using some application logic as follows:
    loop:
    commit;
    DELETE FIRST 1000 FROM sometable;
    If rowcount > 0 then goto loop;
    commit;
    This approach has 5 benefits:
    1. Much less Temp space will be needed.
    2. Replication will be able to process the delets as they occur rather than waiting until all 3M rows have been deleted and then trying to tepliate a single transaction of 3M deletes. This will greatly improve replication performance and also prevent excessive log file buildup.
    3. Checkpointing will be able to purge log files as the delete progresses rather than having to wait until all rowsw have been deleted. This will prevent excessive log file buildup.
    4. The overall time required will be much reduced compared to deleting all rows in a single delete.
    You should not stop replication while the delete s are being done as this just causes log file accumulation.
    To answer your original question. it is not possible ot 'calculate' the required temp space pof log space; rather one must use observed data from when the system is running to determine the necessary size. For Temp size, you can look at the Temp high water mark to see the maximum space used and then set TempSize to somewhat more than that value. For log space, you need enough to sustain the maximum amount of log data generated with some contingency. Running our of log space is a very bad idea...
    If you adopt my suggestions above then you can avoid these issues and also complete the cleanup of data in a shorter time.
    Chris

Maybe you are looking for

  • Call command prompt from oracle sqldeveloper

    Hi all,     Anyone please let me know how to run the cmd prompt from oracle sql developer as like HOST command in sql plus. Thanks

  • Some JDK 1.5 features dont work in JDeveloper 10g (10.1.3) EA  IDE

    for example, the following error message is produced when i try to compile code bellow : Error(7,24): method range(client.Color, client.Color) not found in class java.util.EnumSet this is what my code look like: package client; import java.util.EnumS

  • Itunes crashes when Podcasts begin downloading

    Every time I start up itunes it crashes after the podcast begin downloading.  I have to open task manager to shut down itunes.  I have tried creating a different user account, it seems to be a system wide issue.  I have tried the suggestions on the a

  • Sales Returms - unique requirement

    Dear Friends, The following is my unique requirement to process Sales returns. For sales returns i am using order type RE and movement type 655, 653 and 651. By using this movement types and order types PGR (Post goods receipt) will happen, stocks ar

  • Why Carbon Copy Cloner?

    I am a new MAC user and have a question about cloning a disk drive.  It appears that the "Restore" function of Disk Utility does what's needed.  What is the advantage of using Carobn Copy Cloner that seems to be recommended by everyone? Thanks