0% found this document useful (0 votes)
193 views16 pages

CS502 Midterm Current Papers Fall 2023 (Mubashir) .

The document outlines the topics that will be covered on a midterm exam for an algorithms course. It lists short questions, long questions, and sample problems including quicksort improvements, recursion formulas, loop execution counts, and more. It also provides example questions and answers on algorithms topics like time complexity, divide and conquer, dynamic programming, and sorting algorithms.

Uploaded by

Atif Mubashar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
193 views16 pages

CS502 Midterm Current Papers Fall 2023 (Mubashir) .

The document outlines the topics that will be covered on a midterm exam for an algorithms course. It lists short questions, long questions, and sample problems including quicksort improvements, recursion formulas, loop execution counts, and more. It also provides example questions and answers on algorithms topics like time complexity, divide and conquer, dynamic programming, and sorting algorithms.

Uploaded by

Atif Mubashar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

CS502 Midterm Current Papers Fall 2023 [ Mubashir ].

MCQs
 Few from Waqar, Moaaz & Haadi 1,2, 3 Files.

Short Questions
 Which one of the following is the maximal points (According to 2-D Maxima)?
 Edit-Distance between 2 Words by deleting last column.
 3 steps of Divide & Conquer.

Long Questions
 Suggest how Quick Sort can be improved more.
 Formula of Recursion
 How many times the following given loop will execute?

------------------------------------------------------------------------------------------------------------------------------------------
Question: In Algorithms, write "average" and "worst" time complexity of Quick sort.

Answer: The average time complexity of QuickSort is O(n log n), while the worst-case time complexity is
O(n^2).

Three step or divide and conquer tha ek question

Ek 6 chap ma fib Wala phla algorithm likhna tha chota c Jo ha 3 line

Aur subjective abi shi yad ni lkin 2D Maxima

Long question me 1 Fibonacci sequence ki value ko dynamic programming me krna tha


Ye 2 videos dekh lijiye ga mcqs aur usky related concepts apky clear ho jaye gaye. In Sha Allah Kafi
acha attempt ho jaye ga

https://youtu.be/CD3RCknhCQc?si=qgHD2bHq131-Mffv

https://youtu.be/DlmjtDs6xqQ?si=Me5Tpylu0Iw323RZ

Define edit script

In the context of algorithms, an "edit script" refers to a sequence of edit operations that transform one
object into another. Edit scripts are commonly used in the field of computational biology, text
processing, and computer science in general. The concept is often associated with the problem of
measuring the similarity or dissimilarity between two sequences and finding the minimum set of
operations (edits) needed to transform one sequence into the other.

The basic edit operations include:

1. **Insertion (I):** Adding a new element to the sequence.

2. **Deletion (D):** Removing an element from the sequence.

3. **Substitution (S):** Replacing one element with another.

For example, given two strings "kitten" and "sitting," an edit script to transform "kitten" into "sitting"
might look like:

1. **Insert 's' at position 0:** "skitten"

2. **Substitute 'i' for 'k' at position 1:** "sitten"


3. **Insert 'i' at position 3:** "sititen"

4. **Insert 't' at position 4:** "sittiten"

5. **Substitute 't' for 'e' at position 6:** "sittitn"

6. **Insert 'g' at position 8:** "sittitng"

The minimum edit distance between two sequences is the smallest number of edit operations needed to
transform one sequence into the other. Edit scripts are used to represent and analyze these
transformations in the context of algorithms like the Wagner-Fisher algorithm for dynamic
programming, which efficiently computes the edit distance between two sequences.

Or long ma median find karna tha

How bubble sort algorithm work 3 marks

Bubble Sort is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares
each pair of adjacent items, and swaps them if they are in the wrong order. The pass through the list is
repeated until the list is sorted. The algorithm gets its name because smaller elements "bubble" to the
top of the list.

Here's a step-by-step explanation of how the Bubble Sort algorithm works:

1. **Compare adjacent elements:** Start at the beginning of the list and compare the first two
elements. If the first element is larger than the second one, swap them.

2. **Move to the next pair:** Move to the next pair of elements (the second and third elements) and
compare them. Again, swap them if they are in the wrong order.
3. **Continue through the list:** Continue comparing and swapping adjacent elements throughout the
entire list. After the first pass through the list, the largest element will have "bubbled up" to the end of
the list.

4. **Repeat:** Repeat steps 1-3 for the remaining unsorted elements. After the second pass, the
second-largest element will have bubbled up to its correct position.

5. **Continue until sorted:** Keep repeating the process until the entire list is sorted. In each pass, the
next largest element will move to its correct position.

Here's a simple example to illustrate the process:

Original list: `[5, 2, 9, 1, 5]`

1. Pass 1: `[2, 5, 1, 5, 9]` (swaps: 5 and 2, 9 and 1)

2. Pass 2: `[2, 1, 5, 5, 9]` (swaps: 5 and 1)

3. Pass 3: `[1, 2, 5, 5, 9]` (no swaps)

Now, the list is sorted.

Bubble Sort has a time complexity of O(n^2), where n is the number of elements in the list. It's not the
most efficient sorting algorithm, especially for large lists, but it is easy to understand and implement.
There are more efficient sorting algorithms like Merge Sort or QuickSort for larger datasets.

F=10n^2 , F=n^3 when these functions can be equal 3 marks


Write the principal which differentiate between divide and conquer and dynamics programming 5
marks
1 : Problem selection k steps likhny thy
3 : Ak table tha us me tmam values ki asymptotic notation likhni thi.

4: memoization k bary me 5 marks ka question tha


*Aik question tha how we can Build heap*

1#Seive technique ko selection problem and median sy related working btani thi iski
2#Can we sort array without using combination based algorithms if yess then how?

3#how many ways used to measure time complexity??


1#Brute force and plan sweep comparison?
2#3 names of Slow sorting algo and their worst case running time?

3#define recursive Fibonanci numbers

2.write average and worst time complexity of quick sort

Average-case:

Worst Case:

2why plane sweep is better than brute-force


1) algorithm or us ky advantages
Edit distance applications k 2 names

Dynamic programing

You might also like