AP LAB-1 Syllabus
AP LAB-1 Syllabus
AP LAB-1 Syllabus
a. Course Description
Advance programming is the course in which students will learn how to apply algorithms in order
to solve complex problems. The goal of this course is to teach students how to apply familiar
algorithms to non-intuitive problems.
b. Course Objectives
To give students the ability to write reliable codes.
To provide skills to the students to write compact and efficient code in a quick manner
To provide logic building capability to the student.
To improve the logic building of students to tackle the complex problems.
To implement the different approaches to get appropriate solutions.
c. Course Outcomes
CO1 Understand the problem and find out a better approach to solve a particular problem.
CO2 Apply the knowledge of the programming concept to develop small programs for specific
problems
CO3 Illustrating basic algorithmic challenges through programs, encompassing concepts such
as Arrays, stacks, queues, linked lists, tree traversals, graph traversals, hashing, and the
calculation of shortest paths
CO4 Analyze the appropriate approaches for specific problems and achieve all test cases.
5. Diagonal Difference
Problem Statement: Given a square matrix, calculate the absolute difference between the sums
of its diagonals.
For example, the square matrix is shown below:
123
456
989
The left-to-right diagonal =. The right to left diagonal =. Their absolute difference is.
Function description
Complete the function in the editor below.
Diagonal Difference takes the following parameter:
int arr[n][m]: an array of integers
Return
int: the absolute diagonal difference
Problem Link:
https://www.hackerrank.com/challenges/diagonal-difference/problem
Experiment 2 1. Equal Stack: -
Stacks & Queue Problem Statement: You have three stacks of cylinders where each cylinder has the same
diameter, but they may vary in height. You can change the height of a stack by removing and
discarding its topmost cylinder any number of times.
Find the maximum possible height of the stacks such that all of the stacks are exactly the same
height. This means you must remove zero or more cylinders from the top of zero or more of the
three stacks until they are all the same height, then return the height.
Example
H1= [1,2,1,1,]
H2= [1,1,2]
H3= [1,1]
There are and cylinders in the three stacks, with their heights in the three arrays. Remove the
top 2 cylinders from (heights = [1, 2]) and from (heights = [1, 1]) so that the three stacks all are
2 units tall. Return as the answer.
Note: An empty stack is still a stack.
Problem Link:
https://www.hackerrank.com/challenges/equal-stacks/problem
2. Game of two stack: -
Problem Statement: Alexa has two stacks of non-negative integers, stack and stack where
index denotes the top of the stack. Alexa challenges Nick to play the following game:
In each move, Nick can remove one integer from the top of either stack or stack.
Nick keeps a running sum of the integers he removes from the two stacks.
Nick is disqualified from the game if, at any point, his running sum becomes greater
than some integer given at the beginning of the game.
Nick's final score is the total number of integers he has removed from the two
stacks.
Given, and for games, find the maximum possible score Nick can achieve.
Example
A= [1,2,3,4,5]
B= [6,7,8,9]
The maximum number of values Nick can remove is. There are two sets of choices with this
result.
1. Remove from with a sum of.
2. Remove from and from with a sum of.
Problem Link:
https://www.hackerrank.com/challenges/game-of-two-
stacks/problem
3. Balanced Brackets: -
Problem Statement: A bracket is considered to be any one of the following
characters: (, ), {, }, [, or ].
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {)
occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three
types of matched pairs of brackets: [], {}, and ().
A matching pair of brackets is not balanced if the set of brackets it encloses are not matched.
For example, {[(])} is not balanced because the contents in between { and } are not balanced.
The pair of square brackets encloses a single, unbalanced opening bracket, (, and the pair of
parentheses encloses a single, unbalanced closing square bracket, ].
By this logic, we say a sequence of brackets is balanced if the following conditions are met:
It contains no unmatched brackets.
The subset of brackets enclosed within the confines of a matched pair of brackets is
also a matched pair of brackets.
Given strings of brackets, determine whether each sequence of brackets is balanced. If a string
is balanced, return YES. Otherwise, return NO.
Function Description
Complete the function isBalanced in the editor below.
isBalanced has the following parameter(s):
string s: a string of brackets
Returns
string: either YES or NO
Problem Link:
https://www.hackerrank.com/challenges/balanced-
brackets/problem
Problem Statement: You are given a square grid with some cells open (.) and some blocked
(X). Your playing piece can move along any row or column until it reaches the edge of the
grid or a blocked cell. Given a grid, a start and a goal, determine the minmum number of
moves to get to the goal.
Problem Link:
https://www.hackerrank.com/domains/data-
structures?filters%5Bsubdomains%5D%5B%5D=queues
Problem Statement: - A queue is an abstract data type that maintains the order in which
elements were added to it, allowing the oldest elements to be removed from the front and new
elements to be added to the rear. This is called a First-In-First-Out (FIFO) data structure because
the first element added to the queue (i.e., the one that has been waiting the longest) is always
the first one to be removed.
Problem Link:
https://www.hackerrank.com/challenges/ctci-queue-
using-two-stacks/problem
Experiment 3 1. Compare Two Linked List: -
Linked List Problem Statement: You’re given the pointer to the head nodes of two linked lists.
Compare the data in the nodes of the linked lists to check if they are equal. If all data
attributes are equal and the lists are the same length, return 1 . Otherwise, return 0.
Example
The two lists have equal data attributes for the first 3 nodes. Llist2 is longer, though, so the
lists are not equal. Return 0.
Problem Link:
https://www.hackerrank.com/challenges/compare-two-
linked-lists/problem
2. Sorted Doubly Linked List: -
Problem Statement: Given a reference to the head of a doubly-linked list and an integer, ,
create a new DoublyLinkedListNode object having data value and insert it at the proper location
to maintain the sort.
Example
Head refers to the list
data=3
Return a reference to the new list:
Problem Link:
https://www.hackerrank.com/challenges/insert-a-node-into-a-sorted-doubly-
linked-list/problem
3. Doubly Linked List: -
Problem Statement: Given the pointer to the head node of a doubly linked list, reverse the
order of the nodes in place. That is, change the next and prev pointers of the nodes so that the
direction of the list is reversed. Return a reference to the head node of the reversed list.
Note: The head node might be NULL to indicate that the list is empty.
Problem Link:
https://www.hackerrank.com/challenges/reverse-a-doubly-linked-list/problem
4. Joined Linked List: -
Problem Statement: Given pointers to the head nodes of 2 linked lists that merge together at
some point, find the node where the two lists merge. The merge point is where both lists point
to the same node, i.e. they reference the same memory location. It is guaranteed that the two
head nodes will be different, and neither will be NULL. If the lists share a common node, return
that node's data value.
Note: After the merge point, both lists will share the same node pointers.
Problem Link:
https://www.hackerrank.com/challenges/find-the-merge-point-of-two-joined-
linked-lists/problem
5. Detect cycle: -
Problem Statement: A linked list is said to contain a cycle if any node is
visited more than once while traversing the list. Given a pointer to the head of
a linked list, determine if it contains a cycle. If it does, return 1. Otherwise,
return 0.
Problem Link:
https://www.hackerrank.com/challenges/detect-whether-a-linked-list-
contains-a-cycle/problem
Experiment 4 1. Fraudulent-Activity: -
Searching and
Sorting Problem Statement: HackerLand National Bank has a simple policy for warning clients about
possible fraudulent account activity. If the amount spent by a client on a particular day is greater
than or equal to 2* the client's median spending for a trailing number of days, they send the client
a notification about potential fraud. The bank doesn't send the client any notifications until they
have at least that trailing number of prior days' transaction data.
Given the number of trailing days d and a client's total daily expenditures for a period of n days,
determine the number of times the client will receive a notification over all n days.
Problem Link: https://www.hackerrank.com/challenges/fraudulent
-activity-notifications/problem?isFullScreen=true
2. Missing Number: -
Problem Statement: Given two arrays of integers, find which elements in the second array are
missing from the first array.
Example
The brr array is the original list. The numbers missing are [4,6].
Problem Link:
https://www.hackerrank.com/challenges/missing-numbers/problem
3. Minimum Loss: -
Problem Statement: Lauren has a chart of distinct projected prices for a house over the
next several years. She must buy the house in one year and sell it in another, and she must
do so at a loss. She wants to minimize her financial loss.
Problem Link: https://www.hackerrank.com/challenges/minimum-loss/problem
4. Closet Number: -
Problem Statement: Sorting is useful as the first step in many different tasks.
The most common task is to make finding things easier, but there are other uses
as well. In this case, it will make it easier to determine which pair or pairs of
elements have the smallest absolute difference between them.
Problem Link:
https://www.hackerrank.com/challenges/closest-numbers/problem
5. Quick Sort: -
Problem Statement: The previous challenges covered Insertion Sort, which is a simple and
intuitive sorting algorithm with a running time of O(N2) . In these next few challenges, we're
covering a divide-and-conquer algorithm called Quicksort (also known as Partition Sort). This
challenge is a modified version of the algorithm that only addresses partitioning. It is implemented
as follows:
Step1:Divide
Choose some pivot element, p, and partition your unsorted array, arr, into three smaller
arrays: left, Right, and Equal , where each element in Left<p , each element in Right >p , and
each element in equal=p.
Problem Link:
https://www.hackerrank.com/challenges/quicksort1/problem
Problem Statement: - In this challenge, the user enters a string and a substring. You have to
print the number of times that the substring occurs in the given string. String traversal will take
place from left to right, not from right to left.
Problem Link:
https://www.hackerrank.com/challenges/find-a-string/problem
4. String Reductions
Problem Statement: Given a string, , consisting of lowercase
English characters ( ), remove all of the characters that occurred previously in the
string. Formally, remove all characters,siA , for:
Problem Link:
https://www.hackerrank.com/challenges/string-reductions/problem
3. Inorder Traversal
Problem Statement: In this challenge, you are required to implement inorder traversal of a
tree.Complete the inorder function in your editor below, which has 1 parameter: a pointer to the
root of a binary tree. It must print the values in the tree's inorder traversal as a single line of
space-separated values.
Problem Link:
https://www.hackerrank.com/challenges/tree-inorder-traversal/problem
4. Balanced Forest
Problem Statement: - Greg has a tree of nodes containing integer data. He wants to insert a node
with some non-zero integer value somewhere into the tree. His goal is to be able to cut two edges
and have the values of each of the three new trees sum to the same amount. This is called
a balanced forest. Being frugal, the data value he inserts should be minimal. Determine the
minimal amount that a new node can have to allow creation of a balanced forest. If it's not possible
to create a balanced forest, return -1.
Problem Link:
https://www.hackerrank.com/challenges/balanced-forest/problem
5. Even Tree: -
Problem Statement: You are given a tree (a simple connected graph with no cycles).
Find the maximum number of edges you can remove from the tree to get a forest such that each
connected component of the forest contains an even number of nodes.
Problem Link:
https://www.hackerrank.com/challenges/even-tree/problem
Problem Link:
https://www.hackerrank.com/challenges/costly-graphs/problem
Contact Hours-15
UNIT-3
1. Marcs Cakewalk
Experiment-8 Problem Statement: - Marc loves cupcakes, but he
also likes to stay fit. Each cupcake has a calorie count,
Greedy and Branch
and Marc can walk a distance to expend those
and Bound
calories. If Marc has eaten j cupcakes so far, after
eating a cupcake with c calories he must walk at
least 2j *cmiles to maintain his weight.
Problem link :-
https://www.hackerrank.com/challenges/marcs-
cakewalk/problem
2. Candies
Problem Statement: - Alice is a kindergarten teacher. She wants to give some candies to the
children in her class. All the children sit in a line and each of them has a rating score according
to his or her performance in the class. Alice wants to give at least 1 candy to each child. If two
children sit next to each other, then the one with the higher rating must get more candies. Alice
wants to minimize the total number of candies she must buy.
Problem link :-
https://www.hackerrank.com/challenges/candies/problem
3. Truck Tour: -
Problem Statement: Suppose there is a circle. There are N petrol pumps on that circle. Petrol
pumps are numbered 0 to (N-1) (both inclusive). You have two pieces of information
corresponding to each of the petrol pump: (1) the amount of petrol that particular petrol pump
will give, and (2) the distance from that petrol pump to the next petrol pump.
Initially, you have a tank of infinite capacity carrying no petrol. You can start the tour at any of
the petrol pumps. Calculate the first point from where the truck will be able to complete the
circle. Consider that the truck will stop at each of the petrol pumps. The truck will move one
kilometre for each litre of the petrol.
Problem Link:
https://www.hackerrank.com/challenges/truck-tour/problem
5. Luck Balance
Problem Statement: -Lena is preparing for an important coding competition that is preceded by
a number of sequential preliminary contests. Initially, her luck balance is 0. She believes in
"saving luck", and wants to check her theory.
Problem Link:
https://www.hackerrank.com/challenges/luck-balance/problem?isFullScreen=true
Experiment-9 1. Sudoku: -
Problem Statement: Given a partially filled 9 x 9 sudoku board, you need to output a solution
Back-tracking/ to it.
Dynamic Input-The first line contains N which is the number of Sudoku puzzles. N Sudoku puzzles follow.
Programmingg Each one contains 9 lines with each line containing 9 space separated integers. A 0 indicates an
unfilled square, and an integer between 1 and 9 denotes a filled square with that value.
Output-Output to STDOUT the completely filled Sudoku board for each Sudoku. If there are
multiple solutions, you can output any one.
2. Crossword Puzzle: -
Problem Statement: - A 10*10 Crossword grid is provided to you, along with a set
of words (or names of places) which need to be filled into the grid. Cells are marked
either + or -. Cells marked with a - are to be filled with the word list.
Problem link: -
https://www.hackerrank.com/challenges/crossword-puzzle/problem
3. Fibonacci Numbers: -
Problem Statement: - The Fibonacci sequence appears in nature all around us, in the
arrangement of seeds in a sunflower and the spiral of a nautilus for example.
The Fibonacci sequence begins with Fibonacci (0)=0 and Fibonacci(1)=1 and as its first and
second terms. After these first two elements, each subsequent element is equal to the sum of the
previous two elements.
Problem link: -
https://www.hackerrank.com/challenges/ctci-fibonacci-numbers/problem
4. Queens on Board: -
Problem Statement: You have an N * M chessboard on which some squares are blocked
out. In how many ways can you place one or more queens on the board, such that, no two
queens attack each other? Two queens attack each other, if one can reach the other by
moving horizontally, vertically, or diagonally without passing over any blocked square. At
most one queen can be placed on a square. A queen cannot be placed on a blocked square.
Problem Link:
https://www.hackerrank.com/challenges/construct-the-
array/problem
Problem Link:
https://www.hackerrank.com/challenges/sam-and-substrings/problem
3. Equal
Problem Statement: Christy is interning at HackerRank. One day she has to distribute some
chocolates to her colleagues. She is biased towards her friends and plans to give them more than
the others. One of the program managers hears of this and tells her to make sure everyone gets
the same number.
To make things difficult, she must equalize the number of chocolates in a series of operations.
For each operation, she can give 1,2,5 pieces to all but one colleague. Everyone who gets a
piece in a round receives the same number of pieces.
Given a starting distribution, calculate the minimum number of operations needed so that every
colleague has the same number of pieces.
Problem Link:
https://www.hackerrank.com/challenges/equal/problem?isFull%20Scr%20een
=true
4. Kingdom Division
Problem Statement: - King Arthur has a large kingdom that can be represented as a tree, where
nodes correspond to cities and edges correspond to the roads between cities. The kingdom has a
total of n cities numbered from 1 to n.
The King wants to divide his kingdom between his two children, Reggie and Betty, by giving
each of them 0 or more cities; however, they don't get along so he must divide the kingdom in
such a way that they will not invade each other's cities. The first sibling will invade the second
sibling's city if the second sibling has no other cities directly connected to it
Problem Link: -
https://www.hackerrank.com/challenges/kingdom-division/problem
5. Down to Zero: -
Problem Statement:
You are given Q queries. Each query consists of a single number N. You can perform any of the
operations on in each move:
1: If we take 2 integers a and b
where
2: Decrease the value of N by 1.
2.
Determine the minimum number of moves required to reduce the value of N to 0.
Input Format
The first line contains the integer.
The next lines each contain an integer, N.
Problem Link:
https://www.hackerrank.com/challenges/down-to-zero-ii/problem
e. References
Theory
Marks 60 40
i. CO PO Mapping
Course
PO1 PO PO PSO PS
Outco PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9
0 11 12 1 O2
me
CO1 3 - - - - 2 - - - 1 - - 2 -
CO2 3 3 - 2 3 - - - - 2 - - - -
CO3 - 3 - 3 - - - - - - - - 2 -
CO4 - 3 - 2 3 - - - 2 - - 2 - -
CO5 - - 2 - - - - 1 - - 3 3 - -
AVG 3 3 2 2.3 3 2 - 1 2 1.5 3 2.5 2 -
PSO1
PSO2
PO1 PO1 PO1
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 0 1 2
Course Course Name 1 2 3 4 5 6 7 8 9 1 1 12
Code 0 1
Advance 3 3 2 2.3 3 2 - 1 2 1.5 3 2.5 -
22CSP-314 Programming 2
Lab – I
Beyond Syllabus
Languages/Frameworks: Django (Python), Ruby on Rails (Ruby), Node.js (JavaScript), Flask (Python)
Concepts: MVC architecture, RESTful APIs, full-stack development.
Resources:
"The Django Book" by Adrian Holovaty and Jacob Kaplan-Moss
"Eloquent JavaScript" by Marijn Haverbeke
(Mapped with CO4,CO5)