0% found this document useful (0 votes)
51 views43 pages

The Seven Step Framework For Coding Skills Acquisition: Applying The Pareto Principle To Learning How To Code

The document outlines a 7-step framework for acquiring coding skills through deliberate practice. It involves gradually building skills by working through carefully designed drills focused on one concept at a time. This integrates thinking, doing, reflection and feedback. The process is designed to find the right balance between passive and active learning to overcome issues with only having theoretical knowledge or doing projects without proper practice. It draws from research on expertise and the author's own experiences to structure an effective approach.

Uploaded by

Tyler Johnson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views43 pages

The Seven Step Framework For Coding Skills Acquisition: Applying The Pareto Principle To Learning How To Code

The document outlines a 7-step framework for acquiring coding skills through deliberate practice. It involves gradually building skills by working through carefully designed drills focused on one concept at a time. This integrates thinking, doing, reflection and feedback. The process is designed to find the right balance between passive and active learning to overcome issues with only having theoretical knowledge or doing projects without proper practice. It draws from research on expertise and the author's own experiences to structure an effective approach.

Uploaded by

Tyler Johnson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

The Seven Step Framework

for
Coding Skills Acquisition

Applying the Pareto Principle to


Learning How to Code
This page is intentionally left blank
Introduction
This process is designed by working backwards from the coding problem.
We pick a coding problem that is beyond your current ability to solve and
gradually build the necessary skills by working through a carefully designed
set of drills. Each drill is focused on one thing and incrementally builds the
necessary skills. This makes it easier to make progress towards the
desired outcome. Eventually, you will be able to code the solution to the
given coding problem. This process cuts through all the irrelevant things
and focuses on the essential concepts required to solve coding problems.

Thinking, Doing, Reflecting and Feedback

The 7-Step Framework for Coding Skills Acquisition integrates ​thinking,


doing, reflection and feedback​ in the coding skill acquisition process. The
steps 1, 2 and 3 is where the thinking takes place. The step 4, 5 and 6 is
where the doing takes place. The reflection occurs in the last step 7. The
feedback can occur in steps 6 and 7. The first two steps are already done
for you. You only have the remaining 5 steps to study and work through.

Why this process?


This process is designed to overcome the drawbacks of writing code
without thinking aka copy-paste coding. It is also designed to prevent
consuming too much content without spending enough time on practicing.

Acquiring theoretical knowledge only results in difficulty in writing programs


from scratch. Lack of practice results in inability to apply the knowledge to
solve coding problems. This process finds the right balance between
passive and active learning.
Why you should avoid scrimmage?
One of the bad advice given by self-proclaimed coding geniuses is
encouraging aspiring developers to work on small projects for learning to
code purposes. This is called scrimmage and it is not recommended. You
can read the books below to learn why it is not a good idea.

Where did this process originate?


This process is based on the books:

● Peak: Secrets from the New Science of Expertise by Dr Anders


Ericsson and Robert Pool
● Practice Perfect: 42 Rules for Getting Better at Getting Better by
Doug Lemov

This process is also influenced by my failures in getting through Google


and Amazon interviews. These failures forced me to finally use my brain,
think and come up with a practical, 80-20 way to solve the problem of doing
well in the coding interview.
The 7-Step What...
I am a lazy programmer. Can I skip the drills?
No. Even if you are familiar with the drills, repeating the drills will increase
your speed. Eventually you will be able to visualize the code for the drill. If
you have reached this stage, you can spend a few seconds to visualize it.
In this case, you do not need to type in the code.

Practicing the skill to automaticity frees up your mental power when


tackling difficult coding problems. So, you are more likely to solve
unfamiliar and difficult problems.

Automaticity applies to both teaching and learning a language.


In both cases the more often an activity is done, the more
automatic it becomes. The theory of automaticity relates to
theories of cognitive capacity and cognitive load, which
suggest that at any given time we have a finite amount of
attention to give to an activity or process. When a process
becomes more automatic, less attention is needed and
attention can therefore be given to other processes or tasks.
Dr. Olenka Bilash

This theory of automaticity is applicable to learning to code because our


brains function the same way and the theories of cognition are still
applicable.

In programming, if the basic concepts aren’t so easy that you


don’t even have to think about them, you’re not going to get the
big concepts.
Joel Spolsky (A Programmer from New York)
What is automaticity?
Automaticity is the ability to do things without occupying the mind with the
low-level details required, allowing it to become an automatic response
pattern or habit. It is usually the result of learning, repetition and practice.
There are four stages in skills progression.

