Final Report Exc-1011 - Skills in Competitive Coding Under Codechef-Vit by Madhur Gopal Goel (19bce2100)
Final Report Exc-1011 - Skills in Competitive Coding Under Codechef-Vit by Madhur Gopal Goel (19bce2100)
Arrays
An array is the simplest and most widely used data structure. Other data
structures like stacks and queues are derived from arrays. Each data element is
assigned a positive numerical value called the Index, which corresponds to the
position of that item in the array. The majority of languages define the starting
index of the array as 0. The following are the two types of arrays:
• One-dimensional arrays
• Multi-dimensional arrays (arrays within arrays)
Stacks
We are all familiar with the famous Undo option, which is present in almost
every application. Ever wondered how it works? The idea: you store the
previous states of your work (which are limited to a specific number) in the
memory in such an order that the last one appears first. This can’t be done just
by using arrays. That is where the Stack comes in handy. A real-life example of
Stack could be a pile of books placed in a vertical order. In order to get the
book that’s somewhere in the middle, you will need to remove all the books
placed on top of it. This is how the LIFO (Last In First Out) method works. Basic
operations of stack:
• Push — Inserts an element at the top
• Pop — Returns the top element after removing from the stack
• isEmpty — Returns true if the stack is empty
• Top — Returns the top element without removing from the stack
Queues
Similar to Stack, Queue is another linear data structure that stores the element
in a sequential manner. The only significant difference between Stack and
Queue is that instead of using the LIFO method, Queue implements the FIFO
method, which is short for First in First Out. A perfect real-life example of
Queue: a line of people waiting at a ticket booth. If a new person comes, they
will join the line from the end, not from the start — and the person standing at
the front will be the first to get the ticket and hence leave the line.
Basic operations of Queue:
• Enqueue() — Inserts an element to the end of the queue
• Dequeue() — Removes an element from the start of the queue
• isEmpty() — Returns true if the queue is empty
• Top() — Returns the first element of the queue
Dynamic Programming
Dynamic Programming is mainly an optimization over plain recursion.
Wherever we see a recursive solution that has repeated calls for same inputs,
we can optimize it using Dynamic Programming. The idea is to simply store the
results of subproblems, so that we do not have to re-compute them when
needed later. This simple optimization reduces time complexities from
exponential to polynomial. For example, if we write simple recursive solution
for Fibonacci Numbers, we get exponential time complexity and if we optimize
it by storing solutions of subproblems, time complexity reduces to linear. The
factorial of a positive integer n is equal to 1*2*3*...n. Factorial of a negative
number does not exist. Here a C++ program is given to find out the factorial of
a given input using dynamic programming.
#include <iostream>
using namespace std;
int result[1000] = {0};
int fact(int n) {
if (n >= 0) {
result[0] = 1;
for (int i = 1; i <= n; ++i)
{
result[i] = i * result[i - 1];
}
return result[n];
}
}
int main() {
int n;
while (1) {
cout<<"Enter integer to compute factorial (enter 0 to exit): ";
cin>>n;
if (n == 0)
break;
cout<<fact(n)<<endl;
}
return 0;
}
Online Webinars
CodeInvicta
One of these guest lecturers was Aman Dhattarwal. The webinar was light in
general and instead of being technical, we were guided on the various factors
in a successful life. Before the above mentioned webinar we also had a
technical webinar on ‘Code Optimization and Debugging’. This webinar was
conducted under the mentorship of ‘Mr. Anoop Mishra’.
We learned a lot of ways to deal with debugging.