Skip to main content

Posts

Stack Problem - Balancing of Symbols

Recent posts

Stacks

What is a Stack?
A Stack ADT is an ordered list in which insertion and deletion are done at the top end of the list.
A stack follows LIFO(Last In First Out) Principle i.e, the last element inserted is the first one to be deleted.

Why do we need Stack?
Well, in many algorithms you want to add objects to a temporary list at some point and then pull them off this list again at a later time. Often the order in which you add and remove these objects matters.

Applications of Stack
Balancing of symbolsInfix-to-Postfix conversionEvaluation of postfix expressionImplementing function calls(Recursive)Forward and Backward feature in a browser.Redo & Undo sequence in a text editor.Matching tags in HTML & XML.Used in other algorithms like Tree traversal, Tower of Hanoi, Stock span, N Queens, etc.
Stack Operations
Main stack operations
Push: Inserts data onto stack
Pop: Removes and returns the last inserted element from the stack.

Auxiliary stack operations
Top: Returns the last element without removing…

IOS Q&A -The Basics#01

IOS Interview Questions and Answers The Basics#01
1. What are the Key Features of the Swift programming language?
Modern: Swift is a result of the latest research on programming languages, combined with decades of experience building Apple platforms. Also, Swift is continuously evolving.Safe: Swift is a type-safe language which means, If we pass a String to a variable of type Int by mistake, then Swift throws a compile-time error. Also, it’s a static programming language i.e. any variable or a constant should be declared or inferred to a specific type at the compile time.Fast: Swift was built to be fast using the incredibly high-performance LLVM compiler technology. There are claims that Swift is 2.6x faster than Objective-C and 8.4x faster than Python.Expressive: Swift is called Syntactic sugar because it makes the language “Sweeter” for developer use. Swift offers a simplified syntax and grammar that is easy to read and write.Open source: In 2015, Swift was open-sourced to encourage…

Confused OS Concepts

Difference between MultiProcessor and Multicore Processor? A multiprocessorsystem contains more than one CPU, allowing them to work in parallel.
multicoreCPU has multiple execution cores on one CPU so that multiple cores can work in parallel on separate operations at chip level. Difference between MultiProgramming, MultiTasking, MultiProcessing,      MultiThreading? MultiProgramming:To minimize the CPU Idle time, Multiprogramming was introduced in older days for single core processor. One or more programs are loaded into main memory which are ready to execute still, only one program is able to get the CPU for execution while all others are waiting for their turn. When currently running process is performing an I/O task, then OS may interrupt that process and give the control to another program(process context switching) loaded in main memory for execution and a running process keeps executing until either it voluntarily releases the CPU or when it blocks for an I/O operation.
With Mutil…

Design Patterns in Swift

What is a Design pattern?
A design pattern is a general solution to a real-world problem that can be re-used.
Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system.
They are templates designed to help us write efficient code which is easy to understand, also can be re-used.
It is not a finished design that can be transformed directly into source or machine code.

Why do we need Design patterns?
Saves Time: Design patterns can speed up the development process by providing tested, proven development paradigmsFuture bugs: Effective design pattern can solve issues that may not become visible until later in the implementation, which helps while designing software.Re-use: Reusing design patterns helps to prevent subtle issues that can cause major problems.Code Readability: Improves code readability for coders and architects familiar with the patterns. Best practices: Design patterns teaches us some of the best pra…

UILabel text animation as in UIButton click

Animating UILabel textcolor is not easy as it seems, normal animation won't work on this property. The below code snippet animates the UILabel textcolor as in button click.
Change the duration and UIViewAnimationOptions to play with it. extensionUILabel{ func flashLabel() { func animate(duration:Double,alpha:CGFloat,completion:(()->())?){ UIView.transition(with: self, duration: duration, options: UIViewAnimationOptions.transitionCrossDissolve, animations: { self.textColor = self.textColor?.withAlphaComponent(alpha) }) { _ in completion?() } } animate(duration: 0.1, alpha: 0) { animate(duration: 0.3, alpha: 1, completion: nil) } } } Happy coding...

UIAlertController made easy

Once I read somewhere on the internet, creating an Alert in IOS is comparatively harder than JavaScript. I'm not a big fan of HTML & CSS, but I do know a little Javascript, creating an Alert popup in Javascript is pretty much easier, just like this. alert("I am an alert box!"); That's all it takes to create an alert using JS. If you want to try other types of popups using JS, check out here.
But, let's try with Swift. let alertVC = UIAlertController(title: "Alert", message: "Testing", preferredStyle: .alert) let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) alertVC.addAction(okAction) Looking at the above, IOS needs a little extra code, doesn't it? But, that's not the end, let's make it lesser, reusable and better. How about this? alert(title: "Alert", message: "Auto dismiss in 4 sec") I've written an extension for UIViewController, which uses just the above…