1, What is a Data Structure?
The Data Structure is the way data is organized (stored) and manipulated for
retrieval and access. it also defines the way different sets of data relate to one
another, establishing relationships and forming algorithms,
2. Describe the types of Data Structures?
The following are the types of data structures:
1. Uss: A colecson of elated things inked to the previous rfand following data items.
2. Aarays: Acolecton ol values that are al the same,
3. Records: A collecson of elds, each of wich contains data om a single data ype
‘
Trees: A data structure that organizes data in a herarchical tamewerk. This frm of data
Sructre follows the erderes order of data tem nsarbon leon and moditcaton
S. Tables: The datais saved in tho form of rows and columns. These are comparable te i
that he outcome or aeration of datas marored across the whole lake
3. What is a Linear Data Structure? Name a few examples.
A data structure is near i all its elements or data items are arranged in a sequence
or a linear order. The elements are stored in a non-hierarchical way so that each
tem has successors and predecessors except the first and last element inthe ist.
Examples of linear data structures are Arrays, Stack, Strings, Queue, and Linked
List.
4. What are some applications of Data Structures?
In terms of data structure interview questions, this is one of the most frequently
asked question,
Numerical analysis, operating system, Al, compiler design, database management,
graphics, statistical analysis, and simulation.
Array Data Structure
An array is a collection of items stored at contiguous memory locations. The idea
{sto store multiple items ofthe same type together.
‘This makes it easier to calculate the position ofeach element by simply adding an
‘offset to a base va, i.e, the memory location ofthe frst element of the array
(generally denoted by the name of the aay).
‘The above image can be looked asa top-level view ofa saicase where you are at
‘the base ofthe staircase. Each element can be uniquely identified by their index
the array (in a similar way as you could identify your friends by the step on which
‘they were on in the above example).
‘Wie a program to cycialy rotate an array by one
+ Find he missing integer
+ Count Pais with given sum
‘+ Find duplicates in an aay
1 Sort an Asay using the Quicksor algorithm
‘+ Find common elements in tree sonted aay
“+ Fin theft repeating element in an array of integers
“+ Fin te test non repeating element ina given aray of integers
‘+ Subarrays with equa! 18 and os
‘+ Reavrange the array in aerating postive and negative items
“+ Fin it tere i any subarray with a sum equal to zero
“Find the Largest sum contiguous Subarray
‘+ Find the factorial o large ruber
“Fin Maximum Product Subarray
+ Find the longest consecutive subsequence
‘+ Fin the minimum eloment in aroxatd and sorted aay
Max sum in the configuration
Minimum Platforms
Minimize the maximum difference between the heights
Minimum number of jumps to reach the end
Stock Span problem
Find a triplet that sums to a given value
‘Smallest positive missing number
Find the row with a maximum number of 1's
Print the matrix in a Spiral manner
Find whether an array is a subset of another array
Implement two Stacks in an array
Majority Element
Wave Array
Trapping Rainwater
Maximum index
Max sum path in two arrays
Find Missing And Repeating
Stock buy and sell Problem
Pair with the given sum in a sorted array
Chocolate Dist
Partition Equal Subset Sum
‘Smallest Positive integer that can't be represented as a sum
Coin Change Problem
Longest Alternating subsequence
‘Sings ar define a an ary of characters. The diference baween cht aay anda sg is
‘he ating tomitd wih pel charter "0"
How String is represented in Memory?
nC. a sing can be refered ite sing» rater pier oa curacy When gs
se declred os character arate are stored ie oer peso rays in Fr expe sts
Stauto variable ten the sing i red in the ck seer st ltl or sate arabe hen
Stored in he dia segment
+ Reverse words ina given sting
‘+ Longest Common Prefix
‘+ Roman Number to eteger
+ tneger to Roman
+ Closest srings
+ Divisible by 7
1 Encrypt the String
+ Equal pointin a sing of rackets
+ Isomorphie Stings
1+ Check fo stings are k-anagrams or ot
‘+ Panagram Checking
+ Minimum Deitons
+ Number of Distinct Subsequences
1+ Check sing i rotated by two places
1 implement Ati
+ Validate an addeess
+ Ucense Key Formating
‘+ Find largest word in ictionary
+ Equal, and2
1+ Find and replace in Sting
+ Add Binary Stings
+ Sum of wo large numbers
¢ dhiieediiins
Look and say Pattern
Minimum times A has to be repeated to make B a Substring
Excel Sheet -1
Form a Palindrome
Find the N-th character
Next higher palindromic number using the same set of digits
Length of longest prefix suffix
Longest K unique characters substring
‘Smallest window in string containing all characters
Congest Palindromic Subsequence
Longest substring without repeating characters
Substrings of length k with k-1 distinct elements
Count number of substrings
Interleaved Strings
Print Anagrams together
Rank the permutation
A Special KeyboardLinked List Data Structure
‘Ad nr nse a wich he rt ed cigs my com
‘Thedemerns n nked I wed wing posters ow te blow ge
{nslape wads tise comin of de were ech de coms ela ele) 0
‘eee model
+ Pain.the Neile ofa gven ine ist
+ Patering anes ist
*+ Delete the elements nan tnked ist whose sum s equal to zero
+ Delete mide of takes ist
+ Remove duplicate elements trom sorted inked lst
1+ Aid 1 toa number represented asa inked Ist
1+ Reverse alirked list in groups of given size
+ Detect oop in irked ist
+ Remove oop in inked Hist
+ Find mh node tom tho end of nko ist
+ Functon to check a singly linked ist a painrome
1+ Reverse alternate kode ina singhy irked ist
*+ Delete last occurence ofan Kem from inked st
+ Rotate alinked Hist
+ Delete anodes ater m nodes o inked st.
‘+ Merge a linked ist ito another inked Uist a atemate postions.
+ Wie a functon delete a linked st
‘+ witea tuncton 1 reverse the nodes of a inked ist.
+ Why qucksort is prefered for arrays and merge sor for inked Hits.
Stack Data Structure
‘Stack is. linear data structure which follows a particular order in which the operations are
performed. The order may be LIFO(Last In First Out) or FILOFirst In Last Ou).
‘There are many real-life examples ofa stack. Consider an example of plates stacked over one
another in the canteen, The plate which is at the opis the first one tobe removed, i. the plate
\which hasbeen placed atthe bottommost position remains inthe stack forthe longest period
‘of time, So, it can be simply seen to follow LIFO(Last In Fist Out)/FILO(Fist In Last Out)
order
+ tots wo Posts Conversion wing Stack
+ Prefix to tax Conversion
* Prefix to Pots Conversion
1+ Posts to Prefix Conversion
+ Postfix otic
+ Conver Iti To Prefs Notation
1+ The Stock Span Problem
Check for balance press
1+ Next Greer Eee
expression
1 New Greater Freeny Bement
1 Number of NGES othe ight
1+ Maximum prodct of indexes of next griserom ft and ight
1 The Caley Problem
spree Evaluation
+ Arithmetic Expression Evalton
1+ Evahuton of Postix Expression
1+ trative Tower of Hani
+ Prin nex greater numberof @ queriesWhat is Queue?
A ure define a ner dat srt ope at eth ods adhe patos re permed
nit In Oe (170) order.
Wedfine queue ob tin which lations the st are made toe ed, anal deletions
fromhe i se made tbe ter nd. The lent which st psd imo ner, th operon
str prone ot
FIFO Principle of Queue:
+ AQ she te wating pcs chs we tees pes lin tet person
foved(ePet come fr sr
«Peston of te my ta gure ely oe seve the frst ety tha wl be emaned om te
ewe, caled tro of equi eed quer nay Pt ofthe
iScerey nthe ure tt tone mst recede the rear he allo gu.
See Bow tigre
Characteristics of Queue:
+ Que cantande mb dn
Reem acess th ele
Theyre ind eae
Check fa quee canbe sored ito acter queue sing atch
1 Bread Fire Taversl or BS fora Graph
1 Level Onder Tre Tasers
Reverse pth in BST using queve
+ Construct Complete Binary Tee fom ts Linked List Representation
1+ Program for Page Replaceent Algor | Set 2 (FIFO)
1+ Check wher a given Binary Tie Compete or ot | Set (heave Solon)
1+ Number of siblings ofa given Node in ary Tree
+ 2igZag Tree Traversal
1 FIFO (Pest-inFet-Out approach in Progaming
{FIFO w LO approach in Programing
ss thelial daicesiiaaiia ta tela sc aan ia
Hashing
ashing i atechnique or process of mapping kes, and values into the hash table by
‘using hash hction. fis dane fr faster access to elements. The ficiency of mapping
‘depends on the efficiency ofthe hash function used.
Leta hash function H(x) maps the value at the index x%10 in an Amay. For example
if he list of values is 11,12,13 14,15] wll be stored at postions (1.23.45) inthe
array oF Hashtable respectively.
1 Fad inary oma gen ies
+d aber of Employes Under eey Employee
+ Cau diab ps ina ary
‘Check fan aay canbe vied ops wos sum ssl yk
Lage sary wth su dvs
4 Sutay with np sam ible by K
en ay lees tt vie by ate oe her
4+ Fle ce een fom itient hears sch tha hat +=
+ ind for cemens bc and ina aay ach aD = rd
iad te gest subay wh sa
4 rong ngs cen consecutive sbseoence
+ Longest areaing conectesbgtene
+ Lage sataeqcice sch a dierece bres aces te St?
+ Longest CoaseuiveSabseqece
+ Lagat inceasingsusequene of osc eps
+ Coa ats ning since mbes
+ Coun dat denen in every wad of tek
‘+ Masamum pole smo wino nan aay sch ht eemesfsae win iter ry
aevnigne
+ Deurung hem whe pen aa ak ve ano ken a ame pe
‘+ Doign dan sare ta spots ert deletes ad ean incest ine
+ Check fara oma corps tg hp tre
4+ Lenght he ges sbaray wth como ees
4 adie sasha Osa
ox staray wth su
(6 ed saberay with ven sum | Set2 (Handles Neguive Members)