Algorithms & Data Structures (M)Assessed Exercise

Algorithms & Data Structures (M) Assessed Exercise (2022–23)
In this exercise you will implement an ADT that represents a molecule – i.e. a group of atoms connected by bonds. You do not need to know any chemistry apart from that which is presented here.

Q1703105484The total weighting for the exercise (parts 1 and 2) contribute to 20% of the ADS(M) course assessment.
The deadline is Monday 27th March 2023 at 16:30.

In this exercise you will implement an ADT Molecule which allows us to initialize a molecule, add atoms to a molecule, and print a String representation of a molecule in two different formats. Before introducing the ADT let us look at the underlying chemistry* that has inspired it.

* This description is only loosely based on real chemistry and has been simplified for the purposes of this exercise. We will be able to construct molecules which would never exist in real life (as well as some that would).

Background
In this exercise, we will only consider molecules that are composed of atoms which belong to the ten types named in the lefthand column of table 1 below:


Table 1: Valencies of common elements

For our purposes, an atom consists of an element together with a list of weighted bonds. Again, for our purposes, a bond consists of an atom and a weight.
 
When an atom has yet to be added to a molecule (we’ll call this a free atom), its list of bonds will consist of v bonds each of which consist of a hydrogen atom and a weight equal to 1. Here v is the valency of the element (see the rightmost column of Table 1). We will refer to this type of bond as a hydrogen bond. So, a carbon atom that has yet to be attached to a molecule will have 4 hydrogen bonds and can be visualised as shown in Figure 1:

Figure 1: A free carbon atom

Note that as bonds in this case have weight 1, they are represented by using single line. Bonds of weight 2 will be represented using a double line, and so on. A Hydrogen atom’s bond list is empty.

When two free atoms which are not hydrogen atoms are connected via a bond of weight w, they each lose w hydrogen bonds to accommodate the new bond. So, if the carbon atom above is connected to an oxygen atom via a double bond we have:


 
H

 
H    C    H H
 
H
(2)    H
+    0    C    0
H    H
 
Figure 2: adding a bond between two free atoms

I have added the number 2 above the + sign to indicate that a double bond is being added. Also, the angle at which I have drawn the bonds is not significant (they just look nicer drawn symmetrically).

A similar process occurs when a free atom is added to an existing molecule. E.g.
 
H    H
      
H    C    C    H H        H
 

(2)
+
 
H    H    H
 
0    H    C    C
H    H    O
 
Figure 3: adding a free atom to a molecule

Note that I have coloured the specific C atom to which I want to bond the oxygen atom.
 
Entire molecules can be constructed by starting with a single free atom and adding further atoms and bonds. See the accompanying Examples file for some example molecules and how we would construct them in this way. Note that when atoms are added via a single bond, no number is added above the bond.

In this exercise we will assume that our molecules do not contain loops (or rings).

We can represent a molecule via a string in two different ways, either in a format that we will refer to as the molecule’s structural formula or in a format that is known as its smiles string. For example, the structural formula of the molecule on the left of Figure 3 is CH3CH3 (it is composed of two C atoms, each of which have three H bonds) and its smiles string is CC. Note that the smiles string differs from the structural formula in that the H atoms are omitted.

Another example is the molecule on the right of Figure 3. Its structure is CH3CH=O and its smiles string is CC=O. Note that the double bond is represented by a “=”. A triple bond is represented by a “#”. For example, the molecule shown in Figure 4 has structural formula CH#CH and smiles formula C#C.

H    C    Figure 4: Molecule with triple bond

Branches in molecules are represented in the strings using brackets to enclose all the (non-hydrogen) branches when there is more than one such branch. As an example, see the molecule in Figure 5 below.

 
H    H    H
           
H    C    C    C    O    H
 

Figure 5: Molecule with branching
 

H    C    H
H    H
H


The structural formula is CH3CH(CH3)(CH2OH) and the smiles string is CC(C)(CO). The highlighted C atom has two non-hydrogen branches, one involving a CH3 sub-molecule and the other a CH2OH sub-molecule. There are many more examples of molecules with their structural formulas and smiles strings in the Examples file. Note that convention states that when there are multiple branches all but the last one is enclosed in brackets. You can follow this convention or use brackets for all branches as you choose. mile


The Exercise
You have been provided with a Java interface, Molecule.java. You must not change this file in any way.

Part A: You have also been provided with three outline classes: Atom, Bond
and TreeMolecule. You should complete these three classes. Note that
TreeMolecule.java implements the Molecule interface (and should therefore implement its methods). I have provided a test class, namely TestMolecule.java, which you can use to test your TreeMolecule class. I will use a similar class to
 
test your programs. Note that the test program only calls the methods declared in the Molecule interface. You can include helper methods in your TreeMolecule class, but only to help the implementation of the methods declared in the interface. You should not rely on any other classes, apart from via the usual import statements if required. You should not use a Java collection to implement your TreeMolecule (e.g. don’t just import a LinkedList and add your atoms to that).

Part B: In addition, you should prepare a document in which you provide algorithms associated with each of the methods in Molecule.java, which correspond to your TreeMolecule implementation. This should be formally presented and not include java code (or any sort of programming code or pseudo code). As examples of the sort of thing required, see the lecture notes and tutorial sheet solutions.

Submission
You should submit the following via moodle as a single zipped folder, ADS_2023.zip:
•    your completed files TreeMolecule.java, Atom.java and Bond.java.
•    your algorithm document, algorithms.pdf

You should submit no further files. Each submitted file should contain a comment at the top of the file with your name and student number.


Assessment
Your assessment will be marked against the following criteria:

Part A:
Correctness (pass my test program): 10 marks
Elegance (commenting, brevity, effective use of recursion): 5 marks

Part B:
Proper algorithm presentation: 7 marks

Your total mark will be converted to a grade on the University’s 22-point scale. Your mark will be reduced if your code is clumsy or hard to read, or if you do not follow the above submission instructions.
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值