Artificer | Class Features | Dungeons & Dragons 5e

Author: Jesse

Jun. 17, 2024

Artificer | Class Features | Dungeons & Dragons 5e

Artificer

Hit Points

Hit Dice:

d8 per Artificer level

For more Casting Baginformation, please contact us. We will provide professional answers.

Hit Points at first Level:

8 + your Constitution Modifier

Hit Points at Higher Levels:

1d8 (or 5) + your Constitution modifier per artificer level after 1st

Proficiences

Armor: Light Armour, Medium Armour, ShieldWeapons: Simple Weapons, FirearmsTools: Smithing, Thievery , and one additional crafting proficiency of your choice.

Saving Throws:

Constitution, Intelligence

Skills:

Choose two from Arcana, History, Investigation, Medicine, Nature, Perception, Psionics, or Sleight of Hand.

Overview & Creation

Masters of unlocking magic in everyday objects, artificers are supreme inventors. They see magic as a complex system waiting to be decoded and controlled. Artificers use tools to channel arcane power, crafting magical objects. To cast a spell, an artificer could use alchemist&#;s supplies to create a potent elixir, calligrapher&#;s supplies to inscribe a sigil of power on an ally&#;s armor, or tinker&#;s tools to craft a temporary charm. The magic of artificers is tied to their tools and their talents.  

Class Features

Magical Tinkering

At 1st level, you learn how to invest a spark of magic into mundane objects. To use this ability, you must have tinker&#;s tools or other artisan&#;s tools in hand. You then touch a Tiny non-magical object as an action and give it one of the following magical properties of your choice:

 

&#; The object sheds bright light in a 5-foot radius and dim light for an additional 5 feet.
&#; Whenever tapped by a creature, the object emits a recorded message that can be heard up to 10 feet away. You utter the message when you bestow this property on the object, and the recording can be no more than 6 seconds long.
&#; The object continuously emits your choice of an odor or a nonverbal sound (wind, waves, chirping, or the like). The chosen phenomenon is perceivable up to 10 feet away.
&#; A static visual effect appears on one of the object&#;s surfaces. This effect can be a picture, up to 25 words of text, lines and shapes, or a mixture of these elements, as you like.

 

The chosen property lasts indefinitely. As an action, you can touch the object and end the property early. You can bestow magic on multiple objects, touching one object each time you use this feature, though a single object can only bear one property at a time. The maximum number of objects you can affect with this feature at one time is equal to your Intelligence modifier (minimum of one object). If you try to exceed your maximum, the oldest property immediately ends, and then the new property applies.

 

Spellcasting

You have studied the workings of magic and how to channel it through objects. As a result, you have gained the ability to cast spells. To observers, you don&#;t appear to be casting spells in a conventional way; you look as if you&#;re producing wonders using mundane items or outlandish inventions.

 

Tools Required

You produce your artificer spell effects through your Tools. You must be proficient with the Tool to use it in this way. After you gain the Infuse Item feature at 2nd level, you can also use any item bearing one of your infusions as a spellcasting focus.

 

Cantrips

At 1st level, you know two cantrips of your choice from the

 

Preparing and Casting Spells

The Artificer table shows how many spell slots you have to cast your

Cure Wounds

, you can cast it using a 1st-level or a 2nd-level slot. Casting the spell doesn&#;t remove it from your list of prepared spells. You can change your list of prepared spells when you finish a long rest. Preparing a new list of

 

Spellcasting Ability

Intelligence is your spellcasting ability for your

 

Spell Save DC = 8 + your Proficiency Bonus + your Intelligence modifier
Spell Attack Modifier = your Proficiency Bonus + your Intelligence modifier

 

Study Item

You spend 10 minutes to prepare yourself to examine the pure magical energy of the Weave. For the next ten minutes after your preparations you can sense the faint aura of magic around visible objects within 30 feet of you. The aura tells you the spells school of magic and any noticeable source of magical energy. This ability can penetrate thin barriers, but it is blocked by 1 foot of stone, 1 inch of common metal, a thin sheet of lead, or 3 feet of wood or dirt. Alternatively you can spend 10 minutes to learn the properties of a magical item and how to use them, whether it requires attunement to use, and how many charges it has, if any. You learn whether any spells are affecting the item and what they are. If the item was created by a spell, you learn which spell created it. At 11th level, you can use both of these benefits using an action instead of 10 minutes.

 

Ritual Casting

You can cast an

 

Cantrip Versatility

You can replace a cantrip you know with another cantrip available to you on a long rest.

 

Artificer Specialist

When you select this class you choose the type of specialist you are (Options are at the bottom of the page). Your choice grants you features at 3rd level, 5th level, 9th and 15th level.

 

Infuse Item

At 2nd level, you gain the ability to imbue items with certain magical infusions. The magic items you create with this feature are effectively prototypes of permanent items.

 

Infusions Known

When you gain this feature, pick four

 

Infusing an Item

Whenever you finish a short rest, you can touch a object and imbue it with one of your

 

The Right Tool for the Job

At 3rd level, you learn how to produce exactly the tool you need: with tinker&#;s tools in hand, you can magically create one set of artisan&#;s tools in an unoccupied space within 5 feet of you. This creation requires 1 hour of uninterrupted work, which can coincide with a short or long rest. Though the product of magic, the tools are nonmagical, and they vanish when you use this feature again.

 

Ability Score Improvement or Feat

When you reach 4th Level, and again at 8th, 12th, 16th, and 19th level, you can increase one ability score of your choice by 2, or you can increase two Ability Scores of your choice by 1. As normal, you can&#;t increase an ability score above 20 using this feature. Alternatively you can take a Feat from the

 

Tool Expertise

Starting at 6th level, your proficiency bonus is doubled for any ability check you make that uses your proficiency with a tool.

 

Flash of Genius

Starting at 7th level, you gain the ability to come up with solutions under pressure. When you or another creature you can see within 30 feet of you makes an ability check or a saving throw, you can use your reaction to add your Intelligence modifier to the roll. You can use this feature a number of times equal to your Intelligence modifier (minimum of once). You regain all expended uses when you finish a long rest.

 

Magic Item Adept

When you reach 10th level, you achieve a profound understanding of how to use and make magic items:
&#; You can attune to up to four magic items at once.
&#; If you craft a magic item with a rarity of common or uncommon, it takes you a quarter of the normal time, and it costs you half as much of the usual gold.

 

Spell-Storing Item

At 11th level, you learn how to store a spell in an object. Whenever you finish a long rest, you can touch one simple or martial weapon or one item that you can use as a spellcasting focus, and you store a spell in it, choosing a 1st- or 2nd-level spell from the

 

Magic Item Savant

At 14th level, your skill with magic items deepens more:
&#; You can attune to up to five magic items at once.
&#; You ignore all class, race, spell, and level requirements on attuning to or using a magic item.

 

Magic Item Master

Starting at 18th level, you can attune to up to six magic items at once, and you can craft magic items up to Rare quality.

 

Soul of Artifice

At 20th level, you develop a mystical connection to your magic items, which you can draw on for protection:
&#; You gain a +1 bonus to all saving throws per magic item you are currently attuned to.
&#; If you&#;re reduced to 0 hit points but not killed outright, you can use your reaction to end one of your

Starting Equipment

At 1st level, you learn how to invest a spark of magic into mundane objects. To use this ability, you must have tinker&#;s tools or other artisan&#;s tools in hand. You then touch a Tiny non-magical object as an action and give it one of the following magical properties of your choice:&#; The object sheds bright light in a 5-foot radius and dim light for an additional 5 feet.&#; Whenever tapped by a creature, the object emits a recorded message that can be heard up to 10 feet away. You utter the message when you bestow this property on the object, and the recording can be no more than 6 seconds long.&#; The object continuously emits your choice of an odor or a nonverbal sound (wind, waves, chirping, or the like). The chosen phenomenon is perceivable up to 10 feet away.&#; A static visual effect appears on one of the object&#;s surfaces. This effect can be a picture, up to 25 words of text, lines and shapes, or a mixture of these elements, as you like.The chosen property lasts indefinitely. As an action, you can touch the object and end the property early. You can bestow magic on multiple objects, touching one object each time you use this feature, though a single object can only bear one property at a time. The maximum number of objects you can affect with this feature at one time is equal to your Intelligence modifier (minimum of one object). If you try to exceed your maximum, the oldest property immediately ends, and then the new property applies.You have studied the workings of magic and how to channel it through objects. As a result, you have gained the ability to cast spells. To observers, you don&#;t appear to be casting spells in a conventional way; you look as if you&#;re producing wonders using mundane items or outlandish inventions.You produce your artificer spell effects through your Tools. You must be proficient with the Tool to use it in this way. After you gain the Infuse Item feature at 2nd level, you can also use any item bearing one of your infusions as a spellcasting focus.At 1st level, you know two cantrips of your choice from the Artificer Spell List . At higher levels, you learn additional artificer cantrips of your choice, as shown in the Cantrips Known column of the Artificer table. When you gain a level in this class, you can replace one of the artificer cantrips you know with another cantrip from the artificer spell list.The Artificer table shows how many spell slots you have to cast your Artificer Spells . To cast one of your Artificer Spells of 1st level or higher, you must expend a slot of the spell&#;s level or higher. You regain all expended spell slots when you finish a long rest. You prepare the list of Artificer Spells that are available for you to cast, choosing from the Artificer Spells List . When you do so, choose a number of Artificer Spells equal to your Intelligence modifier + half your artificer level, rounded down (minimum of one spell). The spells must be of a level for which you have spell slots. For example, if you are a 5th-level artificer, you have four 1st-level and two 2nd-level spell slots. With an Intelligence of 14, your list of prepared spells can include four spells of 1st or 2nd level, in any combination. If you prepare the 1st-level spell, you can cast it using a 1st-level or a 2nd-level slot. Casting the spell doesn&#;t remove it from your list of prepared spells. You can change your list of prepared spells when you finish a long rest. Preparing a new list of Artificer Spells requires time spent tinkering with your spellcasting focuses: at least 1 minute per spell level for each spell on your list.Intelligence is your spellcasting ability for your Artificer Spells ; your understanding of the theory behind magic allows you to wield these spells with superior skill. You use your Intelligence whenever an Artificer Spell refers to your spellcasting ability. In addition, you use your Intelligence modifier when setting the saving throw DC for an artificer spell you cast and when making an attack roll with one.= 8 + your Proficiency Bonus + your Intelligence modifier= your Proficiency Bonus + your Intelligence modifierYou spend 10 minutes to prepare yourself to examine the pure magical energy of the Weave. For the next ten minutes after your preparations you can sense the faint aura of magic around visible objects within 30 feet of you. The aura tells you the spells school of magic and any noticeable source of magical energy. This ability can penetrate thin barriers, but it is blocked by 1 foot of stone, 1 inch of common metal, a thin sheet of lead, or 3 feet of wood or dirt. Alternatively you can spend 10 minutes to learn the properties of a magical item and how to use them, whether it requires attunement to use, and how many charges it has, if any. You learn whether any spells are affecting the item and what they are. If the item was created by a spell, you learn which spell created it. At 11th level, you can use both of these benefits using an action instead of 10 minutes.You can cast an Artificer Spell as a ritual if that spell has the ritual tag and you have the spell prepared.You can replace a cantrip you know with another cantrip available to you on a long rest.When you select this class you choose the type of specialist you are (Options are at the bottom of the page). Your choice grants you features at 3rd level, 5th level, 9th and 15th level.At 2nd level, you gain the ability to imbue items with certain magical infusions. The magic items you create with this feature are effectively prototypes of permanent items.When you gain this feature, pick four Artificer Infusions to learn, you learn additional Infusions of your choice when you reach certain levels in this class, as shown in the Infusions Known column of the Artificer table. Whenever you gain a level in this class, you can replace one of the Artificer Infusions you learned with a new one.Whenever you finish a short rest, you can touch a object and imbue it with one of your Artificer Infusions , turning it into a magic item. An Infusion works on only certain kinds of objects, as specified in the infusion&#;s description. If the item requires attunement, you can attune yourself to it the instant you infuse the item. If you decide to attune to the item later, you must do so using the normal process for attunement (spending an hour or during a Short Rest). Your Infusion remains in an item indefinitely, but when you die, the Infusion vanishes after a number of days have passed equal to your Intelligence modifier (minimum of 1 day). The infusion also vanishes if you give up your knowledge of the infusion for another one. You can infuse more than one nonmagical object at the end of a short rest; the maximum number of objects appears in the Infused Items column of the Artificer table. You must touch each of the objects, and each of your infusions can be in only one object at a time. Moreover, no object can bear more than one of your infusions at a time. If you try to exceed your maximum number of infusions, the oldest infusion immediately ends, and then the new infusion applies.At 3rd level, you learn how to produce exactly the tool you need: with tinker&#;s tools in hand, you can magically create one set of artisan&#;s tools in an unoccupied space within 5 feet of you. This creation requires 1 hour of uninterrupted work, which can coincide with a short or long rest. Though the product of magic, the tools are nonmagical, and they vanish when you use this feature again.When you reach 4th Level, and again at 8th, 12th, 16th, and 19th level, you can increase one ability score of your choice by 2, or you can increase two Ability Scores of your choice by 1. As normal, you can&#;t increase an ability score above 20 using this feature. Alternatively you can take a Feat from the Feats List Starting at 6th level, your proficiency bonus is doubled for any ability check you make that uses your proficiency with a tool.Starting at 7th level, you gain the ability to come up with solutions under pressure. When you or another creature you can see within 30 feet of you makes an ability check or a saving throw, you can use your reaction to add your Intelligence modifier to the roll. You can use this feature a number of times equal to your Intelligence modifier (minimum of once). You regain all expended uses when you finish a long rest.When you reach 10th level, you achieve a profound understanding of how to use and make magic items:&#; You can attune to up to four magic items at once.&#; If you craft a magic item with a rarity of common or uncommon, it takes you a quarter of the normal time, and it costs you half as much of the usual gold.At 11th level, you learn how to store a spell in an object. Whenever you finish a long rest, you can touch one simple or martial weapon or one item that you can use as a spellcasting focus, and you store a spell in it, choosing a 1st- or 2nd-level spell from the Artificer Spell List that requires 1 action to cast (you needn&#;t have it prepared). While holding the object, a creature can take an action to produce the spell&#;s effect from it, using your spellcasting ability modifier. If the spell requires concentration, the creature must concentrate. The spell stays in the object until it&#;s been used a number of times equal to twice your Intelligence modifier (minimum of twice) or until you use this feature again to store a spell in an object.At 14th level, your skill with magic items deepens more:&#; You can attune to up to five magic items at once.&#; You ignore all class, race, spell, and level requirements on attuning to or using a magic item.Starting at 18th level, you can attune to up to six magic items at once, and you can craft magic items up to Rare quality.At 20th level, you develop a mystical connection to your magic items, which you can draw on for protection:&#; You gain a +1 bonus to all saving throws per magic item you are currently attuned to.&#; If you&#;re reduced to 0 hit points but not killed outright, you can use your reaction to end one of your Artificer Infusions , causing you to drop to 1 hit point instead of 0.

