This video teaches an algorithm optimization technique called 'binning' to efficiently find pairs of students from the same city whose marks differ by at most 50. Instead of comparing all students (O(n²) complexity), the algorithm first groups students by city into bins using a single pass, then only compares students within each bin. For example, with 5 students, the naive approach requires 10 comparisons, while binning reduces this to just 3-4 comparisons by grouping students by city first. The video also covers fundamental programming concepts including data types (int, string, character, boolean), while loops for iteration, if conditions for decision-making, and nested iteration patterns.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
CT Live
Added:Okay.
So now we have uh we have gotten to procedure to basically check top three marks and based on that we have filtered whether uh a candidate is eligible or not. Okay.
Then we had some more criteria and based on that we will we can uh just uh filter out uh the students and distribute the price. Okay.
Is this clear?
Yes sir.
>> Okay.
>> Now these uh there are some side effects what parameters you need to pass those kind of things you have to understand.
So this slide is just uh showing that.
>> No.
>> Yeah.
>> Are we revising all four weeks now?
>> Yeah. Okay sir. And now we are in week two or week three.
So mostly these are question uh related things. So whatever you have been taught till now till week four all those things are getting covered in this only. Yes.
Uh I think on Monday on Monday we had a session where we used uh the slides uh from the lectures itself and uh uh basically discussed that. In today's session we are doing the same thing but uh we are using uh some questions and based on that whatever topics were discussed in the lectures we are just highlighting those okay >> speech uh but the paradox and bin I couldn't understand very well.
>> Yeah the third problem is related to bin itself. Yeah this one is related to binning itself. Okay.
>> Okay sir.
So let's see the third problem first.
What was it?
So uh we have to find same city pairs whose total marks differ by at most 50 using safe build. Okay. So there are multiple ways to achieve this but uh in the nave way you can get the results but uh the number of comparisons this comparison ba is based on the five rows that uh we see like uh initially I show yeah this one. So based on this data set that particular calculation is done but if you use the full uh data set that we have so the numbers will change. Okay.
Okay. So since we have currently five rows. Okay. If we try to find all the pairs satisfying this particular condition, how many comparisons will we need to do?
It will be 5 into 5 - 4 uh sorry 5 - 1 by 2.
Right?
So there will be there will be 10 comparisons. Right?
Yes sir.
>> Now uh what we can do is instead of doing these many comparisons a better approach would be we do two passes.
Okay. In the first pass what we do? We uh create bins. So currently all the data set is over here. What we can do? We can create maybe three smaller data set. This data set contains uh cards from Chennai. Okay. So we have Chennai related cards over here.
Then this one can have Bangalore.
This one can have any other CD. Okay.
Now to make these three separations, how many passes are required?
How many iterations are required across the data set?
Anyone?
So we have a full data set and uh it has uh all the cities. Now we have to create CTBS basically filter out uh the cards based on city and uh create smaller data sets which are basically filter based on city. So this one is maybe for Chennai, this one is for Bangalore, this one is for Mumbai.
So in how many passes can we create these smaller data sets?
>> One pass right?
>> Yes sir.
>> You have the full data set. You just need to uh check uh three conditions.
Okay. In the first condition you will just check whether I'll just write uh TC for town city. So you will check whether town city is Chennai or not. If it is what you will do you will move this particular card to this pin. Right then again you will do town city is Bangalore or not. If it is you will move the card to right.
So this you can achieve you uh in single pass only. Okay. Now once you create these beans so the results for beans are shown over here. This is again based on the five rows we had in earlier slide.
So once you start uh creating bins for uh that table you'll see that there are Chennai and uh Maduray related students and there are three students in Chennai and two students in Maduray. Okay. Now we uh uh we can see that uh if we have to do the compare comparison or find the pairs what we can do we can compare these two candidates right Kabya and Arshad then we can compare Arshad and Rohan and then we can compare Kabya and Rohan right only three comparisons are needed to get this result right any doubt in this This is card number basically 10 and 11 and the card number is same for this particular data set or 12 whatever we were using in the lecture. So you can see here the ID is same. So that's why we are seeing uh 17 10 kind of things.
Okay.
Is this clear? For this particular things, we just need three comparisons.
If not, if you have any doubts, you can ask.
Okay, I'm assuming there are no doubts.
Now, we can do the same thing for Maduray as well. Right now Maduray has only two students. Now we need to compare. So just one comparison is enough. We can just compare whether Sadhart or you can say just absolute of Sadhart marks.
I just write S dot marks.
Okay. Minus M dot mark.
If it is at uh post okay so we can just say defer by at most 50 or not. So at most if this is getting satisfied we can just say that uh these students can make a pay. Now how many comparisons did we do? Just one right?
We just compared Sedhart and is this clear?
>> Yes sir.
>> Okay.
So this is here.
Let's move to the procedure that we will use.
So first of all, as you remember, we had to create bins, right?
So for that we need another procedure and this uh in these slides I haven't uh included that but that is very simple you just need to check uh the city and based on that you can create the bins right so suppose you have a procedure which you can use to create bins and uh the name is bin by city okay so we are using that procedure and based on that we are getting some bins.
Now in each bin in the previous slide, first we count the number of comparisons or did the comparisons among the students in Chennai, right?
Then we did for Maduray students. So Chennai is one bin and Maduray is one bin. We are doing the same thing. Okay.
the next slide.
So over here first we got the bins. Now in each bin okay we are just uh for uh each bin we have to do the comparisons.
So we pick a bin and uh maybe that bin is bin B.
Then we are checking whether there are pairs in bin B or not. If there are we are picking that pair and then we are checking whether the pair are pairs are valid or not. Okay. So the condition for pairing was their marks the difference of their mark should be at most 50. Okay this was the condition. So valid pair is just checking that condition. And if this particular condition is getting satisfied then we are appending the ids of those two students to pairs that we have defined over here.
Otherwise we will we will just keep those pairs. Okay.
So is the procedure clear what we are trying to achieve or uh what we are trying to do in each line.
>> Yes sir.
>> Okay. If that part is clear then we can represent the same procedure using flowchart as well. So there is the start then we have created the bins initialize our initialized our pairs list then we are checking whether there are more bins or not. If there are we are picking one bin doing the same thing checking the pairs and uh if the pairs are valid we'll append otherwise we won't append we'll just move to next page. Okay.
Now uh over here we are moving to the next bin.
Once we are done with all the beans then we won't have any more beans and just we can return pairs and do that particular list will contain all the pairs of students who are from a particular city and uh their scores differences at most 50. Okay. So that was the condition. So pairs will contain all the pair. Is this clear?
Yes sir.
>> Okay. So these are just some hints that you can use during the exam and yeah that's it. Now if you have any doubts you can ask anyone any doubts.
If there are no doubts, I'll close the session and uh yeah.
>> Can you show the hints again just before you have show?
>> Yeah, sure.
this one.
>> Yes, sir.
>> Okay sir. This will be more useful when you have to write the uh pseudo code yourself. Right? Currently you don't have to write the pseudo code but you have to check the pseudo code what is happening in the pseudo code. So these won't help that much but uh when you start writing pseudo code yourself then these things you have to >> okay sir.
>> Yeah.
any other doubt if not I'll close the session and uh in the next sessions I think there do the session on Friday and then on Saturday we'll discuss some questions and maybe some theory as well >> can you explain boolean strings about >> boolean data types Yeah. Yes sir.
>> So we have some data types like int is there, the string is there, cat is there and then n is there.
What?
>> So int is basically any integer. Okay.
Minus one and so on. Okay.
>> Okay. So >> this is the main type but uh in this one we can have subtypes as well like uh you had marks right? Marks has some categories that marks needs to be in this closed interval, right? It will be uh equal to or uh greater than zero and it will be always less than equal to 100. Mark can't be greater than 100 or less than zero for the data sets that we have defined currently. Okay. Now we have a string. So a string can be anything that has more than one character. Okay.
So you can say maybe apple. It is a string. It has more than one character.
You can say python.
Okay. Similarly you have many strings that you then you have character. Okay.
C is for character. So character as the name suggests it will have just one character. Okay, you can have a you can have e and so on.
Uh sorry now we have boolean. So let me so in conditionals like uh when you use if condition you have some condition over here right you maybe check that marks is greater than 50 or not. Okay.
So suppose the same question is asked to you in English. How will you respond?
You have uh a card in your hand and someone is asking whether the marks is greater than 50 or no.
What will be your answer? It will be either >> yes >> yes or no.
>> Yes. No or something similar. Right?
True false kind of thing. Right?
>> Yes.
>> So this is what boolean is. So uh boolean is what? Basically you can just give the answer in true false.
True false is boolean. The data type is boolean and uh the uh booleans are basically mostly used in conditions. So when you write condition the internal part should either evaluate to true or false. So there we generally use boolean. Now sometimes uh you have to keep track of some flag as well. Right? So for that as well you can have some boolean value for flag and you will then have some procedure some steps and then finally you will switch the value of flag. Okay maybe it was initially false. So that is this clear?
>> Yes sir.
>> Okay.
Anything else?
Any other doubt?
Okay. So, if there are no doubts, I'll just close the session and uh in the meantime before we meet on Friday or Saturday. Just make sure you solve as many problems as you can so that uh you grasp all the concepts and if there are any doubts.
Yeah. Uh there is some doubt. What is your doubt?
Mah can you open your mic? And uh when we use different and file. Okay.
So while is basically used for iterations. Okay.
Suppose you have a list. Okay, there are some numbers or something anything and you have to check something for each value like suppose these are the values in this list. Okay. And uh as per the problem statement maybe you have to check uh whether uh the numbers are divisible by two or not. Okay. Even and odd kind of thing you have to check. So for that you need to do iteration. What does iteration mean? You have to check each element one by one and then you have to evaluate it or do some operation on that element. So for that we use while we will just uh say that uh one second we'll just say that uh while there are some numbers or while uh the list is empty uh list is not empty. Okay. So while length of list we can say is not equal to zero. Okay.
So we will do something. We will just pick the first element maybe and we will do some operation. So for that case we use by okay when we have to do some operation on a group of items that are stored in a list or something similar.
So the data sets that we had those are kind of list. Okay. So we were using a while loop and iterating over all the rows doing some operations on the rows and then getting the total. So for these things we use my Is the while loop clear?
>> Yeah.
Yeah. Any doubt in a while?
No.
>> Yeah. Yeah. Any doubt in while loop?
>> No sir.
>> Okay.
Uh now we can see if condition.
>> Yeah.
>> While loop is done till the cards are lower.
So we have some condition and based on that condition we uh do the iterations for uh your current uh CT related data set >> you will do the iterations until the data set uh is exhausted means you have seen all the cards in the data set but in some cases suppose you have a list okay then you just want to just do some operations on the first three element Okay. So for that you just need to iterate over the first three elements not all the elements.
Okay. So that depends on the condition.
>> Okay sir.
>> Is this clear?
>> Yes sir.
>> Okay.
Now we had if condition.
So if is basically to check some condition, right? So we defined a problem where we had to check whether uh the number are even or not. So in that case we have to evaluate each number. So if is for conditional we will just check whether one is divisible by two or not. Okay.
So this is for first item in the list divisible by two or not. Okay.
Now for the second item you can do the same thing is divisible by two or not and same thing we can do for pip and phone. Okay. And each evaluation we will do inside the iteration of file loop.
Okay. So at the top level we will have a while loop and inside the while loop we will have if condition to evaluate each of the elements.
Is it clear?
>> Yes sir.
>> Nested itation.
Listed iteration is basically at the top level you have a bind and inside this while loop you again have a while. Okay.
So this is your nested iteration. What will be the example? So suppose you have a list and uh in that list maybe you are storing some string and so on. Okay. So there are two strings in a list. Now you have to check whether uh the strings contain D or not. Add this one.
You have to check whether uh D character is there uh in the string. If there are then you will return that as otherwise you will just. So for that what do you need to do? You need to iterate over of the items. Okay. So in the first iteration at the top level iteration you will pick ABC. So in the first iteration for this one you will pick ABC. Okay.
Now you have to check a character right.
So basically you will check whether A is equal to D or not. So that for that thing you have to do the internal loop.
You will use the internal loop. So in the first condition it will check whether A is equal to D or not. In the second condition it will check B is equal to D or not. In the sec third condition it will do for C and based on that you will store the clear while loop is it uh nested loops. Is it clear?
Okay. Uh for three rise problem don't need to understand the full flow chart for that. I'll share this.
>> Can you mute yourself?
I guess can you mute yourself?
>> There's some background noise.
Okay. So for three price problem, you don't need to understand the full flow chart. Okay.
what I will do is I'll upload this PPT to try and share the link with you.
Okay. So that uh whatever flowcharts that we have discussed in this session you can access it and if you are able to understand those many flowcharts and uh also if you are able to understand uh uh the flowcharts that we have discussed uh during uh PS uh and GS. So those flowcharts if you are able to understand you should be fine. Okay.
So let me upload the PP in the meantime if >> yeah the link in chat box.
>> Yeah. Yeah. Uh let me upload it and uh then I'll share. Okay. In the meantime if there are any more doubts you can ask.
Okay, I have to drop the link. Can anyone check and let me know whether you are able to access or access it or not?
sir. It says that we have to request for some access.
So I have dropped the link again. Check that.
It's the same link. So you should be able to access now. Yes sir. Can you repeat right?
Okay.
>> Okay. So any other doubt?
>> Excuse me sir, I'm audible.
>> Yes. Yes.
>> Sir, I have a little bit conceptual doubt while processing the pseudo code.
Can you solve it?
>> What's your doubt? Do you have >> sir? Actually if if yes uh but it's in a portal actually it's in a graded assignment.
>> Okay. So that one minute.
Let me open the portal.
So what's the question number which week?
We are in week four and question number one graded assignment.
This question number one sir uh actually this in this s code it is a nested iteration while right >> yeah yeah yeah >> sir I want to know that what where we have to proceed after line uh when we go to line number 10 do we have to proceed to line number 11 or do we have to check uh again go back to line number five and check that condition so let me give you an example first. So this is using words data set right. I'll uh just pick a simple example.
Okay.
Now the outer loop is trying to pick the element right?
>> Yes.
>> This one or this one. So in the first iteration it will pick this and then uh we have another condition which is checking whether uh uh I is less than equal to letter count only. Okay. So I is less than equal to letter count is basically iterating over all the characters one by one. Okay. So first what you will do I is one. The first iteration for the internal loop I is one. You will check whether uh I is less than equal to which number?
Three.
>> Yes.
>> For this particular example, right?
>> Yes. Yes.
>> And current value of I is one, right? It will evaluate to true.
>> Yes.
>> So you will go inside do the operations till here. Then you will again move to this part because you haven't exited the while loop yet.
Now you will incre you have incremented I right over here inside the while loop itself. So I became two X dot letter count is three right?
>> Yes >> it won't change. Now again this condition is getting satisfied. So you will again do the operations internally.
Then you will again increment I. I became three. You will do this again uh true. So you will again proceed inside the while loop. You will increment I I became four.
Now this is false. Right? Yes.
Since this is false, we won't go inside while loop now and we will start executing the next lines.
Okay. Got it.
>> Yes sir. So that means whenever this closing bracket comes of while, we have to check for the while condition. If that satisfies or not, then we have to proceed.
>> Yeah. Until you're out of the while loop, you can't go ahead. Okay. Once you have to complete or uh uh like finish the while loop, complete the iteration, then you can proceed to the next line.
>> Sir, >> yeah.
>> Like after completing the ninth step, ninth line, we will again like uh initialize B to false or we will just keep it true only like we will go to step four or directly to step five while loop only.
This was executed. Okay. And this is the while loop part. Line five to line 10 or 11 line 10. This part is while loop, right?
>> Yes.
>> So initially like from line four you got I is equal to 1, right? And B you got false, right?
>> Yes sir.
If you go from here to here, if that had been the case, then I will again change to one and B will again change to false.
Do you think that is happening?
>> Not like we can't change I to one. But for B, I'm not sure whether we will initialize it to false again or not. I will never become one. I think again >> if you like if you are going to this line only then these two things will happen otherwise they won't right if you are saying that I won't be equal to one again >> yes >> then B will B once B changes to true it won't change to false >> okay >> okay so whatever you are repeating you are repeating in this part Okay, this is the repetition part.
Line 6 to 9 you will repeat and this condition you will just evaluate whether it's true or not. Once it says that this is false, you will stop the iteration.
You will stop this whole thing and you will start line.
>> Similarly, our code ends at line 15 when line number two condition is false.
Right.
>> Yes.
>> Okay sir. Thank you sir.
>> And the iteration will just do these things again and again. Right.
>> Yes sir.
>> Any other doubt?
>> No sir.
>> Okay.
So I'll close the session now and uh if you have any doubts you can ask any Friday and Saturday session and in the meantime just try to solve as many problems as you can and if you get or if you have any doubts you can just ask.
Okay.
>> Thank you.
Thank you sir.
Thank you sir.
Related Videos

