CODING_2024_25_Final
CODING_2024_25_Final
Week
Week 1
Week 2
Week 3
Week 4
Week 5
Week 6
Week 7
Week 8
Week 9
Week 10
Week 11
Week 12
Week 13
Week 14
GITAM School of Technology
Department of Computer Science and Engineering
week-wise plan for the coding classes
Semester - VII
Topics to be covered
Code review
ineering
Practice Exercises
1) Remove an element: Given an integer array arr and an integer key, write a program in C to
return the number of values not equal to key.
2) Remove duplicates from a given array: Given a sorted integer array arr, write a program in C
to return the array after removing the duplicates, with all the other elements in place.
3) Best time to sell a commodity: Given an array of positive integers that represent the price of a
commodity on a given day, return two integers which represent the best day to buy and later, sell
the commodity.
4) Merging the strings: Given two strings str1 and str2 in two files file1 and file2, write a program
to create a third string str3 with one character from each array alternatively. If one string is longer
than the other, append the extra characters to str3. Write str3 into a different text file called file3.
5) String reversal: Given an string with words separated by empty spaces, commas or fullstops,
write a program to return the string after removing the commas and fullstops and reversing the
words in the string.
6) Move all zeros to the end: Given an integer array arr, return the array with all the zeros moved
to the end of the array. The relative ordering of the non-zero lements should not change.
7) Is substring: Given two strings str1 and str2, write a program to return true if str2 is a substring
of str1 and false otherwise.
8) Is subsequence: Given two strings str1 and str2, write a program to return true if str2 is a
subsequence of str1 and false otherwise.
9) Maximum value subarray: Given an array of integers arr, return the maximum sum of a
subarray (with contiguous elements) of that array.
10) Single occurence of a number: Given an array of integers which all numbers but one occuring
twice, find the number that occurs only once.
1) Reverse a linked list: Given a linked list, reverse the linked lst and return the pointer to the
reversed list.
2) Remove fullstops from a string: Given a string with alphanumeric characters and fullstops,
write a program to remove the fullstops from the string.
3) Middle of a linked list: Given a singly linked list, find the element at the middle of the linked
list.
1) Implement the different sorting algorithms.
2) Peak element of an array: Given an array of n integers, find the first and last peak elements of
the array. A number is a peak if it is greater than both its neighbors.
1 Stack, Queues
Priroty Queues
2 / Heap
3 Dequeue
4 Linked Lists
5 Hashing
Searching
6 Techniques
7 DFS, BFS,
Sorting
8 Techniques
9 Memoization
Binary Search
10 Tree
LINK
https://leetcode.com/problems/flatten-binary-tree-to-linked-list/
https://leetcode.com/problems/trapping-rain-water/
https://leetcode.com/problems/kth-largest-element-in-an-array/
https://leetcode.com/problems/merge-k-sorted-lists/
https://leetcode.com/problems/design-circular-deque/
https://leetcode.com/problems/maximum-sum-circular-subarray
https://leetcode.com/problems/stamping-the-sequence/
https://leetcode.com/problems/design-browser-history/
https://leetcode.com/problems/lru-cache/
https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k/
https://leetcode.com/problems/longest-chunked-palindrome-decomposition/
https://leetcode.com/problems/constrained-subsequence-sum
https://leetcode.com/problems/first-unique-number
https://leetcode.com/problems/max-value-of-equation
https://leetcode.com/problems/unique-binary-search-trees/
https://leetcode.com/problems/all-elements-in-two-binary-search-trees/
https://leetcode.com/problems/flatten-binary-tree-to-linked-list/
https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/
https://leetcode.com/problems/binary-tree-level-order-traversal-ii/
https://codeforces.com/problemset/problem/1675/F
https://codeforces.com/problemset/problem/1674/G
https://codeforces.com/problemset/problem/1669/G
https://codeforces.com/problemset/problem/1670/C
https://leetcode.com/problems/sum-root-to-leaf-numbers/
https://leetcode.com/problems/group-anagrams/
https://leetcode.com/problems/kth-largest-element-in-an-array/
https://codeforces.com/problemset/problem/1669/F
https://leetcode.com/problems/find-median-from-data-stream/
https://leetcode.com/problems/climbing-stairs/description/?envType=problem-list-v2&envId=memoiz
https://leetcode.com/problems/longest-increasing-path-in-a-matrix/
https://leetcode.com/problems/shopping-offers/
https://leetcode.com/problems/shopping-offers/
https://leetcode.com/problems/recover-binary-search-tree/
https://codeforces.com/problemset/problem/1695/E
https://codeforces.com/problemset/problem/1674/E
https://codeforces.com/problemset/problem/1674/D
https://leetcode.com/problems/unique-binary-search-trees-ii
GITAM School
Department of Compute
Week Topics to be Covered
Week - wise plan
Week 01 Overview of Programming Languages:
Introduction to C: History and Features
Setting Up the Development Environment
(IDE/Compiler)
Writing and Running Your First C Program
Basic Syntax and Structure of a C Program
Data Types and Variables
Constants and Literals
Basic Input/Output Operations
Week 02 Control Structures:Operators: Arithmetic, Relational,
Logical, Bitwise
Control Statements: if, if-else, nested if
Looping Structures: for, while, do-while
Week 03 Break, Continue, and Goto Statements,
Week 04 Expressions,Conditional
Functions: Expressions, Precedence and
Introduction to Functions
Function Declaration, Definition, and Calling
Scope and Lifetime of Variables
Recursion
Inline Functions
Storage Classes: auto, extern, static, register
Week 05 Arrays and Strings:
Introduction to Arrays
Single-Dimensional Arrays
Multidimensional Arrays
Strings in C
String Handling Functions
Array of Strings
Week 06 Pointers:
Introduction to Pointers
Pointer Arithmetic
Pointers and Arrays
Pointers and Strings
Pointers to Pointers
Dynamic Memory Allocation: malloc, calloc, realloc,
Week 07 free
Structures and Unions:
Introduction to Structures
Defining and Using Structures
Array of Structures
Pointers to Structures
Introduction to Unions
Differences between Structures and Unions
Typedef , Bit-fields
Week 08 File Handling:
File Operations: Opening, Closing, Reading, Writing
Modes of File Opening
File Pointers
Reading and Writing Binary Files
File Positioning: fseek, ftell, rewind
Error Handling in File Operations
Week 09 Preprocessor Directives:
Introduction to Preprocessor Directives
Macro Substitution
File Inclusion
Conditional Compilation
Other Preprocessor Directives: #define, #undef,
Week 10 #ifdef, #ifndef, #endif
Data Structures:
Linked Lists: Single, Double, Circular
Operations on Linked Lists: Insertion, Deletion,
Week 11 Traversal
Stacks and Queues: Implementation using Arrays and
Linked Lists on Stacks and Queues
Operations
Week 12 Error Handling and Debugging:
Error Handling in C
errno, perror(), and strerror()
Debugging Techniques
Using gdb for Debugging
Common Programming Errors and Solutions
Week 13 Modular Programming:
Introduction to Modular Programming
Header Files and Implementation Files
Creating and Using Libraries
Static and Shared Libraries
Using makefiles for Project Build Automation
Week 14 Project Work and Revision:
Project Discussion and Planning
Working on a Mini Project: Choose a Simple
Application to Implement
Project Presentations and Code Review
Revision of Key Concepts
Week 1 to 9:
Suggested List of Experiments (The teacher may discuss one or two in the class, and give5-6 problems as takeaway exercises incl
1 Conversion of numbers from decimal to binary or hexadecimal number systems and vice versa.
2 Design a flowchart for a program that takes two numbers as input from the user and then performs the following opera
Add the two numbers.
Subtract the second number from the first number.
Multiply the two numbers.
Divide the first number by the second number (ensure to handle division by zero).
The flowchart should include decision points to handle division by zero and should clearly illustrate the flow of the prog
3 Design a flowchart for a program that calculates the total cost of a customer's shopping cart items, including tax and an
Prompt the user to input the prices and quantities of each item they wish to purchase.
Calculate the subtotal by multiplying the price of each item by its quantity and summing up all the totals.
Apply any applicable discounts based on the total purchase amount. For example, if the total purchase amount is abov
Calculate the tax on the subtotal based on a predetermined tax rate.
Add the tax to the subtotal to obtain the total cost.
Display the subtotal, any discounts applied, the tax amount, and the final total cost to the user.
You can break down the program into separate modules or functions, each responsible for a specific calculation (e.g.,
4 Identify and correct the syntactical errors in a given program (example given below) to make it compile and run correct
#include <stdio.h>
int main() {
return 0;
5 Identify and correct the semantic errors in a given program (example given below) to make it compile and run correctly
#include <stdio.h>
int main() {
float average;
average = sum / 2;
return 0;
6 Write a C program that takes an integer as input from the user and prints whether the number is positive, negative, or z
7 Write a C program to implement a simple guessing game. The program should generate a random number between 1
8 Write a C program to print the first 10 natural numbers (1 to 10) in reverse order, one number per line.
9 The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually star
Write a C program to generate the first 20 terms of the Fibonacci sequence and print them.
10 Write a C program that calculates the factorial of a given number using a separate function for the factorial calculation.
11 Write a C program to calculate the average of a set of numbers. The program should prompt the user to enter the num
12 Write a C program that simulates a simple banking system. The program should include the following functionalities:
Deposit: Allow the user to deposit a certain amount into their account.
Withdraw: Allow the user to withdraw a certain amount from their account.
Check balance: Display the current balance in the account.
Use static variables to keep track of the total balance across all transactions. Ensure that the total balance is shared am
13 Write a C program that simulates a simple online shopping system. The program should include the following functiona
Add item to cart: Allow the user to add items to their shopping cart.
Remove item from cart: Allow the user to remove items from their shopping cart.
View cart: Display the items currently in the user's shopping cart.
Ensure that each user has their own shopping cart, and use local variables to represent the items in the cart.
14 Write a C program that simulates a simple text editor. The program should allow the user to perform the following oper
Append: Append a string to the end of the current text.
Insert: Insert a string at a specific position in the current text.
Delete: Delete a substring from the current text.
Replace: Replace a substring in the current text with another string.
Print: Print the current text.
15 Write a C program that calculates the value of a mathematical expression involving trigonometric functions and logarith
sin(x)+cos(y)/log(z)
16 Write a C program that calculates the factorial of a non-negative integer using recursion. The factorial of a non-negativ
n! = n*(n-1)*(n-2)*..*3*2*1
Write a C program that implements a recursive function to generate all possible combinations of a given set of charact
For example, given the input string "ABC", the program should generate the following combinations:
ABC
ACB
BAC
BCA
CAB
CBA
17 Write a C program that defines macros for mathematical operations (e.g., addition, subtraction, multiplication, division)
18 Write a C program that defines a function to swap the values of two integers using pointers. The program should prom
19 Write a C program that takes two nxn matrix as input from the user, calculates the product of the matrices and prints it.
20 Write a C program that takes an array of integers as input, calculates the sum and average of the elements using poin
21 Write a C program that defines a function to count the number of vowels in a string using character pointers. The progr
22 Write a C program that defines a structure called Student to store the details of a student including name, roll number,
23 Write a C program that defines a structure called Book to store the details of books including title, author, and price. Th
24 Write a C program that defines a structure called Employee to store the details of an employee including name, ID, and
25 Write a C program that defines a typedef for a structure called Point to represent a point in 2D space. The structure sh
26 Write a C program that defines a union called Data to represent a data structure that can store either an integer or a flo
27 Given a C program, comprehend the code by doing the following.
Understand and explain what the code does.
Perform code analysis in the following manner.
Identify the purpose of the code.
Describe the input required from the user.
Explain how the code produces output.
Discuss the role of variables n, i, and j.
Describe the control flow of the nested loops.
Explain the output produced by the code for different inputs.
Sample Program 1:
#include <stdio.h>
int main() {
int n, i, j;
scanf("%d", &n);
printf("\n");
return 0;
#include <stdio.h>
int main() {
scanf("%d", &n);
scanf("%d", &arr[i]);
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
printf("\n");
return 0;
}
#include <stdio.h>
int main() {
int n, i, j;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]);
arr[j] = arr[j+1];
arr[j+1] = temp;
printf("\n");
return 0;
}
GITAM School of Technology
Department of Computer Science and Enginnering
Week - wise plan for Coding Classes
Write a C program to implemnet the various operations on a single linked list, double
linked list and circular linked list.
Write a C program to implement the stack and queue operations using arrays and linked
lists.
two in the class, and give5-6 problems as takeaway exercises including some in the Practice Exercises column above. In the next class, start by
or hexadecimal number systems and vice versa.
numbers as input from the user and then performs the following operations:
handle division by zero and should clearly illustrate the flow of the program from input to output.
s the total cost of a customer's shopping cart items, including tax and any applicable discounts. The program should have the following features:
es of each item they wish to purchase.
f each item by its quantity and summing up all the totals.
tal purchase amount. For example, if the total purchase amount is above a certain threshold, apply a percentage discount.
edetermined tax rate.
modules or functions, each responsible for a specific calculation (e.g., subtotal calculation, discount calculation, tax calculation), and then integrate them in
ven program (example given below) to make it compile and run correctly.
of a given number using a separate function for the factorial calculation. The program should prompt the user to enter a non-negative integer, calculate its fa
set of numbers. The program should prompt the user to enter the number of elements in the set, then prompt the user to enter each element. Finally, the p
ing system. The program should include the following functionalities:
ount into their account.
amount from their account.
lance across all transactions. Ensure that the total balance is shared among all instances of the banking system.
editor. The program should allow the user to perform the following operations on a text string:
a mathematical expression involving trigonometric functions and logarithms. The program should prompt the user to input the values of variables and evalua
of a non-negative integer using recursion. The factorial of a non-negative integer n, denoted as n!, is the product of all positive integers less than or equal to
function to generate all possible combinations of a given set of characters. The program should take a string of characters as input and print all possible co
hematical operations (e.g., addition, subtraction, multiplication, division) and uses them to perform calculations. The program should use macros to define th
ap the values of two integers using pointers. The program should prompt the user to input two integers, call the swap function to swap their values, and the
input from the user, calculates the product of the matrices and prints it.
rs as input, calculates the sum and average of the elements using pointers, and then prints the sum and average.
unt the number of vowels in a string using character pointers. The program should prompt the user to input a string, call the function to count the vowels, an
d Student to store the details of a student including name, roll number, and marks in three subjects (Physics, Chemistry, and Mathematics). The program s
d Book to store the details of books including title, author, and price. The program should then create an array of Book structures to store the details of thre
d Employee to store the details of an employee including name, ID, and salary. The program should then create a pointer to an Employee structure and all
tructure called Point to represent a point in 2D space. The structure should have two members: x and y, representing the coordinates of the point. Then, th
ata to represent a data structure that can store either an integer or a floating-point number. Additionally, define a structure called BitField to represent a da
oing the following.
ple program 2.
ogy
d Enginnering
Classes Practice Exercises (from various platforms)
LeetCode: Given an array of integers nums and an integer target, return indices of the
two numbers such that they add up to target.
HackerRank: Diagonal Difference: Calculate the absolute difference between the sums
of the diagonals in a square matrix.
CodeChef: Life, the Universe, and Everything: Write a program that reads numbers
from input and stops processing input after reading the number 42.
Codeforces: Watermelon: Determine if a watermelon can be split into two parts, each
of which weighs an even number of kilos.
LeetCode: Given a string with characters '(', ')', '{', '}', '[', and ']', determine if it is valid.
LeetCode: Fizz Buzz: Write a program that outputs numbers from 1 to n. For multiples
of three, output
LeetCode: "Fizz";
Factorial for multiples
Trailing of five,
Zeroes: Given anoutput
integer"Buzz"; and
n, return fornumber
the multiples of both
of trailing
zeroes in n!.
HackerRank: Day of the Programmer: Given a year, find the day of the 256th day of
that year.
CodeChef: Reverse The Number: Write a function to reverse the digits of a number.
Codeforces: Beautiful Matrix: Find the minimum number of moves to bring the
number
LeetCode:1 to theSum:
Two center of aan
Given 5x5 matrix.
array of integers nums and an integer target, return the
indices of the two numbers such that they add up to target.
Codeforces: Beautiful Matrix: Find the minimum number of moves to bring the
number 1 to the center of a 5x5 matrix.
LeetCode: Swap Nodes in Pairs: Given a linked list, swap every two adjacent nodes and
return its head.
CodeChef: Farmer Feb: Given an array, find the sum of all elements at even positions.
HackerRank: Structs: Write a program to model and process data using structures.
CodeChef: Student Details: Create a structure to store student details and write
functions to manipulate the data.
Codeforces: Little Elephant and Bits: Manipulate bits within a number to achieve a
Codeforces: Little Elephant and Bits: Manipulate bits within a number to achieve a
desired result.
LeetCode: Read N Characters Given Read4: Given a file and an integer n, read n
characters using a given read4 function.
HackerRank: File Processing: Implement a function to read from a file and process its
content.
CodeChef: File Reading and Writing: Read input from a file, process it, and write the
output to another file.
Codeforces:
LeetCode: Add FileTwo
Operations:
Numbers:Implement basic file of
Solve the problem operations in anumbers
adding two competitive
represented as
linked lists.
CodeChef: Macro Substitution: Use macros to optimize code for specific problems.
LeetCode: Remove Nth Node From End of List: Given a linked list, remove the nth node
from the end of the list and return its head.
HackerRank: Debugging Challenge: Solve a problem that contains intentional bugs. Use
debugging techniques to identify and fix the bugs.
CodeChef: Error Handling: Write a program that handles errors such as divide by zero or
accessing out-of-bound indices.
LeetCode: Merge Two Sorted Lists: Merge two sorted linked lists and return it as a new
sorted list.
Exercises column above. In the next class, start by discussing any doubts in the previous set.:)
program should have the following features:
percentage discount.
calculation, tax calculation), and then integrate them into the main program flowchart.
er is positive, check if it's even or odd and print that information as well.
pt the user to guess the number. After each guess, the program should provide feedback to the user, indicating whether the guess is too high, too low, or c
the user to enter a non-negative integer, calculate its factorial using the factorial function, and then print the result.
en prompt the user to enter each element. Finally, the program should calculate and print the average of the entered numbers using separate functions for i
mpt the user to input the values of variables and evaluate the expression. Ensure to handle error cases such as division by zero or undefined values.
the product of all positive integers less than or equal to n. The factorial of n is defined as:
a string of characters as input and print all possible combinations of those characters.
lculations. The program should use macros to define the operations and then demonstrate their usage in various mathematical expressions.
rs, call the swap function to swap their values, and then print the swapped values.
input a string, call the function to count the vowels, and then print the count.
Physics, Chemistry, and Mathematics). The program should prompt the user to input the details of three students, store them in an array of Student structu
e an array of Book structures to store the details of three books. After storing the details, the program should print the details of all books.
then create a pointer to an Employee structure and allocate memory for it dynamically using malloc(). After allocating memory, prompt the user to input the
d y, representing the coordinates of the point. Then, the program should create a variable of type Point and initialize it with some values. Finally, it should p
ally, define a structure called BitField to represent a data structure that stores a set of bit-fields including a flag, an integer value, and a floating-point value.
e guess is too high, too low, or correct. The user should continue guessing until they correctly identify the random number. Additionally, limit the number of
ers using separate functions for input, calculation, and output. Additionally, use an external variable to keep track of the sum of the numbers.
zero or undefined values.
tical expressions.
em in an array of Student structures, and then print the details of all students.
ls of all books.
mory, prompt the user to input the details of an employee using the pointer, and then print the details of the employee.
some values. Finally, it should print the coordinates of the point.
value, and a floating-point value. Then, the program should create variables of type Data and BitField, initialize them with some values, and print their conte
m number. Additionally, limit the number of guesses to 10, and if the user exceeds this limit without guessing the correct number, display a message indica