Stage 1 : Unconscious Incompetence


You are unaware of the skill and your lack of proficiency.

Stage 2 : Conscious Incompetence


You are aware of the skill but not yet proficient.

Stage 3 : Conscious Competence


You are able to use the skill, but only with effort.

Stage 4 : Unconscious Competence


Performing the skill becomes automatic.

You reach the automaticity in the fourth stage of the skills progression.
How fast should I type the code for the solution?
You should be able to type the solution for the problem as fast as you can
type on the keyboard. If you can retrieve the solution as fast as you can
think, you have progressed to an advanced level. This means you have
bypassed the many steps of translating a problem description to code. This
can only happen if you have mastered the concepts needed to solve that
problem.

Joel Spolsky has a good story about this in his book:

Serge Lang, a math professor at Yale, used to give his Calculus


students a fairly simple algebra problem on the first day of classes,
one which almost everyone could solve, but some of them solved it
as quickly as they could write while others took a while, and
Professor Lang claimed that all of the students who solved the
problem as quickly as they could write would get an A in the Calculus
course, and all the others wouldn’t. The speed with which they solved
a simple algebra problem was as good a predictor of the final grade
in Calculus as a whole semester of homework, tests, midterms, and a
final.

Glengarry Glen Ross said that ABC stands for Always Be Coding.
Does that mean I should spend 8 hours a day on practice?
It really doesn’t matter how long. If you practice with your fingers, no
amount is enough. If you practice with your head, two hours a day is plenty.
Improvement requires you giving the task your full attention. One hour of
intense and focused practice is better than 8 hours of practice interrupted
by distractions.

Try out your ideas by visualizing them in action.


– David Seabury

Imagine you have to use punch cards to execute your program. Visualize
the data structure and every line of code using your brain. You will learn
how to visualize in the core concepts module of this unique training
program.

My method is different. I do not rush into actual work. When I


get a new idea, I start at once building it up in my
imagination, and make improvements and operate the device
in my mind. When I have gone so far as to embody
everything in my invention, every possible improvement I can
think of, and when I see no fault anywhere, I put into concrete
form the final product of my brain.
– Nikola Tesla

Think with pen and paper. The act of writing exercises our brains in ways
that typing on the computer cannot. According to research in the
Developmental Science journal, the best way to learn something is to write
it out on paper. Handwriting activates large regions of the brain responsible
for thinking, language, healing and working memory.

In their book, the authors of Software Design Decoded - 66 Ways Experts


Think say:

Experts know that their understanding of the design problem


and their understanding of its solution inevitably deepen and
co-evolve as they design. Experts therefore draw the problem
as much as they draw the solution: by moving back-and-forth,
they not only ensure that both stay in sync, but also explicitly
use advances in the understanding of one to drive advances
in the understanding of the other.

Experts externalize their thoughts by sketching when they think. They


sketch on paper, whiteboards, napkins and inside their minds all the time.
They know that sketching is a way to interact with their own thoughts, an
opportunity to externalize, examine and advance what they have in their
minds.
Is this going to be fun?
No. Going beyond your comfort zone is never fun. You must push yourself
beyond your comfort zone to improve. Getting out of your comfort zone
means trying to do something that you could not do before. You must push
yourself beyond what is familiar and comfortable. Make an effort to do more
than what is already easy for you.

For deliberate practice to be effective, you need to push yourself outside


your comfort zone and maintain your focus, but those are mentally draining
activities. Expert performers do two things :

1. Get enough sleep and keep healthy.

If you are tired or sick, it's much harder to maintain focus and easier to
slack off.

2. Limit the length of your practice sessions to about an hour.

You cannot maintain intense concentration for much longer than that.
When you are first starting out, it's likely to be less. If you want to practice
for longer than an hour, go for an hour and take a break.

Fortunately, you will find that as you maintain your practice over time it will
seem easier. Your body and mind will habituate to the practice. The
practice never becomes fun, but eventually it gets closer to neutral, so it's
not as hard to keep going.

Pushing too hard for too long can lead to burnout and ineffective learning.
The brain changes most quickly in that sweet spot where it is pushed
outside - but not too far outside - its comfort zone. The drills are designed
to do exactly that for your current skill level.
What is the best time to work through this training material?
First hour in the morning is the best time to work through the training
materials. Assuming a good night’s sleep, your mental and physical energy
will be at its peak in the morning.

