{
  "translations" :{
    "en": {
      ".exerciseTitle": "Red-Black Tree Insertion",
      "av_Authors": "Kasper Hellström",
      ".instructLabel": "Instructions:",
      ".instructions": "Move the values from the stack to the tree. Color the nodes and balance the tree using rotations when it becomes necessary."
    },
    "fi": {
      ".exerciseTitle": "Lisäys punamustaan puuhun",
      "av_Authors": "Kasper Hellström",
      ".instructLabel": "Ohjeet:",
      ".instructions": "Lisää pinon avaimet alla olevaan punamustaan hakupuuhun. Muuta solmujen väriä ja tasapainota puuta aina kun se on tarpeellista."
    }
  },
  "code": {
    "english": [
      "1. Search (top-down) and insert the new item u as in a Binary Search Tree.",
      "2. Return (bottom-up) and",
      "2.1 If u is root, make it black and the algorithm ends or",
      "2.2 if its parent t is black, the algorithm ends",
      "2.3 If both u and its parent t are red, do one of the following:",
      "2.3.1. [change colors] If t and its sibling v are red:",
      "         Color t and v black and their parent p red.",
      "         Continue the algorithm with p if necessary.",
      "2.3.2. [rotations] If t is red and v black, perform a rotation.",
      "         After the rotation, p and its new parent exchange their colors.",
      "         There are no longer two consequtive red nodes in the tree.",
      "",
      "ROTATION:",
      "1 While the recursion returns, keep track of",
      "    node p,",
      "    p's child t and",
      "    p's grandchild u within the path from inserted node to p.",
      "2 If rotation is needed in p, do one of the following rotations:",
      "    if (p.left == t) and (p.left.left == u), single rotation right in p;",
      "    if (p.right == t) and (p.right.right == u), single rotation left in p;",
      "    if (p.left == t) and (p.left.right == u), LR-double rotation in p; or",
      "    if (p.right == t) and (p.right.left == u), RL-double rotation in p."
    ],
    "finnish": [
      "1. Haetaan (juuresta lehteen) alkion paikka puussa ja lisätään se uudeksi",
      "   punaiseksi lehdeksi u.",
      "2. Palataan (lehdestä juureen päin) ja",
      "2.1 Jos ollaan juuressa, värjätään se mustaksi ja lopetetaan tai",
      "2.2 jos u:n isä t on musta, voidaan lopettaa.",
      "2.3 Jos u:n isä t on puinainen täytyy tehdä yksi seuraavista operaatioista:",
      "2.3.1. [värinvaihto] Jos sekä t että sen sisarsolmu v ovat punaisia,",
      "       tehdään värien vaihto, jossa t:n isä p muuttuu punaiseksi ja",
      "       t sekä v mustiksi. Tarvittaessa tasapainotusta jatketaan ylempänä",
      "       puussa, jos p:n isä on punainen.",
      "2.3.2. [rotaatio] Jos t on punainen ja v musta, tarvitaan rotaatio,",
      "       joka poistaa peräkkäiset punaiset kaaret. Rotaatio valitaan kuten",
      "       AVL-puussa. Lisäksi p ja uusi juuri (p:n uusi isä) vaihtavat väriä.",
      "       Rotaation jälkeen punaiset kaaret eivät ole enää peräkkäin.",
      "",
      "ROTAATIO:",
      "1 Rekursion palatessa (bottom-up) pidetään kirjaa",
      "    solmusta p,",
      "    p:n lapsesta t ja",
      "    p:n lapsenlapsesta u polulla lisätystä solmusta p:hen.",
      "2 Jos tarvitaan rotaatio solmussa p tehdään jokin seuraavista:",
      "    jos (p.left == t) ja (p.left.left == u),",
      "        yksinkertainen rotaatio oikealle p:ssä;",
      "    jos (p.right == t) ja (p.right.right == u),",
      "        yksinkertainen rotaatio vasemmalle p:ssä;",
      "    jos (p.left == t) ja (p.left.right == u),",
      "        LR-kaksoisrotaatio p:ssä; tai",
      "    jos (p.right == t) ja (p.right.left == u),",
      "        RL-kaksoisrotaatio p:ssä."
    ]
  }
}
