You are Here: Home >< A-levels

# I am so stuck computer science watch

1. Help
2. This is the problem i was never taught it and I have no clue what to do and there is nothing online
Attached Images

3. 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
4. Thanks

TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: November 20, 2016
The home of Results and Clearing

### 1,333

people online now

### 1,567,000

students helped last year
Today on TSR

### University open days

1. Sheffield Hallam University
Tue, 21 Aug '18
2. Bournemouth University
Wed, 22 Aug '18
3. University of Buckingham
Thu, 23 Aug '18
Poll

## All the essentials

### Student life: what to expect

What it's really like going to uni

### Essay expert

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

### Create a study plan

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

### Resources by subject

Everything from mind maps to class notes.

### Study tips from A* students

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