How do I make deliberate practice a daily habit?


Use an external trigger as a cue (that you see, hear or touch) that guides
you to take action.

What is unique about this learning process?


The 7-Step Framework separates:

● The learning of the syntax from semantics of the code.


● Solving the given problem from coding the solution.

You will gain knowledge to match a new problem with a previously learned
solution. The focus is on language independent programming constructs.
This provides a way to implement the solution to a coding problem in any
chosen language. It also builds your vocabulary and provides a relevant
mental model.

Do I need to practice 10,000 hours?


No. The guy who said that is an idiot. For more details read the book by Dr.
Anders Ericsson.
What is a mental model? Why do I need it?
A mental model is a representation of some domain that supports
understanding, reasoning, and prediction. Mental models permit reasoning
about situations not directly experienced. They allow people to mentally
simulate the behavior of a system.

For instance, the knowledge about the computer memory and how it is
used during the program execution can be visualized as shown in the
diagram. This is a useful mental model when solving coding problems.
Because, we are able to make the design choices.

Recursion is a difficult topic for beginners to understand. Experts have the


mental model to understand recursion deeply and they are able to choose
between tail recursion or head recursion based on the problem. They know
about the system stack, frames for the procedure calls and how the values
of variables are bound to the recursive calls.
In the book Peak, Dr Anders Ericsson gives the following example from
chess:

Alekine wrote the chess position he was studying down on a piece of paper
and puzzle over it during school hours. He could hold the entire chessboard
in his memory and move pieces around in his mind, trying various lines of
play. He could play whole games in his mind without looking at a
chessboard.

Expert chess players can analyze a position in terms of general patterns.


The representations also allow the master to zero in on individual pieces
and mentally move them around the board to see how such moves would
change the patterns. They can examine strings of possible moves and
countermoves in great detail and look for a move with the best chance of
winning. In short, the mental representations give masters a view of the
forest that novices lack, they also allow them to zero in on the trees when
necessary.

Similarly, as programmers we can also visualize the data structures and


algorithms to reason, understand and predict the behavior of a program.
Expert programmers organize their programming knowledge in
sophisticated, flexible and viable mental models. They organize their
representations of code segments into larger conceptual-programming
structures according to the function performed by the code. They form
abstract representations based upon the purpose of the code. The expert is
very good at targeted, focused pattern matching. Given a problem, they
can retrieve an appropriate solution schema.

The emergence of the expert programmer from the novice is a process that
involves the formation of multiple mental models, deep and interlinked
knowledge hierarchies and abstract, generalized problem-solving patterns.
In their book, the authors of Software Design Decoded - 66 Ways Experts
Think say:

Experts Simulate Continually


Experts imagine how a design will work - simulating aspects of the
envisioned software and how the different parts of the design support
a variety of scenarios. When working with others, experts regularly
walk through a design by verbalizing its operation step-by-step. When
alone, they simulate mentally, exercising the design repeatedly over
time.

On their own, design diagrams remain passive abstractions. This is why


experts draw examples alongside the diagrams when they simulate a
design. Externalizing their thoughts, juxtaposing the simulation with their
design and envisioning the execution in context, forces them to interpret
what they drew and to test their design more thoroughly in the process.

Mental Model of a Variable

In mathematics, a variable is an unknown which can take on all the


numerical values in a predetermined set. In programming languages, it is
necessary to specify this concept in more detail because the model for
variables depends on the programming paradigm.

The classical imperative paradigm uses modifiable variables. According to


this model, the variable is seen as sort of container or location that refers to
physical memory. We can give a name to the variable and it can contain
values. These values can be changed over time, by execution of
assignment commands.
A programming newbie will have a simple mental model for a variable.

In mathematics a variable represents a value that is unknown but when


such a value is defined the link thus created cannot be modified later.

We can represent a variable with the name x with a box that is filled with a
value. It can be seen that the variable (the box) is different from the name x
which denotes it.
Some object-oriented languages use a different model. According to this
alternative model, a variable is not a container for a value but is a reference
to a value which is typically stored in the heap.

Pure functional languages use a concept of variable similar to the


mathematical one: a variable is nothing more than an identifier that stands
for a value. Functional languages do not have any modifiable variables.
Assignment is the basic command that allows the modification of the values
associated with modifiable variables. It also modifies the state in imperative
languages.

Expert programmers have the knowledge to understand the meaning