TOP 15 Data compression Interview Questions and Answers 2019 Part-2 | Data compression | Wisdom jobs
wisdomjobs
281 views•2019-06-28

CTS 158: 802.11w Management Frame Protection
ClearToSend
4K views•2019-02-04

NDSS 2019 Send Hardest Problems My Way: Probabilistic Path Prioritization for Hybrid Fuzzing
NDSSSymposium
496 views•2019-04-02

How realistic is Cities: Skylines?
CityBeautiful
159K views•2019-02-14

GUIs & TUIs: Choosing a User Interface for Your Python Project | Real Python Podcast
realpython
2K views•2025-04-04

The OSI Model - Explained by Example
hnasr
225K views•2019-05-12

Cloud Computing - Introduction
elithecomputerguy
98K views•2019-10-07

From Traveler's Dilemma to Dynamic Routing | Demystifying Networking
IITBombayJuly
5K views•2019-08-04
Trending

WOW! Judge TURNS THE TABLES on Trump in His OWN $10B LAWSUIT!!!
MeidasTouch
197K views•2026-07-23

Playstation NO DISC/NO BUY Fight Is Over...
DavidJaffeGames
4K views•2026-07-23

Steam and Xbox Just Dropped The Hammer On PlayStation
OhNoItsAlexx
9K views•2026-07-23

Americans Confused in Australia for 17 Minutes Straight
IWrocker
17K views•2026-07-23