Hey there! Sign in to join this conversationNew here? Join for free

I am so stuck computer science Watch

Announcements
    • Thread Starter
    Offline

    0
    ReputationRep:
    Help
    • Thread Starter
    Offline

    0
    ReputationRep:
    This is the problem i was never taught it and I have no clue what to do and there is nothing online
    Attached Images
     
    Offline

    0
    ReputationRep:
    Remember that when accessing the data within an array, the values of the nodes are 0 based, so if the array had the data of Q, S, G, D, and W input into its first 5 spots, with each character occupying a single space within the array, the value 'Q' would be located at the first node in the array, or: tree[0], 'S' would be at tree[1], G: tree[2], D: tree[3], and W: tree[4]. Since it's 0 based, you need to consider tree[0] as the first node in the array.

    So, from here, adding the characters 'P' and 'T', they will occupy tree[5] and tree[6].
    Now, since this is a binary tree, the characters will be placed within the tree by their relative alphanumeric values (which you can lookup on an ASCII table). Since 'Q' is the first entry, it is placed at the top, but from here, each value that is input into the tree will be placed either to the left or to the right of 'Q', depending on whether its ASCII value is lesser or greater than 'Q' (which is #81 on the ASCII table).

    So 'S' is put to the right, 'G' is put to the left, then 'D' to the left of 'G', and finally 'W' is placed at the end on the far right. When we insert 'P', the binary tree algorithm will check to see whether it is greater than or less than 'Q', the top of the tree. Since it is less than 'Q', it will branch to the left of that position, checking the value of 'G' next. It is greater than 'G', and there is no value in the space to the right of 'G', so it occupies that spot.

    With 'T', it travels down the right side of the tree, as it's greater than 'Q', and greater than 'S'. Since it is less than 'W', it is placed to the left of the node pointing to the character 'W'.

    From here, you shouldn't have any issues with determining the values that each node points to. For example, the data node tree[2] has a value of 'G'. This node points to the values in node tree[3] (character 'D') and node tree[5] (character 'P'). So for the chart, you would write the left value as 3 and the right value as 5.

    The one part I don't understand is why the chart says that the first node, tree[0], points to a value of 3 on the left, when it looks like it's pointing at 'G', which should be within tree[2], not tree[3]. Might want to ask someone about that in your class.

    Well, hopefully the information I gave you isn't wrong, but at least it can hopefully point you in the right direction. I'm struggling with CS as well; guess that's why they pay lots of money to people who can actually understand this stuff
    • Thread Starter
    Offline

    0
    ReputationRep:
    Thanks
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Should Spain allow Catalonia to declare independence?
    Help with your A-levels

    All the essentials

    The adventure begins mug

    Student life: what to expect

    What it's really like going to uni

    Rosette

    Essay expert

    Learn to write like a pro with our ultimate essay guide.

    Uni match

    Uni match

    Our tool will help you find the perfect course for you

    Study planner

    Create a study plan

    Get your head around what you need to do and when with the study planner tool.

    Study planner

    Resources by subject

    Everything from mind maps to class notes.

    Hands typing

    Degrees without fees

    Discover more about degree-level apprenticeships.

    A student doing homework

    Study tips from A* students

    Students who got top grades in their A-levels share their secrets

    Study help links and info

    Can you help? Study help unanswered threadsRules and posting guidelines

    Sponsored content:

    HEAR

    HEAR

    Find out how a Higher Education Achievement Report can help you prove your achievements.

    Groups associated with this forum:

    View associated groups
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.