behind an innocent looking statement such as an assignment. They have a
good grasp of concepts such as the system stack and heap. They know
how to make memory management decisions and decide whether to
allocate memory dynamically or static memory is sufficient for a given
problem.

Syntax vs Semantics

Consider the following command:

x=x+1

In mathematics, this is absurd and has no meaning. In programming, the


equal to​ symbol stands for the concept of assignment. We assign to the
variable x its previous value incremented by 1. Sometimes the concepts do
not map directly from mathematics to programming.

For instance the symbol % represents percentage in mathematics whereas


in programming it represents the modulo operation that finds the remainder
after division of one number by another.
Why is C and C++ used as the language of choice in this training?
They enable grasping mental models of the programming easier and more
concrete. They do not abstract away the details of the conceptual model of
a computer architecture as much as other modern programming
languages. General programming abilities are far more important than
language specific details.

Why do I need to work through toy examples?


If you cannot solve small coding problems quickly, you will either not be
able to solve big problems at all or it will take you a long time. The reason
is that the building blocks used in solving small problems can be reused in
solving bigger problems. You can also combine building blocks that arise
from previously learned general patterns to solve new problems.

Why do we need to learn searching and sorting algorithms?


There are libraries available to search and sort any data structure. So
what’s the point of learning them? The reason is that they become
intermediate step in solving other problems.

How can I type the solution to a coding problem as fast as I can


type?
The problem solving patterns and the language constructs will be given
names. Using the name enables us to communicate with other developers
and retrieve the solution from our memory.

For instance, In programming, if you have to solve factorial problem and if


you have built the vocabulary, you will recognize it as a Product
Accumulator. This is a composite building block formed from combining
simple building blocks such as counter, accumulator and multiplication.
What is the right approach to learning to code?
There are different ways to learn programming. We will consider the
different approaches and fit them into the Bloom’s Learning Taxonomy grid.

Producing and Interpreting are the two dimensions of a matrix that can be
used to identify a range of different learning trajectories and hench to guide
students in how to improve their skills and understanding.
Trial and Error Approach

You learn a new programming concept, you first achieve the knowledge of
this concept. If you continue learning by imitating a ready example of a
program but without a deep understanding of the concept, you will be
trapped in a trial and error approach to learning.
Practical Approach

You have the ability to apply and create without the ability to analyse or
evaluate your own program code. The main problem for practical learners
is in not being able to debug their own solutions when they encounter
errors.
Theoretical Approach

You remember and understand the concepts and have the ability to
analyse or evaluate but lack the ability to apply the knowledge and write
code from scratch.
Ideal Approach

The learning of programming can be seen as an iterative process. In the


very beginning, you are taught really simplistic and basic pieces of
information and places to apply them. Instead of learning some things here
and there, programming is a skill that is learned by building new information
on top of earlier information. So in a way the basic pieces of information
you are first struggling with become the bits and pieces you use in
subsequent learning of new material. The spiral process can be seen, in
that when you are learning a new subject, your prerequisites - the materials
to use in building new knowledge - have become your new basic
knowledge, although you have perhaps reached the level Create or
Evaluate on those earlier subjects.
Create could be described as the ability to combine one subject with others
in order to build new solutions. This may also be seen when new solutions
or subjects are learnt by building upon and integrating previous knowledge.
This is easily seen to be true when considering the topics that are difficult
and require in depth analyzing by some are mere basic knowledge for
expert programmers.

Example of a Learning Spiral

In the beginning a programming newbie is taught how to use a loop


structure. He will go through all the levels of Bloom's taxonomy while
learning it. He knows that a loop can be used for iteration. He understands
how the loop works. He is able to apply a loop when told etc., eventually
learning it thoroughly. After reaching the highest levels, the loop structure
has become a tool for the student to use in subsequent programming. As
the student is trying to learn how to sort an array, the loop can be seen as
his basis knowledge upon which he is building his new knowledge. Later as
the student is trying to implement a top-application to his own operating
system, he will use the sorting of an array as a part of his base knowledge.
This page is intentionally left blank
This page is intentionally left blank
Essential Framing Questions
Step 1 : Current Condition

What is the actual condition now?

Identify the obstacles preventing you from solving a coding problem.

Step 2 : Target Condition

What is the target condition?

Identify the skills needed to overcome the obstacles. Establish the target
condition.

Step 3 : Basic Building Blocks

