查看: 880| 回复: 0
收起左侧

2024/12/1 学习日记

大迫瓜 来自APP | 显示全部楼层
本楼:   👍  3
100%
0%
0   👎
全局:   19
86%
14%
3

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
学习日记

今天的学习围绕两个战场展开:CIT 593考试准备和LeetCode练兵,还额外深入了C语言的动态内存管理。
在战斗中总结方法,于难题中练兵,是今天的主旋律。

CIT 593考试准备与动态内存学习
除了考试备战,我还重点学习了C语言的动态内存管理,特别是堆内存(heap memory)与栈内存(stack memory)的使用与区别:

        1.堆内存:
        • 使用 malloc() 和 free() 手动管理内存。
        • 灵活但需要小心避免内存泄漏。

        2.栈内存:
        • 自动分配和释放,局部变量存储于此。
        • 空间有限,适合短期存储需求。

教授的考试建议:
教授特别强调了两点常见错误:

        1.问答题答得太长:问答题只需一两句直击核心,写长文会浪费时间。
        2.不该花太多时间在加分题:加分题耗时长且得分少,应该把主要精力放在必答题上。

复习策略:

        • 先快速浏览讲义,确保关键概念清晰。
        • 复习作业特别是做错的题目,确保在考试中避免重复错误。
        • 最后通过模拟考试检验实力,营造真实考试环境,训练时间分配与解题速度。

学习动态内存的同时,我还深入理解了C语言中如何管理指针与数组,特别是在高效利用内存时避免陷入未初始化或双重释放的陷阱。

LeetCode Practice

1. Doubly Linked List with HashMap: A Perfect Duo
This question focused on implementing an LRU Cache using a combination of HashMap and doubly linked list.

        • The HashMap acts as the forward attacker with O(1) lookups.
        • The doubly linked list handles order maintenance, ensuring efficient updates for the most and least recently used items.

The challenge was initializing the doubly linked list. Adding a head and tail dummy node simplified operations. This allowed quick additions at the head and deletions from the tail. With modular helper functions like addToHead() and removeNode(), the implementation became clean and efficient.

2. Regex Matching: Dynamic Programming in Action

The second problem was a hard-level regex matching task involving * and . operators:

        • *: Matches zero or more occurrences of the preceding character.
        • .: Matches any single character.

I solved it with a 2D dynamic programming table, where:

        • dp[i][j] determined if the first i characters of the string matched the first j characters of the pattern.

        • Key strategies:
                1. * as zero matches: Ignore the preceding character entirely (dp[i][j] = dp[i][j-2]).
                2. * as one or more matches: Extend the match backward (dp[i][j] = dp[i-1][j]).

Though edge cases like empty strings or consecutive * were tricky, a methodical approach to defining base cases and transitions led to success.

3. Word Ladder: Turning Strings into a Graph

This problem asked for the shortest path between two words, where a word could transform into another if they differed by exactly one letter. For example:

        • APPLE and APPLI are connected (1 letter difference).
        • APPLE and APPPP are not connected (2 letters difference).

Key insights:

        1.Graph Representation: I used wildcard patterns (e.g., A*PLE, AP*LE) to group similar words in a HashMap, allowing O(1) neighbor lookups.
        2.Breadth-First Search (BFS): BFS was perfect for finding the shortest path, exploring neighbors layer by layer. The first match to the target word guarantees the shortest path.

Once the graph was clear, the problem transitioned from daunting to straightforward.

总结

今天的学习是对细节的深入打磨与核心策略的总结。

        • 在CIT 593中,复习动态内存的管理让我更加理解堆与栈的差异与应用场景。考试复习则让我明确了抓重点、避陷阱的策略。
        • 在LeetCode中,三道题目让我体会到数据结构与算法的深层妙用:从链表与HashMap的组合,到动态规划的逻辑清晰,再到图论中的路径计算。

今天,是胜利的一天。

上一篇:nyu mscs想进组,求学长学姐指点
下一篇:有25spring tufts上学的uu吗 求组织
您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

Advertisement
>
快速回复 返回顶部 返回列表