• 6 days ago
Transcript
00:00Now, one more thing is, which we have implemented in the way,
00:04we have to name the circular queue.
00:07Circular queue is implemented in the circle.
00:11For example, we have to move on.
00:14We have to say size,
00:15and we have to say n, and we have to say elements stored.
00:19So, n size is the array.
00:21We have to say elements stored 1, 2, 3, 4, 5, 6, 7, and 8.
00:26So, the front will be here and rear will be here.
00:31Now, the normal queue was implemented,
00:33the remove time complexity was the big of n.
00:37We want to say that the time complexity is big of 1.
00:39So, we have to implement our queue.
00:42So, with this intention,
00:44we have to use the array in the circular queue.
00:46How do we implement the circular queue?
00:48We will see how we can implement the queue.
00:51So, our front will be here, our rear will be here.
00:54Now, if we have to remove the front elements,
00:58we will remove the element here.
01:00We will remove the element here,
01:00we will completely delete it,
01:04and our front will become the index.
01:10This is index number 1.
01:12Before, we were able to remove the elements.
01:15We were able to shift the elements,
01:16but this time, our front will only shift the position.
01:20This process is easy.
01:21It was done by the process.
01:23Now, the time we will remove the element here,
01:25because we will only shift the pointer to one point.
01:27So, the elements will not shift the elements.
01:30Now, the front will remove the elements.
01:32So, the two will remove the element here,
01:34and the front will shift the element by one.
01:36So, the front will be here and the value will be 2.
01:39If we insert the array into the inside,
01:41how do we check the array?
01:43The rear will compare the size minus 1.
01:47Now, that will change the diameter's line arrive.
01:48But in this case, this area is equal to be 2 feet.
01:55These are flat elements.
01:58This is the main element by going to move 2 feet until the front will extend the column to the
02:02right.
02:02So, coming up to our equal to the other side,
02:06now, the other term minus oneações
02:14so, in this case,
02:15have a preference of n equal to the previous two we have to check here and then we will
02:21buy one rear onto the next one where is this number of the plus 1 plus 1 is that if
02:28we
02:29look at this number of the last index are left with 0th at the next level we have to
02:36change it now first we have open up to the next circle does the 0 this array for the
02:41के लिए size की value हमारे पास 8 है और rear की value साथ है तो
02:47rear बन जाएगा 7 plus 1 modulo 8 जिसकी value होती है 8 modulo 8 remainder
02:53आएगा 0 तो हमारा rear क्या करेगा last index से first index पर आ
02:57जाएगा तो यहां से यह rear बढ़कर यहां आ जाएगा और हमारा
03:01जो अगला element होगा यानि अगर हमें 9 को अपने area के अंदर डालना है तो
03:049 यहां पर आ जाएगा और यह rear यहां से completely हट जाएगा अब मान लीजे
03:10एक और element हमें delete करना है एक और delete करना है तो यहां से हम 3 को
03:15हटा देंगे और इस f को ले आएंगे front को ले आएंगे इस position पर
03:19यानि f is equal to 3 पर और rear हमारा यहां पर है अब एक और element को
03:25insert करना है तो किस तरीके से करेंगे एक और element के insertion के लिए
03:29हमारा rear दुबारा से बन जाएगा 0 plus 1 modulo 8 जो की होता है 1 modulo 8
03:39यानि 1 तो rear यहां से बढ़कर यहां आ जाएगा और हम 10 को यहां पर store करतेंगे
03:45अब जैसे जैसे हम elements को एक एक करके delete करते जाएगे यहां से भी front हट जाएगा
03:51यहां से भी front हटेगा यहां से भी front हटेगा यहां से भी front हटेगा यहां से भी front हटेगा
04:08to front ko plus plus to kar nis saktay
04:10kyunki array joe hai humara bhar gaya hai
04:12to front ke liye bhi hume wahi formula
04:14leena padega updation ka jomne rear
04:15ke liya hai, yaani
04:17ye wala formula, to front ke liye
04:20bhi yehi formula leengue
04:21to humahre paas value kya aegi
04:23front is equal to
04:25front plus one
04:28modulo size
04:29to is tariqe se front ki value bhi
04:31yahaan se agar amne element ko uta diya
04:338 ko uta diya, to front bhi update
04:35hokar, is index se
04:37yahaan par chala jayega, aur yeh ban jayega
04:39hamaara naya front
04:41front yaha hai, aur rear yaha hai
04:43to is tariqe se, bas
04:45updation ka formula change karna hai
04:47updation ke formulae me pehle
04:49humahre paas hoota tha front plus plus
04:51aur hoota tha rear plus plus
04:53ya minus minus
04:54ab updation ke liye rear me yeh karna hai
04:57aur front meh hume karna hai
05:00ab apne normal qo wale
05:02code mehi changes karate hai, humahre paas
05:03area fix size ka size humne store kara hai
05:06thoa, is bar kya karenge, front ko bhi store kara lenge
05:09front ko kya store kara raha hai, is bar kyunki pishli baar to front
05:12phải liege
05:14in the beginning
05:16for the function
05:36should be
05:39therefore
05:39so
05:39Let's see
05:40this
05:40rear plus one modulo size
05:44will equal to front.
05:48So, rear plus one modulo size
05:51we want to increase the same
05:53and the next index will be front.
05:55Now, front will be already an element
05:58so we can increase the same
06:00so we can increase the whole queue
06:02in circle.
06:04So, this is our full condition.
06:06Now, add function in the changes.
06:08Changes करते हैं, अगर हमारी
06:10queue full है, तो यहाँ
06:11is full लिख लेते हैं, तो उस case में
06:14print करवा देंगे, queue is full and return करवा देंगे,
06:16नहीं तो rear को update करेंगे,
06:18update करने की condition क्या थी?
06:19Rear plus one modulo size
06:23तो यहाँने update कर दिया
06:24rear को और area of rear में
06:26store करा दिया अपने data को.
06:27अब यहाँ पर एक extra condition हमें
06:29add करनी पड़ेगी, कि अगर हमारा
06:31जो element है, वो हम पहली बार element
06:33add कर रहे हैं, यानि
06:34rear भी minus one है, front भी minus one है,
06:37तो rear तो change होंकि zero हो जाएगा,
06:39front को भी तो change करना पड़ेगा हमें,
06:41तो उस case में, जिस case में
06:43हमारा front equal to
06:45equal to minus one है,
06:47वहाँ पर हम front को
06:49बना देंगे zero, यह वो case है,
06:51जिसमें हम add कर रहे हैं
06:53first element को,
06:56तो यह बन गया
06:57हमारा add function, अब आते हैं अपने
06:59remove function की तरफ, remove function में
07:01is empty वाली condition हमारी same रहेगी,
07:04remove करने के लिए अब इस loop को
07:05उटा देंगे, क्योंकि यह जो function है
07:07यह big of one में हम implement करने वाले हैं,
07:10big of one में कैसे implement करेंगे,
07:11front को हमने store कर लिए,
07:13अब front को store कर आएंगे,
07:15एक result variable में,
07:18array of front,
07:20अब हमें rear को change नहीं करना,
07:22जैसे हम remove कर रहे हैं,
07:23अब हमें front को update करना है,
07:25तो front बन जाएगा,
07:28front plus one,
07:30modulo, size के equal,
07:31और यहाँ से return कर देंगे हम अपने,
07:35अब यहाँ पर भी एक special case होगा,
07:37special case ही यह होगा,
07:38कि क्या हम last element को delete कर रहे हैं,
07:40मतलब क्यूं तो बाकी तो सारी खाली हो गई है,
07:42उसके अंदर एक ही element बचा है,
07:44अगर उसको delete कर रहे हैं,
07:45उसको हटा दिया,
07:46तो हमारा जो front है और हमारा जो rear है,
07:50उन दोनों को हमें minus one बनाना पड़ेगा,
07:52क्यूंकि क्यूं खाली हो गई हैं,
07:55तो last element को जब हम delete कर रहे हैं,
07:58या remove कर रहे हैं,
08:00इसका मतलब है कि अगर हमारा rear equal to equal to front है,
08:06तो उस case में rear, front,
08:09दोनों बन जाएंगे minus one के equal,
08:13और ऐसा अगर नहीं है, यानि बाकी cases हैं,
08:16तो फिर हम front को update कर देंगे,
08:18to front plus one modulo size में,
08:21तो इस तरीके से हमारा remove function हमने implement कर लिया है,
08:24इसके बाद implement करेंगे अपना peak function,
08:27peak function के अंदर वही same conditions रहेंगे,
08:29और इस बार return कर देंगे array of front को,
08:32तो इस तरीके से peak को भी big of one में implement करेंगे,
08:36remove को भी big of one में implement करेंगे,
08:38और add को भी big of one में implement करेंगे,
08:41तो यह हमारी अच्छी implementation है,
08:43क्यूंकि यह सारी की सारी conditions same रहेंगे,
08:45इसको save कर लेते हैं और code को run करते हैं,
08:48output में हमारे पास आएगा 1, 2 and 3,
08:52अब क्या करते हैं, इस array को ना 3 size का ही बनाते हैं,
08:553 size का हमने save कर लिया,
08:57एक बार हमने सारे के सारे elements को remove कर दिया,
09:00और अपनी Q को खाली कर दिया,
09:02यहाँ पर बीच में कुछ conditions add करेंगे,
09:04जो सिर्कुलर Q पर काम करेंगे,
09:06यानि पहले हम remove करवा लेंगे,
09:11अपने front में Q को,
09:13अब Q में add कर देंगे element number 4 को,
09:17दुबारा से remove करवाएंगे Q से,
09:19Q से remove कराएंगे front को,
09:21और एक और number को store कर देंगे which is 5,
09:25इसको save करते हैं और run करते हैं,
09:29output हमारे पास आया 1, 2, 3, 4, 5,
09:33कैसे आया output, उसकी बात करते हैं,
09:35Q में सबसे पहले 1, 2 और फिर 3, ये 1, 2, 3 element store हुए होंगे,
09:41इसको diagram से समझे तो और थोड़ा सा better clarity आएगी,
09:45हमारे पास एक Q थी 3 size की,
09:48जिसके अंदर हमने store किया 1 को, 2 को, 3 को,
09:51पहले ये है हमारा front और ये है हमारा rear,
09:55अब हमने क्या किया, Q से front को remove किया,
09:57front को जैसे ही remove किया, print हो गया, हमारे पास 1,
10:00तो 1 यहां से हट गया,
10:03और front update होकर आ गया,
10:05यहां पर, अब हमने add किया,
10:07इस Q में 4 को,
10:08तो 4 हमारा add हुआ यहां पर,
10:11तो rear हमारा यहां पर आ गया,
10:13और rear यहां से हट गया,
10:15अब हमें क्या करना है,
10:16दुबारा से front में से remove करना है कुछ,
10:18front से remove करेंगे कुछ,
10:19तो यह element हटेगा,
10:21यानि 2 यहां से हट जाएगा,
10:22front update हो जाएगा,
10:23front update होकर आ जाएगा,
10:24यहां पर,
10:25और हमारा जो 2 था,
10:26वो हमारे लिए print हो जाएगा,
10:27अब हम add करेंगे 5 को,
10:295 कहां पर add होगा,
10:30पहले rear update होगा,
10:31rear update होकर आ गया है,
10:32यहां पर,
10:33यहां पर add हो जाएगा 5,
10:35और rear यहां से हट चुका है,
10:37अब हमें क्या करना है,
10:38एक एक करके elements को निकालना है,
10:39elements को कैसे निकालेंगे,
10:41सबसे पहले,
10:42हमारे front से,
10:43यहां से element निकलेगा,
10:45तो print होगा 3,
10:46अब यह front update होकर,
10:48यहां पर आ जाएगा,
10:49तो यह बन जाएगा हमारा front,
10:51अब 1, 2 और 3 तो output में हमारे पास आ गए है,
10:55next front क्या होगा,
10:56next front होगा हमारे लिए 4,
10:58तो front यहां से हट जाएगा,
11:01और यहां आ जाएगा,
11:01अब यह दोनो rear और front सेम जगे point कर रहे हैं,
11:04तो यहां से front को अटाएगे,
11:065 को print कर आएगे,
11:07और इस case में rear और front दोनों बन जाएगे,
11:10minus 1,
11:11और हमारे output की तरफ देखे,
11:13तो output में हमारे पास आ जाएगे,
11:151, 2, 3, 4 and 5,
11:17तो इस तरीके से हम circular Q को implement कर देंगे,
11:19अपने array से,