What is the background knowledge required for acquiring the skills?

Acquire the appropriate mental model and the vocabulary that provides the
background knowledge required to acquire the skills. The mental model is
either simple or complex based on the demands of the coding problem that
acts as a performance measuring stick.

The vocabulary built in this step becomes a basic building block that can be
combined with other building blocks to form a conceptually more complex
building blocks. The vocabulary enables you to think like a computer
scientist and solve computational problems.
Step 4 : Skills Breakdown

How can you break down the identified skills into sub-skills?

Discrete drills are designed to acquire the sub-skills individually. Work


through the discrete drills to acquire the sub skills.

Step 5 : Acquire the Identified Skills

What are the integrative drills required to combine the discrete drills?

Work through the drills designed to integrate discrete skills. In this step, you
acquire the identified skills. You are now ready to tackle the coding
problem.

Step 6 : Apply the Skills

Are you ready to work through the coding problem?

Solve the coding problem and code the solution. If you are stuck, reach out
for guidance. In this step, you gain experience in applying your knowledge
and skills to write code from scratch. You can now directly translate visual
diagrams into code. You will understand every line of code that you write
and can reason about the code to make time-space tradeoffs.
Step 7 : Reflect and Get Feedback

What did you learn?

Reflect on how you have done and revise your approach to perform better
the next time. Correct previous poor task performance. You have to know
whether you are doing something right and if not, how you are going wrong.
Feedback points out your mistakes and identifies exactly where and how
you are falling short.

Get feedback to improve your solution. Compare your solution with


alternative solutions. Reading and understanding code written by others is
part of acquiring the skills to write programs from scratch.
This page is intentionally left blank
This page is intentionally left blank
Focused Practice for Coding Mastery
Focused Practice #1 : Counters

Basic for and while Loop Drills

1. Print 1 through 10 using ​for ​loop. ​solution


2. Print 1 through 10 using ​while ​loop.
3. Print a 10 element array using ​for​ loop.
4. Print a 10 element array using a ​while​ loop.

The number of iterations is known in definite loop.

Vocabulary

Simple Building Blocks


Loop Initialization, Loop Termination Condition, Loop Variable Update,
Index Variable

Composite Building Block


Definite Loop

Building Blocks
Coding Problems

Counter
Counter is also a composite building block that uses loop as its building
block.

1. Implement ​divide​ method that takes two arguments and returns the
result of dividing the first argument by the second. Do not use the
division operator: /. Use ​while ​loop.
2. Implement ​multiply​ method that takes two arguments and returns the
result of multiplying those two numbers. Do not use the multiplication
operator: *. Use ​while ​loop.
3. Implement ​powers m ​ ethod that takes an argument n, where n is >= 0.
It prints powers of 2 from 1 through n.
Focused Practice #2 : Counters

Basic for and while Loop Drills

1. Print 1 through 10 using ​for ​loop.


2. Print 1 through 10 using ​while ​loop.
3. Print a 10 element array using ​for​ loop.
4. Print a 10 element array using a ​while​ loop.
5. Read the input from a user and print it back to the terminal.

Vocabulary

Simple Building Blocks


Indefinite Loop

Composite Building Block


Counter

Coding Problems

Counters

1. Get input from the terminal and count the number of lines typed in by
a user. Print the value to the terminal.
2. Get input from the terminal and count the number of characters typed
in by a user. Print the value to the terminal.
Focused Practice # 3: Summation Accumulator

Basic for and while Loop Drills

1. Print 1 through 10 using ​for ​loop.


2. Print 1 through 10 using ​while ​loop.
3. Print a 10 element array using ​for​ loop.
4. Print a 10 element array using a ​while​ loop.

Summation Accumulator
Create a summation accumulator that prints the result of adding numbers
from 1 through 10.

1. Use ​for l​ oop.


2. Use w​ hile l​ oop.

Vocabulary

Simple Building Blocks


Counter, Accumulator, Summation

Composite Building Blocks


Summation Accumulator

Coding Problem

Combining Counter and Summation Accumulator

Given an array of integers, add all the elements in the array. Array
elements are not sorted.
Focused Practice # 4: Product Accumulator

Basic for and while Loop Drills

1. Print 1 through 10 using ​for ​loop.


2. Print 1 through 10 using ​while ​loop.
3. Print a 10 element array using ​for​ loop.
4. Print a 10 element array using a ​while​ loop.

Product Accumulators
Create a product accumulator that prints the result of multiplying numbers
from 1 through 10.