Roll 5d4 x10gp

 

One of the highest staring gold amounts, the artificer has some of the most expensive gear outside of Heavy Armour, usually having to balance several crafting choices as well as magical item creation.

Subclass Options

One of the highest staring gold amounts, the artificer has some of the most expensive gear outside of Heavy Armour, usually having to balance several crafting choices as well as magical item creation.

Alchemist Specialists

An Alchemist is an expert at combining reagents to produce mystical effects, by far the most far-flunk of Artificers. The heartland of this particular craft is in Halruaa, Chult, and the Trade Lanes of the Serpent Isles, where powerful and reactive reagents and arcane plant life grow in abundance. These craftsmen can often settle down with impunity, many townships lacking Doctor&#;s or the various Church-run scams throwing resources and support behind a good Alchemist.

 

Travelling Doctor Build
Arcanist Robes [Alchemist] (1gp)
Dagger (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gp
Light Crossbow (1d8 piercing, range 80/320ft, Ammunition, Loading, Two-Handed): 5lb, 25gp
Healer&#;s Kit (4gp), Herbalist Pouch (10gp) and Alchemist&#;s Station (50gp)
Scholar&#;s Pack (14gp) containing a backpack, a notebook, ink & pen, parchment, a little bag of sand, and a sealing wax.

 

Tool Proficiency

When you adopt this specialization you gain proficiency with

 

Alchemist Spells

You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the

 

Experimental Elixir

Beginning at 3rd level, you have become a master of mixing reactive solutions to create unique

 

Alchemical Savant

At 5th level, you develop masterful command of magical chemicals, enhancing the healing and damage you create through them. Whenever you cast a spell using your alchemist&#;s supplies as the spellcasting focus or an alchemy attack, you gain a bonus to one roll of the spell. That roll must restore hit points or be a damage roll that deals acid, fire, necrotic, or poison damage, and the bonus equals your Intelligence modifier (minimum of +1). This increases to 1d8 + your Intelligence modifier at 9th level, and 2d8 + your Intelligence modifier at 15th level. You also gain the following additional elixir affects;

 

Restorative Reagents

Starting at 9th level, you can incorporate restorative reagents into some of your works:
&#; Whenever a creature drinks an experimental elixir or healing tincture you created, the creature gains temporary hit points equal to 2d6 + your Intelligence modifier (minimum of 1 temporary hit point).
&#; You can cast

Lesser Restoration

without expending a spell slot and without preparing the spell, provided you use alchemist&#;s supplies as the spellcasting focus. You can do so a number of times equal to your Intelligence modifier (minimum of once), and you regain all expended uses when you finish a long rest.
You also gain the following additional elixir affects;

 

Chemical Mastery

By 15th level, you have been exposed to so many chemicals that they pose little risk to you, and you can use them to quickly end certain ailments:
&#; You gain resistance to acid damage and fire damage, and you are immune to poison.
&#; You can cast

Greater Restoration

and

Heal

without expending a spell slot, without preparing the spell, and without material components, provided you use alchemist&#;s supplies as the spellcasting focus. Once you cast either spell with this feature, you can&#;t cast that spell with it again until you finish a long rest.

 

 

Archivist Specialists

What are the best ways to store vast amounts of information? That question has occupied chroniclers and librarians for centuries. Scrolls and books were the finest information-storing methods for a long time, but the first Archivists imagined something greater: using that magic to improve the world around them. Storing is not enough, but making it available to the world. These techniques have yet to be perfected and institutionalized, and of all artificers, archivists are on the cutting edge of arcane science.

 

Librarian Build
Studded Leather (12 + Dex mod AC): 13lb, 45gp
Staff (1d6/d8 bludgeoning): 4lb, 2sp
Simple Flintlock (2d10 force, range 10/40ft, Loading): 5lb, 12gp
Spell Prism (120gp), Calligapher&#;s Kit (1gp)
Scholar&#;s Pack (14gp) containing a backpack, a notebook, ink & pen, parchment, a little bag of sand, and a sealing wax.

 

Tool Proficiency

When you adopt this specialization you gain proficiency with

 

Archivist Spells

You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the

 

Secular Scrivener

You became proficient in the ways of

 

Fateful Naming

Starting at 3rd level, you can bend magic to assist or hinder creatures through the power of their true names, and even use those names as an anchor to affect others around them. The

Bane

and

Bless

spells are Artificer spells for you, and you add them to your spellbook. You cvan cast both of these spells at a level equal to your proficiency bonus, a number of times equal to your Intelligence modifier (minimum of 1), and you regain all expended uses when you finish a long rest.

 

Pen is Mightier Than the Sword

Beginning at 5th level, when you use your action to use a Scroll, you can also use your bonus action to make a basic melee attack, or cast a cantrip.

 

Greater Onomancy

Starting at 9th level, as an action you can touch a creature that is possessed, expend a spell slot of 1st level or higher, and exorcise the presence. The target must succeed on a Wisdom saving throw against your Artificer Spell Save or be exorcised and banished to their home reality. Additionally you can cast the

Protection from Evil and Good

at a level equal to your proficiency bonus, and a number of times equal to your Intelligence modifier (minimum of 1). You regain all expended uses of this ability after a long rest.

 

True Onomancy

At 15th level, You have learned how to bypass a named creature&#;s defenses against certain types of damage. When you cast a spell that deals damage to a creature whose True Name you speak as part of casting the spell, you can cause the spell to deal force or psychic damage to the creature, instead of the spell&#;s normal damage type.

 

 

Armourer Specialists

A recent innovation from the Halls of Stormwind and birthplace of the Warforged. Ambitious Artificers at the school managed to adapt the learning of mechanisation and automaton to armour. Designed to enhance the artificers magic, unleash potent attacks, and generate a formidable defense. The artificer bonds with a single set of powered armor, becoming one with it even as they experiment with it and refine its magical capabilities into a second skin.

 

Travelling Blacksmith Build
Cuirass (16 AC): 30lb, 75gp and Heater Shield (+2 AC): 8lb, 20gp
Light Hammer (1d6 bludgeoning, range 20/60ft, Light): 2lb, 5gp
Appraisal Kit (5gp), Smiths&#; Tools (20gp), Leatherworking Kit (15gp), and Runecarvers&#; Tools (50gp)
Dungeoneer&#;s Pack (8gp) containing a backpack, a crowbar, a hammer, 10 pitons, 10 torches, 50ft of hemp rope, a tinderbox.

 

Tool Proficiency

When you adopt this specialization you gain proficiency with

 

Armourer Spells

You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the

 

Power Armour

Your metallurgical pursuits have led to you making armour a conduit for your artificer magic. During a Long Rest, you can turn a suit of heavy armour you are wearing into power armour, provided you have smith&#;s tools in hand. You gain the following benefits while wearing the power armour:
&#; The power armour attaches to you and can&#;t be removed against your will. It also expands to cover your entire body, and it replaces any missing limbs, functioning identically to a body part it is replacing.
&#; While wearing power armour, melee weapons can use your Intelligence modifier, instead of Strength or Dexterity, for the attack and damage rolls.
&#; If the armour normally has a Strength requirement, the power armour lacks this requirement for you.
&#; You can use the power armour as a spellcasting focus for your artificer spells.
The armour continues to be power armour until you create another set of Power Armour, or you die.

 

Guardian Repulsors

Beginning at 3rd level, you have completed addition of repulsors in your armour. Your unarmed strikes now deal 1d8 + Intelligence modifier thunder damage, you can also fire off your gauntlets with a range of 20/60ft to deal 1d8 + Intelligence force damage. The gaunlets automatically return to the wearer and reattach to your armour. Your weapon attacks also deal an additional 1d4 force damage. A creature hit by your spells or weapons has disadvantage on attack rolls against targets other than you until the start of your next turn, as the armour magically emits a distracting pulse when the creature attacks someone else. You also gain a bonus action that you can use on each of your turns to gain temporary hit points equal to your level in this class, replacing any temporary hit points you already have. You lose these temporary hit points if you doff the armour.

 

Extra Attack

Starting at 5th level, you can attack twice, rather than once, whenever you take the Attack action on your turn.

 

Modular Armour

Beginning at 9th level, you learn how to use your artificer infusions to specially modify the armour enhanced by your Power Armor feature. That armour now counts as separate items for the purposes of your Infuse Items feature: armour (the chest piece), amulet, belt, boots, bracers, and rings. Each of those items can bear one of your infusions. In addition, the maximum number of items you can infuse at once increases by 2, but those extra items must be part of your power armour.

 

Perfected Armour

At 15th level, tinkering with your armours energy system leads you to discover a powerful pulling force. When a creature you can see ends its turn within 30 feet of you, you can use your reaction to force the creature to succeed on a Strength saving throw against your spell save DC or be pulled up to 30 feet toward you to an unoccupied space. If you pull the target to space within 5 feet of you, you can make a melee weapon attack against it as part of this reaction. You can use this reaction a number of times equal to your Intelligence modifier (minimum of once). You regain all expended uses of it when you finish a long rest.

 

 

Artillerist Specialists

The mastery of arcanotech Artillery is still one lead by Gnomes, the Gnomes of Lantan&#;s Rest that is. One of the smallest geographical settlements in the Sword Coast, their Skyships and Navy are universally feared for their legions of Artillerist artificers. Their destructive potential from a stationary point in unmatched except maybe by the highest of War Magic&#;s, with many other Navy&#;s paltry attempts producing a few capable Artillerist&#;s.

 

Gunnery Pirate Build
Studded Leather (12 + Dex mod AC): 13lb, 45gp
Dagger (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gp
Simple Flintlock (2d10 force, range 10/40ft, Loading): 5lb, 12gp
Thieves&#; Tools (25gp), Scrimshaws&#; Tools (15gp), Smiths&#; Tools (20gp), and Leatherworking Kit (15gp).
Burglar&#;s Pack (4gp) containing a backpack, a bag of 1,000 ball bearings, 50ft of hemp rope, string, bells, a crowbar, a hooded lantern, flasks of oil, tinderbox.

 

Tool Proficiency

When you adopt this specialization you gain proficiency with

 

Artillerist Spells

You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the

 

Eldritch Cannon

At 3rd level, you learn how to create a magical cannon, you can take an action to magically create a Small or Tiny eldritch cannon in an unoccupied space on a horizontal surface within 5 feet of you. A Small eldritch cannon occupies its space, and a Tiny one can be held in one hand. Once you create a cannon, you can&#;t do so again until you finish a long rest or until you expend a spell slot of 1st level or higher. You can have only one cannon at a time and can&#;t create one while your cannon is present. The cannon is a magical object. Regardless of size, the cannon has an AC of 18 and a number of hit points equal to five times your artificer level. It is immune to poison and psychic damage. If it is forced to make an ability check or a saving throw, treat all its ability scores as 10 (+0). If the

Mending

spell is cast on it, it regains 2d6 hit points. It disappears if it is reduced to 0 hit points or after 1 hour. You can dismiss it early as an action. When you create the cannon, you determine its appearance and whether it has legs. You also decide which type it is, choosing from the options on the Eldritch Cannons table. On each of your turns, you can take a bonus action to cause the cannon to activate if you are within 60 feet of it. As part of the same bonus action, you can direct the cannon to walk or climb up to 15 feet to an unoccupied space, provided it has legs.

 

Eldritch Cannons
&#; Flamethrower: The can non exhales fire in an adjacent 15-foot cone that you designate. Each creature in that area must make a Dexterity saving throw against your spell save DC, taking 2d8 fire damage on a failed save or half as much damage on a successful one. The fire ignites any flammable objects in the area that aren&#;t being worn or carried.
&#; Force Balista: Make a ranged spell attack, originating from the cannon, at one creature or object within 120 feet of it. On a hit, the target takes 2d8 force damage, and if the target is a creature, it is pushed up to 5 feet away from the cannon.
&#; Protector: The cannon emits a burst of positive energy that grants itself and each creature of your choice within 10 feet of it a number of temporary hit points equal to 1d8 + your Intelligence modifier (minimum of +1) .

 

Arcane Firearm

At 5th level, you know how to turn a wand, staff, or rod into an arcane firearm, a conduit for your destructive spells. When you finish a long rest, you can use woodcarver&#;s tools to carve the material of a wand, staff, or rod and thereby turn it into a flintlock in addition to an arcane focus. The firearm turns back into its original form if you repeat this process on another Item. The change otherwise last indefinitely. When you cast an

 

Explosive Cannon

Starting at 9th level, every eldritch cannon you create is more destructive:
&#; The cannon&#;s damage rolls all increase by 1d8.
&#; As an action, you can command the cannon to detonate if you are within 60 feet of it. Doing so destroys the cannon and forces each creature within 20 feet of it to make a Dexterity saving throw against your spell save DC, taking 3d8 force damage on a failed save or half as much damage on a successful one.

 

Fortified Position

Starting at 15th level, you&#;re a master at forming well-defended emplacements using Eldritch Cannon:
&#; You and your allies have half cover while within 10 feet of a cannon you create with Eldritch Cannon, as a result of a shimmering field of magical protection that the cannon emits.
&#; You can now have two cannons at the same time. You can create two with the same action (but not the same spell slot), and you can activate both of them with the same bonus action. You determine whether the cannons are identical to each other or different. You can&#;t create a third cannon while you have two.

 

 

Battle Smith Specialists

The newest of Dwarven ingenuity, mixing the lessons of their Gnomish allies with Dwarven martial tradition, comes the Battle Smith. Protected, mobile, and able to create a rolling defence crucial in the treacherous Underdark. A combination of protectorate and medic, a Battle Smith is an expert at defending others and repairing both material and personnel. To aid in their work, Battle Smiths are accompanied by a automaton called a &#;steel defender&#;, a protective companion of their own creation.

 

Underdark Guardian Build
Hauberk (13 + Dex mod [max 2] AC): 30lb, 60gp and Heater Shield (+2 AC): 8lb, 20gp
Warhammer (1d8/d10 bludgeoning): 2lb, 15gp or Cavalry Mace (1d10 bludgeoning, Reach 1): 18lb, 35gp
2 Light Hammer (1d6 bludgeoning, range 20/60ft, Light): 2lb, 5gp
Steppe Pony (30gp)
Smiths&#; Tools (20gp)
Dungeoneer&#;s Pack (8gp) containing a backpack, a crowbar, a hammer, 10 pitons, 10 torches, 50ft of hemp rope, a tinderbox.

 

Tool Proficiency

When you adopt this specialization you gain proficiency with

 

Battle Smith Spells

You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the

 

Steel Defender

By 3rd level, your tinkering has borne you a faithful companion, a steel defender. It is friendly to you and your companions, it defaults to a Dodge Action, unless you spend a Bonus action to make it Rend, Repair, Dash, Disengage, Help, Hide or Search. If you are incapacitated, the defender can take any action of its choice, not just Dodge.

 

Steel Defender (medium/large) AC: 15 HP: 2 + your Intelligence modifier +5 times your artificer level Speed: 40ft Senses: Darkvision 60ft
Str 14 (+2) Dex 12 (+1) Con 14 (+2) Int 4 (-4) Wis 10 (+0) Cha 6 (-2)
Saving Throws: Dex +1 + Proficiency Bonus, Con +2 + Proficiency Bonus.
Skills: Athletics +2 + Proficiency Bonus, Perception +Proficiency Bonus x 2
Immunity: Charmed, Disease, Exhaustion, Poison, Surprise
Force-Empowered Rend: +spell attack modifier to hit, 1d8 +proficiency bonus force damage.
Repair (3/Day): The magical mechanisms inside the defender restore 2d8 +Proficiency Bonus hit points to itself or to one construct or object within 5 feet of it.
Deflect Attack (Reaction): The defender imposes disadvantage on the attack roll of one creature it can see that is within 5 feet of it, provided the attack roll is against a creature other than the defender.

 

You determine the creature&#;s appearance and whether it has two legs or four; your choice has no effect on its game statistics. If the

Mending

spell is cast on it, it regains 2d6 hit points. If it has died within the last hour, you can use your smith&#;s tools as an action to revive it, provided you are within 5 feet of it and you expend a spell slot of 1st level or higher. The steel defender returns to life after 1 minute with all its hit points restored. At the end of a long rest, you can create a new steel defender if you have your smith&#;s tools with you. If you already have a steel defender from this feature, the first one immediately perishes.

 

Extra Attack

Starting at 5th level, you can attack twice, rather than once, whenever you take the Attack action on your turn.

 

Arcane Jolt

At 9th level, you learn new ways to channel arcane energy to harm or heal. When either you hit a target with a magic weapon attack or your steel defender hits a target, you can channel magical energy through the strike to create one of the following effects:
&#; The target takes an extra 2d6 force damage.
&#; Choose one creature or object you can see within 30 feet of the target. Healing energy flows into the chosen recipient, restoring 2d6 hit points to it.
You can use this energy a number of times equal to your Intelligence modifier (minimum of once), but you can do so no more than once on a turn. You regain all expended uses when you finish a long rest.

 

Improved Defender

At 15th level, your Arcane jolt and steel defender become more powerful:
&#; The extra damage and the healing of your Arcane jolt both increase to 4d6.
&#; Your steel defender gains a +2 bonus to Armor Class and a 80ft flying speed.
&#; Whenever your steel defender uses its Deflect Attack, the attacker takes force damage equal to 1d4 + your Intelligence modifier.

 

 

Portal Engineer Specialists

Teleportation has always been a popular path of arcane study, with most falling into the traditional methods tried and tested by braver spellcrafters. But never before has such a bone-headed and crazy level of experimental risk been taken before. The Portal Engineers of the Waterdeep and Illusk took the higher craft of Planeswalkers and reduced it into the most basic of abilities. And now they abuse the laws of the cosmos for quick hop and a skip around town&#;

 

Crazy Inventor Build
Studded Leather (12 + Dex mod AC): 13lb, 45gp
Dagger (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gp
Simple Flintlock (2d10 force, range 10/40ft, Loading): 5lb, 12gp
Thieves&#; Tools (25gp), Astronomy Equipment (35gp), and Planewalker&#;s Case (65gp)
Burglar&#;s Pack (4gp) containing a backpack, a bag of 1,000 ball bearings, 50ft of hemp rope, string, bells, a crowbar, a hooded lantern, flasks of oil, tinderbox.

 

Tool Proficiency

When you adopt this specialization you gain proficiency with

 

Portal Engineer Spells

You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the

 

Thinking With Portals

At 3rd level, you have mastered the art of creating portals. Using your bonus action, you create a portal within 30ft, the portal is 3 feet wide and 6 feet tall, and connect it to another portal within 30ft as the same size. Spells cannot travel through the portal but ranged attacks can. A creature must be willing to enter the portal to use it. This ability can be used a number of times equal to your Intelligence modifier, you regain all expended uses of this ability on a long rest. This range increases to 60ft at 9th level. Additionally, your weapon deals an additional 1d8 force damage through portal energy, this increases to 2d8 at 9th level.

 

I Don't Want Your Damn Lemons!

Starting at 5th level, you&#;ve learnt to channel your teleportation energy into those who travel through it. Once per round when a creature moves through your portal, they deal an additional 1d8 force damage to their attack. This increases to twice per round at 9th level, and three times per round at 15th level. You can choose to obscure the view of the portal, choose to make it one-way, or two-way obscurement.

 

Here Come the Test Results

At 9th level, you&#;ve learnt to teleport creatures other than yourself. As a reaction you can move an ally within 60ft of you anywhere else within 60ft of you. You regain the use of this ability on a short or long rest. Your portals can now also be used to teleport unwilling creatures that move through it.

 

The Cake is a Lie

At 15th level, you can cast

Teleport

 or

Plane Shift

 without having the spell prepared. You regain this ability on a long rest.

 

Puppeteer Specialists

A newly formed specialty of artifice using complex pulleys and nearly in-perceivable strings to move creatures and objects and control the world around you. While most artificers are overt and dangerously direct, you can appear harmless and unseen if you need to.

 

Marionetter Build
Hauberk (13 + Dex mod [max 2] AC): 30lb, 60gp
Dagger (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gp
Simple Flintlock (2d10 force, range 10/40ft, Loading): 5lb, 12gp
Thieves&#; Tools (25gp)
Burglar&#;s Pack (4gp) containing a backpack, a bag of 1,000 ball bearings, 50ft of hemp rope, string, bells, a crowbar, a hooded lantern, flasks of oil, tinderbox.

 

Tool Proficiency

When you adopt this specialization you gain proficiency with

 

Puppeteer Spells

You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the

 

If you are looking for more details, kindly visit Purchase Fiberglass Filtration Mesh.

Related links:
5 Things to Know Before Buying Stainless Steel Wire Mesh

Arcane Conduit

At 3rd level, you can bind a creature within 60ft to yourself with silk string, channeling energy to and from them. Once you create a magical string, you can&#;t do so again until you finish a long rest or until you expend a spell slot of 1st level or higher. You can only have one magical string at a time. If you create a new one, the original one loses its magic. The string also loses its magic after 1 hour, and you can dismiss its magic early as an action. This connection remains even if the creature moves out of range. As an action on each of your turns, you can reconnect the string to another creature. This connection ends when the string loses its magic. You can target the represented creature with spells that have a range of Touch, by casting such a spell on the string. As a bonus action on each of your turns, you can expose the string to a harmful effect within 5 feet of you to potentially damage the connected creature. The harmful effect must deal bludgeoning, piercing, slashing, acid, cold, fire, lightning, necrotic, radiant, or thunder damage. When you affect the string, the represented creature must succeed on a Wisdom saving throw or else take 2d8 of the corresponding damage type. If you use your action to cast a spell that deals a qualifying type of damage, you can choose for the string connection to deal that type of damage. For example, if you use your action to cast

Frostbite

, you can choose for the effigy connection to deal cold damage, regardless of whether you exposed the effigy to the actual spell effects or not.

 

Forceful Strings

Starting at 5th level, if your stringed creature makes a Strength or Dexterity based saving throw, attack roll, or ability check, you can use your reaction to force them to do it with advantage or disadvantage (your choice).
KEY BENEFITS OF 304 STAINLESS STEEL
How Does Aluminum Garden Fences Work?

 

Puppet Theatre

Beginning at 9th level, the damage rolls caused by your string increase by 1d8. As an action, you can see through the creature&#;s eyes and hear what it hears, and continue to do so until you use your action to return to your normal senses or until the string disappears. The creature is aware someone is perceiving through its senses, but does not necessarily know who it is or how they can do it.

 

Overpowering Strings

At 15th level, you have become a master of control. You can cast

Dominate Monster

on a stringed creature once without expending a spell slot. Once you have used this feature, you cannot use it again until you finish a long rest.

 

 

Sabtoteur Specialists

Most artificers are focused on stability and reliability. Now, reliability is always nice, but you were intensely interested in the unstable. The explosive, best executed in the enemies faces. Stealth and knowledge of your surrounding are your bread and butter more than the explosives you covet, but you also have the quickness of hand to deploy mid-combat in a pinch if caught unawares. But hopefully they never hear you coming&#; just your arrival.

 

Forest Trapper Build
Studded Leather (12 + Dex mod AC): 13lb, 45gp
Longbow (1d8 piercing, range 150/600ft, Ammunition, Heavy, Two-Handed): 2lb, 50gp
2 Daggers (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gp
Thieves&#; Tools (25gp), Alchemist&#;s Station (50gp)
Burglar&#;s Pack (4gp) containing a backpack, a bag of 1,000 ball bearings, 50ft of hemp rope, string, bells, a crowbar, a hooded lantern, flasks of oil, tinderbox.

 

Tool Proficiency

When you adopt this specialization you gain proficiency with

Mould Earth

cantrip.

 

Trapmaker Spells

You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the

 

Vulnerable Mark

You have learned to further enhance the magical affects of

Hunter's Mark

. When you cas the spell, you have advantage on Lore checks about your marked target and learn vulnerabilities and saving throws. You can cast the spell at 1st level a number of times equal to your proficiency bonus without using a spell slot. You regain all expended uses of this feature on a long rest.

 

Force Barricade

Starting at 3rd level, you learn how to create a deployable wall. You can use your action to deploy a semi-circle wall of half cover that is 15 feet diameter and 2 feet thick, originating at a point you can see within 60 feet. This cover has an AC of 10 + your Intelligence modifier and a number of hit points equalling ten times your Intelligence modifier. It is immune to poison damage, psychic damage, and all conditions. If it is forced to make an ability check or a saving throw, treat all its ability scores as 10 (+0). If the

Mending

spell is cast on it, it regains 2d6 hit points. It disappears if it is reduced to 0 hit points or after 1 hour. You can dismiss it early as an action. Once you create the barricade, you can&#;t do so again until you finish a long rest or until you expend a spell slot of 1st level or higher. You can only have one barricade at a time and can&#;t create one while your barricade is present. When you create cover, your allies gain the following additional effects below:
&#; Hospitality: As a bonus action on your turn, you can activate the protective energies within your barricade. When you activate this feature, all friendly creatures within 30ft of your cover gain 1d8 + Intelligence modifier temporary hit points.
&#; Reflection: This explosive barrier is built for defense. As a reaction, when your cover or an ally protected by your cover would be hit by an attack, you can activate this barricade to make a spell attack damage or deal 2d8 force damage to the attacker.

 

Rapid Deployment

Starting at 5th level, you can now create cover with your bonus action. The wall is now a full circle. In addition, you are able to take better aim from behind your cover. Once on each of your turns, while within 5ft of your cover when you hit a creature with an attack, you can cause the attack to deal an additionally 1d8 force damage to the target. When you reach 15th level, the extra damage increases to 2d8.

 

True Bastion

At 9th level, the cover you create for others is charged with extra power. Rapid Deployment, Hospitality, and Reflection gain an additional 1d8 to their respective healing or damage.

 

Fortified Barricade

At 15th level, you are masterful at keeping others safe. The cover you can build gains the following upgrades:
&#; Benefits of your cover gains an additional +2 to its Armour Class.
&#; Grants advantage against Area of Affect spells that target behind cover.

An Alchemist is an expert at combining reagents to produce mystical effects, by far the most far-flunk of Artificers. The heartland of this particular craft is in Halruaa, Chult, and the Trade Lanes of the Serpent Isles, where powerful and reactive reagents and arcane plant life grow in abundance. These craftsmen can often settle down with impunity, many townships lacking Doctor&#;s or the various Church-run scams throwing resources and support behind a good Alchemist.Arcanist Robes [Alchemist] (1gp)Dagger (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gpLight Crossbow (1d8 piercing, range 80/320ft, Ammunition, Loading, Two-Handed): 5lb, 25gpHealer&#;s Kit (4gp), Herbalist Pouch (10gp) and Alchemist&#;s Station (50gp)Scholar&#;s Pack (14gp) containing a backpack, a notebook, ink & pen, parchment, a little bag of sand, and a sealing wax.When you adopt this specialization you gain proficiency with Alchemy and Herbalism . You can also use and administer Alchemy Potions or Herbalism Tinctures as a bonus action. You can use a divine spell foci as a focus for your artifcier spells.You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they don&#;t count against the number of Artificer Spells you prepare.Beginning at 3rd level, you have become a master of mixing reactive solutions to create unique Elixirs . You can administer elixirs to others or yourself as a bonus action. These Elixirs can be added to Alchemy Potions Herbalism Tinctures , and Poisons to pair with the affect. You learn a number of Elixirs equal to your Intelligence modifier +1 (minimum of 2). At the end of a long rest, you create a number of Elixirs equal to double your proficiency modifier. You can use an action to refill an expended Elixir by expending a spell slot of 1st level or higher for each one.At 5th level, you develop masterful command of magical chemicals, enhancing the healing and damage you create through them. Whenever you cast a spell using your alchemist&#;s supplies as the spellcasting focus or an alchemy attack, you gain a bonus to one roll of the spell. That roll must restore hit points or be a damage roll that deals acid, fire, necrotic, or poison damage, and the bonus equals your Intelligence modifier (minimum of +1). This increases to 1d8 + your Intelligence modifier at 9th level, and 2d8 + your Intelligence modifier at 15th level. You also gain the following additional elixir affects;Starting at 9th level, you can incorporate restorative reagents into some of your works:&#; Whenever a creature drinks an experimental elixir or healing tincture you created, the creature gains temporary hit points equal to 2d6 + your Intelligence modifier (minimum of 1 temporary hit point).&#; You can castwithout expending a spell slot and without preparing the spell, provided you use alchemist&#;s supplies as the spellcasting focus. You can do so a number of times equal to your Intelligence modifier (minimum of once), and you regain all expended uses when you finish a long rest.You also gain the following additional elixir affects;By 15th level, you have been exposed to so many chemicals that they pose little risk to you, and you can use them to quickly end certain ailments:&#; You gain resistance to acid damage and fire damage, and you are immune to poison.&#; You can castandwithout expending a spell slot, without preparing the spell, and without material components, provided you use alchemist&#;s supplies as the spellcasting focus. Once you cast either spell with this feature, you can&#;t cast that spell with it again until you finish a long rest.What are the best ways to store vast amounts of information? That question has occupied chroniclers and librarians for centuries. Scrolls and books were the finest information-storing methods for a long time, but the first Archivists imagined something greater: using that magic to improve the world around them. Storing is not enough, but making it available to the world. These techniques have yet to be perfected and institutionalized, and of all artificers, archivists are on the cutting edge of arcane science.Studded Leather (12 + Dex mod AC): 13lb, 45gpStaff (1d6/d8 bludgeoning): 4lb, 2spSimple Flintlock (2d10 force, range 10/40ft, Loading): 5lb, 12gpSpell Prism (120gp), Calligapher&#;s Kit (1gp)Scholar&#;s Pack (14gp) containing a backpack, a notebook, ink & pen, parchment, a little bag of sand, and a sealing wax.When you adopt this specialization you gain proficiency with Astrology and Scribing . Also, when Scribing Spell Scrolls it takes you a quarter of the normal time, and it costs you half as much of the usual gold. You can also use arcane spell foci as your artificer spell focus.You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they don&#;t count against the number of Artificer Spells you prepare.You became proficient in the ways of Wizard Spellcrafting , even without an innate talent. You gain your own Spellbook, where you can transcribe both Wizard Scrolls and create scrolls from Cleric Ritual Spells . You start off a combination of six 1st level Wizard Spells and Cleric Spells . These spells can be ritual or non-ritual, but you can only cast them normally with your Artificer Spell Slots if they have the ritual tag.Starting at 3rd level, you can bend magic to assist or hinder creatures through the power of their true names, and even use those names as an anchor to affect others around them. Theandspells are Artificer spells for you, and you add them to your spellbook. You cvan cast both of these spells at a level equal to your proficiency bonus, a number of times equal to your Intelligence modifier (minimum of 1), and you regain all expended uses when you finish a long rest.Beginning at 5th level, when you use your action to use a Scroll, you can also use your bonus action to make a basic melee attack, or cast a cantrip.Starting at 9th level, as an action you can touch a creature that is possessed, expend a spell slot of 1st level or higher, and exorcise the presence. The target must succeed on a Wisdom saving throw against your Artificer Spell Save or be exorcised and banished to their home reality. Additionally you can cast theat a level equal to your proficiency bonus, and a number of times equal to your Intelligence modifier (minimum of 1). You regain all expended uses of this ability after a long rest.At 15th level, You have learned how to bypass a named creature&#;s defenses against certain types of damage. When you cast a spell that deals damage to a creature whose True Name you speak as part of casting the spell, you can cause the spell to deal force or psychic damage to the creature, instead of the spell&#;s normal damage type.A recent innovation from the Halls of Stormwind and birthplace of the Warforged. Ambitious Artificers at the school managed to adapt the learning of mechanisation and automaton to armour. Designed to enhance the artificers magic, unleash potent attacks, and generate a formidable defense. The artificer bonds with a single set of powered armor, becoming one with it even as they experiment with it and refine its magical capabilities into a second skin.Cuirass (16 AC): 30lb, 75gp and Heater Shield (+2 AC): 8lb, 20gpLight Hammer (1d6 bludgeoning, range 20/60ft, Light): 2lb, 5gpAppraisal Kit (5gp), Smiths&#; Tools (20gp), Leatherworking Kit (15gp), and Runecarvers&#; Tools (50gp)Dungeoneer&#;s Pack (8gp) containing a backpack, a crowbar, a hammer, 10 pitons, 10 torches, 50ft of hemp rope, a tinderbox.When you adopt this specialization you gain proficiency with Heavy Armour and Weaving . Also when applying armour tags or creating armour, you take half the required amount of time for the work.You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as artificer spells for you, but they don&#;t count against the number of artificer spells you prepare.Your metallurgical pursuits have led to you making armour a conduit for your artificer magic. During a Long Rest, you can turn a suit of heavy armour you are wearing into power armour, provided you have smith&#;s tools in hand. You gain the following benefits while wearing the power armour:&#; The power armour attaches to you and can&#;t be removed against your will. It also expands to cover your entire body, and it replaces any missing limbs, functioning identically to a body part it is replacing.&#; While wearing power armour, melee weapons can use your Intelligence modifier, instead of Strength or Dexterity, for the attack and damage rolls.&#; If the armour normally has a Strength requirement, the power armour lacks this requirement for you.&#; You can use the power armour as a spellcasting focus for your artificer spells.The armour continues to be power armour until you create another set of Power Armour, or you die.Beginning at 3rd level, you have completed addition of repulsors in your armour. Your unarmed strikes now deal 1d8 + Intelligence modifier thunder damage, you can also fire off your gauntlets with a range of 20/60ft to deal 1d8 + Intelligence force damage. The gaunlets automatically return to the wearer and reattach to your armour. Your weapon attacks also deal an additional 1d4 force damage. A creature hit by your spells or weapons has disadvantage on attack rolls against targets other than you until the start of your next turn, as the armour magically emits a distracting pulse when the creature attacks someone else. You also gain a bonus action that you can use on each of your turns to gain temporary hit points equal to your level in this class, replacing any temporary hit points you already have. You lose these temporary hit points if you doff the armour.Starting at 5th level, you can attack twice, rather than once, whenever you take the Attack action on your turn.Beginning at 9th level, you learn how to use your artificer infusions to specially modify the armour enhanced by your Power Armor feature. That armour now counts as separate items for the purposes of your Infuse Items feature: armour (the chest piece), amulet, belt, boots, bracers, and rings. Each of those items can bear one of your infusions. In addition, the maximum number of items you can infuse at once increases by 2, but those extra items must be part of your power armour.At 15th level, tinkering with your armours energy system leads you to discover a powerful pulling force. When a creature you can see ends its turn within 30 feet of you, you can use your reaction to force the creature to succeed on a Strength saving throw against your spell save DC or be pulled up to 30 feet toward you to an unoccupied space. If you pull the target to space within 5 feet of you, you can make a melee weapon attack against it as part of this reaction. You can use this reaction a number of times equal to your Intelligence modifier (minimum of once). You regain all expended uses of it when you finish a long rest.The mastery of arcanotech Artillery is still one lead by Gnomes, the Gnomes of Lantan&#;s Rest that is. One of the smallest geographical settlements in the Sword Coast, their Skyships and Navy are universally feared for their legions of Artillerist artificers. Their destructive potential from a stationary point in unmatched except maybe by the highest of War Magic&#;s, with many other Navy&#;s paltry attempts producing a few capable Artillerist&#;s.Studded Leather (12 + Dex mod AC): 13lb, 45gpDagger (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gpSimple Flintlock (2d10 force, range 10/40ft, Loading): 5lb, 12gpThieves&#; Tools (25gp), Scrimshaws&#; Tools (15gp), Smiths&#; Tools (20gp), and Leatherworking Kit (15gp).Burglar&#;s Pack (4gp) containing a backpack, a bag of 1,000 ball bearings, 50ft of hemp rope, string, bells, a crowbar, a hooded lantern, flasks of oil, tinderbox.When you adopt this specialization you gain proficiency with Carpentry and Siege Weapons . Also when applying weapon tags or creating weapons, you take half the required amount of time for the work. You can use your ranged weapons as a focus for your Artificer Spells You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they don&#;t count against the number of Artificer Spells you prepare.At 3rd level, you learn how to create a magical cannon, you can take an action to magically create a Small or Tiny eldritch cannon in an unoccupied space on a horizontal surface within 5 feet of you. A Small eldritch cannon occupies its space, and a Tiny one can be held in one hand. Once you create a cannon, you can&#;t do so again until you finish a long rest or until you expend a spell slot of 1st level or higher. You can have only one cannon at a time and can&#;t create one while your cannon is present. The cannon is a magical object. Regardless of size, the cannon has an AC of 18 and a number of hit points equal to five times your artificer level. It is immune to poison and psychic damage. If it is forced to make an ability check or a saving throw, treat all its ability scores as 10 (+0). If thespell is cast on it, it regains 2d6 hit points. It disappears if it is reduced to 0 hit points or after 1 hour. You can dismiss it early as an action. When you create the cannon, you determine its appearance and whether it has legs. You also decide which type it is, choosing from the options on the Eldritch Cannons table. On each of your turns, you can take a bonus action to cause the cannon to activate if you are within 60 feet of it. As part of the same bonus action, you can direct the cannon to walk or climb up to 15 feet to an unoccupied space, provided it has legs.The can non exhales fire in an adjacent 15-foot cone that you designate. Each creature in that area must make a Dexterity saving throw against your spell save DC, taking 2d8 fire damage on a failed save or half as much damage on a successful one. The fire ignites any flammable objects in the area that aren&#;t being worn or carried.Make a ranged spell attack, originating from the cannon, at one creature or object within 120 feet of it. On a hit, the target takes 2d8 force damage, and if the target is a creature, it is pushed up to 5 feet away from the cannon.The cannon emits a burst of positive energy that grants itself and each creature of your choice within 10 feet of it a number of temporary hit points equal to 1d8 + your Intelligence modifier (minimum of +1) .At 5th level, you know how to turn a wand, staff, or rod into an arcane firearm, a conduit for your destructive spells. When you finish a long rest, you can use woodcarver&#;s tools to carve the material of a wand, staff, or rod and thereby turn it into a flintlock in addition to an arcane focus. The firearm turns back into its original form if you repeat this process on another Item. The change otherwise last indefinitely. When you cast an Artificer Spell through the firearm, roll a d8, and you gain a bonus to one of the spell&#;s damage rolls equal to the number rolled.Starting at 9th level, every eldritch cannon you create is more destructive:&#; The cannon&#;s damage rolls all increase by 1d8.&#; As an action, you can command the cannon to detonate if you are within 60 feet of it. Doing so destroys the cannon and forces each creature within 20 feet of it to make a Dexterity saving throw against your spell save DC, taking 3d8 force damage on a failed save or half as much damage on a successful one.Starting at 15th level, you&#;re a master at forming well-defended emplacements using Eldritch Cannon:&#; You and your allies have half cover while within 10 feet of a cannon you create with Eldritch Cannon, as a result of a shimmering field of magical protection that the cannon emits.&#; You can now have two cannons at the same time. You can create two with the same action (but not the same spell slot), and you can activate both of them with the same bonus action. You determine whether the cannons are identical to each other or different. You can&#;t create a third cannon while you have two.The newest of Dwarven ingenuity, mixing the lessons of their Gnomish allies with Dwarven martial tradition, comes the Battle Smith. Protected, mobile, and able to create a rolling defence crucial in the treacherous Underdark. A combination of protectorate and medic, a Battle Smith is an expert at defending others and repairing both material and personnel. To aid in their work, Battle Smiths are accompanied by a automaton called a &#;steel defender&#;, a protective companion of their own creation.Hauberk (13 + Dex mod [max 2] AC): 30lb, 60gp and Heater Shield (+2 AC): 8lb, 20gpWarhammer (1d8/d10 bludgeoning): 2lb, 15gp or Cavalry Mace (1d10 bludgeoning, Reach 1): 18lb, 35gp2 Light Hammer (1d6 bludgeoning, range 20/60ft, Light): 2lb, 5gpSteppe Pony (30gp)Smiths&#; Tools (20gp)Dungeoneer&#;s Pack (8gp) containing a backpack, a crowbar, a hammer, 10 pitons, 10 torches, 50ft of hemp rope, a tinderbox.When you adopt this specialization you gain proficiency with Riding and Martial Weapons . Also, when you attack with a magic weapon, you can use your Intelligence modifier, instead of Strength or Dexterity modifier, for the attack and damage rolls. You can use your martial weapon as a focus for your artificer spells.You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they don&#;t count against the number of Artificer Spells you prepare.By 3rd level, your tinkering has borne you a faithful companion, a steel defender. It is friendly to you and your companions, it defaults to a Dodge Action, unless you spend a Bonus action to make it Rend, Repair, Dash, Disengage, Help, Hide or Search. If you are incapacitated, the defender can take any action of its choice, not just Dodge.152 + your Intelligence modifier +5 times your artificer level40ftDarkvision 60ft14 (+2)12 (+1)14 (+2)4 (-4)10 (+0)6 (-2)Dex +1 + Proficiency Bonus, Con +2 + Proficiency Bonus.Athletics +2 + Proficiency Bonus, Perception +Proficiency Bonus x 2Charmed, Disease, Exhaustion, Poison, Surprise+spell attack modifier to hit, 1d8 +proficiency bonus force damage.The magical mechanisms inside the defender restore 2d8 +Proficiency Bonus hit points to itself or to one construct or object within 5 feet of it.The defender imposes disadvantage on the attack roll of one creature it can see that is within 5 feet of it, provided the attack roll is against a creature other than the defender.You determine the creature&#;s appearance and whether it has two legs or four; your choice has no effect on its game statistics. If thespell is cast on it, it regains 2d6 hit points. If it has died within the last hour, you can use your smith&#;s tools as an action to revive it, provided you are within 5 feet of it and you expend a spell slot of 1st level or higher. The steel defender returns to life after 1 minute with all its hit points restored. At the end of a long rest, you can create a new steel defender if you have your smith&#;s tools with you. If you already have a steel defender from this feature, the first one immediately perishes.Starting at 5th level, you can attack twice, rather than once, whenever you take the Attack action on your turn.At 9th level, you learn new ways to channel arcane energy to harm or heal. When either you hit a target with a magic weapon attack or your steel defender hits a target, you can channel magical energy through the strike to create one of the following effects:&#; The target takes an extra 2d6 force damage.&#; Choose one creature or object you can see within 30 feet of the target. Healing energy flows into the chosen recipient, restoring 2d6 hit points to it.You can use this energy a number of times equal to your Intelligence modifier (minimum of once), but you can do so no more than once on a turn. You regain all expended uses when you finish a long rest.At 15th level, your Arcane jolt and steel defender become more powerful:&#; The extra damage and the healing of your Arcane jolt both increase to 4d6.&#; Your steel defender gains a +2 bonus to Armor Class and a 80ft flying speed.&#; Whenever your steel defender uses its Deflect Attack, the attacker takes force damage equal to 1d4 + your Intelligence modifier.Teleportation has always been a popular path of arcane study, with most falling into the traditional methods tried and tested by braver spellcrafters. But never before has such a bone-headed and crazy level of experimental risk been taken before. The Portal Engineers of the Waterdeep and Illusk took the higher craft of Planeswalkers and reduced it into the most basic of abilities. And now they abuse the laws of the cosmos for quick hop and a skip around town&#;Studded Leather (12 + Dex mod AC): 13lb, 45gpDagger (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gpSimple Flintlock (2d10 force, range 10/40ft, Loading): 5lb, 12gpThieves&#; Tools (25gp), Astronomy Equipment (35gp), and Planewalker&#;s Case (65gp)Burglar&#;s Pack (4gp) containing a backpack, a bag of 1,000 ball bearings, 50ft of hemp rope, string, bells, a crowbar, a hooded lantern, flasks of oil, tinderbox.When you adopt this specialization you gain proficiency with Astrology and you can teleport objects that are less than 10 pounds unless their are worn or held by a hostile creature. You can also use items from other planes as spellcasting foci for your Artificer Spells You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they don&#;t count against the number of Artificer Spells you prepare.At 3rd level, you have mastered the art of creating portals. Using your bonus action, you create a portal within 30ft, the portal is 3 feet wide and 6 feet tall, and connect it to another portal within 30ft as the same size. Spells cannot travel through the portal but ranged attacks can. A creature must be willing to enter the portal to use it. This ability can be used a number of times equal to your Intelligence modifier, you regain all expended uses of this ability on a long rest. This range increases to 60ft at 9th level. Additionally, your weapon deals an additional 1d8 force damage through portal energy, this increases to 2d8 at 9th level.Starting at 5th level, you&#;ve learnt to channel your teleportation energy into those who travel through it. Once per round when a creature moves through your portal, they deal an additional 1d8 force damage to their attack. This increases to twice per round at 9th level, and three times per round at 15th level. You can choose to obscure the view of the portal, choose to make it one-way, or two-way obscurement.At 9th level, you&#;ve learnt to teleport creatures other than yourself. As a reaction you can move an ally within 60ft of you anywhere else within 60ft of you. You regain the use of this ability on a short or long rest. Your portals can now also be used to teleport unwilling creatures that move through it.At 15th level, you can castorwithout having the spell prepared. You regain this ability on a long rest.A newly formed specialty of artifice using complex pulleys and nearly in-perceivable strings to move creatures and objects and control the world around you. While most artificers are overt and dangerously direct, you can appear harmless and unseen if you need to.Hauberk (13 + Dex mod [max 2] AC): 30lb, 60gpDagger (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gpSimple Flintlock (2d10 force, range 10/40ft, Loading): 5lb, 12gpThieves&#; Tools (25gp)Burglar&#;s Pack (4gp) containing a backpack, a bag of 1,000 ball bearings, 50ft of hemp rope, string, bells, a crowbar, a hooded lantern, flasks of oil, tinderbox.When you adopt this specialization you gain proficiency with Weaving Carpentry , and three string-based Instruments of your choice. You can also use Instruments as spellcasting foci for your Artificer Spells You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they don&#;t count against the number of Artificer Spells you prepare.At 3rd level, you can bind a creature within 60ft to yourself with silk string, channeling energy to and from them. Once you create a magical string, you can&#;t do so again until you finish a long rest or until you expend a spell slot of 1st level or higher. You can only have one magical string at a time. If you create a new one, the original one loses its magic. The string also loses its magic after 1 hour, and you can dismiss its magic early as an action. This connection remains even if the creature moves out of range. As an action on each of your turns, you can reconnect the string to another creature. This connection ends when the string loses its magic. You can target the represented creature with spells that have a range of Touch, by casting such a spell on the string. As a bonus action on each of your turns, you can expose the string to a harmful effect within 5 feet of you to potentially damage the connected creature. The harmful effect must deal bludgeoning, piercing, slashing, acid, cold, fire, lightning, necrotic, radiant, or thunder damage. When you affect the string, the represented creature must succeed on a Wisdom saving throw or else take 2d8 of the corresponding damage type. If you use your action to cast a spell that deals a qualifying type of damage, you can choose for the string connection to deal that type of damage. For example, if you use your action to cast, you can choose for the effigy connection to deal cold damage, regardless of whether you exposed the effigy to the actual spell effects or not.Starting at 5th level, if your stringed creature makes a Strength or Dexterity based saving throw, attack roll, or ability check, you can use your reaction to force them to do it with advantage or disadvantage (your choice).Beginning at 9th level, the damage rolls caused by your string increase by 1d8. As an action, you can see through the creature&#;s eyes and hear what it hears, and continue to do so until you use your action to return to your normal senses or until the string disappears. The creature is aware someone is perceiving through its senses, but does not necessarily know who it is or how they can do it.At 15th level, you have become a master of control. You can caston a stringed creature once without expending a spell slot. Once you have used this feature, you cannot use it again until you finish a long rest.Most artificers are focused on stability and reliability. Now, reliability is always nice, but you were intensely interested in the unstable. The explosive, best executed in the enemies faces. Stealth and knowledge of your surrounding are your bread and butter more than the explosives you covet, but you also have the quickness of hand to deploy mid-combat in a pinch if caught unawares. But hopefully they never hear you coming&#; just your arrival.Studded Leather (12 + Dex mod AC): 13lb, 45gpLongbow (1d8 piercing, range 150/600ft, Ammunition, Heavy, Two-Handed): 2lb, 50gp2 Daggers (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gpThieves&#; Tools (25gp), Alchemist&#;s Station (50gp)Burglar&#;s Pack (4gp) containing a backpack, a bag of 1,000 ball bearings, 50ft of hemp rope, string, bells, a crowbar, a hooded lantern, flasks of oil, tinderbox.When you adopt this specialization you gain proficiency with Poisoning Longbows and Stealth checks. You also know thecantrip.You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they don&#;t count against the number of Artificer Spells you prepare.You have learned to further enhance the magical affects of. When you cas the spell, you have advantage on Lore checks about your marked target and learn vulnerabilities and saving throws. You can cast the spell at 1st level a number of times equal to your proficiency bonus without using a spell slot. You regain all expended uses of this feature on a long rest.Starting at 3rd level, you learn how to create a deployable wall. You can use your action to deploy a semi-circle wall of half cover that is 15 feet diameter and 2 feet thick, originating at a point you can see within 60 feet. This cover has an AC of 10 + your Intelligence modifier and a number of hit points equalling ten times your Intelligence modifier. It is immune to poison damage, psychic damage, and all conditions. If it is forced to make an ability check or a saving throw, treat all its ability scores as 10 (+0). If thespell is cast on it, it regains 2d6 hit points. It disappears if it is reduced to 0 hit points or after 1 hour. You can dismiss it early as an action. Once you create the barricade, you can&#;t do so again until you finish a long rest or until you expend a spell slot of 1st level or higher. You can only have one barricade at a time and can&#;t create one while your barricade is present. When you create cover, your allies gain the following additional effects below:As a bonus action on your turn, you can activate the protective energies within your barricade. When you activate this feature, all friendly creatures within 30ft of your cover gain 1d8 + Intelligence modifier temporary hit points.This explosive barrier is built for defense. As a reaction, when your cover or an ally protected by your cover would be hit by an attack, you can activate this barricade to make a spell attack damage or deal 2d8 force damage to the attacker.Starting at 5th level, you can now create cover with your bonus action. The wall is now a full circle. In addition, you are able to take better aim from behind your cover. Once on each of your turns, while within 5ft of your cover when you hit a creature with an attack, you can cause the attack to deal an additionally 1d8 force damage to the target. When you reach 15th level, the extra damage increases to 2d8.At 9th level, the cover you create for others is charged with extra power. Rapid Deployment, Hospitality, and Reflection gain an additional 1d8 to their respective healing or damage.At 15th level, you are masterful at keeping others safe. The cover you can build gains the following upgrades:&#; Benefits of your cover gains an additional +2 to its Armour Class.&#; Grants advantage against Area of Affect spells that target behind cover.

1.3 Bags, Queues, and Stacks

1.3   Bags, Queues, and Stacks


Several fundamental data types involve collections of objects. Specifically, the set of values is a collection of objects, and the operations revolve around adding, removing, or examining objects in the collection. In this section, we consider three such data types, known as the bag, the queue, and the stack. They differ in the specification of which object is to be removed or examined next.

APIs.

We define the APIs for bags, queues, and stacks. Beyond the basics, these APIs reflect two Java features: generics and iterable collections.

We define the APIs for bags, queues, and stacks. Beyond the basics, these APIs reflect two Java features: generics and iterable collections.

  • Generics. An essential characteristic of collection ADTs is that we should be able to use them for any type of data. A specific Java mechanism known as generics enables this capability. The notation <Item> after the class name in each of our APIs defines the name Item as a type parameter, a symbolic placeholder for some concrete type to be used by the client. You can read Stack<Item> as "stack of items." For example, you can write code such as
    Stack<String> stack = new Stack<String>();
    stack.push("Test");
    ...
    String next = stack.pop(); 
    
    to use a stack for String objects.

  • Autoboxing. Type parameters have to be instantiated as reference types, so Java automatically converts between a primitive type and its corresponding wrapper type in assignments, method arguments, and arithmetic/logic expressions. This conversion enables us to use generics with primitive types, as in the following code:
    Stack<Integer> stack = new Stack<Integer>();
    stack.push(17);        // autoboxing (int -> Integer)
    int i = stack.pop();   // unboxing   (Integer -> int)
    
    Automatically casting a primitive type to a wrapper type is known as autoboxing, and automatically casting a wrapper type to a primitive type is known as unboxing.

  • Iterable collections. For many applications, the client's requirement is just to process each of the items in some way, or to iterate through the items in the collection. Java's foreach statement supports this paradigm. For example, suppose that collection is a Queue<Transaction>. Then, if the collection is iterable, the client can print a transaction list with a single statement:
    for (Transaction t : collection)
       StdOut.println(t);
    

  • Bags. A bag is a collection where removing items is not supported&#;its purpose is to provide clients with the ability to collect items and then to iterate through the collected items. Stats.java is a bag client that reads a sequence of real numbers from standard input and prints out their mean and standard deviation.

  • FIFO queues. A FIFO queue is a collection that is based on the first-in-first-out (FIFO) policy. The policy of doing tasks in the same order that they arrive is one that we encounter frequently in everyday life: from people waiting in line at a theater, to cars waiting in line at a toll booth, to tasks waiting to be serviced by an application on your computer.

  • Pushdown stack. A pushdown stack is a collection that is based on the last-in-first-out (LIFO) policy. When you click a hyperlink, your browser displays the new page (and pushes onto a stack). You can keep clicking on hyperlinks to visit new pages, but you can always revisit the previous page by clicking the back button (popping it from the stack). Reverse.java is a stack client that reads a sequence of integers from standard input and prints them in reverse order.

  • Arithmetic expression evaluation. Evaluate.java is a stack client that evaluates fully parenthesized arithmetic expressions. It uses Dijkstra's 2-stack algorithm:
    • Push operands onto the operand stack.
    • Push operators onto the operator stack.
    • Ignore left parentheses.
    • On encountering a right parenthesis, pop an operator, pop the requisite number of operands, and push onto the operand stack the result of applying that operator to those operands.

    This code is a simple example of an interpreter.

Array and resizing array implementations of collections.

  • Fixed-capacity stack of strings. FixedCapacityStackOfString.java implements a fixed-capacity stack of strings using an array.

  • Fixed-capacity generic stack. FixedCapacityStack.java implements a generic fixed-capacity stack.

  • Array resizing stack. ResizingArrayStack.java implements a generic stack using a resizing array. With a resizing array, we dynamically adjust the size of the array so that it is both sufficiently large to hold all of the items and not so large as to waste an excessive amount of space. We double the size of the array in push() if it is full; we halve the size of the array in pop() if it is less than one-quarter full.

  • Array resizing queue. ResizingArrayQueue.java implements the queue API with a resizing array.

Linked lists.

A linked list is a recursive data structure that is either empty (null) or a reference to a node having a generic item and a reference to a linked list. To implement a linked list, we start with a nested class that defines the node abstraction
private class Node {
   Item item;
   Node next;
}

  • Building a linked list. To build a linked list that contains the items to, be, and or, we create a Node for each item, set the item field in each of the nodes to the desired value, and set the next fields to build the linked list.

  • Insert at the beginning. The easiest place to insert a new node in a linked list is at the beginning.

  • Remove from the beginning. Removing the first node in a linked list is also easy.

  • Insert at the end. To insert a node at the end of a linked list, we maintain a link to the last node in the list.

  • Traversal. The following is the idiom for traversing the nodes in a linked list.
    for (Node x = first; x != null; x = x.next) {
       // process x.item
    }
    

A linked list is a recursive data structure that is either empty (null) or a reference to a node having a generic item and a reference to a linked list. To implement a linked list, we start with a nested class that defines the node abstraction

Linked-list implementations of collections.

  • Linked list implementation of a stack. Stack.java implements a generic stack using a linked list. It maintains the stack as a linked list, with the top of the stack at the beginning, referenced by an instance variable first. To push() an item, we add it to the beginning of the list; to pop() an item, we remove it from the beginning of the list.

  • Linked list implementation of a queue. Program Queue.java implements a generic FIFO queue using a linked list. It maintains the queue as a linked list in order from least recently to most recently added items, with the beginning of the queue referenced by an instance variable first and the end of the queue referenced by an instance variable last. To enqueue() an item, we add it to the end of the list; to dequeue() an item, we remove it from the beginning of the list.

  • Linked list implementation of a bag. Program Bag.java implements a generic bag using a linked list. The implementation is the same as Stack.java except for changing the name of push() to add() and removing pop().

Iteration.

To consider the task of implementing iteration, we start with a snippet of client code that prints all of the items in a collection of strings, one per line:

Stack<String> collection = new Stack<String>();
...
for (String s : collection)
   StdOut.println(s);
...
This foreach statement is shorthand for the following while statement:
Iterator<String> i = collection.iterator();
while (i.hasNext()) { 
   String s = i.next();
   StdOut.println(s);
}
To implement iteration in a collection:

  • Include the following import statement so that our code can refer to Java's java.util.Iterator interface:
    import java.util.Iterator;
    

  • Add the following to the class declaration, a promise to provide an iterator() method, as specified in the java.lang.Iterable interface:
    implements Iterable<Item>
    

  • Implement a method iterator() that returns an object from a class that implements the Iterator interface:
    public Iterator<Item> iterator() {
        return new LinkedIterator();
    }
    

  • Implement a nested class that implements the Iterator interface by including the methods hasNext(), next(), and remove(). We always use an empty method for the optional remove() method because interleaving iteration with operations that modify the data structure is best avoided.

    • The nested class LinkedIterator in Bag.java illustrates how to implement a class that implements the Iterator interface when the underlying data structure is a linked list.

    • The nested class ArrayIterator in ResizingArrayBag.java does the same when the underlying data structure is an array.

This foreach statement is shorthand for the followingstatement:To implement iteration in a collection:


Autoboxing Q + A

Q. How does autoboxing handle the following code fragment?

Integer a = null;
int b = a;

A. It results in a run-time error. Primitive type can store every value of their corresponding wrapper type except null.

Q. Why does the first group of statements print true, but the second false?

Integer a1 = 100;
Integer a2 = 100;
System.out.println(a1 == a2);   // true

Integer b1 = new Integer(100);
Integer b2 = new Integer(100);
System.out.println(b1 == b2);   // false

Integer c1 = 150;
Integer c2 = 150;
System.out.println(c1 == c2);   // false

A. The second prints false because b1 and b2 are references to different Integer objects. The first and third code fragments rely on autoboxing. Surprisingly the first prints true because values between -128 and 127 appear to refer to the same immutable Integer objects (Java's implementation of valueOf() retrieves a cached values if the integer is between -128 and 127), while Java constructs new objects for each integer outside this range.

Here is another Autoboxing.java anomaly.

Generics Q + A

Q. Are generics solely for auto-casting?

A. No, but we will use them only for "concrete parameterized types", where each data type is parameterized by a single type. The primary benefit is to discover type-mismatch errors at compile time instead of run time. There are other more general (and more complicated) uses of generics, including wildcards. This generality is useful for handling subtypes and inheritance. For more information, see this Generics FAQ and this Java generics tutorial.

Q. Can concrete parameterized types be used in the same way as normal types?

A. Yes, with a few exceptions (array creation, exception handling, with instanceof, and in a class literal).

Q. Can I make the Node class static?

A. For LinkedStackOfString.java, you can do so with no other changes and save 8 bytes (of inner class overhead) per node. However, the nested class Node in LinkedStack.java uses the type information of Item from the outer class, so you would need to do a bit of extra work to make it static. Stack.java accomplishes this by making the nested class (and the nester iterator) generic: there are three separate generic type parameters, each of which is named Item.

Q. Why do I get a "can't create an array of generics" error when I try to create an array of generics?

public class ResizingArrayStack<Item> {
   Item[] a = new Item[1];

A. Unfortunately, creating arrays of generics is not possible in Java 1.5. The underlying cause is that arrays in Java are covariant, but generics are not. In other words, String[] is a subtype of Object[], but Stack<String> is not a subtype of Stack<Object>. To get around this defect, you need to perform an unchecked cast as in ResizingArrayStack.java. ResizingArrayStackWithReflection.java is an (unwieldy) alternative that avoids the unchecked cast by using reflection.

Q. So, why are arrays covariant?

A. Many programmers (and programming language theorists) consider covariant arrays to be a serious defect in Java's type system: they incur unnecessary run-time performance overhead (for example, see ArrayStoreException) and can lead to subtle bugs. Covariant arrays were introduced in Java to circumvent the problem that Java didn't originally include generics in its design, e.g., to implement Arrays.sort(Comparable[]) and have it be callable with an input array of type String[].

Q. Can I create and return a new array of a parameterized type, e.g., to implement a toArray() method for a generic queue?

A. Not easily. You can do it using reflection provided that the client passes an object of the desired concrete type to toArray() This is the (awkward) approach taken by Java's Collection Framework. GenericArrayFactory.java provides an alternate solution in which the client passes a variable of type Class. See also Neal Gafter's blog for a solution that uses type tokens.

Iterator Q + A

Q. Why is the construct called foreach if it uses the keyword for?

A. Other languages use the keyword foreach, but the Java developers did not want to introduce a new keyword and break backward compatibility.

Q. Are Strings iterable?

A. No.

Q. Are arrays Iterable?

A. No. You can use the foreach syntax with them. However, you can not pass an array to a method that expects an Iterable or return an array from a method which returns an Iterable. This would be convenient, but it doesn't work that way.

Q. What's wrong with the following code fragment?

String s;
for (s : listOfStrings)
   System.out.println(s);

A. The enhanced for loop requires that the iterating variable be declared inside the loop.


Exercises

  1. Add a method isFull() to FixedCapacityStackOfStrings.java.
  2. Give the output printed by java Stack for the input
    it was - the best - of times - - - it	was - the - -
    
    Solution. was best times of the was the it (1 left on stack)
  3. Suppose that an intermixed sequence of (stack) push and pop operations are performed. The pushes push the integers 0 through 9 in order; the pops print out the return value. Which of the following sequence(s) could not occur?
    (a)  4 3 2 1 0 9 8 7 6 5
    
    (b)  4 6 8 7 5 3 2 9 0 1
    
    (c)  2 5 6 7 4 8 9 3 1 0
    
    (d)  4 3 2 1 0 5 6 7 8 9
    
    (e)  1 2 3 4 5 6 9 8 7 0
    
    (f)  0 4 6 5 3 8 1 7 2 9
    
    (g)  1 4 7 9 8 6 5 3 0 2
    
    (h)  2 1 4 3 6 5 8 7 9 0
    

    Answer: (b), (f), and (g).

  4. Write a stack client Parentheses.java that reads in sequence of left and right parentheses, braces, and brackets from standard input and uses a stack to determine whether the sequence is properly balanced. For example, your program should print true for [()]{}{[()()]()} and false for [(]).
  5. What does the following code fragment print when n is 50? Give a high-level description of what it does when presented with a positive integer n.
    Stack<Integer> s = new Stack<Integer>();
    while (n > 0) {
       s.push(n % 2);
       n = n / 2;
    }
    while (!s.isEmpty())
        System.out.print(s.pop());
    System.out.println();
    

    Answer: Prints the binary representation of N ( when n is 50).

  6. What does the following code fragment do to the queue q?
    Stack<String> s = new Stack<String>();
    while(!q.isEmpty())
       s.push(q.dequeue());
    while(!s.isEmpty())
       q.enqueue(s.pop());
    
    Answer: Reverses the items on the queue.
  7. Add a method peek to Stack.java that returns the most recently inserted item on the stack (without popping it).
  8. Write a filter Program InfixToPostfix.java that converts an arithmetic expression from infix to postfix.
  9. Write a program EvaluatePostfix.java that that takes a postfix expression from standard input, evaluates it, and prints the value. (Piping the output of your program from the previous exercise to this program gives equivalent behavior to Evaluate.java.)
  10. Suppose that a client performs an intermixed sequence of (queue) enqueue and dequeue operations. The enqueue operations put the integers 0 through 9 in order onto the queue; the dequeue operations print out the return value. Which of the following sequence(s) could not occur?
    (a)  0 1 2 3 4 5 6 7 8 9
    
    (b)  4 6 8 7 5 3 2 9 0 1 
    
    (c)  2 5 6 7 4 8 9 3 1 0
    
    (d)  4 3 2 1 0 5 6 7 8 9
    
    Answer: (b), (c), and (d).
  11. Develop a class ResizingArrayQueueOfStrings that implements the queue abstraction with a fixed-size array, and then extend your implementation to use array resizing to remove the size restriction.

    Solution: ResizingArrayQueue.java

Linked-List Exercises

Creative Problems

  1. Josephus problem. In the Josephus problem from antiquity, N people are in dire straits and agree to the following strategy to reduce the population. They arrange themselves in a circle (at positions numbered from 0 to N-1) and proceed around the circle, eliminating every Mth person until only one person is left. Legend has it that Josephus figured out where to sit to avoid being eliminated. Write a Queue client Josephus.java that takes M and N from the command line and prints out the order in which people are eliminated (and thus would show Josephus where to sit in the circle).
     % java Josephus 2 7
    1 3 5 0 4 2 6
    
  2. Copy a stack. Create a new constructor for the linked-list implementation of Stack.java so that Stack t = new Stack(s) makes t reference a new and independent copy of the stack s.

    Recursive solution: create a copy constructor for a linked list starting at a given Node and use this to create the new stack.

    Node(Node x) {
       item = x.item;
       if (x.next != null) next = new Node(x.next);
    }
    
    public Stack(Stack<Item> s) { first = new Node(s.first); }
    

    Nonrecursive solution: create a copy constructor for a single Node object.

    Node(Node x) { this.item = x.item; this.next = x.next; }
    
    public Stack(Stack<Item> s) {
       if (s.first != null) {
          first = new Node(s.first);
          for (Node x = first; x.next != null; x = x.next)
             x.next = new Node(x.next);
       }
    }
    
  3. Stack generability. Suppose that we have a sequence of intermixed push and pop operations as with our test stack client, where the integers 0, 1, ..., N-1 in that order (push directives) are intermixed with N minus signs (pop directives). Devise an algorithm that determines whether the intermixed sequence causes the stack to underflow. (You may use only an amount of space independent of N&#;you cannot store the integers in a data structure.) Devise a linear-time algorithm that determines whether a given permutation can be generated as output by our test client (depending on where the pop operations occur).

    Solution. The stack does not underflow unless there exists an integer k such that the first k pop operations occur before the first k push operations.

    If a given permutation can be generated, it is uniquely generated as follows: if the next integer in the permutation is in the top of the stack, pop it; otherwise, push the next integer in the input sequence onto the stack (or stop if N-1 has already been pushed). The permutation can be generated if and only if the stack is empty upon termination.

  4. Forbidden triple for stack generability. (R. Tarjan) Prove that a permutation can be generated by a stack (as in the previous question) if and only if it has no forbidden triple (a, b, c) such that a < b < c with c first, a second, and b third (possibly with other intervening integers between c and a and between a and b).

    Partial solution. Suppose that there is a forbidden triple (a, b, c). Item c is popped before a and b, but a and b are pushed before c. Thus, when c is pushed, both a and b are on the stack. Therefore, a cannot be popped before b.

  5. Catenable queues, stacks, or steques. Add an extra operation catenation that (destructively) concatenates two queues, stacks, or steques. Hint: use a circular linked list, maintaining a pointer to the last item.
  6. Fail-fast iterator. Modify the iterator code in Stack.java to immediately throw a java.util.ConcurrentModificationException if the client modifies the collection (via push() or pop()) during iteration.

    Solution: Maintain a counter that counts the number of push() and pop() operations. When creating an iterator, store this value as an iterator instance variable. Before each call to hasNext() and next(), check that this value has not changed since construction of the iterator; if it has, throw an exception.

  7. Expression evaluation with precedence. Write a program EvaluateDeluxe.java that extends Evaluate.java to handle expressions that are not fully parenthesized, using the standard precedence order for the operators +, -, *, and /.

Web Exercises

  1. Tail. Write a program Tail so that Tail k < file.txt prints the last k lines of the file file.txt. Use StdIn.readLine(). Which data structure should you use?
  2. Bounded stack. A bounded stack is a stack that has a capacity of at most N. (Applications: undo or history with finite buffer.)
  3. Delete ith element. Create a data type that supports the following operations: isEmpty, insert, and remove(int i), where the deletion operation deletes and returns the ith least recently added object on the queue. Do it with an array, then do it with a linked list. What is the running time for each operation?
  4. Dynamic shrinking. With the array implementations of stack and queue, we doubled the size of the array when it wasn't big enough to store the next element. If we perform a number of doubling operations, and then delete a lot of elements, we might end up with an array that is much bigger than necessary. Implement the following strategy: whenever the array is 1/4 full or less, shrink it to half the size. Explain why we don't shrink it to half the size when it is 1/2 full or less.
  5. Stack + max. Create a data structure that efficiently supports the stack operations (pop and push) and also return the maximum element. Assume the elements are integers or reals so that you can compare them.

    Hint: use two stacks, one to store all of the elements and a second stack to store the maximums.

  6. PostScript. PostScript is a stack-based language used by most printers. Implement a small subset of PostScript using a stack.
  7. Interview question. Given a stack of an unknown number of strings, print out the 5th to the last one. It's OK to destroy the stack in the process. Hint: use a queue of 5 elements.
  8. Tag systems. Write a program that reads in a binary string from the command line and applies the following (00, ) tag-system: if the first bit is 0, delete the first three bits and append 00; if the first bit is 1, delete the first three bits and append . Repeat as long as the string has at least 3 bits. Try to determine whether the following inputs will halt or go into an infinite loop: , . Use a queue.
  9. Turing tape. Implement an one-dimensional Turing tape. The tape consists of a sequence of cells, each of which stores an integer (that is initialized to 0). At any instant, there is a tape head which points to one of the cells. Support the following interface methods: moveLeft to move the tape head one cell to the left, moveRight to move the tape head one cell to the right, look to return the contents of the active cell, and write(int a) to change the contents of the active cell to a. Hint: use an int for the active cell, and two stacks for the left and right parts of the tape. Similar to text editor buffer.
  10. Palindrome checker. Write a program that reads in a sequence of strings and checks whether it constitutes a palindrome. Ignore punctuation and spaces and case. (A MAN, A PLAN, A CANAL - PANAMA). Use one stack and one queue.
  11. Streaming algorithm. Given a long sequence of items, design a data structure to store the k items most recently seen.
  12. 2 M/M/1 queues. Next customer is assigned to the smaller of the two queues. Use 2 FIFO queues. Perception that you always pick the longer line (or wrong lane) when approaching a toll plaza. Suppose two cars enter the toll plaza at the same time and pick different queues of the same length. Compute average length in time that one car will beat the other car by.
  13. M/M/k queue. Compare k independent M/M/1 queues vs. M/M/k queue.
  14. M/G/1 queue. Analyze queueing model with a different service distribution (G = general).
  15. Infix to postfix with precedence order. Write a program to convert an infix expression to postfix. Scan the infix expression from left to right.
    • Operand: output it.
    • Left parentheses: push onto stack.
    • Right parentheses: repeatedly pop elements from the stack and output them until a left parenthesis is encountered. Discard both parentheses.
    • Operator with high precedence than top of stack: push onto stack.
    • Operator with lower or equal precedence than top of stack: repeatedly pop elements from the stack and output them until top of stack has higher precedence. Push the scanned operator onto the stack.
    Afterward, pop remaining elements off stack and output them.
  16. Check for duplicates. Write a code fragment that determines if a bag contains any duplicate items. Use two nested iterators.
  17. Check for triplicates. Write a code fragment that determines if a bag contains any item repeated at least three times. Use triply nested iterators.
  18. Equality. Two queues are equal if they contain the same items in the same order. Two bags are equal if they contain the same items in any order.
  19. Set of integers. Create a data type that represents a set of integers (no duplicates) between 0 and N-1. Support add(i), exists(i), remove(i), size(), intersect, difference, symmetricDifference, union, isSubset, isSuperSet, and isDisjointFrom. Include an iterator.
  20. Colon. Experienced programmers know that it's usually a bad idea to write a loop like
    for (double x = 0.0; x <= N; x += 0.1) {
       ..
    }
    
    since as a result of floating point precision, the loop will execute 10N times if N = xxx, and 10N + 1 times if N = yyy. Create an data type Mesh so that x ranges from left to right in increments of size delta. Assuming right >= left, the loop should execute exactly If 1 + floor((right - left) / delta) times.
    for (double x : new Mesh(left, right, delta)) {
       ..
    }
    
    This is how the colon operator works in MATLAB. You should also instrument your program so that it works even left > right and delta is negative.
  21. List iterators. We might also want to include methods hasPrevious() and previous() for going backwards in the list. To implement previous() we can use a doubly-linked list. Program DoublyLinkedList.java implements this strategy. It uses Java's java.util.ListIterator interface to support moving forwards and backwards. We implement all optional methods, including remove(), set(), and add(). The method remove() deletes the last element returned by either next() or previous(). The method set() overwrites the value of the last element returned by either next() or previous(). The method add() inserts an element before the next element that would be returned by next(). It is legal to call set() and remove() only after a call either to next() or previous(), and with no intervening calls to either remove() or add().

    We use a dummy head and tail node to avoid extra cases. We also store an extra variable lastAccessed which stores the node accessed in the most recent call to next() or previous(). After removing an element, we reset lastAccessed to null; this designates that calling remove() is illegal (until after a subsequent call to either next() or previous().

  22. TwoWayIterator. Define an interface TwoWayIterator that supports four methods: hasNext(), hasPrevious(), next(), and previous(). Implement a list that supports a TwoWayIterator. Hint: implement the list using an array or doubly linked list.
  23. Adding one bag to the end of another. Write a method that adds the items of one bag b to the end of the invoking bag a. Assume both bags store items of the same type.

    Hint: iterate through the items of b using an iterator, and add each to the end of the invoking bag.

  24. Replace all. Write a method that replaces all occurrences of an item from with the item to in a queue or stack.
  25. Adding a list to itself. What is the result of the following code fragment?
    List list1 = new ArrayList();
    List list2 = new ArrayList();
    list1.add(list2);
    list2.add(list1);
    System.out.println(list1.equals(list2));
    
    List list = new ArrayList();
    list.add(list);
    System.out.println(list.hashCode());
    
    Answer: stack overflow. The Java documents says that "while it is permissible for lists to contain themselves as elements, extreme caution is advised: the equals and hashCode methods are no longer well defined on a such a list."
  26. Song playlist. Create an data type that supports the following operations: enqueue (add a new song to the end of the list), play (print the name of the next song), skip (skip the next song in the list, and do not prints its name) and back (go back one song). Use a list that supports an iterator with forward and backwards.
  27. Josephus. Program Josephus.java computes Josephus number.
  28. Will the following print out the integers 0 through 9 (in ascending order)?
    int[] vals = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    for (int val : vals) {
       System.out.print(val + " ");
       StdRandom.shuffle(vals);     // mutate the array while iterating
    }
    System.out.println();
    
    No. It will print out 10 values, but with some duplicates and not in ascending order. The iterator does not save a copy of the original array - instead, it uses the mutated copy.
  29. Queue with one access pointer. Re-implement a queue, with all operations taking constant time, but only one instance variable (instead of two). Hint: use a circular linked list, maintaining a pointer to the last item.
  30. Steque. A stack-ended queue or steque is a data type that supports push, pop, and enqueue. Knuth calls it an output-restricted deque. Implement it using a singly-linked list.
  31. Queue with two stacks. Implement a queue with two stacks so that each queue operations takes a constant amortized number of stack operations. Hint: If you push elements onto a stack and then pop them all, they appear in reverse order. If you repeat this process, they're now back in order.

    Solution: QueueWithTwoStacks.java.

  32. Queue with a constant number of stacks. Implement a queue with a constant number of stacks so that each queue operations takes a constant (worst-case) number of stack operations. Warning: Very high degree of difficulty.
  33. Stack with a queue. Implement a stack with a single queue so that each stack operations takes a linear number of queue operations. Hint: to delete an item, get all of the elements on the queue one at a time, and put them at the end, except for the last one which you should delete and return. (Admittedly very inefficient.)
  34. Two stacks with a deque. Implement two stacks with a single deque so that each operation takes a constant number of deque operations.
  35. Steque with two stacks. (R. Tarjan) Implement a steque with two stacks so that each steque operation takes a constant amortized number of stack operations.
  36. Deque with a stack and a steque. (R. Tarjan) Implement a deque with a stack and a steque so that each deque operation takes a constant amortized number of stack and steque operations.
  37. Deque with three stacks. (R. Tarjan) Implement a deque with three stacks so that each deque operation takes a constant amortized number of stack operations.

  38. Multi-word search. Program MultiwordSearch.java reads a sequence of query words q[1], ..., q[k] from the command line and a sequence of documents words d[1], ..., d[N] from standard input and finds the shortest interval in which the k words appear in the same order. (Here shortest means the number of words in the interval.) That is find indices i and j such that d[i1] = q[1], d[i2] = q[2], ..., d[ik] = q[k] and i1 < i2 < ... < ik.

    Answer: for each query word, create a sorted list of the indices where it appears in the document. Scan through lists 2 to k in that order, deleting indices at the front of each list until the the first elements of the resulting k lists are in ascending order.

    q[1]: 50 123 555  
    q[2]: 33 44 93 333 606 613
    q[3]: 60 200
    q[4]: 12 18 44 55 203 495
    
    q[1]: 50 123 555  
    q[2]: 93 333 606 613
    q[3]: 200
    q[4]: 203 495
    
    The sequence of first elements on the lists forms the shortest interval containing the first element on list 1.

    Now delete the first element on list 1. Repeatedly delete elements from list 2 until it agrees with list 1. Repeat for list 3, and so on until the whole array is in ascending order. Check this sequence of first elements, etc.

  39. M/M/1 queue. The Markov/Markov/Single-Server model is a fundamental queueing model in operations research and probability theory. Tasks arrive according to a Poisson process at a certain rate λ. This means that λ customers arrive per hour. More specifically, the arrivals follow an exponential distribution with mean 1 / λ: the probability of k arrivals between time 0 and t is (λ t)^k e^(-λ t) / k!. Tasks are serviced in FIFO order according to a Poisson process with rate μ. The two M's standard for Markov: it means that the system is memoryless: the time between arrivals is independent, and the time between departures is independent.

    Analysis of M/M/1 model. We are interested in understanding the queueing system. If &lambda > μ the queue size increases without limit. For simple models like M/M/1 we can analyze these quantities analytically using probability theory. Assuming μ > λ, the probability of exactly n customers in the system is (λ / μ)^n (1 - λ / &mu).

    • L = average number of customers in the system = λ / (μ - λ).
    • LQ = average number of customers in the queue = λ2 / (μ (μ - λ)).
    • W = average time a customer spends in the system = 1 / (μ - λ).
    • WQ = average time a customer spends in the queue = W - 1 / μ.

    Program MM1Queue.java For more complex models we need to resort to simulation like this. Variants: multiple queues, multiple servers, sequential multi-stage servers, using a finite queue and measuring number of customers that are turned away. Applications: customers in McDonalds, packets in an internet router,

  40. Listing files. A Unix directory is a list of files and directories. Program Directory.java takes the name of a directory as a command-line argument and prints out all of the files contained in that directory (and any subdirectories) in level-order. It uses a queue.

  41. Interrupt handling. When programming a real-time system that can be interrupted (e.g., by a mouse click or wireless connection), it is necessary to attend to the interrupts immediately, before proceeding with the current activity. If the interrupts should be handles in the same order they arrive, then a FIFO queue is the appropriate data structure.

  42. Library implementation. Java has a built in library called Stack, but you should avoid using it. It has additional operations that are not normally associated with a stack, e.g., getting the ith element and adding an element to the bottom of the stack (instead of the top). Although having such extra operations may appear to be a bonus, it is actually a curse. We use ADTs not because they provide every available operation, but rather because they limit the types of operations we are allowed to perform! This prevents us from performing operations that we don't actually want. If we need more than just LIFO access, we should use a different data type. We can still build a stack data type from the Java libraries, but we are careful to limit the types of operations. There is no Java queue implementation.
  43. Load balancing. N users must choose among N identical servers in a network. Goal: balance users across resources. Checking each resource to find an empty one (or least busy one) is too expensive. Instead, choose a random server. At any step, you should be able to see which jobs are on each machine. Program Server.java Plot distribution of loads. Theory: avg load = 1, max load = log N / log log N.
  44. Load balancing reloaded. (Azar, Broder, Karlin, and Upfal) Choose two random resources. Insert on least busy of the two. Theory: avg load = 1, max load = log log N.
  45. Gridding. Given N Euclidean points in the unit box and a parameter d, find all pairs that are within distance d. Divide box into a G-by-G grid where G = ceil(1/d). Put all points in a list in given grid cell. Any neighbor within distance d must be in that cell or one of its 8 neighbors. Program Grid.java implements this strategy using the helper data type Point2D.java.
  46. Java library. Java contains library classes LinkedList and ArrayList that implement a list. Has wider interface than our Sequence data type: access an element by its index, delete an element, search for an element. No urns.
  47. Add a method dup() to Stack that creates a second copy of the topmost element and pushes it onto the stack.
  48. Add a method exch() to Stack that exchanges the top two elements on the stack.
  49. Add a method size() to Stack that returns the number of elements on the stack.
  50. Add a method Item[] multiPop(int k) to Stack that pops k elements from the stack and returns them as an array of objects.
  51. Add a method Item[] toArray() to Queue that returns all N elements on the queue as an array of length N.
  52. Write a recursive function that takes as input a queue, and rearranges it so that it is in reverse order. Hint: dequeue the first element, recursively reverse the queue, and the enqueue the first element.
  53. Given a queue, create two new queues q1 and q2 so that q1 contains the even elements of q and q2 contains the odd elements, e.g., as in dealing a deck of cards.
  54. What does the following code fragment do?
    Queue<Integer> q = new Queue<Integer>();
    q.enqueue(0);
    q.enqueue(1);
    for (int i = 0; i < 10; i++) {
        int a = q.dequeue();
        int b = q.dequeue();
        q.enqueue(b);
        q.enqueue(a + b);
        System.out.println(a);
    }
    
  55. What data type would you choose to implement an "Undo" feature in a word processor?
  56. Suppose you have a single array of size N and want to implement two stacks so that you won't get overflow until the total number of elements on both stacks is N+1. How would you implement this?
  57. Suppose that you implemented push in the linked list implementation of Stack.java with the following code. What is the mistake?
    public void push(Item item) {
       Node second = first;
       Node first = new Node();
       first.item = item;
       first.next = second;
    }
    

    Answer: By redeclaring first, you are create a new local variable named first, which is different from the instance variable named first.

  58. Minimum stack. Design a data type that implements the following operations, all in constant time: push, pop, min. Assume that the items are Comparable.

    Solution:: maintain two stacks, one which contains all of the items and another which contains the minima. To push an item, push it on the first stack; if it is smaller than the topmost item on the second stack, push it on the second stack as well. To pop an item, pop it from the first stack; if it is the top item on the second stack, pop it from the second stack as well. To find the minimum, return the top item on the second stack.

  59. Doubling and halving. What is the effect of replacing the halving test in ResizingArrayStack.java from if (N > 0 && N == a.length/4) resize(a.length/2); to if (N == a.length/4) resize(2*N);?
  60. Shunting-yard algorithm. Implement Dijkstra's shunting-yard algorithm to convert an infix expression into a postfix expression. Support operator precedence, including both left and right associative operators.
  61. FIFO queue with random deletion. Implement a data type that suports insert an item, delete the item added least recently, and delete a random item. Each operation should take constant expected amortized time per operation and should use space (at most) proportional to the numer of items in the data structure.
  62. Stock prices. Given an array of daily stock prices prices[], create an array days[] so that days[i] tells you how many days you have to wait, starting at day i, until the stock price exceeds prices[i].

    Hint: your algorithm should take linear time and use a stack of array indices.

    If you want to learn more, please visit our website Casting Foundry Gate Filter.



76

0

Comments

Please Join Us to post.

0/2000

All Comments ( 0 )

Guest Posts

If you are interested in sending in a Guest Blogger Submission,welcome to write for us!

Your Name: (required)

Your Email: (required)

Subject:

Your Message: (required)