Report College
Report College
SUBMITTED TO:
1
CERTIFICATE
This is to certify that Mr. / Ms. Latika Narayan has completed the Minor Industrial Training
during the period from 15/4/2024 to 21 /8/2024 in our Organization / Industry as a Partial
Fulfillment of Degree of Bachelor of Technology in Computer Science & Engineering. He / She was trained
2
DECLARATION
I hereby declare that the Industrial Training Report on Data Structure with C++,
Industry is an authentic record of my own work as requirements of Minor
Industrial Training during the period from 15 /4/ 2024 to 21 /8/ 2024 for the award
of degree of B.Tech. (Computer Science & Engineering), UIT, Uttaranchal
University, Dehradun (U.K.), under the guidance of Assistant Professor Stuti Bhatt.
Date:
Certified that the above statement made by the student is correct to the best
of our knowledge and belief.
Examined by:
(Signature)
(Signature) Head of
Department
3
ACKNOWLEDGEMENT
esteemed Mentor Mr. Sanket Singh who has contributed so much for
valuable guidance.
Next I would like to tender my sincere thanks to Professor Dr. Madhu Kirola
4
TABLE OF CONTENTS
Content .............................................................................................. 1-9
CERTIFICATE………………………………………………………………………2
DECLARATION…………………………………………………………………….3
ACKNOWLEDGEMENT…………………………………………………………...4
CHAPTER
Chapter 1 – Introduction…………………………………………………………………….10
1. PW Skills
o Popular website for developers
o Repository of articles
o Free and paid courses
o Founded by Mr. Alakh Pandey
2. Data Structure –
o Definition and explanation
o Primitive data types
o Arrays (linear data structure)
o Other structures: linked lists, stacks, trees
3. Algorithms
o Definition and importance
o Step-by-step process
o Role in time and space optimization
o Real-world applications
2. Introduction
o 2.1 Time Complexity
Theta (Θ) Notation
Big O (O) Notation
Omega (Ω) Notation
o 2.2 Space Complexity
3. Mathematics
o 3.1 Arithmetic and Geometric Progression
5
o 3.2 Mean and Median
o 3.3 LCM and HCF
o 3.4 Modular Arithmetic
4. Bit Magic
o 4.1 Bitwise Operations
AND, OR, XOR, Shift Operations
o 4.2 Bit Manipulation Problems
Counting Set Bits
Finding Unique Elements
Swapping Bits
5. Recursion
o 5.1 Recursion Basics
o 5.2 Tail Recursion
o 5.3 Examples
Subset Generation
Josephus Problem
String Permutation
6. String
o 6.1 String Functions
Substring, Concatenation, Length, Comparison
o 6.2 Pattern Searching Algorithms
Naive Pattern Searching
Rabin-Karp Algorithm
KMP Algorithm
7. Data Structure
o 7.1 Array
Operations: Insertion, Deletion, Rotation, Reversing
STL Implementations: Vectors and Lists (C++), ArrayList (Java)
8. Searching
o 8.1 Linear Search
o 8.2 Binary Search
o 8.3 Ternary Search
9. Sorting
6
o 9.1 Introduction to Sorting
o 9.2 Types of Sorting Techniques
Insertion Sort
Quick Sort
Merge Sort
Heap Sort
Counting Sort
10. Matrix
11. Hashing
13. Stack
14. Queue
7
15. Deque
16. Tree
18. Heap
19. Graphs
. References
9
CHAPTER – 1
INTRODUCTION
1. PW SKILLS
PW SKILLS is a popular website among the developer community, known for its vast repository of well-crafted
articles that cover various complex topics in computer science. Founded by Mr. Alakh Pandey . The platform
offers valuable resources that are otherwise difficult to find within the computer science community. In addition
to their insightful articles on algorithms and techniques for coding interviews, they provide both free and paid
courses. One of their most popular offerings is the Data Structures and Algorithms (DSA) course, which has
2. Data Structure
A Data Structure is an efficient method for organizing and storing data. When handling large amounts of
information, primitive types like int, float, char, and double are insufficient. Instead, more structured forms
like arrays come into play. Arrays, for example, store data in a linear fashion, making them a type of linear data
structure. During my summer internship at PW Skills in the "Decode C++ with DSA" course, under the guidance
of Mr. Sanket Singh, I gained hands-on experience with various data structures, including arrays. Although arrays
are quite useful, they are just one of many types of data structures we explored, such as linked lists, stacks, and
3. Algorithms
Real-world applications require precision, efficiency, and optimization in terms of time and memory. This is
where algorithms come into play. In essence, an algorithm is a step-by-step process or a set of instructions to
perform a task. As I deepened my understanding through the internship and the DSA course, I realized how
essential it is to create algorithms that balance time complexity and space complexity for real-world applications.
A poorly designed algorithm can have devastating consequences not only on the application but also on a wider
scale.
10
CHAPTER – 2
INTRODUCTION TO DATASTRUCTURES
1. Introduction
1.1 Time Complexity
Time complexity measures the time required to run an algorithm as a function of the size of the input. Common notations
include:
2. Mathematics
2.1 Arithmetic and Geometric Progression
Used to identify sequences in mathematical calculations, where numbers follow a pattern of addition (AP) or multiplication
(GP).
2.2 Mean and Median
Statistical measures used to find the average (mean) or the middle value (median) in a data set.
2.3 LCM and HCF
Least Common Multiple (LCM) and Highest Common Factor (HCF) are essential in number theory for finding multiples
and factors of numbers.
2.4 Modular Arithmetic
A system of arithmetic for integers, where numbers wrap around after reaching a certain value, called the modulus.
3. Bit Magic
3.1 Bitwise Operations
Operations on binary digits (bits), including AND, OR, XOR, and Shift operations. These operations are fundamental in
tasks like setting, toggling, or clearing specific bits in data.
3.2 Bit Manipulation Problems
Basic problems such as counting set bits, finding unique elements, and swapping bits can be solved efficiently with bit
manipulation techniques.
4. Recursion
4.1 Recursion Basics
11
Recursion occurs when a function calls itself with a modified argument. Each recursive function requires a base case to
stop the recursive calls.
Naïve Pattern Searching: A straightforward method to search patterns by sliding the pattern over the text.
Rabin-Karp Algorithm: Uses hashing to find patterns efficiently.
KMP Algorithm: Preprocesses the pattern to reduce the time spent in matching by avoiding redundant comparisons.
6. Data Structure
6.1 Array
An array is a linear data structure where elements are stored in contiguous memory locations.
8. Sorting
8.1 Introduction to Sorting
Sorting involves arranging data in a specific order, such as ascending or descending.
8.2 Types of Sorting Techniques
12
Insertion Sort: Inserts elements in their proper place within a sorted sub-array.
Quick Sort: Uses divide and conquer to sort elements by partitioning the array.
Merge Sort: Recursively divides the array and merges sorted sub-arrays.
Heap Sort: Converts the array into a heap to sort elements.
Counting Sort: An integer sorting algorithm based on element frequency.
9. Matrix
9.1 Matrix Operations
A matrix is a 2D array of numbers, where operations like addition, subtraction, and multiplication are performed on rows
and columns.
9.2 Matrix Rotation
Rotating the matrix by 90°, 180°, or 270° as part of matrix manipulation.
10. Hashing
10.1 Hashing Basics
Hashing provides an efficient way to store and retrieve data using hash functions that map data to a hash table.
10.2 Open Addressing
A collision-handling method in hash tables where empty slots are searched sequentially for storing collided data.
12. Stack
12.1 Stack Basics
A linear data structure following Last In, First Out (LIFO).
12.2 Applications
Used in expression evaluation, conversion (Infix to Postfix), and managing function calls in recursion.
13. Queue
13.1 Queue Basics
A linear data structure following First In, First Out (FIFO).
13.2 Applications
Used in scheduling tasks, handling resources, and implementing circular queues.
13
14. Deque
14.1 Deque Basics
A double-ended queue allowing insertions and deletions at both ends.
14.2 Applications
Supports both queue and stack operations and can be used in designing data structures with min and max operations.
15. Tree
15.1 Binary Tree
A tree where each node has at most two children.
15.2 Binary Tree Operations
Traversals (in-order, pre-order, post-order), insertion, deletion, and finding the lowest common ancestor (LCA).
17. Heap
17.1 Heap Basics
A complete binary tree used for priority queues. It supports operations like finding the minimum/maximum element
efficiently.
17.2 Heap Operations
Insertion, deletion, and heapification to maintain heap properties.
18. Graphs
18.1 Graph Basics
A collection of nodes (vertices) connected by edges.
18.2 Graph Algorithms
14
CHAPTER – 3
ADVANCE ALGORITHMS
3.1 Greedy Algorithms
Greedy is an algorithmic paradigm that builds solutions step-by-step, always picking the immediate, most beneficial option.
It works well for problems where choosing the locally optimal solution also leads to the globally optimal solution.
Job Sequencing Problem: A classic problem solved using the Greedy algorithm by optimizing tasks based on their deadlines
and profits.
3.2 Backtracking
Backtracking is a recursive algorithmic technique for solving problems by incrementally building a solution and discarding
those that don’t meet the constraints. It allows us to explore all possibilities and "backtrack" when necessary.
3.2.2.2 N-Queen Problem: Placing queens on a chessboard such that no two queens attack each other.
3.2.2.3 Sudoku Problem: Solving a Sudoku puzzle by filling numbers in a grid while maintaining valid conditions.
Dynamic Programming is an efficient method used to solve complex problems by breaking them down into simpler sub-
problems and storing the results of these sub-problems to avoid redundant computations.
15
3.3.2.1 Properties of Dynamic Programming Problems:
Optimal Substructure: An optimal solution to the problem contains an optimal solution to its sub-problems.
16
CHAPTER – 4
PROJECTS
4.1 Hidden Number Hunt
Objective:
The goal of the Hidden Number Hunt game is to find a hidden number within a range using a
series of guesses. The program provides feedback to the player, whether the guessed number is
too high or too low, to narrow down the search.
Steps Involved:
The program randomly selects a number from a predefined range (e.g., 1 to 100).
The player is prompted to guess the number.
After each guess, the program tells whether the guess is too high or too low.
The game continues until the player correctly guesses the hidden number.
What we learnt:
Code Syntax:
#include <iostream>
#include <cstdlib> // for rand() and srand()
#include <ctime> // for time()
int main() {
srand(time(0)); // seed the random number generator
int hiddenNumber = rand() % 100 + 1; // generates a number between 1 and 100
int guess;
int attempts = 0;
17
cout << "Welcome to Hidden Number Hunt! Guess the number between 1 and 100.\n";
do {
cout << "Enter your guess: ";
cin >> guess;
attempts++;
return 0;
}
Output:
Objective:
Wizards Word Challenge is a word-guessing game where the player has to guess a secret word by guessing individual
letters. The game gives feedback on correct and incorrect guesses, revealing letters in the word as they are guessed.
Steps Involved:
What we learnt:
Managing strings and character arrays
Using loops and conditionals for game logic
Keeping track of correct and incorrect guesses
Revealing parts of the word dynamically
Code Syntax:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
vector<string> words = {"wizard", "magic", "dragon", "potion", "spell"};
srand(time(0));
string secretWord = words[rand() % words.size()]; // pick a random word from the list
string guessedWord(secretWord.length(), '_'); // initially, all letters are hidden
int attempts = 7;
char guess;
bool correctGuess;
cout << "Welcome to Wizards Word Challenge! Guess the magical word.\n";
if (!correctGuess) {
attempts--;
cout << "Wrong guess! Try again.\n";
}
if (guessedWord == secretWord) {
cout << "Congratulations! You've guessed the word: " << secretWord << endl;
19
} else if (attempts == 0) {
cout << "You've run out of attempts! The word was: " << secretWord << endl;
}
}
return 0;
}
Output:
20
Chapter - 5
Conclusion
Algorithm is vast topic and it is all about making a program more efficient. These Algorithms arethe ones that
make our experience smother with the software. Take google search engine for example how fast it provides the
best search result in few seconds of times. That is the power of algorithms. That is why many companies ask
Through this Course I have Learnt a vast number of interesting topics like Trees, Graphs, LinkedList and many
other more. Their implementation in practical problems and understanding their base concepts.
While working in IT sector we need to solve the problems and make programs write tons of codewhich will help
us with the given problem and to write a program one need to make different algorithms. Many algorithms
combine to make a program. Now, algorithm are writen in some lenguages but they are not dependen ton them,
one need to make a plan and algo first then write it into any language wether i tis C++ or JAVA or C or any other
programing language. Algorithmis based on data structure and its implementation and working. So, basiclly one
21
References
1. https://en.cppreference.com/w/
2. https://www.geeksforgeeks.org/rand-and-srand-in-ccpp/
3. https://www.geeksforgeeks.org/building-simple-guessing-game-c/
4. https://www.cplusplus.com/reference/string/string/
5. https://www.programiz.com/cpp-programming/if-else
6. https://www.udacity.com/course/c-plus-plus-game-programming--ud162
22
23