1. Use ​for l​ oop.


2. Use w​ hile l​ oop.

Vocabulary

Simple Building Blocks


Counter, Accumulator, Product

Composite Building Blocks


Product Accumulator

Coding Problem

Counter and Product Accumulator

Given an array of integers, print the product of all the elements in the array.
Focused Practice #5: Reduction

Basic for and while Loop Drills

1. Print 1 through 10 using ​for ​loop.


2. Print 1 through 10 using ​while ​loop.
3. Print a 10 element array using ​for​ loop.
4. Print a 10 element array using a ​while​ loop.
5. Implement ​step​ method that takes a positive integer as the argument,
reduces the given argument by two through each iteration and prints
each of those values until the reduced value becomes 0 or negative.
Use a ​while ​loop for this drill.

Vocabulary

Reduction

Coding Problems

1. Implement ​remainder​ method that takes two positive integers and


computes the remainder of dividing the first argument by the second
argument. Do not use the % operator or any other builtin method that
computes the remainder. Use the ​while​ loop to implement.
2. Compute the GCD of given two positive integers using the ​while​ loop.
Focused Practice Session #6

Pushing Through Your Knowledge Threshold

Loop

Implement ​square_root​ method that computes the square root of a given


number.

Counter and Product Accumulator

1. Print the factorial of a given positive number using iteration.


2. Implement a function for exponentiation. The ​power(m,n)​ must raise
integer m to a positive of small integers.

Basic Arithmetic

1. Implement ​even? m ​ ethod that takes an integer and returns true if the
number is an even number, otherwise false. Do not use any language
builtin even number method.
2. Implement ​odd? m​ ethod that takes an integer and returns true if the
number is an odd number, otherwise false. Do not use any language
built in odd number method.
3. Implement a pseudo random number generator. The method can
take a number as the seed.
Focused Practice #7 : Pascal Triangle

Nested Loops, Two Dimensional Array Drills

1. Create nested loops with one outer ​for​ loop and one inner ​for​ loop.
Print the outer loop variable and inner loop variable values inside the
inner loop.
2. Create nested loops with one outer ​for​ loop and one inner ​while​ loop.
Print the outer loop variable and inner loop variable values inside the
while​ loop.
3. Given a two dimensional array, print all the elements.
4. Variation on 1: Print only if the outer loop and inner loop variable
value is the same.
5. Variation on 1: Print only if the outer loop and inner variable values
are different.

Vocabulary

Two Dimensional Array, Nested Loops

Coding Problems

1. Print the Pascal triangle.


2. Calculate the number of times the inner for loop executes in a nested
for loop. Print the value.
Focused Practice #8 : Shift and Rotate

Drills for Shifting Array Elements

1. Create one ​for​ loop and traverse forward. Print the loop variable
values inside the loop.
2. Create one ​for​ loop and traverse backward. Print the loop variable
values inside the loop.
3. Move the second element in the array to the left by one.
4. Copy the first element in the array to the last position of the array.

Vocabulary

Traverse Forward, Traverse Backward, Copy, Move, Shift, Rotate

Coding Problems

1. Implement Shift Left operation on an array. Move all elements in an


array to the left by one. First element is removed from the array and
the last element is filled with 0.
2. Implement: Rotate Left operation on an array. First element moves to
the last location of the array and all other elements shift to the left by
one.
Practice Session #9 : Shifting in Place

Drills for Shifting Array Elements

1. Swap the first two elements in an array.


2. Swap the first and last two elements in an array.
3. Create one ​for​ loop with two index variables i and j that traverse
forward and backward in each iteration. Print the values of i and j
inside the loop.
4. Create one ​for​ loop with two index variables i and j that traverse
forward and backward in each iteration until the value of i and j
becomes equal. Print the values of i and j inside the loop.
5. Copy all elements from one array into another.
6. Given an array with 10 elements, compare the first element with all
other elements and print if the first element is less than the other
element or not.

Vocabulary

Traverse Forward, Traverse Backward, Copy, Move, Swap, Shift in Place,


Compare

Coding Problems

1. Given array with negative and positive numbers, implement ​rearrange


operation on an array, all the negative numbers go to right and
positive numbers go to the left.
2. Implement ​append o​ peration on an array that appends a given
element to the end of the array.
3. Given two sorted arrays, implement ​merge​ operation for an array that
merges them into one sorted array.

You might also like